万年素人からHackerへの道

万年素人がHackerになれるまで殴り書きするぜ。

  • ・資産運用おすすめ
    10万円は1000円くらい利益
    資産運用ブログ アセマネ
    • ・寄付お願いします
      YENTEN:YYzNPzdsZWqr5THWAdMrKDj7GT8ietDc2W
      BitZenny:ZfpUbVya8MWQkjjGJMjA7P9pPkqaLnwPWH
      c0ban:8KG95GXdEquNpPW8xJAJf7nn5kbimQ5wj1
      Skycoin:KMqcn7x8REwwzMHPi9fV9fbNwdofYAWKRo

    NGUIでNowLoadingを作ろう C# Unity

    今回は某ゴミ言語ではなくC#で書きますよ。

    まずはHierarchyにこのように作ろう。

    Panel作成機能で作った”Panel”の子へ”LoadingScript”GameObject
    さらにその子に”OriginalLabel”GameObject

    LoadingScriptにはこのスクリプトを貼ってね。
    → 修正したgistURL: https://gist.github.com/shinriyo/8621249

    using UnityEngine;
    using System.Collections;
    
    public class LoadingScript : MonoBehaviour
    {
        public string WORD = "NOW LOADING...";
        public float HEIGHT = 30;
        public float SPEED = 160;
        public float DELTA_X = 25;
        public float TIME_DELTA = 30;
        public Vector3 WORD_SIZE = new Vector3 (28, 28, 1);
        private int _stringSize;
        private bool _endFlg = false;
        private Transform[] labelArray;
    
        void Awake ()
        {
            _stringSize = WORD.Length;
            labelArray = new Transform[_stringSize];
            for (int i=0; i<_stringSize; i++) {
                Transform trans = transform.Find ("OriginalLabel");
                GameObject go = NGUITools.AddChild (gameObject, trans.gameObject);
                go.name = i.ToString () + "Label";
                go.transform.localScale = WORD_SIZE;
                go.transform.localPosition = new Vector3 (i * DELTA_X, 0, -1);
                UILabel uILabel = go.transform.GetComponent<UILabel> ();
                uILabel.text = WORD.Substring (i, 1);
                uILabel.depth = 1;
                labelArray [i] = go.transform;
            }
        }
    
        // Use this for initialization
        IEnumerator Start ()
        {
            yield return new WaitForSeconds(3.0f);
            _endFlg = true;
        }
    
        // Update is called once per frame
        void Update ()
        {
            float rad = Time.time * SPEED % 360;
    
            for (int i=0; i<_stringSize; i++) {
                float yPos = Mathf.Sin ((rad - i * TIME_DELTA) * Mathf.Deg2Rad) * HEIGHT;
    
                if (yPos < 0) {
                    yPos = 0;
                }
                labelArray [i].localPosition = new Vector3(labelArray [i].localPosition.x,yPos,-1);
            }
        }
    }
    

    ↑これはOriginalLabelをコピーしてそれに文字を流し込むよ。

    ・OriginalLabelはUILabelをアタッチし、その中のtextはInspectorビューで空っぽにしてね。

    ・LoadingScriptのInspectorビューではこのように設定してね。