Ejemplo n.º 1
0
        static ScriptableObject CloneReferencedPlayableAsset(ScriptableObject original, PlayableDirector directorInstance)
        {
            var clone = Object.Instantiate(original);

            TimelineUndo.RegisterCreatedObjectUndo(clone, "Create clip");
            if (clone == null || (clone as IPlayableAsset) == null)
            {
                throw new InvalidCastException("could not cast instantiated object into IPlayableAsset");
            }

            if (directorInstance != null)
            {
                // Use serialize object to make a copy
                var originalObject      = new SerializedObject(original);
                var cloneObject         = new SerializedObject(clone);
                SerializedProperty prop = originalObject.GetIterator();
                if (prop.Next(true))
                {
                    do
                    {
                        cloneObject.CopyFromSerializedProperty(prop);
                    } while (prop.Next(false));
                }
                cloneObject.ApplyModifiedProperties();

                EditorUtility.SetDirty(directorInstance);

                // The exposedName of exposed properties needs to be cleared otherwise the clone will act as an instance
                var exposedRefs = clone.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Where(f => f.FieldType.IsGenericType && f.FieldType.GetGenericTypeDefinition() == typeof(ExposedReference <>)).ToList();
                foreach (FieldInfo fi in exposedRefs)
                {
                    var exposedRefInstance  = fi.GetValue(clone);
                    var exposedNameProperty = exposedRefInstance.GetType().GetField("exposedName");
                    if (exposedNameProperty != null)
                    {
                        var exposedNameValue = (PropertyName)exposedNameProperty.GetValue(exposedRefInstance);

                        bool isValid           = false;
                        var  originalReference = directorInstance.GetReferenceValue(exposedNameValue, out isValid);

                        if (isValid)
                        {
                            // generate new reference in directorInstance
                            var newPropertyName = new PropertyName(GUID.Generate().ToString());
                            directorInstance.SetReferenceValue(newPropertyName, originalReference);
                            exposedNameProperty.SetValue(exposedRefInstance, newPropertyName);

                            if (!EditorApplication.isPlaying)
                            {
                                EditorSceneManager.MarkSceneDirty(directorInstance.gameObject.scene);
                            }
                        }
                    }
                    fi.SetValue(clone, exposedRefInstance);
                }
            }

            return(clone);
        }
        public static void SetFightContext([NotNull] PlayableDirector playableDirector, FightContext fightContext)
        {
            //IL_000d: Unknown result type (might be due to invalid IL or missing references)
            PropertyName val = default(PropertyName);

            val._002Ector("fight");
            playableDirector.SetReferenceValue(val, fightContext);
        }
Ejemplo n.º 3
0
        public IEnumerator CreatePlayableAsset()
        {
            EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects);

            //Add director
            GameObject       directorGo = new GameObject("Director");
            PlayableDirector director   = directorGo.AddComponent <PlayableDirector>();

            //Setup scene cache
            GameObject       sceneCacheGo     = new GameObject();
            SceneCachePlayer sceneCachePlayer = sceneCacheGo.AddComponent <SceneCachePlayer>();

            Assert.IsFalse(sceneCachePlayer.IsSceneCacheOpened());
            SceneCachePlayerEditorUtility.ChangeSceneCacheFile(sceneCachePlayer, Path.GetFullPath(MeshSyncTestEditorConstants.CUBE_TEST_DATA_PATH));


            //Create timeline asset
            TimelineAsset asset = ScriptableObject.CreateInstance <TimelineAsset>();

            director.playableAsset = asset;

            //Create PlayableAsset/Track/ etc
            SceneCachePlayableAsset playableAsset   = ScriptableObject.CreateInstance <SceneCachePlayableAsset>();
            SceneCacheTrack         sceneCacheTrack = asset.CreateTrack <SceneCacheTrack>(null, "TestSceneCacheTrack");
            TimelineClip            clip            = sceneCacheTrack.CreateDefaultClip();

            clip.asset = playableAsset;
            director.SetReferenceValue(playableAsset.GetSceneCachePlayerRef().exposedName, sceneCachePlayer);


            //Select gameObject and open Timeline Window. This will trigger the TimelineWindow's update etc.
            EditorApplication.ExecuteMenuItem("Window/Sequencing/Timeline");
            Selection.activeTransform = directorGo.transform;
            yield return(null);

            director.time = 0;
            yield return(null);

            Assert.AreEqual(0, sceneCachePlayer.GetRequestedNormalizedTime());
            double timePerFrame = 1.0f / sceneCacheTrack.timelineAsset.editorSettings.fps;

            double directorTime = clip.start + clip.duration - timePerFrame;

            SetDirectorTime(director, directorTime);
            yield return(null);

            //Check clipData and curve
            SceneCacheClipData clipData = playableAsset.GetBoundClipData();

            Assert.IsNotNull(clipData);
            AnimationCurve curve = clipData.GetAnimationCurve();

            Assert.IsNotNull(curve);
            float normalizedTime = curve.Evaluate((float)directorTime);


            Assert.AreEqual(normalizedTime, sceneCachePlayer.GetRequestedNormalizedTime());
        }
Ejemplo n.º 4
0
        private static ScriptableObject CloneReferencedPlayableAsset(ScriptableObject original, PlayableDirector directorInstance)
        {
            ScriptableObject scriptableObject = Object.Instantiate <ScriptableObject>(original);

            if (scriptableObject == null || !(scriptableObject is IPlayableAsset))
            {
                throw new InvalidCastException("could not cast instantiated object into IPlayableAsset");
            }
            if (directorInstance != null)
            {
                SerializedObject   serializedObject  = new SerializedObject(original);
                SerializedObject   serializedObject2 = new SerializedObject(scriptableObject);
                SerializedProperty iterator          = serializedObject.GetIterator();
                if (iterator.Next(true))
                {
                    do
                    {
                        serializedObject2.CopyFromSerializedProperty(iterator);
                    }while (iterator.Next(false));
                }
                serializedObject2.ApplyModifiedProperties();
                EditorUtility.SetDirty(directorInstance);
            }
            if (directorInstance != null)
            {
                List <FieldInfo> list = (from f in scriptableObject.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
                                         where f.FieldType.IsGenericType && f.FieldType.GetGenericTypeDefinition() == typeof(ExposedReference)
                                         select f).ToList <FieldInfo>();
                foreach (FieldInfo current in list)
                {
                    object    value = current.GetValue(scriptableObject);
                    FieldInfo field = value.GetType().GetField("exposedName");
                    if (field != null)
                    {
                        PropertyName propertyName   = (PropertyName)field.GetValue(value);
                        bool         flag           = false;
                        Object       referenceValue = directorInstance.GetReferenceValue(propertyName, ref flag);
                        if (flag)
                        {
                            PropertyName propertyName2 = new PropertyName(GUID.Generate().ToString());
                            directorInstance.SetReferenceValue(propertyName2, referenceValue);
                            field.SetValue(value, propertyName2);
                        }
                    }
                    current.SetValue(scriptableObject, value);
                }
            }
            IEnumerable <FieldInfo> enumerable = from f in scriptableObject.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
                                                 where !f.IsNotSerialized && f.FieldType == typeof(AnimationClip)
                                                 select f;

            foreach (FieldInfo current2 in enumerable)
            {
                current2.SetValue(scriptableObject, TimelineHelpers.CloneAnimationClipIfRequired(current2.GetValue(scriptableObject) as AnimationClip, original));
            }
            return(scriptableObject);
        }
 public void Bind(IEnumerable <IDynamicBind <CinemachineVirtualCamera> > RefData, PlayableDirector director)
 {
     foreach (var item in RefData)
     {
         TrackAsset   track    = item.Timeline.GetOutputTracks().FirstOrDefault(x => x.name == item.TrackName);
         TimelineClip clip     = track.GetClips().FirstOrDefault(x => x.displayName == item.ClipName);
         var          VcamClip = clip.asset as CinemachineShot;
         director.SetReferenceValue(VcamClip.VirtualCamera.exposedName, _BindTable[item.ListKey]);
     }
 }
        public static void SetContextProvider([NotNull] PlayableDirector playableDirector, [NotNull] ITimelineContextProvider provider)
        {
            //IL_0014: Unknown result type (might be due to invalid IL or missing references)
            PropertyName val = default(PropertyName);

            val._002Ector("context");
            Object timelineBinding = provider.GetTimelineBinding();

            playableDirector.SetReferenceValue(val, timelineBinding);
        }
