public void StartTimelineInstance()
    {
        // instantiate the nested timeline
        m_generatedNestedTimelineObject = Instantiate(m_nestedCassetteTimeline, transform);
        var nestedTimeline = m_generatedNestedTimelineObject.GetComponent <PlayableDirector>();

        nestedTimeline.stopped += (director) =>
        {
            // when the nested timeline finished playing, the parent is allowed to move forward the set marker
            timelineConditionMet = true;
            Destroy(m_generatedNestedTimelineObject);
        };

        // create parent timeline bindings
        foreach (var track in m_timelineDirector.playableAsset.outputs)
        {
            if (track.sourceObject is ControlTrack)
            {
                ControlTrack ct = (ControlTrack)track.sourceObject;
                if (ct.name == "nestedTimeline")
                {
                    foreach (TimelineClip timelineClip in ct.GetClips())
                    {
                        ControlPlayableAsset playableAsset = (ControlPlayableAsset)timelineClip.asset;
                        playableAsset.postPlayback   = ActivationControlPlayable.PostPlaybackState.Revert;
                        playableAsset.updateDirector = false;
                        playableAsset.updateParticle = false;

                        // set the reference of the nested timeline to the parent playable asset
                        m_timelineDirector.SetReferenceValue(playableAsset.sourceGameObject.exposedName, nestedTimeline.gameObject);
                        // rebind the playableGraph of the parent timeline director
                        m_timelineDirector.RebindPlayableGraphOutputs();
                    }
                }
            }
        }

        // now I can play the timeline
        m_timelineDirector.Play();
    }
Exemplo n.º 2
0
    public void BuildTimeline()
    {
        Debug.Log("Buidilng Timeline");
        TimelineAsset timelineAsset = (TimelineAsset)timeline.playableAsset;

        //TODO: make it so that it deletes all tracks and rebuilds them every each time
        for (int i = 0; i < timelineAsset.rootTrackCount; i++)
        {
            timelineAsset.DeleteTrack(timelineAsset.GetRootTrack(0));
        }
        for (int i = 0; i < timelineAsset.outputTrackCount; i++)
        {
            timelineAsset.DeleteTrack(timelineAsset.GetOutputTrack(0));
        }

        ControlTrack controlTrack = (ControlTrack)timelineAsset.CreateTrack(typeof(ControlTrack), null, "Control Track");

        clipToTime = new Dictionary <ClipSettings, double>();

        // map all timeline clips first
        for (int i = 0; i < timelineClips.Count; i++)
        {
            TimelineClip         tc  = controlTrack.CreateDefaultClip();
            ControlPlayableAsset cpa = tc.asset as ControlPlayableAsset;
            cpa.sourceGameObject.exposedName = UnityEditor.GUID.Generate().ToString();
            timeline.SetReferenceValue(cpa.sourceGameObject.exposedName, timelineClips[i].timelineTrack.gameObject);

            if (i != 0)
            {
                tc.start = tc.start + 1;
            }

            clipToTime.Add(timelineClips[i], tc.start);

            tc.duration = timelineClips[i].timelineTrack.duration;
        }

        //map remix clips
        int j = 0;

        foreach (TimelineClip tc in controlTrack.GetClips())
        {
            foreach (TriggerMapping triggerMapping in timelineClips[j].triggers)
            {
                TimeMachineTrack timeMachineTrack = (TimeMachineTrack)timelineAsset.CreateTrack(typeof(TimeMachineTrack), null, "Trigger Track");
                if (triggerMapping.type == TriggerType.CONTINUOUS)
                {
                    TimelineClip     triggerCip = timeMachineTrack.CreateDefaultClip();
                    TimeMachineAsset tma        = triggerCip.asset as TimeMachineAsset;

                    tma.action          = TimeMachineBehavior.TimeMachineAction.JumpToTime;
                    tma.condition       = TimeMachineBehavior.Condition.TriggerOff;
                    tma.timeToJumpTo    = (float)clipToTime[triggerMapping.targetTrack];
                    triggerCip.start    = tc.start;
                    triggerCip.duration = tc.duration;


                    tma.trigger.exposedName = UnityEditor.GUID.Generate().ToString();
                    // tma.timeToJumpTo = triggerMapping.timeToJumpTo;
                    timeline.SetReferenceValue(tma.trigger.exposedName, triggerMapping.trigger);
                }
                else
                {
                    TimelineClip     triggerCip = timeMachineTrack.CreateDefaultClip();
                    TimeMachineAsset tma        = triggerCip.asset as TimeMachineAsset;

                    tma.action          = TimeMachineBehavior.TimeMachineAction.JumpToTime;
                    tma.condition       = TimeMachineBehavior.Condition.TriggerOff;
                    tma.timeToJumpTo    = (float)clipToTime[triggerMapping.targetTrack];
                    triggerCip.start    = tc.end;
                    triggerCip.duration = 1;

                    tma.trigger.exposedName = UnityEditor.GUID.Generate().ToString();
                    timeline.SetReferenceValue(tma.trigger.exposedName, triggerMapping.trigger);
                }
            }
            j++;
        }
        Debug.Log("Finished");
    }
