示例#1
0
        public override Playable CreatePlayable(PlayableGraph graph, GameObject go)
        {
            List <Playable> list       = new List <Playable>();
            GameObject      gameObject = this.sourceGameObject.Resolve(graph.GetResolver());

            if (this.prefabGameObject != null)
            {
                Transform parentTransform = (!(gameObject != null)) ? null : gameObject.transform;
                ScriptPlayable <PrefabControlPlayable> playable = PrefabControlPlayable.Create(graph, this.prefabGameObject, parentTransform);
                gameObject = playable.GetBehaviour().prefabInstance;
                list.Add(playable);
            }
            this.m_Duration    = PlayableBinding.DefaultDuration;
            this.m_SupportLoop = false;
            Playable result;

            if (gameObject == null)
            {
                result = Playable.Create(graph, 0);
            }
            else
            {
                IList <PlayableDirector> component  = this.GetComponent <PlayableDirector>(gameObject);
                IList <ParticleSystem>   component2 = this.GetComponent <ParticleSystem>(gameObject);
                this.UpdateDurationAndLoopFlag(component, component2);
                PlayableDirector component3 = go.GetComponent <PlayableDirector>();
                if (component3 != null)
                {
                    this.m_ControlDirectorAsset = component3.playableAsset;
                }
                if (go == gameObject && this.prefabGameObject == null)
                {
                    Debug.LogWarning("Control Playable (" + base.name + ") is referencing the same PlayableDirector component than the one in which it is playing.");
                    this.active = false;
                    if (!this.searchHierarchy)
                    {
                        this.updateDirector = false;
                    }
                }
                if (this.active)
                {
                    this.CreateActivationPlayable(gameObject, graph, list);
                }
                if (this.updateDirector)
                {
                    this.SearchHierarchyAndConnectDirector(component, graph, list);
                }
                if (this.updateParticle)
                {
                    this.SearchHiearchyAndConnectParticleSystem(component2, graph, list);
                }
                if (this.updateITimeControl)
                {
                    ControlPlayableAsset.SearchHierarchyAndConnectControlableScripts(ControlPlayableAsset.GetControlableScripts(gameObject), graph, list);
                }
                Playable playable2 = ControlPlayableAsset.ConnectPlayablesToMixer(graph, list);
                result = playable2;
            }
            return(result);
        }
        private static void SetHideFlagsRecursive(GameObject gameObject)
        {
            gameObject.set_hideFlags(20);
            if (!Application.get_isPlaying())
            {
                gameObject.set_hideFlags(gameObject.get_hideFlags() | 1);
            }
            IEnumerator enumerator = gameObject.get_transform().GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    Transform transform = (Transform)enumerator.Current;
                    PrefabControlPlayable.SetHideFlagsRecursive(transform.get_gameObject());
                }
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = (enumerator as IDisposable)) != null)
                {
                    disposable.Dispose();
                }
            }
        }
        private static void SetHideFlagsRecursive(GameObject gameObject)
        {
            gameObject.hideFlags = (HideFlags.DontSaveInEditor | HideFlags.DontSaveInBuild);
            if (!Application.isPlaying)
            {
                gameObject.hideFlags |= HideFlags.HideInHierarchy;
            }
            IEnumerator enumerator = gameObject.transform.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    object    obj       = enumerator.Current;
                    Transform transform = (Transform)obj;
                    PrefabControlPlayable.SetHideFlagsRecursive(transform.gameObject);
                }
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = (enumerator as IDisposable)) != null)
                {
                    disposable.Dispose();
                }
            }
        }
 public GameObject Initialize(GameObject prefabGameObject, Transform parentTransform)
 {
     if (prefabGameObject == null)
     {
         throw new ArgumentNullException("Prefab cannot be null");
     }
     if (this.m_Instance != null)
     {
         Debug.LogWarningFormat("Prefab Control Playable ({0}) has already been initialized with a Prefab ({1}).", new object[]
         {
             prefabGameObject.get_name(),
             this.m_Instance.get_name()
         });
     }
     else
     {
         this.m_Instance = Object.Instantiate <GameObject>(prefabGameObject, parentTransform, false);
         this.m_Instance.set_name(prefabGameObject.get_name() + " [Timeline]");
         this.m_Instance.SetActive(false);
         PrefabControlPlayable.SetHideFlagsRecursive(this.m_Instance);
     }
     return(this.m_Instance);
 }
        /// <summary>
        /// Creates the root of a Playable subgraph to control the contents of the game object.
        /// </summary>
        /// <param name="graph">PlayableGraph that will own the playable</param>
        /// <param name="go">The GameObject that triggered the graph build</param>
        /// <returns>The root playable of the subgraph</returns>
        public override Playable CreatePlayable(PlayableGraph graph, GameObject go)
        {
            // case 989856
            if (prefabGameObject != null)
            {
                if (s_CreatedPrefabs.Contains(prefabGameObject))
                {
                    Debug.LogWarningFormat("Control Track Clip ({0}) is causing a prefab to instantiate itself recursively. Aborting further instances.", name);
                    return(Playable.Create(graph));
                }
                s_CreatedPrefabs.Add(prefabGameObject);
            }

            Playable root      = Playable.Null;
            var      playables = new List <Playable>();

            GameObject sourceObject = sourceGameObject.Resolve(graph.GetResolver());

            if (prefabGameObject != null)
            {
                Transform parenTransform  = sourceObject != null ? sourceObject.transform : null;
                var       controlPlayable = PrefabControlPlayable.Create(graph, prefabGameObject, parenTransform);

                sourceObject = controlPlayable.GetBehaviour().prefabInstance;
                playables.Add(controlPlayable);
            }

            m_Duration    = PlayableBinding.DefaultDuration;
            m_SupportLoop = false;

            if (sourceObject != null)
            {
                var directors       = updateDirector ? GetComponent <PlayableDirector>(sourceObject) : k_EmptyDirectorsList;
                var particleSystems = updateParticle ? GetParticleSystemRoots(sourceObject) : k_EmptyParticlesList;

                // update the duration and loop values (used for UI purposes) here
                // so they are tied to the latest gameObject bound
                UpdateDurationAndLoopFlag(directors, particleSystems);

                var director = go.GetComponent <PlayableDirector>();
                if (director != null)
                {
                    m_ControlDirectorAsset = director.playableAsset;
                }

                if (go == sourceObject && prefabGameObject == null)
                {
                    Debug.LogWarningFormat("Control Playable ({0}) is referencing the same PlayableDirector component than the one in which it is playing.", name);
                    active = false;
                    if (!searchHierarchy)
                    {
                        updateDirector = false;
                    }
                }

                if (active)
                {
                    CreateActivationPlayable(sourceObject, graph, playables);
                }

                if (updateDirector)
                {
                    SearchHierarchyAndConnectDirector(directors, graph, playables, prefabGameObject != null);
                }

                if (updateParticle)
                {
                    SearchHiearchyAndConnectParticleSystem(particleSystems, graph, playables);
                }

                if (updateITimeControl)
                {
                    SearchHierarchyAndConnectControlableScripts(GetControlableScripts(sourceObject), graph, playables);
                }

                // Connect Playables to Generic to Mixer
                root = ConnectPlayablesToMixer(graph, playables);
            }

            if (prefabGameObject != null)
            {
                s_CreatedPrefabs.Remove(prefabGameObject);
            }

            if (!root.IsValid())
            {
                root = Playable.Create(graph);
            }

            return(root);
        }