Ejemplo n.º 7
0
 public void SetFxGameObject(PlayableDirector pd, GameObject go)
 {
     if (prefabGameObject.exposedName.GetHashCode() != 0)
     {
         pd.SetReferenceValue(prefabGameObject.exposedName, go);
     }
     else
     {
         prefabGameObject.defaultValue = go;
     }
 }
Ejemplo n.º 8
0
    public void Play(EventType eventType, IActorManager player, IActorManager opponent)
    {
        pd.playableAsset = GetTimelineAsset(eventType);
        TimelineAsset timeline = (TimelineAsset)pd.playableAsset;

        foreach (var track in timeline.GetOutputTracks())
        {
            if (track.name == "Player Animation")
            {
                pd.SetGenericBinding(track, player.GetAnimator());
            }
            else if (track.name == "Opponent Animation")
            {
                pd.SetGenericBinding(track, opponent.GetAnimator());
            }
            else if (track.name == "Player Script")
            {
                pd.SetGenericBinding(track, player);
                foreach (var clip in track.GetClips())
                {
                    LockAnimatorClip lockClip = (LockAnimatorClip)clip.asset;
                    lockClip.am.exposedName = System.Guid.NewGuid().ToString();
                    pd.SetReferenceValue(lockClip.am.exposedName, player);
                }
            }
            else if (track.name == "Opponent Script")
            {
                pd.SetGenericBinding(track, opponent);
                foreach (var clip in track.GetClips())
                {
                    LockAnimatorClip lockClip = (LockAnimatorClip)clip.asset;
                    lockClip.am.exposedName = System.Guid.NewGuid().ToString();
                    pd.SetReferenceValue(lockClip.am.exposedName, opponent);
                }
            }
        }
        pd.Evaluate();
        pd.Play();
    }
Ejemplo n.º 9
0
//----------------------------------------------------------------------------------------------------------------------    

    internal static TimelineClip AddSceneCacheTrackAndClip(PlayableDirector director, string trackName, 
        SceneCachePlayer sceneCachePlayer) 
    {
        TimelineAsset timelineAsset = director.playableAsset as TimelineAsset;
        Assert.IsNotNull(timelineAsset);
    
        SceneCacheTrack         sceneCacheTrack = timelineAsset.CreateTrack<SceneCacheTrack>(null, trackName);
        TimelineClip            clip            = sceneCacheTrack.CreateDefaultClip();
        SceneCachePlayableAsset playableAsset = clip.asset as SceneCachePlayableAsset;
        Assert.IsNotNull(playableAsset);
        director.SetReferenceValue(playableAsset.GetSceneCachePlayerRef().exposedName, sceneCachePlayer );
        return clip;
    }
Ejemplo n.º 10
0
        public void BindTimelineGlobal(PlayableDirector director)
        {
            foreach (var output in director.playableAsset.outputs)
            {
                if (!output.sourceObject || director.GetGenericBinding(output.sourceObject))
                {
                    continue;
                }
                GameObject go = PlayableManager.I.GetBindTarget(output.streamName);
                if (!go)
                {
                    continue;
                }
                if (output.outputTargetType.Equals(typeof(GameObject)))
                {
                    director.SetGenericBinding(output.sourceObject, go);
                }
                else
                {
                    var bind = go.GetComponent(output.outputTargetType);
                    director.SetGenericBinding(output.sourceObject, bind);
                }

                if (!(output.sourceObject is CinemachineTrack))
                {
                    continue;
                }
                var  cinemachineTrack = output.sourceObject as CinemachineTrack;
                bool b;
                foreach (var clip in cinemachineTrack.GetClips())
                {
                    var cinemachineShot = clip.asset as CinemachineShot;
                    if (director.GetReferenceValue(cinemachineShot.VirtualCamera.exposedName, out b))
                    {
                        continue;
                    }
                    GameObject go2 = PlayableManager.I.GetBindTarget(clip.displayName);
                    if (!go2)
                    {
                        continue;
                    }
                    var vc = go2.GetComponent <Cinemachine.CinemachineVirtualCameraBase>();
                    director.SetReferenceValue(cinemachineShot.VirtualCamera.exposedName, vc);
                }
            }
        }
Ejemplo n.º 11
0
    public void SetupPlayableDirector()
    {
        PlayableDirector pd = GetComponent <PlayableDirector>();

        if (pd == null)
        {
            pd = gameObject.AddComponent <PlayableDirector>();
        }
        pd.playableAsset     = tl;
        pd.playOnAwake       = playOnAwake;
        pd.extrapolationMode = wrapMode;
        pd.initialTime       = initTime;

        if (bindingInfos != null && bindingInfos.Length > 0)
        {
            int trackCount = tl.outputTrackCount;
            foreach (var item in bindingInfos)
            {
                if (item.index < 0 || item.index >= trackCount || item.obj == null)
                {
                    continue;
                }
                var track = tl.GetOutputTrack(item.index);
                if (track != null)
                {
                    pd.SetGenericBinding(track, item.obj);
                }
            }
        }

        if (exposInfos != null && exposInfos.Length > 0)
        {
            foreach (var item in exposInfos)
            {
                if (!string.IsNullOrEmpty(item.id) && item.obj != null)
                {
                    pd.SetReferenceValue(item.id, item.obj);
                }
            }
        }
    }
    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();
    }
