万年素人からHackerへの道

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

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

    ex2dのAnimation Helperコンポーネント Unity

    http://www.ex-dev.com/ex2d/wiki/doku.php?id=manual:advance:animation_helper_usage

    Unity自体のアニメーションを使うときに必要。

    • 例えばテキストを、blink(点滅)させたいとき


    ex2dのデモの”_demo”フォルダの08にあるサンプルで使用している”text_blink”は消さないこと!

    Component -> Miscellanceous -> Animationをアタッチ。
    インスペクタで、アニメーションを”text_blink”にする。
    ※blinkは画像用


    このようにチェックは外す。
    使いたいときは、自分で作成する必要があります。

    カメラでGUIを分ける Unity

    http://www.cis.sojo-u.ac.jp/~izumi/Unity_Documentation_jp/Documentation/Components/class-Camera.html
    通常カメラ:深度0
    武器のみカメラ:深度1、クリアフラグ(Clear Flags)を深度のみ(depth only)

    Input.mousePosition はVector3 Unity

    http://unity3d.com/support/documentation/ScriptReference/Input-mousePosition.html
    ここには
    「static var mousePosition : Vector3」とある。
    Z軸になにがあるの?→0だった。

    ・Vector3→Vector2とVector2→Vector3の相互代入が可能

    Vector2 hoge = new Vector3(10, 20, 30);
    Debug.Log(hoge.x); //=>10
    Debug.Log(hoge.y); //=>20
    
    Vector3 bar = new Vector2(10, 20);
    Debug.Log(bar.x); //=>10
    Debug.Log(bar.y); //=>20
    Debug.Log(bar.z); //=>0
    

    Vector2→Vector3のときはもともとZがないので、0としてZに入る。
    Vector3→Vector2のときはXとYそのまま、Zがなくなる。

    連想配列 C#

    UnityのC#でも連想配列使える。
    Pythonの辞書型みたいなの。

    Hashtable ht = new Hashtable();
    ht["foo"] = "ふう";
    

    しかもこれもいいし

    ht.Add("baa", "ばあ");
    


    これを利用してOnGUIで使うデバッグを作った。

    ぼくが考えたさいきょうのデバッガ
    ・宣言部

    // DEBUG STRINGS
    private Hashtable debugHash = new Hashtable();
    

    デバッグに出したい値のとり方


    ・OnGUIでの処理

    void OnGUI() {
    	int heightDel = 10;
    	int height = Screen.height-160;
    	foreach (string key in debugHash.Keys) {
    		GUI.Label(new Rect(Screen.width/2, height, Screen.width-10, 50), (string)debugHash[key]);
    		height  += heightDel;
    	}
    }
    

    →object形なのでstringにするよ。



    ex2dでのSpriteObjectで作った画像のScale Unity

    TransformのScaleは直接いじるなとかいてる
    http://www.ex-dev.com/ex2d/wiki/doku.php?id=manual:advance:less_drawcall&s[]=scale#scale_the_sprite

    Ex spriteコンポーネントのScaleをいじれと。
    →Vector2で入れられる

    GameObject hogeObg;
    hogeObg.GetComponent<exSprite>().scale = new Vector2(0.2F,0.2F);
    

    ex2dでのSpriteObjectで作った画像の座標 Unity

    ex2dでScreen座標に対して位置を変えたいことがある。

    ↑Screenにセット


    ↑Ex Screen PositionにてScreen XとScreen Yで座標が設定できる。
    Anchorは左下を選んだほうがいい
    ※キャプチャ画像と違うので注意


    ・座標に代入したい。
    参考:http://www.ex-dev.com/ex2d/script_ref/classex_screen_position.html
    ScreenXという変数でもScreen.Xでもなかった。

    マウス位置に移動させる。※Anchorは左下で。

    GameObject hogeObj;
    hogeObj.GetComponent<exScreenPosition>().x = Input.mousePosition.x;
    hogeObj.GetComponent<exScreenPosition>().y = Input.mousePosition.y;
    


    http://www.ex-dev.com/ex2d/script_ref/classex_viewport_position.html
    ビューポートポジションなら

    float X = 0.12F;
    float Y = 0.12F;
    arrow.GetComponent<exViewportPosition>().x = X;
    arrow.GetComponent<exViewportPosition>().y = Y;