Beispiel #1
0
    protected void SetActiveFrames(string moveName, string hitboxName, int startTime, int endTime)
    {
        AnimationClip animClip = null;

        foreach (AnimationClip tempClip in anim.runtimeAnimatorController.animationClips)
        {
            if (tempClip.name == moveName)
            {
                animClip = tempClip;
            }
        }
        if (animClip == null)
        {
            Debug.LogError("Error: Could not find animation clip to bind active frames to");
            return;
        }
        AnimationEvent animEventStart = new AnimationEvent();

        animEventStart.intParameter    = 1;
        animEventStart.time            = startTime * (1.0f / Constants.ANIMATION_FRAME_RATE);
        animEventStart.stringParameter = hitboxName;
        animEventStart.functionName    = "setHitbox";

        AnimationEvent animEventEnd = new AnimationEvent();

        animEventEnd.intParameter    = 0;
        animEventEnd.time            = endTime * (1.0f / Constants.ANIMATION_FRAME_RATE);
        animEventEnd.stringParameter = hitboxName;
        animEventEnd.functionName    = "setHitbox";

        animClip.AddEvent(animEventStart);
        animClip.AddEvent(animEventEnd);
    }
Beispiel #2
0
    void Start()
    {
        timeToIdle2 = Random.Range(_MinTimeToIdle2, _MaxTimeToIdle2);
        antr        = GetComponent <Animator>();

        //Pickup
        AnimationEvent ev = new AnimationEvent();

        ev.functionName = "FirePickup";
        ev.time         = 0.4f;
        AnimationClip cl = antr.runtimeAnimatorController.animationClips.Where(x => x.name == "pickup").First();

        if (cl.events.Count() == 0)
        {
            cl.AddEvent(ev);
        }

        //Attack
        ev = new AnimationEvent();
        ev.functionName = "FireAttack";
        ev.time         = 0.7f;
        cl = antr.runtimeAnimatorController.animationClips.Where(x => x.name == "attack").First();

        if (cl.events.Count() == 0)
        {
            cl.AddEvent(ev);
        }
    }
Beispiel #3
0
    void Awake()
    {
        gameObject.layer = LayerMask.NameToLayer("door");
        animator         = GetComponent <Animator>();
        boxCollider2D    = GetComponent <BoxCollider2D>();
        audioSource      = GetComponent <AudioSource>();
        dashCounter      = dashTime;
        openCounter      = openTime;
        open.events      = null;
        close.events     = null;

        AnimationEvent OpenEndEvent = new AnimationEvent {
            time         = open.length,
            functionName = "OpenEnd"
        };
        AnimationEvent OpenStartEvent = new AnimationEvent {
            time         = 0,
            functionName = "OpenStart"
        };

        open.AddEvent(OpenStartEvent);
        open.AddEvent(OpenEndEvent);

        AnimationEvent CloseEndEvent = new AnimationEvent {
            time         = close.length,
            functionName = "CloseEnd"
        };

        close.AddEvent(CloseEndEvent);
    }
Beispiel #4
0
    void Start()
    {
        evt = new AnimationEvent();

        switch (buttonAnimationEvent)
        {
        case ButtonAnimationEvent.PlayAnimation:
            break;

        case ButtonAnimationEvent.PlayAnimationAndToMainScene:
            evt.time         = 0.7f;
            evt.functionName = "ToMainScene";
            clip.AddEvent(evt);
            break;

        case ButtonAnimationEvent.PlayAnimationAndToStartScene:
            evt.time         = 0.7f;
            evt.functionName = "ToStartScene";
            clip.AddEvent(evt);
            break;
        }

        anim      = GetComponent <Animation>();
        anim.clip = clip;
    }