Ejemplo n.º 13
0
    public void BindToPlayableDirector(PlayableDirector playableDirector)
    {
        foreach (var output in playableDirector.playableAsset.outputs)
        {
            Binding binding = null;
            if (output.sourceObject is CinemachineTrack)
            {
                CinemachineTrack cinemachineTrack = output.sourceObject as CinemachineTrack;
                if (bindingMap.TryGetValue(cinemachineTrack.name, out binding))
                {
                    playableDirector.SetGenericBinding(cinemachineTrack, binding.cinemachineBrain);
                }

                foreach (var clip in cinemachineTrack.GetClips())
                {
                    if (bindingMap.TryGetValue(clip.displayName, out binding))
                    {
                        var cinemachineShot = clip.asset as CinemachineShot;
                        playableDirector.SetReferenceValue(cinemachineShot.VirtualCamera.exposedName, binding.cinemachineVCam);
                    }
                }
            }
            else if (output.sourceObject is AnimationTrack)
            {
                AnimationTrack animationTrack = output.sourceObject as AnimationTrack;
                if (bindingMap.TryGetValue(animationTrack.name, out binding))
                {
                    playableDirector.SetGenericBinding(animationTrack, binding.animator);
                }
            }
            else if (output.sourceObject != null)
            {
                if (bindingMap.TryGetValue(output.sourceObject.name, out binding))
                {
                    playableDirector.SetGenericBinding(output.sourceObject, binding.gameObject);
                }
            }
        }
    }
            public void PrepareBindings(PlayableAsset asset)
            {
                if (_playableDirector == null)
                {
                    _playableDirector = GetComponent <PlayableDirector>();
                }

                PlayableAssetData assetData = GetAssetData(asset);

                if (assetData != null)
                {
                    for (int i = 0; i < assetData._sceneBindings.Length; i++)
                    {
                        _playableDirector.SetGenericBinding(assetData._sceneBindings[i]._key, assetData._sceneBindings[i]._value);
                    }

                    for (int i = 0; i < assetData._exposedReferences.Length; i++)
                    {
                        _playableDirector.SetReferenceValue(assetData._exposedReferences[i]._key, assetData._exposedReferences[i]._value);
                    }
                }
            }
Ejemplo n.º 15
0
        public IEnumerator TestTimelineTrack()
        {
            director.Play();
            exporter.MaxCaptureFrame = 30;
            yield return(RecordAlembic());

            deleteFileList.Add(exporter.Recorder.Settings.OutputPath);
            var go       = TestAbcImported(exporter.Recorder.Settings.OutputPath);
            var root     = PrefabUtility.InstantiatePrefab(go) as GameObject;
            var player   = root.GetComponent <AlembicStreamPlayer>();
            var timeline = director.playableAsset as TimelineAsset;
            var abcTrack = timeline.CreateTrack <AlembicTrack>(null, "");
            var clip     = abcTrack.CreateClip <AlembicShotAsset>();
            var abcAsset = clip.asset as AlembicShotAsset;
            var refAbc   = new ExposedReference <AlembicStreamPlayer> {
                exposedName = Guid.NewGuid().ToString()
            };

            abcAsset.StreamPlayer = refAbc;
            director.SetReferenceValue(refAbc.exposedName, player);
            director.RebuildGraph();
            var cubeGO = root.GetComponentInChildren <MeshRenderer>().gameObject;

            director.time = 0;
            director.Evaluate();
            yield return(null);

            var t0 = cubeGO.transform.position;

            director.time = player.Duration;
            director.Evaluate();
            yield return(null);

            var t1 = cubeGO.transform.position;

            Assert.AreNotEqual(t0, t1);
        }
    public void BindVirtualCameraAndPlayFromDirector(int i, int j, CinemachineVirtualCamera virtualCamera)
    {
        if (playableDirectors.Count <= i || playableDirectors[i] == null)
        {
            Debug.LogWarning($"{name} playableDirector at current idx {i} is null");
            return;
        }

        if (timelines.Count <= j || timelines[j] == null)
        {
            Debug.LogWarning($"{name} timeline at current idx {j} is null");
            return;
        }

        PlayableDirector director = playableDirectors[i];
        TimelineAsset    timeline = timelines[j];

        foreach (var track in timeline.GetOutputTracks())
        {
            var clips = track.GetClips();

            foreach (TimelineClip clip in clips)
            {
                var shot = clip.asset as CinemachineShot;

                if (shot == null)
                {
                    continue;
                }

                director.SetReferenceValue(shot.VirtualCamera.exposedName, virtualCamera);
            }
        }

        PlayableDirectorPlayFromTimelines(i, j);
    }
Ejemplo n.º 17
0
    public void PlayFrontStab(ActorManager attack, ActorManager victim)
    {
        pd.playableAsset = Instantiate(frontStab);

        TimelineAsset timeline = (TimelineAsset)pd.playableAsset;

        foreach (var track in timeline.GetOutputTracks())
        {
            if (track.name == "Attacker Script")
            {
                pd.SetGenericBinding(track, attack);
                foreach (var clip in track.GetClips())
                {
                    AmPlayableClip      amClip      = (AmPlayableClip)clip.asset;
                    AmPlayableBehaviour amBehaviour = amClip.template;
                    amClip.am.exposedName = System.Guid.NewGuid().ToString();
                    pd.SetReferenceValue(amClip.am.exposedName, attack);
                }
            }
            else if (track.name == "Victim Script")
            {
                pd.SetGenericBinding(track, victim);
                foreach (var clip in track.GetClips())
                {
                    AmPlayableClip      amClip      = (AmPlayableClip)clip.asset;
                    AmPlayableBehaviour amBehaviour = amClip.template;
                    amClip.am.exposedName = System.Guid.NewGuid().ToString();
                    pd.SetReferenceValue(amClip.am.exposedName, victim);
                }
            }
            else if (track.name == "Attacker Animation")
            {
                pd.SetGenericBinding(track, attack.ac.anim);
            }
            else if (track.name == "Victim Animation")
            {
                pd.SetGenericBinding(track, victim.ac.anim);
            }
        }

        pd.Evaluate();
        pd.Play();
    }
Ejemplo n.º 18
0
 private void TeleportBind(TeleportObject tpObj, GameObject obj_to_move, Transform start_pos, Transform end_pos)
 {
     tpObj.ThingToMove.exposedName    = UnityEditor.GUID.Generate().ToString();
     tpObj.StartTransform.exposedName = UnityEditor.GUID.Generate().ToString();
     tpObj.EndTransform.exposedName   = UnityEditor.GUID.Generate().ToString();
     director.SetReferenceValue(tpObj.ThingToMove.exposedName, obj_to_move);
     director.SetReferenceValue(tpObj.StartTransform.exposedName, start_pos);
     director.SetReferenceValue(tpObj.EndTransform.exposedName, end_pos);
 }
