Skip to content

Instantly share code, notes, and snippets.

@baobao
Last active March 9, 2025 13:37
Show Gist options
  • Save baobao/9e752a10f8124d2ce02670e588933461 to your computer and use it in GitHub Desktop.
Save baobao/9e752a10f8124d2ce02670e588933461 to your computer and use it in GitHub Desktop.
https://shibuya24.info/entry/unity-animation-event で使用したサンプルコード
using UnityEngine;
using System.Collections.Generic;
public class EventReceiverSample : MonoBehaviour
{
public enum AnimType {
TYPE_1, TYPE_2, TYPE_3
}
/// <summary>【実行可能】引数の無い関数</summary>
public void CallNoArg () => Debug.Log ("no arg");
/// <summary>【実行可能】float型の引数</summary>
public void SetFloat (float value) => Debug.Log (value);
/// <summary>【実行可能】int型の引数</summary>
public void SetInt (int value) => Debug.Log (value);
/// <summary>【実行可能】bool型の引数</summary>
public void SetBool (bool value) => Debug.Log (value);
/// <summary>【実行可能】string型の引数</summary>
public void SetString (string value) => Debug.Log (value);
/// <summary>【実行可能】enum型の引数</summary>
public void SetType (AnimType type) => Debug.Log (type);
/// <summary>【実行可能】GameObject型の引数</summary>
public void SetGameObject(GameObject obj) => Debug.Log(obj);
/// <summary>【実行可能】コンポーネントの引数</summary>
public void SetCollider(BoxCollider obj) => Debug.Log(obj);
/// <summary>【実行可能】Objectの引数</summary>
public void SetObject(ScriptableObject obj) => Debug.Log(obj);
/// <summary>【不可】複数引数</summary>
public void SetMultiArgs (int value1, float value2)
=> Debug.Log (value1 + " / " + value2);
/// <summary>【不可】クラス型の引数</summary>
public void SetAnimData (AnimData data) => Debug.Log (data);
/// <summary>【不可】List型</summary>
public void SetList (List<int> list) => Debug.Log (list);
}
[System.Serializable]
public class AnimData
{
public int index;
public float value;
public bool flg;
}
public class ObjectData : ScriptableObject
{
public int index;
public float value;
public bool flg;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment