Exemplo n.º 1
0
    /// <summary>
    /// 检查并处理动画剪辑的始末事件.
    /// </summary>
    /// <param name="ac">Ac.</param>
    /// <param name="create"> <c>true</c>:创建模式 <c>   false</c>:清除模式  </param>
    public static void CheckAnimationClipEvent(AnimationClip ac, bool create = true)
    {
        AnimationEvent[]      ae_ary      = AnimationUtility.GetAnimationEvents(ac);
        List <AnimationEvent> ae_rnc_lstt = new List <AnimationEvent>(ae_ary);

        //移除 _start && _end 事件
        for (int o = 0; o < 2; o++)
        {
            for (int i = 0; i < ae_rnc_lstt.Count; i++)
            {
                AnimationEvent ae = ae_rnc_lstt[i];
                if (ae.functionName == "_start" && ae.time == 0)
                {
                    ae_rnc_lstt.RemoveAt(i);
                }
                else if (ae.functionName == "_end" && ae.time == ac.length)
                {
                    ae_rnc_lstt.RemoveAt(i);
                }
            }
        }

        //添加 _start && _end 事件
        if (create)
        {
            AnimationEvent e = new AnimationEvent();
            e.functionName    = "_start";
            e.time            = 0f;
            e.stringParameter = ac.name;
            ae_rnc_lstt.Add(e);

            e = new AnimationEvent();
            e.functionName = "_end";
            e.time         = ac.length;
            ae_rnc_lstt.Add(e);
        }

        ae_ary = GameHelp.ListToArray <AnimationEvent>(ae_rnc_lstt);
        AnimationUtility.SetAnimationEvents(ac, ae_ary);
    }