ラベル Unity の投稿を表示しています。 すべての投稿を表示
ラベル Unity の投稿を表示しています。 すべての投稿を表示

2012年4月21日土曜日

Unity アニメーションイベント

マテリアルのシェーダーは Transparent/Diffuse を使用

TestGL2_b.cs

using UnityEngine;
//using System.Collections;
 
//[RequireComponent(typeof(Animation))]
public class TestGL2_b : MonoBehaviour {
    Vector3[]       m_VtxArray;                 // 頂点の配列
    Vector2[]       m_UvArray;                  // UVの配列
    Vector2         m_uvOffset = Vector2.zero;  // UVのオフセット

    public Material m_Mtl;                      // マテリアル

    AnimationCurve  m_animCurve;                // アニメカーブ

    AnimationEvent  m_animEvtStart;             // 開始イベント
    AnimationEvent  m_animEvtEnd;               // 終了イベント

    AnimationClip   m_animClip;                 // アニメクリップ
    string          m_animName = "anim1";       // アニメ名

    int             m_loopCount = 0;            // ループ回数

    public void Start () {
        // アニメコンポーネントを追加
        Animation anim = GetComponent();
        if(null == anim) anim = gameObject.AddComponent();
        
        // 頂点とUVの作成
        m_VtxArray = new Vector3[4];
        m_UvArray = new Vector2[4];

        m_VtxArray[0] = new Vector3(0.0f, 0.0f, 0.0f);  // BottomLeft
        m_VtxArray[1] = new Vector3(0.0f, 1.0f, 0.0f);  // TopLeft
        m_VtxArray[2] = new Vector3(1.0f, 0.85f, 0.0f); // TopRight
        m_VtxArray[3] = new Vector3(1.0f, 0.0f, 0.0f);  // BottomRight

        m_UvArray[0] = new Vector2(0.0f, 0.0f);
        m_UvArray[1] = new Vector2(0.0f, 1.0f);
        m_UvArray[2] = new Vector2(1.0f, 1.0f);
        m_UvArray[3] = new Vector2(1.0f, 0.0f);

        CreateAnim();
    }

    void OnRenderObject() {
        // フェードイン、アウトをループさせるテスト
        // マテリアルの色変更
        Color color = m_Mtl.GetColor("_Color");
        // アニメの時間取得
        float time = animation[m_animName].time;    // アニメーションの経過時間になる
        
        time -= m_loopCount * animation[m_animName].length;
        // アニメカーブの値を取得
        float value = m_animCurve.Evaluate(time);
        color.a = value;

        // マテリアルの色セット
        m_Mtl.SetColor("_Color", color);

        // 四角形を描画
        DrawQuad();
    }

    // アニメーションを作成
    void CreateAnim() {
        float startTime = 0.0f;
        float endTime = 5.0f;
        float midTime = (endTime - startTime) * 0.5f;

        // アニメカーブを作成
        m_animCurve = new AnimationCurve();

        // アルファ値のキーフレームを追加
        m_animCurve.AddKey( new Keyframe(startTime, 0.0f) );
        m_animCurve.AddKey( new Keyframe(midTime, 1.0f) );
        m_animCurve.AddKey( new Keyframe(endTime, 0.0f) );

        // アニメーションクリップを作成
        m_animClip = new AnimationClip();
        m_animClip.wrapMode = WrapMode.Loop;
        m_animClip.SetCurve("", typeof(Material), "_Color.a", m_animCurve);

        // アニメーションイベントを作成
        m_animEvtStart = new AnimationEvent();
        m_animEvtStart.time = startTime;
        m_animEvtStart.intParameter = 987;
        m_animEvtStart.stringParameter = "start";
        m_animEvtStart.functionName = "AnimEventStart";

        m_animEvtEnd = new AnimationEvent();
        m_animEvtEnd.time = endTime;
        m_animEvtEnd.intParameter = 123;
        m_animEvtEnd.stringParameter = "end";
        m_animEvtEnd.functionName = "AnimEventEnd";

        // クリップにイベントを追加
        m_animClip.AddEvent(m_animEvtStart);
        m_animClip.AddEvent(m_animEvtEnd);

        // アニメーションにクリップを追加
        animation.AddClip(m_animClip, m_animName);
        // アニメーションの再生開始
        animation.Play(m_animName);
    }

    // パラメータ数は 0個か1個 2個だと実行時にエラー
    void AnimEventStart(string s) {
        print("AnimEventStart() " + s);
    }

