示例#1
0
    public bool PlayPriorityAnimation(int id, AnimPriority priority, float speed = 1.0f, bool loop = false, bool reverse = false, float fadeLength = 0.15f, float time = 0.0f, bool async = true)
    {
        excel_anim_list animList = excel_anim_list.Find(id);

        if (animList == null)
        {
            Debug.LogError("未找到ID为" + id + "的动画表");
            return(false);
        }
        string path = mAnimPath + animList.name;

        return(PlayPriorityAnimation(path, priority, speed, loop, reverse, fadeLength, time, async));
    }
示例#2
0
    public bool PlayPriorityAnimation(string name, AnimPriority priority, float speed = 1.0f, bool loop = false, bool reverse = false, float fadeLength = 0.15f, float time = 0.0f, bool async = true)
    {
        float curTime = Time.realtimeSinceStartup;

        for (int i = 0; i < (int)priority; ++i)
        {
            float length = mPriorityLength[i];
            if (length < 0)
            {
                return(false);
            }
            float startTime = mPriorityStartTimes[i];
            if (length >= curTime - startTime)
            {
                return(false);
            }
        }
        if (async)
        {
            // 未来Lambda改成Request
            ResourceSystem.LoadAsync <AnimationClip>(name, (o) => {
                AnimationClip c = o as AnimationClip;
                if (c == null)
                {
                    return;
                }
                if (loop)
                {
                    mPriorityLength[(int)priority] = -1.0f;
                }
                else
                {
                    mPriorityLength[(int)priority] = c.length;
                }
                mPriorityStartTimes[(int)priority] = Time.realtimeSinceStartup;
                var state = PlayClipAnimation(c, c.name, AnimPlayType.Priority, speed, loop, reverse, fadeLength, time);
                if (state != null)
                {
                    float sign = 1.0f;
                    if (state.speed < 0.0f)
                    {
                        sign = -1.0f;
                    }
                    state.speed = mAnimSpeed * sign;
                }
            });
        }
        else
        {
            AnimationClip c = ResourceSystem.Load <AnimationClip>(name);
            if (c == null)
            {
                return(false);
            }
            if (loop)
            {
                mPriorityLength[(int)priority] = -1.0f;
            }
            else
            {
                mPriorityLength[(int)priority] = c.length;
            }
            mPriorityStartTimes[(int)priority] = Time.realtimeSinceStartup;
            var state = PlayClipAnimation(c, c.name, AnimPlayType.Priority, speed, loop, reverse, fadeLength, time);
            if (state != null)
            {
                float sign = 1.0f;
                if (state.speed < 0.0f)
                {
                    sign = -1.0f;
                }
                state.speed = mAnimSpeed * sign;
            }
        }
        return(true);
    }