Ejemplo n.º 19
0
    // Start is called before the first frame update
    void Start()
    {
        playable    = gameObject.GetComponent <PlayableDirector>();
        light       = gameObject.GetComponent <Light>();
        bindingDict = new Dictionary <string, PlayableBinding>();
        foreach (var bind in playable.playableAsset.outputs)
        {
            bindingDict.Add(bind.streamName, bind);
        }

        // 动态绑定轨道中的节点 SetGenericBinding
//        playable.SetGenericBinding(bindingDict["LightTrack1"].sourceObject, light);
        playable.SetGenericBinding(bindingDict["Animation1"].sourceObject, sphere);


        // 动态绑定轨道中clip的节点 SetReferenceValue
        foreach (var track in ((TimelineAsset)playable.playableAsset).GetOutputTracks())
        {
//            track.muted = false;
            foreach (var clip in track.GetClips())
            {
                LightControlAsset asset = clip.asset as LightControlAsset;
                if (asset != null)
                {
                    playable.SetReferenceValue(asset.light.exposedName, light);
                }
                ControlPlayableAsset asset2 = clip.asset as ControlPlayableAsset;
                if (asset2 != null)
                {
                    playable.SetReferenceValue(asset2.sourceGameObject.exposedName, sphere);
                }
            }
        }
        playable.SetGenericBinding(bindingDict["ActivationTrack"].sourceObject, null);
//        playable.RebuildGraph();
        // 获取track信息
        TimelineAsset timelineAsset = (TimelineAsset)playable.playableAsset;
//        timelineAsset.DeleteTrack()
//        timelineAsset.A
        var count = timelineAsset.outputTrackCount;

        for (int i = 1; i < count; i++)
        {
            TrackAsset asset = timelineAsset.GetOutputTrack(i);
            var        clips = asset.GetClips();
            foreach (TimelineClip clip in clips)
            {
                var playableAsset = (PlayableAsset)clip.asset;
                var lightAsset    = playableAsset as LightControlAsset;
                if (lightAsset != null)
                {
//                    lightAsset.behaviour.OnGraphStop();
                }
//                var behaviout = playableAsset.behaviour;
            }
        }

//        var graphCount = playable.playableGraph.GetOutputCount();
//        for (int i = 0; i < graphCount; i++)
//        {
//
////            var playable1 = playable.playableGraph.GetRootPlayable(i);
//            PlayableOutput output = playable.playableGraph.GetOutput(i);
//            var p1 = output.GetSourcePlayable();
////            p1.GetInputCount();
//            Playable i1 = p1.GetInput(1);
////            playable.playableAsset
////            i1.SetInputWeight(0);
//
////            output.SetWeight();
//            var graph = playable.playableGraph;
////            graph
//            var playable2 = output.GetSourcePlayable();
//        }
        playable.Play();
    }
Ejemplo n.º 20
0
 public void TransformToBind(LerpToMoveObjectAsset tpObj, GameObject obj_to_move, Transform end_pos)
 {
     tpObj.ObjectToMove.exposedName = UnityEditor.GUID.Generate().ToString();
     tpObj.LerpMoveTo.exposedName   = UnityEditor.GUID.Generate().ToString();
     playableDirector.SetReferenceValue(tpObj.ObjectToMove.exposedName, obj_to_move);
     playableDirector.SetReferenceValue(tpObj.LerpMoveTo.exposedName, end_pos);
 }
    // Use this for initialization
    void Awake()
    {
        List <List <string> > clipList = readFabula();

        foreach (List <string> clipItem in clipList)
        {
            Debug.Log("Clip:");
            foreach (string item in clipItem)
            {
                Debug.Log(item);
            }
        }

        timeline = (TimelineAsset)ScriptableObject.CreateInstance("TimelineAsset");

        PlayableDirector director = GetComponent <PlayableDirector>();

        TrackAsset    ctrack = timeline.CreateTrack <ControlTrack>(null, "control_track");
        PlayableTrack ntrack = timeline.CreateTrack <PlayableTrack>(null, "nav_track");

        foreach (List <string> clipitem_list in clipList)
        {
            string name = clipitem_list[0];
            string type = clipitem_list[1];

            if (type.Equals("animate"))
            {
                float  start         = float.Parse(clipitem_list[2]);
                float  dur           = float.Parse(clipitem_list[3]);
                string anim_location = clipitem_list[4];
                string animation_obj = clipitem_list[5];

                start_pos = GameObject.Find(anim_location).transform;
                var lerp_clip = ntrack.CreateClip <LerpMoveObjectAsset>();
                var lerpclip  = lerp_clip.asset as LerpMoveObjectAsset;

                var clip = ctrack.CreateDefaultClip();
                clip.start       = start;
                clip.duration    = dur;
                clip.displayName = name;
                animTimeline     = GameObject.Find(animation_obj);
                var controlAnim = clip.asset as ControlPlayableAsset;
                anim_transform = animTimeline.transform;
                anim_loc       = anim_transform.position;
                anim_rot       = anim_transform.rotation;

                setClipOffset(animTimeline, anim_loc, anim_rot);
                //List<TimelineClip> lerp_clips = target_lerp_track.GetClips().ToList();

                lerpclip.ObjectToMove.exposedName = UnityEditor.GUID.Generate().ToString();
                lerpclip.LerpMoveTo.exposedName   = UnityEditor.GUID.Generate().ToString();
                //director.SetReferenceValue(lerpclip.ObjectToMove.exposedName, movingObj);
                director.SetReferenceValue(lerpclip.LerpMoveTo.exposedName, start_pos);

                // Set control clip to be on fabula timeline
                controlAnim.sourceGameObject.exposedName = UnityEditor.GUID.Generate().ToString();
                director.SetReferenceValue(controlAnim.sourceGameObject.exposedName, animTimeline);
            }
            else if (type.Equals("navigate"))
            {
                float  start          = float.Parse(clipitem_list[2]);
                float  dur            = float.Parse(clipitem_list[3]);
                string start_location = clipitem_list[4];
                string end_location   = clipitem_list[5];
                string agent          = clipitem_list[6];
                float  speed          = float.Parse(clipitem_list[7]);

                //ntrack
                ////var clip = ctrack.CreateDefaultClip();
                var lerp_clip = ntrack.CreateClip <LerpMoveObjectAsset>();
                var clip      = ntrack.CreateClip <SetAgentTargetAsset>();


                //var navclip = clip.asset as SetAgentTargetAsset;
                lerp_clip.start       = start;
                lerp_clip.duration    = .05f;
                lerp_clip.displayName = "lerp";

                clip.start       = start + .05f;
                clip.duration    = dur - .05f;
                clip.displayName = name;
                GameObject   movingObj       = GameObject.Find(agent);
                NavMeshAgent navigatingAgent = movingObj.GetComponent <NavMeshAgent>();

                start_pos = GameObject.Find(start_location).transform;
                Transform end_pos = GameObject.Find(end_location).transform;

                var navclip  = clip.asset as SetAgentTargetAsset;
                var lerpclip = lerp_clip.asset as LerpMoveObjectAsset;



                navclip.AgentSpeed = speed;
                //navclip.Agent = navigatingAgent as NavMeshAgent;

                navclip.Target.exposedName = UnityEditor.GUID.Generate().ToString();
                navclip.Agent.exposedName  = UnityEditor.GUID.Generate().ToString();
                director.SetReferenceValue(navclip.Agent.exposedName, navigatingAgent);
                director.SetReferenceValue(navclip.Target.exposedName, end_pos);
                lerpclip.ObjectToMove.exposedName = UnityEditor.GUID.Generate().ToString();
                lerpclip.LerpMoveTo.exposedName   = UnityEditor.GUID.Generate().ToString();
                director.SetReferenceValue(lerpclip.ObjectToMove.exposedName, movingObj);
                director.SetReferenceValue(lerpclip.LerpMoveTo.exposedName, start_pos);
            }
            else
            {
                Debug.Log("incorrect clip type");
            }
        }

        director.Play(timeline);
    }