    void AnimEventEnd(string s) {
        m_loopCount++;
        print("AnimEventEnd() " + s);
    }

    void DrawQuad() {
        m_Mtl.SetPass(0);

        GL.PushMatrix();
        GL.LoadOrtho();
        // 左下が 0, 0, 0
        GL.Begin(GL.QUADS);
        for(int i = 0; i < 4; i++) {
            GL.TexCoord(m_UvArray[i] + m_uvOffset);
            GL.Vertex(m_VtxArray[i]);
        }
        GL.End();
        GL.PopMatrix();
        m_uvOffset.x -= 0.001f;
        m_uvOffset.y -= 0.001f;
    }
}

Unity GL (2) 四角形の描画

TestGL2.cs

using UnityEngine;
 
public class TestGL2 : MonoBehaviour {
    Vector3[]       m_VtxArray;                 // 頂点の配列
    Vector2[]       m_UvArray;                  // UVの配列
    Vector2         m_uvOffset = Vector2.zero;  // UVのオフセット

    public Material m_Mtl;                      // 使用するマテリアル

    public void Start () {
        // 頂点とUVの作成
        m_VtxArray = new Vector3[4];
        m_UvArray = new Vector2[4];

        // 時計回りだと描画される?
        m_VtxArray[0] = new Vector3(0.25f, 0.25f, 0.0f); // BottomLeft
        m_VtxArray[1] = new Vector3(0.25f, 0.95f, 0.0f); // TopLeft
        m_VtxArray[2] = new Vector3(0.75f, 0.75f, 0.0f); // TopRight
        m_VtxArray[3] = new Vector3(0.75f, 0.25f, 0.0f); // BottomRight

        m_UvArray[0] = new Vector2(0.0f, 0.0f);
        m_UvArray[1] = new Vector2(0.0f, 1.0f);
        m_UvArray[2] = new Vector2(1.0f, 1.0f);
        m_UvArray[3] = new Vector2(1.0f, 0.0f);
    }

    void OnRenderObject() {
        DrawQuad();
    }

    void DrawQuad() {
        m_Mtl.SetPass(0);

        GL.PushMatrix();
        GL.LoadOrtho();         // 正射影 左下が 0, 0, 0
        //GL.LoadIdentity();
        //GL.LoadProjectionMatrix(Matrix4x4.identity);
        
        GL.Begin(GL.QUADS);
#if false
        // 反時計回り 描画されない
        for(int i = 3; i >= 0; i--) {
            GL.TexCoord(m_UvArray[i] + m_uvOffset);
            GL.Vertex(m_VtxArray[i]);
        }
#else
        // 時計回り 描画された 
        for(int i = 0; i < 4; i++) {
            GL.TexCoord(m_UvArray[i] + m_uvOffset);
            GL.Vertex(m_VtxArray[i]);
        }
#endif
        GL.End();
        GL.PopMatrix();

        m_uvOffset.x -= 0.001f;
        m_uvOffset.y -= 0.001f;
    }
}

2012年4月12日木曜日

Unity GL (1) ライン描画

GL.LINESでライン描画

空オブジェクトにスクリプトを追加、インスペクター上で、描画するメッシュを選択

TestGL1.cs

using UnityEngine;
 
public class TestGL1 : MonoBehaviour {
    Material        m_Material;                 // マテリアル
    Vector3[]       m_lineVtxArray;             // ライン描画用の頂点の配列
    public Color    m_lineColor = Color.blue;   // 描画色
    public Mesh     m_Mesh;                     // メッシュ

    public void Start () {
        CreateMaterial();
        CreateVtxArray();
    }

    void OnRenderObject() {
        DrawLine();
    }

    // OnPostRender カメラにスクリプトをアタッチすると呼ばれた
    void OnPostRender() {
//        print("OnPostRender");
    }

    // マテリアルを作成
    void CreateMaterial() {
        m_Material = new Material( "Shader \"Lines/Color\" {" +
            "SubShader {" +
            "    Pass { " +
            "       Blend SrcAlpha OneMinusSrcAlpha" +  // αブレンド
//          "       Blend Off" +        // ブレンド オフ
            "       Cull Off" +         // カリング オフ
            "       ZWrite Off" +       // Z値の書き込み オフ
//          "       ZTest Always" +     // Zテスト 常に描画
            "       ZTest Less" +       // Zテスト Z値が小さいと描画
            "       Fog { Mode Off }" + // フォグ オフ
            "       BindChannels {" +
            "           Bind \"Vertex\", vertex" + 
            "           Bind \"Color\", color" +
            "       }" +
            "} } }" );
        m_Material.hideFlags = HideFlags.HideAndDontSave;
        m_Material.shader.hideFlags = HideFlags.HideAndDontSave;
    }