Exemplo n.º 3
0
    public override void ExecuteState(StateMachine stateMachine, IState prevState, object param1, object param2)
    {
        base.ExecuteState(stateMachine, prevState, param1, param2);

        mCurrSkillID = (int)param1;
        mChangeState = false;

        mSkillInfo = SkillConfig.singleton.GetSkillInfo(mCurrSkillID);
        if (mSkillInfo == null || mSkillInfo.mTimeline == null)
        {
            return;
        }
        mTargetRole = mRole.mRoleData.GetTargetRole();

        if (Skill.ExecuteSkill(mRole, mTargetRole, mSkillInfo))
        {
            mChangeState = false;
        }
        else
        {
            StateComplete();
            return;
        }

        // 获取timeline
        mDirector = mSkillInfo.mTimeline.GetComponent <PlayableDirector>();
        mDirector.Stop();

        // 取出timeline 左边的名字进行绑定右边的资源
        foreach (PlayableBinding bind in mDirector.playableAsset.outputs)
        {
            if (bind.streamName == "Self")
            {
                AnimationTrack animationTrack = bind.sourceObject as AnimationTrack;
                mDuringTime = (float)animationTrack.duration;
                mBeginTime  = Time.fixedTime;
                mDirector.SetGenericBinding(bind.sourceObject, mAnimator);
            }
            else if (bind.streamName == "Target")
            {
                mDirector.SetGenericBinding(bind.sourceObject, mTargetRole.mAnimator);

                mRole.transform.position = -mRole.transform.forward * mSkillInfo.mAtkDistance + mTargetRole.transform.position;

                mRole.mRoleData.SetForward(mTargetRole.transform.position, mRole.transform.position);
                mRole.transform.rotation = Quaternion.LookRotation(mRole.mRoleData.GetForward());

                mTargetRole.mRoleData.SetForward(mRole.transform.position, mTargetRole.transform.position);
                mTargetRole.transform.rotation = Quaternion.LookRotation(mTargetRole.mRoleData.GetForward());
            }
            else if (bind.streamName == "SelfEffect")
            {
                mDirector.SetGenericBinding(bind.sourceObject, mSkillInfo.mSelfEffect);
            }
            else if (bind.streamName == "TargetEffect")
            {
                mDirector.SetGenericBinding(bind.sourceObject, mSkillInfo.mTargetEffect);
            }
            else if (bind.streamName == "Control Track")
            {
                ControlTrack ct = bind.sourceObject as ControlTrack;
                foreach (var clip in ct.GetClips())
                {
                    ControlPlayableAsset playableAsset = clip.asset as ControlPlayableAsset;
                    mDirector.SetReferenceValue(playableAsset.sourceGameObject.exposedName, mRole.gameObject);
                }
            }
            else if (bind.streamName == "Playable Track")
            {
                PlayableTrack ct = bind.sourceObject as PlayableTrack;
                foreach (TimelineClip clip in ct.GetClips())
                {
                    PlayableAssetEx playableAsset = clip.asset as PlayableAssetEx;
                    if (playableAsset)
                    {
                        // 1.自定义脚本获取绑定 自定义的变量
                        playableAsset.mParamAttackTL = this;
                    }
                }
            }
        }

        mDirector.Play(); // 播放timeline
    }