Ejemplo n.º 22
0
    public void PlayTimeline(string timelineName, ActorManager attacker, ActorManager victim)
    {
        if (playableDirector.state == PlayState.Playing)
        {
            return;
        }
        if (timelineName == "frontStab")
        {
            playableDirector.playableAsset = Instantiate(frontStab);
            //找到相应的timeline给导演
            TimelineAsset timeline = (TimelineAsset)playableDirector.playableAsset;
            foreach (var track in timeline.GetOutputTracks())
            {
                if (track.name == "Attacker Script")
                {
                    playableDirector.SetGenericBinding(track, attacker);
                    foreach (var clip in track.GetClips())
                    {
                        MySuperPlayableClip      myClip  = (MySuperPlayableClip)clip.asset;
                        MySuperPlayableBehaviour myBehav = myClip.template;
                        myBehav.myFloat = 111;
                        myClip.actorManager.exposedName = System.Guid.NewGuid().ToString();
                        playableDirector.SetReferenceValue(myClip.actorManager.exposedName, attacker);
                    }
                }
                else if (track.name == "Victim Script")
                {
                    playableDirector.SetGenericBinding(track, victim);
                    foreach (var clip in track.GetClips())
                    {
                        MySuperPlayableClip      myClip  = (MySuperPlayableClip)clip.asset;
                        MySuperPlayableBehaviour myBehav = myClip.template;
                        myBehav.myFloat = 222;
                        myClip.actorManager.exposedName = System.Guid.NewGuid().ToString();
                        playableDirector.SetReferenceValue(myClip.actorManager.exposedName, victim);
                    }
                }
                else if (track.name == "Attacker Animation")
                {
                    playableDirector.SetGenericBinding(track, attacker.actorController.animator);
                }
                else if (track.name == "Victim Animation")
                {
                    playableDirector.SetGenericBinding(track, victim.actorController.animator);
                }
            }

            playableDirector.Evaluate();

            playableDirector.Play();
        }
        else if (timelineName == "openBox")
        {
            playableDirector.playableAsset = Instantiate(openBox);
            //找到相应的timeline给导演
            TimelineAsset timeline = (TimelineAsset)playableDirector.playableAsset;
            foreach (var track in timeline.GetOutputTracks())
            {
                if (track.name == "Player Script")
                {
                    playableDirector.SetGenericBinding(track, attacker);
                    foreach (var clip in track.GetClips())
                    {
                        MySuperPlayableClip      myClip  = (MySuperPlayableClip)clip.asset;
                        MySuperPlayableBehaviour myBehav = myClip.template;
                        myClip.actorManager.exposedName = System.Guid.NewGuid().ToString();
                        playableDirector.SetReferenceValue(myClip.actorManager.exposedName, attacker);
                    }
                }
                else if (track.name == "Box Script")
                {
                    playableDirector.SetGenericBinding(track, victim);
                    foreach (var clip in track.GetClips())
                    {
                        MySuperPlayableClip      myClip  = (MySuperPlayableClip)clip.asset;
                        MySuperPlayableBehaviour myBehav = myClip.template;
                        myClip.actorManager.exposedName = System.Guid.NewGuid().ToString();
                        playableDirector.SetReferenceValue(myClip.actorManager.exposedName, victim);
                    }
                }
                else if (track.name == "Player Animation")
                {
                    playableDirector.SetGenericBinding(track, attacker.actorController.animator);
                }
                else if (track.name == "Box Animation")
                {
                    playableDirector.SetGenericBinding(track, victim.actorController.animator);
                }
            }

            playableDirector.Evaluate();

            playableDirector.Play();
        }
        else if (timelineName == "leverUp")
        {
            playableDirector.playableAsset = Instantiate(leverUp);
            //找到相应的timeline给导演
            TimelineAsset timeline = (TimelineAsset)playableDirector.playableAsset;
            foreach (var track in timeline.GetOutputTracks())
            {
                if (track.name == "Player Script")
                {
                    playableDirector.SetGenericBinding(track, attacker);
                    foreach (var clip in track.GetClips())
                    {
                        MySuperPlayableClip      myClip  = (MySuperPlayableClip)clip.asset;
                        MySuperPlayableBehaviour myBehav = myClip.template;
                        myClip.actorManager.exposedName = System.Guid.NewGuid().ToString();
                        playableDirector.SetReferenceValue(myClip.actorManager.exposedName, attacker);
                    }
                }
                else if (track.name == "Lever Script")
                {
                    playableDirector.SetGenericBinding(track, victim);
                    foreach (var clip in track.GetClips())
                    {
                        MySuperPlayableClip      myClip  = (MySuperPlayableClip)clip.asset;
                        MySuperPlayableBehaviour myBehav = myClip.template;
                        myClip.actorManager.exposedName = System.Guid.NewGuid().ToString();
                        playableDirector.SetReferenceValue(myClip.actorManager.exposedName, victim);
                    }
                }
                else if (track.name == "Player Animation")
                {
                    playableDirector.SetGenericBinding(track, attacker.actorController.animator);
                }
                else if (track.name == "Lever Animation")
                {
                    playableDirector.SetGenericBinding(track, victim.actorController.animator);
                }
            }

            playableDirector.Evaluate();

            playableDirector.Play();
        }
    }