Beispiel #5
0
    public void order(Animation a, float x, float z, float alpha)
    {
        AnimationClip ac = new AnimationClip();

        ac.legacy = true;
        //Gira
        AnimationCurve rot = AnimationCurve.EaseInOut(alpha + 30f, gameObject.transform.eulerAngles.y, alpha + 30.5f, goTo(x, z));
        //Eventos de animación de caminar
        AnimationEvent cWalk = new AnimationEvent();

        cWalk.time         = alpha + 30.5f;
        cWalk.functionName = "walkCycle";
        ac.AddEvent(cWalk);
        cWalk              = new AnimationEvent();
        cWalk.time         = alpha + 36f;
        cWalk.functionName = "walkCycle";
        ac.AddEvent(cWalk);
        //camina
        AnimationCurve xgap = AnimationCurve.EaseInOut(alpha + 30.5f, gameObject.transform.position.x, alpha + 36f, x);
        AnimationCurve zgap = AnimationCurve.EaseInOut(alpha + 30.5f, gameObject.transform.position.z, alpha + 36f, z);

        ac.SetCurve("", typeof(Transform), "localPosition.x", xgap);
        ac.SetCurve("", typeof(Transform), "localPosition.y", AnimationCurve.Constant(30, 50, gameObject.transform.localPosition.y));
        ac.SetCurve("", typeof(Transform), "localPosition.z", zgap);
        ac.SetCurve("", typeof(Transform), "localEulerAngles.y", rot);
        a.AddClip(ac, "order");
        a.Play("order");
    }
    void SetSkyboxEvents()
    {
        amanecerEvent  = new AnimationEvent();
        mediodiaEvent  = new AnimationEvent();
        atardecerEvent = new AnimationEvent();
        nocheEvent     = new AnimationEvent();

        mediodiaEvent.time  = 0.0f;
        atardecerEvent.time = (sunAnimation.length / 2.0f) - 4.0f;
        nocheEvent.time     = (sunAnimation.length / 2.0f) + 1.0f;
        amanecerEvent.time  = sunAnimation.length - 2.0f;

        mediodiaEvent.intParameter  = 1;
        atardecerEvent.intParameter = 2;
        nocheEvent.intParameter     = 3;
        amanecerEvent.intParameter  = 4;


        amanecerEvent.functionName  = "ChangeSkybox";
        mediodiaEvent.functionName  = "ChangeSkybox";
        atardecerEvent.functionName = "ChangeSkybox";
        nocheEvent.functionName     = "ChangeSkybox";

        sunAnimation.AddEvent(amanecerEvent);
        sunAnimation.AddEvent(mediodiaEvent);
        sunAnimation.AddEvent(atardecerEvent);
        sunAnimation.AddEvent(nocheEvent);
    }
