コード例 #1
0
    public static void SetTestCode(KeyCode key, System.Action callback)
    {
#if !UNITY_EDITOR
        return;
#else
        int keyValue = callback.GetHashCode();

        if (!Instance.callbackDic.ContainsKey(keyValue))
        {
            TestCodeData data = new TestCodeData();
            data.keyValue = callback.GetHashCode();
            data.key      = key;
            data.callback = callback;

            Instance.callbackDic.Add(keyValue, data);
            Instance.testCodeCallbackList.Add(data);
        }
        else
        {
            Instance.callbackDic[keyValue].key      = key;
            instance.callbackDic[keyValue].callback = callback;
        }
#endif
    }
コード例 #2
0
    public static void RemoveTestCode(System.Action method)
    {
#if !UNITY_EDITOR
        return;
#else
        int keyValue = method.GetHashCode();
        if (Instance.callbackDic.ContainsKey(keyValue))
        {
            Instance.testCodeCallbackList.Remove(Instance.callbackDic[keyValue]);
            Instance.callbackDic.Remove(keyValue);
        }
        else
        {
            Debug.Log("ah?");
        }
#endif
    }
コード例 #3
0
    /// <summary>
    /// 注册无参事件
    /// </summary>
    /// <param name="clip">动画片</param>
    /// <param name="time">事件</param>
    /// <param name="onAnimEvent">回调</param>
    public void AddAnimEvent(AnimationClip clip, float time, System.Action onAnimEvent)
    {
        AnimationEvent animEvent = new AnimationEvent();

        //固定一个事件方法,就不需要对每个事件都写一个
        animEvent.functionName   = "OnAnimEvent";
        animEvent.time           = time;
        animEvent.messageOptions = SendMessageOptions.RequireReceiver;
        //用hash码记录是哪一个回调函数,还没想到更好的方法
        animEvent.intParameter = onAnimEvent.GetHashCode();

        if (!onAnimEventDic.ContainsKey(animEvent.intParameter))
        {
            onAnimEventDic.Add(animEvent.intParameter, onAnimEvent);
        }

        clip.AddEvent(animEvent);
    }
コード例 #4
0
    public void AddAnimEvent(object obj, AnimationClip clip, float time, System.Action <object> onAnimEventObj)
    {
        AnimationEvent animEvent = new AnimationEvent();

        animEvent.functionName   = "OnAnimEventParam";
        animEvent.time           = time;
        animEvent.messageOptions = SendMessageOptions.RequireReceiver;
        //用hash码记录回调函数
        animEvent.intParameter = onAnimEventObj.GetHashCode();

        if (!onAnimEventObjDic.ContainsKey(animEvent.intParameter))
        {
            onAnimEventObjDic.Add(animEvent.intParameter, onAnimEventObj);
        }
        if (!paramDic.ContainsKey(animEvent.intParameter))
        {
            paramDic.Add(animEvent.intParameter, obj);
        }

        clip.AddEvent(animEvent);
    }
コード例 #5
0
    public static bool IsAddedTestCode(System.Action method)
    {
        int key = method.GetHashCode();

        return(Instance.callbackDic.ContainsKey(key));
    }