Ejemplo n.º 23
0
    public void PlayFrontStab(string timelineName, ActorManager attcker, ActorManager victim)
    {
        if (timelineName == "frontStab")
        {
            pd.playableAsset = Instantiate(frontStab);

            TimelineAsset timeline = (TimelineAsset)pd.playableAsset;

            foreach (var track in timeline.GetOutputTracks())
            {
                if (track.name == "Attacker Scipt")
                {
                    pd.SetGenericBinding(track, attacker);
                    foreach (var clip in track.GetClips())
                    {
                        MyPlayableClip      myclip  = (MyPlayableClip)clip.asset;
                        MyPlayableBehaviour mybehav = myclip.template;
                        myclip.am.exposedName = System.Guid.NewGuid().ToString();
                        pd.SetReferenceValue(myclip.am.exposedName, attacker);
                    }
                }
                else if (track.name == "Victim Scipt")
                {
                    pd.SetGenericBinding(track, victim);
                    foreach (var clip in track.GetClips())
                    {
                        MyPlayableClip      myclip  = (MyPlayableClip)clip.asset;
                        MyPlayableBehaviour mybehav = myclip.template;
                        myclip.am.exposedName = System.Guid.NewGuid().ToString();
                        pd.SetReferenceValue(myclip.am.exposedName, victim);
                    }
                }
                else if (track.name == "Attacker Animator")
                {
                    pd.SetGenericBinding(track, attacker.ac.anim);
                }
                else if (track.name == "Victim Animator")
                {
                    pd.SetGenericBinding(track, victim.ac.anim);
                }
            }
            pd.Evaluate();
            pd.Play();
        }

        else if (timelineName == "openBox")
        {
            pd.playableAsset = Instantiate(openBox);

            TimelineAsset timeline = (TimelineAsset)pd.playableAsset;

            foreach (var track in timeline.GetOutputTracks())
            {
                if (track.name == "Player Scipt")
                {
                    pd.SetGenericBinding(track, attacker);
                    foreach (var clip in track.GetClips())
                    {
                        MyPlayableClip      myclip  = (MyPlayableClip)clip.asset;
                        MyPlayableBehaviour mybehav = myclip.template;
                        myclip.am.exposedName = System.Guid.NewGuid().ToString();
                        pd.SetReferenceValue(myclip.am.exposedName, attacker);
                    }
                }
                else if (track.name == "Box Scipt")
                {
                    pd.SetGenericBinding(track, victim);
                    foreach (var clip in track.GetClips())
                    {
                        MyPlayableClip      myclip  = (MyPlayableClip)clip.asset;
                        MyPlayableBehaviour mybehav = myclip.template;
                        myclip.am.exposedName = System.Guid.NewGuid().ToString();
                        pd.SetReferenceValue(myclip.am.exposedName, victim);
                    }
                }
                else if (track.name == "Player Animation")
                {
                    pd.SetGenericBinding(track, attacker.ac.anim);
                }
                else if (track.name == "Box Animation")
                {
                    pd.SetGenericBinding(track, victim.ac.anim);
                }
            }
            pd.Evaluate();
            pd.Play();
        }

        else if (timelineName == "leverUp")
        {
            pd.playableAsset = Instantiate(leverUp);

            TimelineAsset timeline = (TimelineAsset)pd.playableAsset;

            foreach (var track in timeline.GetOutputTracks())
            {
                if (track.name == "Player Scipt")
                {
                    pd.SetGenericBinding(track, attacker);
                    foreach (var clip in track.GetClips())
                    {
                        MyPlayableClip      myclip  = (MyPlayableClip)clip.asset;
                        MyPlayableBehaviour mybehav = myclip.template;
                        myclip.am.exposedName = System.Guid.NewGuid().ToString();
                        pd.SetReferenceValue(myclip.am.exposedName, attacker);
                    }
                }
                else if (track.name == "Lever Scipt")
                {
                    pd.SetGenericBinding(track, victim);
                    foreach (var clip in track.GetClips())
                    {
                        MyPlayableClip      myclip  = (MyPlayableClip)clip.asset;
                        MyPlayableBehaviour mybehav = myclip.template;
                        myclip.am.exposedName = System.Guid.NewGuid().ToString();
                        pd.SetReferenceValue(myclip.am.exposedName, victim);
                    }
                }
                else if (track.name == "Player Animation")
                {
                    pd.SetGenericBinding(track, attacker.ac.anim);
                }
                else if (track.name == "Lever Animation")
                {
                    pd.SetGenericBinding(track, victim.ac.anim);
                }
            }
            pd.Evaluate();
            pd.Play();
        }
    }
Ejemplo n.º 24
0
 public void Start()
 {
     playableDirector.SetReferenceValue("title", label);
 }