    // メッシュから頂点の配列を作成
    void CreateVtxArray() {
        if(null == m_Mesh) return;

        Vector3[] vertices = m_Mesh.vertices;
        int[] triangles = m_Mesh.triangles;

        print("triangles.Length = " + triangles.Length);
        m_lineVtxArray = new Vector3[triangles.Length];
        for (int i = 0; i < triangles.Length / 3; i++) {
            m_lineVtxArray[i * 3 + 0] = vertices[triangles[i * 3 + 0]];
            m_lineVtxArray[i * 3 + 1] = vertices[triangles[i * 3 + 1]];
            m_lineVtxArray[i * 3 + 2] = vertices[triangles[i * 3 + 2]];
        }
    }

    // 線分の描画
    void DrawLine() {
        Vector3 vPos = Vector3.zero;
        Quaternion qRot = Quaternion.identity;
        Matrix4x4 mtx = Matrix4x4.TRS(vPos, qRot, Vector3.one); 
        
        m_Material.SetPass(0);

        GL.PushMatrix();
        GL.MultMatrix(mtx);
        
        GL.Begin(GL.LINES);
        GL.Color(m_lineColor);

        for (int i = 0; i < m_lineVtxArray.Length / 3; i++) {
            GL.Vertex(m_lineVtxArray[i * 3]);
            GL.Vertex(m_lineVtxArray[i * 3 + 1]);

            GL.Vertex(m_lineVtxArray[i * 3 + 1]);
            GL.Vertex(m_lineVtxArray[i * 3 + 2]);

            GL.Vertex(m_lineVtxArray[i * 3 + 2]);
            GL.Vertex(m_lineVtxArray[i * 3]);
        }
        GL.End();
        GL.PopMatrix();
    }
}

2012年4月7日土曜日

Unity WWW (2)

UnityのWWWで、ローカルホストにアクセスするテスト

サーバーにAIMLを実装したJ-Aliceを使用


ボット同士の会話

TestWWW2.cs

using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using UnityEngine;

// テキストフィールドに入力した文字列を、Sendボタンでサーバーに送信
public class TestWWW2 : MonoBehaviour {
    public int  m_nPortNo = 8000;       // ポート番号
    public TestWWW2     m_objTalkTo;    // 話し相手
    
    string      m_InputTxt = "";        // 聞いた内容
    string      m_OutputTxt = "";       // 話した内容
    GameObject  m_objCamera;            // 描画用のカメラ

    public void Start() {
        // カメラを取得
        m_objCamera = GameObject.Find("Main Camera");
    }

    // 話したテキストをセット 話し相手側から呼びだす
    public void SetTaledTxt(string txt) {
        m_InputTxt = txt;
        StartCoroutine( ConnectToLocal( m_InputTxt ) );
    }

    // ローカルサーバーのJ-Aliceに接続
    IEnumerator ConnectToLocal(string inputTxt) {
        // URL引数
        string arg = "?input=" + WWW.EscapeURL(inputTxt);
        // URL
//        string url = "http://localhost:" + m_nPortNo.ToString() + arg;
        string url = "http://127.0.0.1:" + m_nPortNo.ToString() + arg;

        // WWWでURLに接続
        WWW www = new WWW(url);
        yield return www;

        // ShiftJisのエンコーディングを取得
        int codepage = 932;
        Encoding enc = Encoding.GetEncoding( codepage );

        // WWWから文字列を取得
        string str = enc.GetString( www.bytes );

        // J-Aliceからの応答部分の文字列を切り取り 仮
        int nStartIndex = str.IndexOf(":");
        int nEndIndex = str.IndexOf("<p>");
        int nLen = nEndIndex - nStartIndex - 2;
        str = str.Substring(nStartIndex + 2, nLen);

        m_OutputTxt = str;          // 描画するテキストをセット

        // 表示フラグ変更用のウェイト開始
        StartCoroutine( WaitOutputTxt() ); 
    }

    IEnumerator WaitOutputTxt() {
        yield return new WaitForSeconds(3.0f);  // ウェイト

        if(null != m_objTalkTo) {
            // 話相手に話した内容をセット
            m_objTalkTo.SetTaledTxt( m_OutputTxt );
        }
    }

