Beispiel #1
0
    /// <summary>
    /// 使用*表示将Action应用到所有的状态当中
    /// 使用如Attack_*表示所有带有Attack_前缀的添加Action
    /// 当不带*时表示全字符匹配
    /// </summary>
    public void SetEvent(AnimatorEventType type, CommonStateMachineBehaviour.StateEvent action, params string[] stateName)
    {
        int length = stateName.Length;

        for (int i = 0; i < length; i++)
        {
            if (stateName[i].Contains(MatchSign))
            {
                if (stateName[i].Length == 1)
                {
                    for (int j = 0; j < FullStateName.Length; j++)
                    {
                        Behaviour.AddEvent(type, action, FullStateName[j]);
                    }
                }
                else
                {
                    stateName[i] = stateName[i].Replace(MatchSign, "");
                    for (int j = 0; j < FullStateName.Length; j++)
                    {
                        if (FullStateName[j].Contains(stateName[i]))
                        {
                            Behaviour.AddEvent(type, action, FullStateName[j]);
                        }
                    }
                }
            }
            else
            {
                Behaviour.AddEvent(type, action, stateName[i]);
            }
        }
    }
Beispiel #2
0
    public void RemoveEvent(AnimatorEventType type, StateEvent action, string stateName)
    {
        int         hash = Animator.StringToHash(stateName);
        EventStruct eventValue;

        if (!Events.TryGetValue(hash, out eventValue))
        {
            return;
        }
        switch (type)
        {
        case AnimatorEventType.Enter:
            eventValue.EnterEvents -= action;
            break;

        case AnimatorEventType.Exit:
            eventValue.ExitEvents -= action;
            break;

        case AnimatorEventType.Running:
            eventValue.RunningEvents -= action;
            break;

        default:
            throw new ArgumentOutOfRangeException("type", type, null);
        }
    }