Ejemplo n.º 25
0
    public void PlayFrontStab(string timelineName, ActorManager attacker, ActorManager victim)
    {
        // if(pd.playableAsset != null)
        // {
        //     return;
        // }


        // if(pd.state == PlayState.Playing)
        // {
        //     return;
        // }


        if (timelineName == "frontStab")
        {
            pd.playableAsset = Instantiate(frontStab);

            TimelineAsset timeline = (TimelineAsset)pd.playableAsset;



            foreach (var track in timeline.GetOutputTracks())
            {
                if (track.name == "Attacker Script")
                {
                    pd.SetGenericBinding(track, attacker);
                    foreach (var clip in track.GetClips())
                    {
                        MySuperPlayableClip      myclip  = (MySuperPlayableClip)clip.asset;
                        MySuperPlayableBehaviour mybehav = myclip.template;
                        myclip.am.exposedName = System.Guid.NewGuid().ToString();
                        pd.SetReferenceValue(myclip.am.exposedName, attacker);
                    }
                }
                else if (track.name == "Victim Script")
                {
                    pd.SetGenericBinding(track, victim);
                    foreach (var clip in track.GetClips())
                    {
                        MySuperPlayableClip      myclip  = (MySuperPlayableClip)clip.asset;
                        MySuperPlayableBehaviour mybehav = myclip.template;
                        myclip.am.exposedName = System.Guid.NewGuid().ToString();
                        pd.SetReferenceValue(myclip.am.exposedName, victim);
                    }
                }
                else if (track.name == "Attacker Animation")
                {
                    pd.SetGenericBinding(track, attacker.ac.anim);
                }
                else if (track.name == "Victim Animation")
                {
                    pd.SetGenericBinding(track, victim.ac.anim);
                }
            }

            pd.Evaluate();
            pd.Play();
            // foreach (var trackBinding in pd.playableAsset.outputs)
            // {
            //     if (trackBinding.streamName == "Attacker Script")
            //     {
            //         pd.SetGenericBinding(trackBinding.sourceObject, attacker);
            //     }
            //     else if (trackBinding.streamName == "Victim Script")
            //     {
            //         pd.SetGenericBinding(trackBinding.sourceObject, victim);
            //     }
            //     else if (trackBinding.streamName == "Attacker Animation")
            //     {
            //         pd.SetGenericBinding(trackBinding.sourceObject, attacker.ac.anim);
            //     }
            //     else if (trackBinding.streamName == "Victim Animation")
            //     {
            //         pd.SetGenericBinding(trackBinding.sourceObject, victim.ac.anim);
            //     }
            // }
        }
        else if (timelineName == "openBox")
        {
            pd.playableAsset = Instantiate(openBox);

            TimelineAsset timeline = (TimelineAsset)pd.playableAsset;



            foreach (var track in timeline.GetOutputTracks())
            {
                if (track.name == "Player Script")
                {
                    pd.SetGenericBinding(track, attacker);
                    foreach (var clip in track.GetClips())
                    {
                        MySuperPlayableClip      myclip  = (MySuperPlayableClip)clip.asset;
                        MySuperPlayableBehaviour mybehav = myclip.template;
                        myclip.am.exposedName = System.Guid.NewGuid().ToString();
                        pd.SetReferenceValue(myclip.am.exposedName, attacker);
                    }
                }
                else if (track.name == "Box Script")
                {
                    pd.SetGenericBinding(track, victim);
                    foreach (var clip in track.GetClips())
                    {
                        MySuperPlayableClip      myclip  = (MySuperPlayableClip)clip.asset;
                        MySuperPlayableBehaviour mybehav = myclip.template;
                        myclip.am.exposedName = System.Guid.NewGuid().ToString();
                        pd.SetReferenceValue(myclip.am.exposedName, victim);
                    }
                }
                else if (track.name == "Player Animation")
                {
                    pd.SetGenericBinding(track, attacker.ac.anim);
                }
                else if (track.name == "Box Animation")
                {
                    pd.SetGenericBinding(track, victim.ac.anim);
                }
            }
            pd.Evaluate();
            pd.Play();
        }


        else if (timelineName == "leverUp")
        {
            pd.playableAsset = Instantiate(leverUp);

            TimelineAsset timeline = (TimelineAsset)pd.playableAsset;



            foreach (var track in timeline.GetOutputTracks())
            {
                if (track.name == "Player Script")
                {
                    pd.SetGenericBinding(track, attacker);
                    foreach (var clip in track.GetClips())
                    {
                        MySuperPlayableClip      myclip  = (MySuperPlayableClip)clip.asset;
                        MySuperPlayableBehaviour mybehav = myclip.template;
                        myclip.am.exposedName = System.Guid.NewGuid().ToString();
                        pd.SetReferenceValue(myclip.am.exposedName, attacker);
                    }
                }
                else if (track.name == "Lever Script")
                {
                    pd.SetGenericBinding(track, victim);
                    foreach (var clip in track.GetClips())
                    {
                        MySuperPlayableClip      myclip  = (MySuperPlayableClip)clip.asset;
                        MySuperPlayableBehaviour mybehav = myclip.template;
                        myclip.am.exposedName = System.Guid.NewGuid().ToString();
                        pd.SetReferenceValue(myclip.am.exposedName, victim);
                    }
                }
                else if (track.name == "Player Animation")
                {
                    pd.SetGenericBinding(track, attacker.ac.anim);
                }
                else if (track.name == "Lever Animation")
                {
                    pd.SetGenericBinding(track, victim.ac.anim);
                }
            }
            pd.Evaluate();
            pd.Play();
        }
    }
    public void PlayFrontStab(ActorManager attacker, ActorManager victim)
    {
        if (IsPlaying)
        {
            return;
        }

        pd.playableAsset = Instantiate(frontStab);

        TimelineAsset timeline = (TimelineAsset)pd.playableAsset;



        foreach (var track in timeline.GetOutputTracks())
        {
            Object obj = null;

            switch (track.name)
            {
            case "Attacker Animation":
                obj = attacker.actorController.anim;
                break;

            case "Attacker Script":
                obj = attacker;
                foreach (var clip in track.GetClips())
                {
                    MySuperPlayableClip      myClip  = clip.asset as MySuperPlayableClip;
                    MySuperPlayableBehaviour myBehav = myClip.template;
                    myBehav.myFloat = 777;
                    //给他一个单独的KEY 防止地址重复
                    myClip.actorManager.exposedName = System.Guid.NewGuid().ToString();
                    pd.SetReferenceValue(myClip.actorManager.exposedName, attacker);
                }
                break;

            case "Victim Animation":
                obj = victim.actorController.anim;
                break;

            case "Victim Script":
                foreach (var clip in track.GetClips())
                {
                    MySuperPlayableClip      myClip  = clip.asset as MySuperPlayableClip;
                    MySuperPlayableBehaviour myBehav = myClip.template;
                    myBehav.myFloat = 6666;
                    myClip.actorManager.exposedName = System.Guid.NewGuid().ToString();
                    pd.SetReferenceValue(myClip.actorManager.exposedName, victim);
                }
                break;
            }

            if (obj != null)
            {
                pd.SetGenericBinding(track, obj);
            }
        }

        // 强行执行一次插值 , 把值初始一次
        pd.Evaluate();

        pd.Play();
    }
    public static void DupTimeline()
    {
        // Fetch playable director, fetch timeline
        GameObject       playableDirectorObj = UnityEditor.Selection.activeObject as GameObject;
        PlayableDirector playableDirector    = playableDirectorObj.GetComponent <PlayableDirector>();
        TimelineAsset    timelineAsset       = playableDirector.playableAsset as TimelineAsset;

        // Duplicate
        string path    = AssetDatabase.GetAssetPath(timelineAsset);
        string newPath = path.Replace(".", "(Clone).");

        if (!AssetDatabase.CopyAsset(path, newPath))
        {
            if (showLogs)
            {
                Debug.LogError("Couldn't Clone Asset");
            }
            return;
        }

        // Copy Bindings
        TimelineAsset newTimelineAsset = AssetDatabase.LoadMainAssetAtPath(newPath) as TimelineAsset;

        PlayableBinding[] oldBindings = timelineAsset.outputs.ToArray();
        PlayableBinding[] newBindings = newTimelineAsset.outputs.ToArray();
        for (int i = 0; i < oldBindings.Length; i++)
        {
            playableDirector.playableAsset = timelineAsset;
            Object boundTo = playableDirector.GetGenericBinding(oldBindings[i].sourceObject);

            playableDirector.playableAsset = newTimelineAsset;
            playableDirector.SetGenericBinding(newBindings[i].sourceObject, boundTo);
        }

        // Copy Exposed References
        playableDirector.playableAsset = newTimelineAsset;
        foreach (TrackAsset newTrackAsset in newTimelineAsset.GetRootTracks())
        {
            foreach (TimelineClip newClip in newTrackAsset.GetClips())
            {
                foreach (FieldInfo fieldInfo in newClip.asset.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
                {
                    if (fieldInfo.FieldType.IsGenericType && fieldInfo.FieldType.GetGenericTypeDefinition() == typeof(ExposedReference <>))
                    {
                        // Fetch Old Exposed Name
                        object       exposedReference = fieldInfo.GetValue(newClip.asset);
                        PropertyName oldExposedName   = (PropertyName)fieldInfo.FieldType
                                                        .GetField("exposedName")
                                                        .GetValue(exposedReference);
                        bool isValid;

                        // Fetch Old Exposed Value
                        Object oldExposedValue = playableDirector.GetReferenceValue(oldExposedName, out isValid);
                        if (!isValid)
                        {
                            if (showLogs)
                            {
                                Debug.LogError("Failed to copy exposed references to duplicate timeline. Could not find: " + oldExposedName);
                            }
                            return;
                        }

                        // Replace exposedName on struct
                        PropertyName newExposedName = new PropertyName(UnityEditor.GUID.Generate().ToString());
                        fieldInfo.FieldType
                        .GetField("exposedName")
                        .SetValue(exposedReference, newExposedName);

                        // Set ExposedReference
                        fieldInfo.SetValue(newClip.asset, exposedReference);

                        // Set Reference on Playable Director
                        playableDirector.SetReferenceValue(newExposedName, oldExposedValue);
                    }
                }
            }
        }
    }
Ejemplo n.º 28
0
    public void PlayFrontStab(string timelineName, ActorManager attacker, ActorManager victim)
    {
        if (pd.state == PlayState.Playing)
        {
            return;
        }
        if (timelineName == "StabTimeline")
        {
            pd.playableAsset = frontStab;

            TimelineAsset timeline = (TimelineAsset)pd.playableAsset;
            foreach (var track in timeline.GetOutputTracks())
            {
                if (track.name == "Attacker Track")
                {
                    pd.SetGenericBinding(track, attacker);
                    foreach (var clip in track.GetClips())
                    {
                        MySuperPlayableClip      myClip  = (MySuperPlayableClip)clip.asset;
                        MySuperPlayableBehaviour myBehav = myClip.template;
                        myClip.myAM.exposedName = System.Guid.NewGuid().ToString();
                        myBehav.myFloat         = 777;
                        pd.SetReferenceValue(myClip.myAM.exposedName, attacker);
                    }
                }
                else if (track.name == "Victim Track")
                {
                    pd.SetGenericBinding(track, victim);
                    foreach (var clip in track.GetClips())
                    {
                        MySuperPlayableClip      myClip  = (MySuperPlayableClip)clip.asset;
                        MySuperPlayableBehaviour myBehav = myClip.template;
                        myClip.myAM.exposedName = System.Guid.NewGuid().ToString();
                        myBehav.myFloat         = 888;
                        pd.SetReferenceValue(myClip.myAM.exposedName, victim);
                    }
                }
                else if (track.name == "Attacker Animation")
                {
                    pd.SetGenericBinding(track, attacker.ac.anim);
                }
                else if (track.name == "Victim Animation")
                {
                    pd.SetGenericBinding(track, victim.ac.anim);
                }
            }

            //foreach (var trackBinding in pd.playableAsset.outputs)
            //{
            //    if (trackBinding.streamName == "Attacker Track")
            //    {
            //        pd.SetGenericBinding(trackBinding.sourceObject, attacker);
            //    }
            //    else if (trackBinding.streamName == "Victim Track")
            //    {
            //        pd.SetGenericBinding(trackBinding.sourceObject, victim);
            //    }
            //    else if (trackBinding.streamName == "Attacker Animation")
            //    {
            //        pd.SetGenericBinding(trackBinding.sourceObject, attacker.ac.anim);
            //    }
            //    else if (trackBinding.streamName == "Victim Animation")
            //    {
            //        pd.SetGenericBinding(trackBinding.sourceObject, victim.ac.anim);
            //    }
            //}
            pd.Play();
        }
    }
Ejemplo n.º 29
0
    public void PlayFrontStab(string timelineName, ActorMgr attacker, ActorMgr Victim)
    {
        //if(playDir.state == PlayState.Playing)
        //{
        //    return;
        //}

        if (timelineName == "frontStab")
        {
            playDir.playableAsset = Instantiate(frontStab);

            TimelineAsset timeline = (TimelineAsset)playDir.playableAsset;

            foreach (var track in timeline.GetOutputTracks())
            {
                if (track.name == "Attacker Script")
                {
                    playDir.SetGenericBinding(track, attacker);
                    foreach (var clip in track.GetClips())
                    {
                        MySuperPlayableClip      myClips = (MySuperPlayableClip)clip.asset;
                        MySuperPlayableBehaviour myBehav = myClips.template;
                        myBehav.myFloat = 666;
                        //myClips._actMgr.exposedName = GetInstanceID().ToString();//18年版本官方没有初始化,也暂时忘记跟Operator讲述
                        myClips._actMgr.exposedName = System.Guid.NewGuid().ToString();//这种不会同一获得同一东西
                        playDir.SetReferenceValue(myClips._actMgr.exposedName, attacker);
                        Debug.Log(myClips._actMgr.exposedName);
                        //不支持加载固件,只能加载资源
                    }
                }
                else if (track.name == "Victim Script")
                {
                    playDir.SetGenericBinding(track, victim);
                    foreach (var clip in track.GetClips())
                    {
                        MySuperPlayableClip      myClips = (MySuperPlayableClip)clip.asset;
                        MySuperPlayableBehaviour myBehav = myClips.template;
                        myBehav.myFloat             = 777;
                        myClips._actMgr.exposedName = System.Guid.NewGuid().ToString();//这种不会同一获得同一东西
                        playDir.SetReferenceValue(myClips._actMgr.exposedName, victim);
                        Debug.Log(myClips._actMgr.exposedName);
                        //不支持加载固件,只能加载资源
                    }
                }
                else if (track.name == "Attacker Animation")
                {
                    playDir.SetGenericBinding(track, attacker.actCtrl.anim);
                }
                else if (track.name == "Victim Animation")
                {
                    playDir.SetGenericBinding(track, victim.actCtrl.anim);
                }
            }
            playDir.Evaluate();//在MySuperPlayableClip的类里,要加入物体数值的初始化,先前官方没有添加
            playDir.Play();
        }

        else if (timelineName == "openBox")
        {
            playDir.playableAsset = Instantiate(openBox);

            TimelineAsset timeline = (TimelineAsset)playDir.playableAsset;

            foreach (var track in timeline.GetOutputTracks())
            {
                if (track.name == "Player Script")
                {
                    playDir.SetGenericBinding(track, attacker);
                    foreach (var clip in track.GetClips())
                    {
                        MySuperPlayableClip      myClips = (MySuperPlayableClip)clip.asset;
                        MySuperPlayableBehaviour myBehav = myClips.template;
                        myClips._actMgr.exposedName = System.Guid.NewGuid().ToString();//这种不会同一获得同一东西
                        playDir.SetReferenceValue(myClips._actMgr.exposedName, attacker);
                        Debug.Log(myClips._actMgr.exposedName);
                    }
                }
                else if (track.name == "Box Script")
                {
                    playDir.SetGenericBinding(track, victim);
                    foreach (var clip in track.GetClips())
                    {
                        MySuperPlayableClip      myClips = (MySuperPlayableClip)clip.asset;
                        MySuperPlayableBehaviour myBehav = myClips.template;
                        myClips._actMgr.exposedName = System.Guid.NewGuid().ToString();
                        playDir.SetReferenceValue(myClips._actMgr.exposedName, victim);
                        Debug.Log(myClips._actMgr.exposedName);
                    }
                }
                else if (track.name == "Player Animation")
                {
                    playDir.SetGenericBinding(track, attacker.actCtrl.anim);
                }
                else if (track.name == "Box Animation")
                {
                    Debug.Log("this is 123pre on DirectorMgr :" + victim.actCtrl.anim.name);
                    playDir.SetGenericBinding(track, victim.actCtrl.anim);
                }
            }
            playDir.Evaluate();//在MySuperPlayableClip的类里,要加入物体数值的初始化,先前官方没有添加
            playDir.Play();
        }

        else if (timelineName == "leverUp")
        {
            playDir.playableAsset = Instantiate(leverUp);

            TimelineAsset timeline = (TimelineAsset)playDir.playableAsset;

            foreach (var track in timeline.GetOutputTracks())
            {
                if (track.name == "Player Script")
                {
                    playDir.SetGenericBinding(track, attacker);
                    foreach (var clip in track.GetClips())
                    {
                        MySuperPlayableClip      myClips = (MySuperPlayableClip)clip.asset;
                        MySuperPlayableBehaviour myBehav = myClips.template;
                        myClips._actMgr.exposedName = System.Guid.NewGuid().ToString();//这种不会同一获得同一东西
                        playDir.SetReferenceValue(myClips._actMgr.exposedName, attacker);
                        //Debug.Log(myClips._actMgr.exposedName);
                    }
                }
                else if (track.name == "Lever Script")
                {
                    playDir.SetGenericBinding(track, victim);
                    foreach (var clip in track.GetClips())
                    {
                        MySuperPlayableClip      myClips = (MySuperPlayableClip)clip.asset;
                        MySuperPlayableBehaviour myBehav = myClips.template;
                        myClips._actMgr.exposedName = System.Guid.NewGuid().ToString();
                        playDir.SetReferenceValue(myClips._actMgr.exposedName, victim);
                    }
                }
                else if (track.name == "Player Animation")
                {
                    playDir.SetGenericBinding(track, attacker.actCtrl.anim);
                    //Debug.Log(attacker.actCtrl.anim);
                }
                else if (track.name == "Lever Animation")
                {
                    playDir.SetGenericBinding(track, victim.actCtrl.anim);
                }
            }
            playDir.Evaluate();//在MySuperPlayableClip的类里,要加入物体数值的初始化,先前官方没有添加
            playDir.Play();
        }
    }
Ejemplo n.º 30
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
    }