    void OnGUI () {
        // ワールド座標をスクリーン座標に変換
        Vector3 pos = transform.position;
        Vector3 screenPos = m_objCamera.camera.WorldToScreenPoint( pos );

        // 入力文字列編集用のテキストフィールド
        string outTxt = GUI.TextField( new Rect(screenPos.x - 64.0f, 10.0f, 128.0f, 18.0f), m_InputTxt);
        if(0 != outTxt.CompareTo(m_InputTxt)) {
            m_InputTxt = outTxt;
        }

        // 送信ボタン
        if(GUI.Button(new Rect(screenPos.x - 64.0f + 140.0f, 10.0f, 64.0f, 18.0f), "Send")) {
            // コルーチンの開始
            StartCoroutine( ConnectToLocal( m_InputTxt ) );
        }
        // 応答テキストを表示
        GUI.TextArea( new Rect(screenPos.x - 100.0f, 60.0f, 200.0f, 64.0f), m_OutputTxt);
    }
}

2012年4月1日日曜日

Unity ギズモの描画と編集

空のゲームオブジェクトにTestGizmo.csを追加

ギズモを選択、編集タイプに応じて移動、サイズ変更がシーンウィンドウで行える

Assets/Script/TestGizmo.cs

using UnityEngine;

// ギズモのテスト用クラス
public class TestGizmo : MonoBehaviour {
  // 編集タイプの種類
  public enum EditType {
    Invalid,
    BoundCenter,
    BoundSize
  }

  // 編集タイプ
  public EditType editType = EditType.Invalid;

  // ギズモの形状
  public Bounds   bound = new Bounds(Vector3.zero, Vector3.one);

  // ギズモの描画
  void OnDrawGizmos () {
    Gizmos.color = Color.magenta;
    Gizmos.DrawWireCube(bound.center, bound.size);
  }
}

Assets/Editor/EditorTestGizmo.cs

using UnityEngine;
using UnityEditor;

// TestGizmoの編集用クラス
[CustomEditor( typeof(TestGizmo) )]     // ←編集対象のクラスを指定
public class EditorTestGizmo : Editor {

  // Editor.OnSceneGUI シーンウィンドウ上のGUI処理
  void OnSceneGUI () {
    // 編集対象を取得
    TestGizmo t = target as TestGizmo;

      switch(t.editType) {
      case TestGizmo.EditType.BoundCenter:
          // 位置の変更
          t.bound.center = Handles.PositionHandle(t.bound.center, 
                                      Quaternion.identity);
          break;
      case TestGizmo.EditType.BoundSize:
          // サイズの変更
          t.bound.size = Handles.ScaleHandle(t.bound.size, 
                           t.bound.center, Quaternion.identity, 5.0f);
          break;
      }
      if (GUI.changed) {
//          Debug.Log("GUI.changed");
      }
  }
}

2012年3月24日土曜日

Unity エディットウィンドウ(2) 三角形の描画

エディットウィンドウで三角形を描画するテスト
GLを使用すると描画できた
Editor/EditWindowD.cs


using UnityEngine;
using UnityEditor;

public class EditWindowD : EditorWindow {
    Material    m_Material;    // マテリアル
    Vector2 []  m_VecArray;    // 頂点の配列
    int         m_VecNum = 3;  // 頂点数

    // メニューに追加
    [MenuItem ("Window/EditWindowD")]
    static void Init() {
        EditWindowD window = (EditWindowD)EditorWindow.GetWindow( typeof (EditWindowD) );
        window.Show();
    }

    // スクリプトのロード時に呼ばれる ScriptableObject.OnEnable()
    void OnEnable() {
        CreateVertexArray();
        CreateMaterial();
    }
    
    // エディタウィンドウのGUI処理をここに記述 EditorWindow.OnGUI()
    void OnGUI() {
        // 再描画イベント時に描画処理を行う
        if (EventType.Repaint != Event.current.type) return;

        // 実行するとウィンドウが真っ白
        //GL.Clear(false, true, Color.white);

        m_Material.SetPass(0);
        DrawLine();
    }

