UnityのInspectorで構造体使う方法

Unityではpublicもしくは[SerializeField]の変数をInspectorから設定することができます。このInspectorで独自に定義した構造体を使いたい場合は[System.Serializable]を使うと良いそうです。

[System.Serializable]
public struct Example
{
  public string name;
  piblic int value;
}

[SerializeField]
Example example;

リンク

C#で構造体をInspectorで使える様にする方法 – 強火で進め
http://d.hatena.ne.jp/nakamura001/20110805/1312563959

Gentoo LinuxでC#を使ってみた

Gentoo LinuxのMonoでC#を使ってみたので、使い方をメモしてみます。

インストール

# emerge -av mono

プログラミング

$ vi hello.cs
$ cat hello.cs
using System;
public class Hello
{
  static public void Main ()
  {
    Console.WriteLine("Hello world!");
  }
}

コンパイル&実行

$ mcs hello.cs
$ ls
hello.cs  hello.exe*
$ mono hello.exe
Hello world!

リンク

Home | Mono
http://www.mono-project.com/

iTweenでSystem.Actionを使う方法

iTweenはとても便利なAssetですが、onupdateoncompletedelegateが使えないという点が少し不便だったので調べてみたところ簡単に変更できるようです。

//throw an error if a string wasn't passed for callback:
if (tweenArguments[callbackType].GetType() == typeof(System.String)) {
  target.SendMessage((string)tweenArguments[callbackType],(object)tweenArguments[callbackType+"params"],SendMessageOptions.DontRequireReceiver);
}else{
  Debug.LogError("iTween Error: Callback method references must be passed as a String!");
  Destroy (this);
}

という部分を

//throw an error if a string wasn't passed for callback:
if (tweenArguments[callbackType] is Action<object>) {
  ((Action<object>)tweenArguments[callbackType]).Invoke((object)tweenArguments[callbackType + "params"]);
}else{
  Debug.LogError("iTween Error: Callback method references must be passed as a String!");
  Destroy (this);
}

と書き換えます。

すると、次のような感じでonupdateが使えるようになります。

Hashtable ht = new Hashtable ();
ht.Add ("from", 0.0f);
ht.Add ("to", 1.0f);
ht.Add ("onupdate", (System.Action<object>)(v => {
  Debug.Log("v = " + (float)v);
}));
iTween.MoveTo(gameObject, ht);

便利です。

リンク

Specifying a delegate for the value of onupdate in iTween. – Unity Answers
https://answers.unity.com/questions/490719/specifying-a-delegate-for-the-value-of-onupdate-in.html