Beispiel #7
0
        /// <summary>
        /// Create events to be called on Fade In
        /// </summary>
        private void CreateFadeInEvents()
        {
            try
            {
                AnimationClip fadeInClip = animator.runtimeAnimatorController.animationClips[0];
                fadeInClip.events = null;

                // First frame event
                AnimationEvent firstFrameEvent = new AnimationEvent();
                firstFrameEvent.intParameter = 2;
                firstFrameEvent.time         = 0f;
                firstFrameEvent.functionName = FunctionNames.DefineGameState;
                fadeInClip.AddEvent(firstFrameEvent);

                fadeInClip = animator.runtimeAnimatorController.animationClips[0];

                // Last frame event
                AnimationEvent lastFrameEvent = new AnimationEvent();
                lastFrameEvent.intParameter = 0;
                lastFrameEvent.time         = 1f;
                lastFrameEvent.functionName = FunctionNames.DefineGameState;
                fadeInClip.AddEvent(lastFrameEvent);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #8
0
    public void CreateAnimation(Player player, GameObject animationObject, WeaponItem weapon, Transform targetTransform, float animationSpeed)
    {
        //Set the animation's sprite
        //TODO make or find a sprite for fisticuffs attacks
        Sprite         weaponSprite            = weapon == null ? player.sprite : weapon.GroundSprite;
        SpriteRenderer animationSpriteRenderer = animationObject.GetComponent <SpriteRenderer>();

        animationSpriteRenderer.sprite = weaponSprite;

        //Calculate relative location of the enemy
        Vector3 targetLoc = targetTransform.position - animationObject.transform.position;

        Animation attackAnimation = animationObject.GetComponent <Animation>();

        AnimationClip attackClip = new AnimationClip();

        attackClip.legacy = true;

        AnimationEvent showSprite = new AnimationEvent();

        showSprite.functionName             = "EnableSprite";
        showSprite.objectReferenceParameter = animationSpriteRenderer;
        showSprite.time = 0.0f;

        AnimationEvent hideSprite = new AnimationEvent();

        hideSprite.functionName             = "DisableSprite";
        hideSprite.objectReferenceParameter = animationSpriteRenderer;
        hideSprite.time = 2.0f;

        attackClip.AddEvent(showSprite);
        attackClip.AddEvent(hideSprite);

        // create curves to move the sprite
        //Create shared initial and end frames
        Keyframe initFrame = new Keyframe(0.0f, 0.0f);
        Keyframe endFrame  = new Keyframe(2.0f, 0.0f);

        //Create keyframe array for x position transformation
        Keyframe[]     xKeys  = new Keyframe[] { initFrame, new Keyframe(1.0f, targetLoc.x), endFrame };
        AnimationCurve xCurve = new AnimationCurve(xKeys);

        //Create keyframe array for y position transformation
        Keyframe[]     yKeys  = new Keyframe[] { initFrame, new Keyframe(1.0f, targetLoc.y), endFrame };
        AnimationCurve yCurve = new AnimationCurve(yKeys);



        attackClip.SetCurve("", typeof(Transform), "localPosition.x", xCurve);
        attackClip.SetCurve("", typeof(Transform), "localPosition.y", yCurve);

        attackAnimation.AddClip(attackClip, "attack");

        attackAnimation["attack"].speed = animationSpeed;

        Debug.Log("animation speed: " + animationSpeed.ToString());

        //attackAnimation.Play("attack");
        Vector3 endLoc = animationObject.transform.position;
    }
Beispiel #9
0
    // When a new Floor get's spawned, the Operator need to adjust his animation and create new events
    private void ExpandAnimation(int floorCount)
    {
        floorCount -= 2; // we only need the unlocked floors - the first floor
        float firstFloorKeyframeTime = 0.3f / 2.3f;

        AnimationCurve curve = AnimationCurve.Constant(0, floorCount + firstFloorKeyframeTime, 0);

        Keyframe floorKeyframe = new Keyframe(floorCount, floorCount * -2.0f - 0.3f);

        curve.AddKey(floorKeyframe);

        curve.RemoveKey(curve.keys.Length - 1);
        Keyframe endKeyframe = new Keyframe(floorCount * 2, 0);

        curve.AddKey(endKeyframe);

        _elevateClip.SetCurve("", typeof(Transform), "localPosition.y", curve);

        AnimationEvent work = new AnimationEvent();

        work.functionName = "Work";
        work.time         = floorKeyframe.time;
        work.intParameter = floorCount;
        _elevateClip.AddEvent(work);
        _workEvents.Add(work);

        RemoveEventFromAnimation("StoreCoins");
        _storeCoins.time = floorCount * 2;
        _elevateClip.AddEvent(_storeCoins);
    }
Beispiel #10
0
    const float END_CALL_TIME   = 0.65f; //キック終了の関数の呼びだし時間(0 ~ 1)

    /// <summary>
    /// 初期化
    /// </summary>
    public void Init(Animator anim)
    {
        animator = anim;

        //AnimationEventの登録内容
        AnimationEvent startEvt, endEvt, voiceEvt;

        //  キックのトリガーを入れる
        startEvt              = new AnimationEvent();
        startEvt.time         = START_CALL_TIME; //呼び出し時間
        startEvt.functionName = "StartFunc";     //呼び出し関数

        //  キックのトリガーを切る
        endEvt              = new AnimationEvent();
        endEvt.time         = END_CALL_TIME; //呼び出し時間
        endEvt.functionName = "EndFunc";     //呼び出し関数

        //  ボイスを流す
        voiceEvt              = new AnimationEvent();
        voiceEvt.time         = VOICE_CALL_TIME; //呼び出し時間
        voiceEvt.functionName = "VoiceFunc";     //呼び出し関数

        //AnimationEventをクリップに追加
        AnimationClip clip = animator.runtimeAnimatorController.animationClips[KICK_CLIP_INDEX];

        //var v = new AnimationEvent[100];
        //float f = 0;
        //for(int i=0;i<v.Length;i++)
        //{

        //    v[i] = new AnimationEvent();
        //    v[i].time = f;    //呼び出し時間
        //    v[i].functionName = "TmpFunc";//呼び出し関数
        //    v[i].floatParameter = f;
        //    clip.AddEvent(v[i]);
        //    f += 0.01f;
        //}
        clip.AddEvent(startEvt);
        clip.AddEvent(endEvt);
        clip.AddEvent(voiceEvt);

        //予め生成して起き内容を変更する
        AnimationClip[] clips = animator.runtimeAnimatorController.animationClips;

        foreach (var it in clips)
        {
            //Debug.Log("model = " + animator.gameObject.transform.parent.gameObject.name + "/Eventカウント" + it.events.Length);
            foreach (var t in it.events)
            {
                //Debug.Log("model = " + animator.gameObject.transform.parent.gameObject.name + "クリップName = " + it.name + "/関数名 ≒ " + t.functionName);
            }
        }
        //  Debug.Log("model = " + animator.transform.parent.gameObject.name + "Event個数" + clips.Sum(it => it.events.Length));
    }
Beispiel #11
0
    public void captain(Animation a)
    {
        AnimationClip ac = new AnimationClip();

        ac.legacy = true;
        //se voltea
        AnimationCurve rot = AnimationCurve.EaseInOut(18f, gameObject.transform.eulerAngles.y, 20f, gameObject.transform.eulerAngles.y - 180);
        //Evento de animación de caminar 1
        AnimationEvent cWalk = new AnimationEvent();

        cWalk.time         = 21;
        cWalk.functionName = "walkCycle";
        ac.AddEvent(cWalk);
        //camina
        AnimationCurve xgap    = AnimationCurve.EaseInOut(21f, gameObject.transform.position.x, 27f, 2.6f);
        AnimationCurve zgap    = AnimationCurve.EaseInOut(21f, gameObject.transform.position.z, 27f, 0.5f);
        AnimationCurve despawn = AnimationCurve.EaseInOut(25.35f, gameObject.transform.position.y, 29f, -2f);

        ac.SetCurve("", typeof(Transform), "localPosition.x", xgap);
        ac.SetCurve("", typeof(Transform), "localPosition.y", despawn);
        ac.SetCurve("", typeof(Transform), "localPosition.z", zgap);
        ac.SetCurve("", typeof(Transform), "localEulerAngles.y", rot);
        a.AddClip(ac, "capi");
        a.Play("capi");
    }
Beispiel #12
0
        public void SetUp()
        {
            idle = new AnimationClip();
            idle.AddEvent(new AnimationEvent {
                functionName = "ShadowEvent"
            });
            walking = new AnimationClip();
            walking.AddEvent(new AnimationEvent {
                functionName = "ShadowEvent"
            });
            working = new AnimationClip();
            working.AddEvent(new AnimationEvent {
                functionName = "ShadowEvent"
            });

            generatedEmpData = Substitute.For <EmployeeData>();
            generatedEmpData.generatedData = new EmployeeGeneratedData
            {
                name             = "surname lastname",
                gender           = "female",
                idleClipIndex    = 1,
                walkingClipIndex = 4,
                workingClipIndex = 8
            };

            specialEmpData = Substitute.For <EmployeeData>();
            specialEmpData.EmployeeDefinition = ScriptableObject.CreateInstance <EmployeeDefinition>();
            specialEmpData.EmployeeDefinition.IdleAnimation    = idle;
            specialEmpData.EmployeeDefinition.WalkingAnimation = walking;
            specialEmpData.EmployeeDefinition.WorkingAnimation = working;

            SceneManager.LoadScene("MainGame");
        }
    private void AddAnimationMoveToPlayerDeck(Vector3 endPosition)
    {
        var clip  = new AnimationClip();
        var curve = AnimationCurve.EaseInOut(0, transform.position.x, 1, endPosition.x);

        clip.SetCurve("", typeof(Transform), "localPosition.x", curve);
        curve = AnimationCurve.EaseInOut(0, transform.position.y, 0.7f, 0f);
        clip.SetCurve("", typeof(Transform), "localPosition.y", curve);
        curve = new AnimationCurve();
        curve.AddKey(0, transform.position.z);
        var keyframe = curve[0];

        keyframe.outTangent = 1;
        curve.MoveKey(0, keyframe);
        curve.AddKey(0.4f, transform.position.z - 2.5f);
        curve.AddKey(0.70f, transform.position.z - 4.7f);
        curve.AddKey(1f, endPosition.z);
        keyframe           = curve[3];
        keyframe.inTangent = 0;
        curve.MoveKey(3, keyframe);
        clip.SetCurve("", typeof(Transform), "localPosition.z", curve);
        clip.wrapMode = WrapMode.Once;

        var animEv = new AnimationEvent();

        animEv.functionName = "animFinished";
        animEv.time         = clip.length;
        clip.AddEvent(animEv);

        clip.legacy = true;
        GetComponent <Animation>().AddClip(clip, "MoveToPlayerDeckAnimation");
    }
        public void AddAnimationEvent(string name, string action, float time)
        {
            AnimationClip clip = GetClip(name);

            if (clip == null)
            {
                return;
            }
            AnimationEvent e = new AnimationEvent();

            if (time < 0)
            {
                e.time = 0;
            }
            else if (time > clip.length)
            {
                e.time = clip.length;
            }
            else
            {
                e.time = time;
            }
            e.functionName = action;
            clip.AddEvent(e);
        }
Beispiel #15
0
    public void MoveToAndDestory(Vector3 destination, float moveDuration)
    {
        if (!_animation || !IsChainGrid() || IsRemoving)
        {
            return;
        }
        if (_animation.isPlaying)
        {
            return;
        }
        AnimationClip animclip = new AnimationClip();

#if UNITY_5
        animclip.legacy = true;
#endif

        animclip.SetCurve("", typeof(Transform), "localPosition.x", AnimationCurve.Linear(0, transform.localPosition.x, moveDuration, destination.x));
        animclip.SetCurve("", typeof(Transform), "localPosition.y", AnimationCurve.Linear(0, transform.localPosition.y, moveDuration, destination.y));
        AnimationEvent animEvent = new AnimationEvent();
        animEvent.time         = moveDuration;
        animEvent.functionName = "OnMoveToAndDestoryDone";
        animclip.AddEvent(animEvent);

        _animation.AddClip(animclip, "MoveToAndDestory");
        _animation.Play("MoveToAndDestory");
        Destroy(animclip, moveDuration);

        GameManager.Instance.AnimationCount++;
    }
Beispiel #16
0
    public void ScaleToAndRemove(float scaleX, float scaleY, float duration)
    {
        if (!_animation || !IsChainGrid() || IsRemoving)
        {
            return;
        }
        if (_animation.isPlaying)
        {
            return;
        }

        AnimationClip animclip = new AnimationClip();

#if UNITY_5
        animclip.legacy = true;
#endif
        animclip.SetCurve("", typeof(Transform), "localScale.x", AnimationCurve.Linear(0, transform.localScale.x, duration, scaleX));
        animclip.SetCurve("", typeof(Transform), "localScale.y", AnimationCurve.Linear(0, transform.localScale.y, duration, scaleY));
        AnimationEvent animEvent = new AnimationEvent();
        animEvent.time         = duration;
        animEvent.functionName = "OnMoveToAndDestoryDone";
        animclip.AddEvent(animEvent);

        _animation.AddClip(animclip, "ScaleToAndRemove");
        _animation.Play("ScaleToAndRemove");
        Destroy(animclip, duration);

        GameManager.Instance.AnimationCount++;
    }
Beispiel #17
0
 // Use this for initialization
 void Start()
 {
     try
     {
         foreach (StepAnimInfo info in m_StepAnimInfos)
         {
             AnimationClip animclip = GetComponent <Animation>()[info.m_AnimName].clip;
             if (animclip == null)
             {
                 continue;
             }
             foreach (float time in info.m_StepTimes)
             {
                 AnimationEvent ae = new AnimationEvent();
                 ae.time                     = time;
                 ae.functionName             = "PlayStepSound";
                 ae.objectReferenceParameter = info.m_StepSound;
                 animclip.AddEvent(ae);
             }
         }
         if (m_IsDebug && m_DebugIndex >= 0 && m_DebugIndex < m_StepAnimInfos.Length)
         {
             StepAnimInfo debuginfo = m_StepAnimInfos[m_DebugIndex];
             m_DebugAnimName = debuginfo.m_AnimName;
             GetComponent <Animation>()[debuginfo.m_AnimName].speed = m_AnimSpeed;
             GetComponent <Animation>().Play(debuginfo.m_AnimName);
         }
     }
     catch (System.Exception ex)
     {
         ArkCrossEngine.LogicSystem.LogErrorFromGfx("[Error]:Exception:{0}\n{1}", ex.Message, ex.StackTrace);
     }
 }
    /// <summary>
    /// 添加帧事件(从所有动画片段层级中找)
    /// </summary>
    /// <param name="clipName">动画片段名称</param>
    /// <param name="frame">第几帧</param>
    /// <param name="action">回调</param>
    public void AddEvent(string clipName, int frame, System.Action action)
    {
        bool hasAdd = HasAddEvent(clipName, frame);

        if (hasAdd)
        {
            return;
        }


        ParaObj para = ScriptableObject.CreateInstance <ParaObj>();

        para.action = action;

        Animator      ani = GetComponent <Animator>();
        AnimationClip ac  = System.Array.Find <AnimationClip>(ani.runtimeAnimatorController.animationClips, (AnimationClip _clip) =>
        {
            AnimationClip _ac = null;
            if (_clip.name == clipName)
            {
                _ac = _clip;
            }
            return(_ac);
        });
        //AnimationClip clip = ani.GetClip(clipName);

        AnimationEvent ae = new AnimationEvent();

        ae.time                     = frame / ac.frameRate;
        ae.functionName             = "Callback";
        ae.objectReferenceParameter = para;
        ac.AddEvent(ae);
    }
Beispiel #19
0
 // Animation clips might be shared by many objects.
 // If the clip was already visited, ignores that clip.
 // Optimization depends on no clips being added or having the same function name.
 // If one clip has this function name, then exits.
 private void OnEnd(Animator animator, string functionName)
 {
     AnimationClip[] clips = animator.runtimeAnimatorController.animationClips;
     for (int index = 0, end = clips.Length; index < end; ++index)
     {
         AnimationClip    clip   = clips[index];
         AnimationEvent[] events = clip.events;
         bool             isNew  = true;
         for (int e = 0, eEnd = events.Length; e < eEnd; ++e)
         {
             AnimationEvent thatEvent = events[e];
             if (thatEvent.functionName == functionName &&
                 thatEvent.time == clip.length)
             {
                 isNew = false;
                 break;
             }
         }
         if (!isNew)
         {
             continue;
         }
         AnimationEvent onEnd = new AnimationEvent();
         onEnd.time         = clip.length;
         onEnd.functionName = functionName;
         clip.AddEvent(onEnd);
     }
 }
    void SetAnimationClipCallBack(string tClipName, string tCallBackName, float tEventTimes = 99.9f, int tCallBackPara = 0)
    {
        AnimationClip tAnimationClip = mAnimation.GetClip(tClipName);

        for (int i = 0; i < tAnimationClip.events.Length; i++)
        {
            if (tAnimationClip.events[i].functionName == tCallBackName)
            {
                return;
            }
        }
        AnimationEvent tEvt = new AnimationEvent();

        tEvt.intParameter = tCallBackPara;
        if (tEventTimes == 99.9f)
        {
            tEvt.time = tAnimationClip.length - 0.05f;
        }
        else
        {
            tEvt.time = tEventTimes;
        }
        tEvt.functionName = tCallBackName;
        tAnimationClip.AddEvent(tEvt);
    }
Beispiel #21
0
    void Start()
    {
        Animation anim = GetComponentInChildren <Animation>();

        if (anim != null)
        {
            AnimationEvent _event = new AnimationEvent();
            _event.time         = 0.5f;
            _event.functionName = "GoundDirtyEffect";

            AnimationClip _clip = anim["skywalk"].clip;
            if (_clip != null)
            {
                _clip.AddEvent(_event);
            }

            AnimationClip _clip1 = anim["skyaTKIdle"].clip;
            if (_clip1 != null)
            {
                _clip1.AddEvent(_event);
            }

            AnimationClip _clip2 = anim["skyrun"].clip;
            if (_clip2 != null)
            {
                _clip2.AddEvent(_event);
            }

            AnimationClip _clip3 = anim["skyidle"].clip;
            if (_clip3 != null)
            {
                _clip3.AddEvent(_event);
            }
        }
    }
Beispiel #22
0
    public void Inject(Animator target_animator)
    {
        clip_index.Clear();

        if (target_animator != null)
        {
            RuntimeAnimatorController runtime_ctrl = target_animator.runtimeAnimatorController;
            AnimationClip[]           clips        = runtime_ctrl.animationClips;

            foreach (var clip in clips)
            {
                clip_index[clip.name] = clip;
            }

            foreach (var injectE in inject_events)
            {
                AnimationClip clip = null;
                clip_index.TryGetValue(injectE.TargetClip, out clip);
                if (clip != null)
                {
                    clip.AddEvent(injectE.GetAnimEvent(clip.length));
                    Debug.Log("Event injected for command " + injectE.stringParam);
                }
                else
                {
                    Debug.Log("<color=red> Clip with name " + injectE.TargetClip + " is not exist! </color>");
                }
            }

            target_animator.Rebind();
        }
    }
Beispiel #23
0
 void AddStepSyncEvent(AnimationClip clip)
 {
     var stepSyncEvent = new AnimationEvent();
     stepSyncEvent.time = clip.length;
     stepSyncEvent.functionName = "OnStepSync";
     clip.AddEvent(stepSyncEvent);
 }
Beispiel #24
0
 //这个方法来往Clip里添加动画事件(mEvent.time是事件触发时间)
 private void AddEvent()
 {
     mEvent = new AnimationEvent();
     mEvent.functionName = "AnimEventLaunch";
     mEvent.time         = time;
     Clip.AddEvent(mEvent);
 }
Beispiel #25
0
 void Awake()
 {
     m_Animation = gameObject.GetComponent <Animation>();
     if (null != m_Animation)
     {
         for (int i = 0; i < m_AniEvents.Length; i++)
         {
             AniEvent aniEvent = m_AniEvents[i];
             if (null != aniEvent)
             {
                 if (!string.IsNullOrEmpty(aniEvent.m_AniName) && aniEvent.m_Times.Length > 0)
                 {
                     AnimationClip aniClip = m_Animation.GetClip(aniEvent.m_AniName);
                     if (null != aniClip)
                     {
                         AnimationEvent evt = new AnimationEvent();
                         for (int j = 0; j < aniEvent.m_Times.Length; j++)
                         {
                             evt.time         = aniEvent.m_Times[j];
                             evt.functionName = "OnAniEvent";
                             evt.intParameter = j + 1;
                             aniClip.AddEvent(evt);
                         }
                     }
                     else
                     {
                         Debug.AssertFormat(false, "{0} No_Animation: {1}", gameObject.name, aniEvent.m_AniName);
                     }
                 }
             }
         }
     }
 }
Beispiel #26
0
    public void MoveTo(Vector3 destination)
    {
        if (!_animation)
        {
            return;
        }
        AnimationClip animclip = new AnimationClip();

#if UNITY_5
        animclip.legacy = true;
#endif

        animclip.SetCurve("", typeof(Transform), "localPosition.x", AnimationCurve.Linear(0, transform.localPosition.x, _moveDuration, destination.x));
        animclip.SetCurve("", typeof(Transform), "localPosition.y", AnimationCurve.Linear(0, transform.localPosition.y, _moveDuration, destination.y));
        AnimationEvent animEvent = new AnimationEvent();
        animEvent.time         = _moveDuration;
        animEvent.functionName = "OnMoveToDone";
        animclip.AddEvent(animEvent);

        _animation.AddClip(animclip, "MoveTo");
        _animation.Play("MoveTo");
        Destroy(animclip, _moveDuration);

        GameManager.Instance.AnimationCount++;

        GridManager.Instance.MovedGridsList.Add(this);
    }
Beispiel #27
0
    /// <summary>
    /// 给动画片段添加事件
    /// </summary>
    /// <param name="clipName">动画片段名称</param>
    public static void AddAnimEvent(Animator _Animator, string clipName, string fun, float timeWeight = -1f)
    {
        AnimationClip[]      clips      = _Animator.runtimeAnimatorController.animationClips;
        List <AnimationClip> _ListClips = new List <AnimationClip>();

        foreach (var item in clips)
        {
            _ListClips.Add(item);
        }
        AnimationClip clip = _ListClips.Find(p => p.name.StartsWith(clipName));

        if (clip != null)
        {
            AnimationEvent animEnd = new AnimationEvent
            {
                functionName = fun//响应事件
            };
            if (timeWeight < 0)
            {
                animEnd.time = clip.length; //设定对应事件触发时间点为结尾
            }
            else
            {
                animEnd.time = clip.length * timeWeight;
            }
            clip.AddEvent(animEnd); //把事件添加到时间轴上
            _Animator.Rebind();     //重新绑定动画器属性。
        }
    }
Beispiel #28
0
        /// <summary>
        /// 注册时间轴事件
        /// </summary>
        /// <param name="name">Name.</param>
        /// <param name="time">Time.</param>
        /// <param name="handler">Handler.</param>
        public void RegisterAnimationEventCallback(string name, float time, AnimationTimeLineDelegate handler)
        {
            Animator animator = this.GetComponent <Animator> ();

            if (animator == null)
            {
                return;
            }

            RuntimeAnimatorController controller = animator.runtimeAnimatorController;

            for (int i = 0; i < controller.animationClips.Length; i++)
            {
                AnimationClip clip = controller.animationClips [i];
                if (clip.name != name)
                {
                    continue;
                }

                TimeLineCallBack callback = new TimeLineCallBack();
                callback.Handler      = handler;
                callback.Name         = name;
                callback.Time         = time;
                callback.EndAnimation = false;

                AnimationEvent animationEvent = new AnimationEvent();
                animationEvent.time                     = time;
                animationEvent.functionName             = "OnTimeLineEvent";
                animationEvent.objectReferenceParameter = callback as Object;
                clip.AddEvent(animationEvent);
            }
        }
Beispiel #29
0
    private void AddEvent(string clipName, string functionName, float time)
    {
        AnimationClip foundClip = null;

        foreach (var tmpClip in animator.runtimeAnimatorController.animationClips)
        {
            if (tmpClip.name == clipName)
            {
                foundClip = tmpClip;
                break;
            }
        }
        if (foundClip != null)
        {
            AnimationEvent animationEvent = new AnimationEvent();
            animationEvent.functionName   = functionName;
            animationEvent.floatParameter = foundClip.length - time;
            animationEvent.time           = time;
            foundClip.AddEvent(animationEvent);
        }
        else
        {
            Debug.LogError("Clip not found");
        }
    }
Beispiel #30
0
        protected void AddAnEvent(AnimationEvent evt, string functionName, float time)
        {
            if (animator != null)
            {
                if (evt != null)
                {
                    evt.time           = time;
                    evt.functionName   = functionName;
                    evt.messageOptions = SendMessageOptions.DontRequireReceiver;
                    if (mainClip == null)
                    {
                        //第二次就读不到,可能是unity4.6的bug
                        AnimatorClipInfo[] anims = animator.GetCurrentAnimatorClipInfo(0);
                        if (anims.Length > 0)
                        {
                            mainClip = anims[0].clip;
                        }
                    }

                    if (mainClip != null)
                    {
                        mainClip.AddEvent(evt);
                    }
                }
            }
        }
Beispiel #31
0
        public void Test_AddEvent()
        {
            var clip = new AnimationClip (100, "Clip");
            var count = 0;
            var args1 = new EventArgs ();
            var args2 = new EventArgs ();
            clip.AddEvent (0, (x, y) => count++, args1);
            clip.AddEvent (1, (x, y) => count++, args2);

            Assert.AreEqual (2, clip.EventCount);
            Assert.AreEqual (2, clip.Events.Count ());

            Assert.AreEqual (0, clip.GetEvent (0).Position);
            Assert.AreEqual (1, clip.GetEvent (1).Position);
            Assert.AreEqual (args1, clip.GetEvent (0).Args);
            Assert.AreEqual (args2, clip.GetEvent (1).Args);
        }
        public void Test_OnAnimate_Event_2()
        {
            var clip = new AnimationClip (100, "TestClip");
            clip.WrapMode = WrapMode.Once;
            clip.Play ();

            var args1 = new MyEventArgs (1);
            var args2 = new MyEventArgs (2);
            var args3 = new MyEventArgs (3);

            var count = 0;
            clip.AddEvent (0, (sender, args) => count = 1, null);
            clip.AddEvent (50, (sender, args) => count = 2, null);
            clip.AddEvent (100, (sender, args) => count += 1, null);
            clip.AddEvent (100, (sender, args) => count += 1, null);

            var anim = new AnimationController ();
            anim.AddClip (clip);

            // 停止中のクリップはイベントを発火しない
            clip.Stop ();
            anim.OnAnimate (0, 0);
            Assert.AreEqual (0, count);

            clip.Play ();

            // 逆再生中の dtime は逆方向
            // clip.SetSpeed (-1, 50);
            // anim.OnAnimate (40, 10);
            // Assert.AreEqual (2, count);

            count = 0;
            clip.Speed = 1;

            // 同じポジションで重複したイベントは両方発火
            anim.OnAnimate (100, 0);
            Assert.AreEqual (2, count);
        }
        public void Test_OnAnimate_Event_Handler()
        {
            var clip = new AnimationClip (100, "TestClip");
            clip.WrapMode = WrapMode.Once;
            clip.Play ();

            var count = 0;
            clip.AddEvent (0, (x, y) => count = 1, null);
            clip.AddEvent (50, (x, y) => count = 2, null);
            clip.AddEvent (100, (x, y) => count = 3, null);

            var anim = new AnimationController ();
            anim.AddClip (clip);

            anim.OnAnimate (0, 0);
            Assert.AreEqual (1, count);

            anim.OnAnimate (50, 0);
            Assert.AreEqual (2, count);

            anim.OnAnimate (100, 0);
            Assert.AreEqual (3, count);
        }
        public void Test_OnAnimate_Event_Args()
        {
            var clip = new AnimationClip (100, "TestClip");
            clip.WrapMode = WrapMode.Once;
            clip.Play ();

            var args1 = new MyEventArgs (1);
            var args2 = new MyEventArgs (2);
            var args3 = new MyEventArgs (3);

            var count = 0;
            clip.AddEvent (0, (sender, args) => count = ((MyEventArgs)args).Value, args1);
            clip.AddEvent (50, (sender, args) => count = ((MyEventArgs)args).Value, args2);
            clip.AddEvent (100, (sender, args) => count = ((MyEventArgs)args).Value, args3);

            var anim = new AnimationController ();
            anim.AddClip (clip);

            anim.OnAnimate (0, 0);
            Assert.AreEqual (1, count);

            anim.OnAnimate (50, 0);
            Assert.AreEqual (2, count);

            anim.OnAnimate (100, 0);
            Assert.AreEqual (3, count);
        }
Beispiel #35
0
        public void Test_RemoveEvent()
        {
            var clip = new AnimationClip (100, "Clip");
            var count = 0;
            var args1 = new EventArgs ();
            var args2 = new EventArgs ();
            clip.AddEvent (0, (x, y) => count++, args1);
            clip.AddEvent (1, (x, y) => count++, args2);

            clip.RemoveEvent (0);
            clip.RemoveEvent (0);

            Assert.AreEqual (0, clip.EventCount);
            Assert.AreEqual (0, clip.Events.Count ());
        }