    // マテリアルの作成
    void CreateMaterial() {
        m_Material = new Material( "Shader \"Lines/Colored_Blended\" {" +
            "SubShader { Pass { " +
            "    Blend SrcAlpha OneMinusSrcAlpha " +
            "    ZWrite Off Cull Off Fog { Mode Off } " +
            "    BindChannels {" +
            "      Bind \"vertex\", vertex" + 
            "      Bind \"color\", color" +
            "} } } }" );
        m_Material.hideFlags = HideFlags.HideAndDontSave;
        m_Material.shader.hideFlags = HideFlags.HideAndDontSave;
    }

    // 頂点の配列を作成
    void CreateVertexArray() {
        m_VecArray = new Vector2[m_VecNum];
        m_VecArray[0] = new Vector2(50, 10);
        m_VecArray[1] = new Vector2(10, 60);
        m_VecArray[2] = new Vector2(90, 60);
    }

    // 線分の描画
    void DrawLine() {
        GL.Color(Color.blue);
        GL.Begin( GL.LINES );
        for(int i = 0; i < m_VecNum; i++) {
            int idx0 = i;
            int idx1 = (i == m_VecNum - 1) ? 0 : idx0 + 1;
            GL.Vertex(m_VecArray[idx0]);
            GL.Vertex(m_VecArray[idx1]);
        }
        GL.End();
    }
}

2012年2月26日日曜日

Unity 処理時間計測 (2)

C#版

using System;
using System.Collections.Generic;
using System.Collections;

using UnityEngine;

class TestObject {
 int n;
 string name;

 public TestObject() {
  n = 0;
  name = "abc";
 }
}

// テスト用のクラス
public class TestClass : MonoBehaviour {

 const int ArrayNum = 5000;  // 配列数

 float fBaseTime = 0.0f;
 float fCurTime = 0.0f;

 int [] array; // 配列
 
 System.Collections.ArrayList al0;
 System.Collections.ArrayList al1;
 System.Collections.ArrayList al2;
 System.Collections.ArrayList al3;

 void Start() {
  TestArray();
 }

 void Update() {
  if(Input.GetKeyDown(KeyCode.Alpha1)) {
   StartCoroutine( WaitFunc(1.0F) );
  }
  if(Input.GetKeyDown(KeyCode.Alpha2)) {
   StartCoroutine( WaitFunc(1.5F) );
  }

  if(Input.GetKeyDown(KeyCode.Alpha4)) {
   TestArray();
  }
 }

 // 配列のテスト
 void TestArray() {
  // 配列の作成
  array = new int [ ArrayNum ];

  al0 = new ArrayList();
  al1 = new ArrayList();
  al2 = new ArrayList();
  al3 = new ArrayList();

  // Test1 何もしない
  fBaseTime = Time.realtimeSinceStartup;
  fCurTime = Time.realtimeSinceStartup;
  Debug.Log("Test1 time = " + ((fCurTime - fBaseTime) * 1000.0f).ToString()+"(ms)");

  // Test2 配列に値セット
  fBaseTime = Time.realtimeSinceStartup;
  for(int i = 0; i < ArrayNum; i++) {
   array[i] = i;
  }
  fCurTime = Time.realtimeSinceStartup;
  Debug.Log("Test2 time = " + ((fCurTime - fBaseTime) * 1000.0f).ToString()+"(ms)");


  // Test3 配列に整数を追加
  fBaseTime = Time.realtimeSinceStartup;
  for(int i = 0; i < ArrayNum; i++) {
   al0.Add( i );
  }
  fCurTime = Time.realtimeSinceStartup;

  Debug.Log("Test3 time = " + ((fCurTime-fBaseTime) * 1000.0f).ToString()+"(ms)");
  Debug.Log("al0.Count = " + al0.Count);

  // Test4 配列に整数を追加
  fBaseTime = Time.realtimeSinceStartup;
  for(int i = 0; i < ArrayNum; i++) {
   al1.Add( 9876 );
  }
  fCurTime = Time.realtimeSinceStartup;
  Debug.Log("Test4 time = " + ((fCurTime-fBaseTime) * 1000.0f).ToString()+"(ms)");

  // Test5 配列に文字列を追加
  fBaseTime = Time.realtimeSinceStartup;
  for(int i = 0; i < ArrayNum; i++) {
   al2.Add( "abcdefghijklmnopqrstu" );
  }
  fCurTime = Time.realtimeSinceStartup;
  Debug.Log("Test5 time = " + ((fCurTime-fBaseTime) * 1000.0f).ToString()+"(ms)");

  // Test5 配列にクラスを追加
  fBaseTime = Time.realtimeSinceStartup;
  for(int i = 0; i < ArrayNum; i++) {
   TestObject o = new TestObject();
   al3.Add( o );
  }
  fCurTime = Time.realtimeSinceStartup;
  Debug.Log("Test6 time = " + ((fCurTime-fBaseTime) * 1000.0f).ToString()+"(ms)");
 }

 IEnumerator WaitFunc(float t) {
  fBaseTime = Time.realtimeSinceStartup;
  yield return new WaitForSeconds( t );
  fCurTime = Time.realtimeSinceStartup;
  Debug.Log("Test6 time = " + ((fCurTime-fBaseTime) * 1000.0f).ToString()+"(ms)");
 }
}


Unity 処理時間計測 (1)

Time.realtimeSinceStartup を使用
JavaScript版

private var nArrayNum : int = 5000;
private var numArray : int[];
private var arr0 : Array;

private var fBaseTime : float = 0.0f;
private var fCurTime : float = 0.0f;

function Start() {
 TestArray();
}

function Update() {
 if(Input.GetKeyDown(KeyCode.Keypad4)) {
  TestArray();
 }
}

// 配列のテスト
function TestArray() {
 var i : int = 0;
 numArray = new int[ nArrayNum ];
 arr0 = new Array();
 
 // Test1
 fBaseTime = Time.realtimeSinceStartup;
 for(i = 0; i < nArrayNum; i++) {
  numArray[i] = i;
 }
 fCurTime = Time.realtimeSinceStartup;
 Debug.Log("Test1 time = " + ((fCurTime - fBaseTime) * 1000.0f).ToString() + "(ms)");

 // Test2
 fBaseTime = Time.realtimeSinceStartup;
 for(i = 0; i < nArrayNum; i++) {
  arr0.Push( i );
 }
 fCurTime = Time.realtimeSinceStartup;
 Debug.Log("Test2 time = " + ((fCurTime - fBaseTime) * 1000.0f).ToString() + "(ms)");

}

2012年2月12日日曜日

Unity WWW (1)


(笑)の略ではなくWorld Wide Web
System.Web.HttpUtility.UrlEncodeが使えない
WWW.EscapeURL()の結果がおかしい?

指定したurlにアクセスして受信結果をテキストファイルに保存するテスト


using System;
using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Text;
//using System.Web;     // ERROR System.Webが無い
using UnityEngine;

public class TestWWW : MonoBehaviour
{
 public IEnumerator Start() {

        // URLエンコードを行う 結果が"abc+123"
        print(WWW.EscapeURL("abc 123"));

        string url = "http://www.google.co.jp/";

        WWW www = new WWW(url);
        yield return www;
        
        // ShiftJisのエンコーディングを取得
        int codepage = 932;
        Encoding enc = Encoding.GetEncoding( codepage );

        // 受信結果をファイルに保存     ファイルはプロジェクトフォルダにある
        StreamWriter sw = new StreamWriter("./result.html", false, enc);
//        sw.Write(www.text);           // 文字化けしている
        // wwwのバイト配列から文字列を取得
        string strShiftJis = enc.GetString( www.bytes );
        sw.Write(strShiftJis);
        sw.Close();

        print("Start() end");
 }
}

2012年2月4日土曜日

Unity ボーン行列の変更(1)


MonoBehaviour.LateUpdate()内で
変更処理を実行すると描画に反映される

/*
ボーンのTransform
インスペクタ上で変更するボーンを指定
or GameObject.Find("...")でボーンを取得
*/
public Transform    testBone;

/*
MonoBehaviour.LateUpdate
MonoBehaviour.Update 後に呼ばれる
*/
public void LateUpdate () {
 /*
 ボーンの位置を変更
 子のボーンにも変更が適用される
 */
 testBone.position = new Vector3(0.0f, 0.5f, 0.0f);
}

2012年1月25日水曜日

Unity キーフレームアニメ


 // 空のアニメーションカーブを作成
 AnimationCurve animCurve = new AnimationCurve();

 // キーフレームの追加
 animCurve.AddKey( new Keyframe(0.0f, 1.0f) );
 animCurve.AddKey( new Keyframe(2.0f, 0.1f) );

 // アニメーションカーブの値を取得
 print(animCurve.Evaluate(0.0f)); // 1.0
 print(animCurve.Evaluate(1.25f)); // 0.3847657
 print(animCurve.Evaluate(2.0f)); // 0.1
 print(animCurve.Evaluate(2.5f)); // 0.1


KeyframeのinTangentとoutTangentの値は0