Ejemplo n.º 1
0
        public bool Initialize(Animator animator, IList <IRigLayer> layers)
        {
            if (isInitialized)
            {
                return(true);
            }

            m_RigIndices = new List <int>(layers.Count);
            for (int i = 0; i < layers.Count; ++i)
            {
                if (!layers[i].IsValid())
                {
                    continue;
                }

                m_RigIndices.Add(i);
            }

            m_Data = RigUtils.CreateSyncSceneToStreamData(animator, layers);
            if (!m_Data.IsValid())
            {
                return(false);
            }

            job = RigUtils.syncSceneToStreamBinder.Create(animator, m_Data);

            return(isInitialized = true);
        }
Ejemplo n.º 2
0
        public void Destroy()
        {
            if (!isInitialized)
            {
                return;
            }

            RigUtils.DestroyAnimationJobs(m_Constraints, m_Jobs);
            m_Constraints = null;
            m_Jobs        = null;

            isInitialized = false;
        }
Ejemplo n.º 3
0
        public bool Initialize(Animator animator)
        {
            if (isInitialized)
            {
                return(true);
            }

            m_Constraints = RigUtils.GetConstraints(this);
            if (m_Constraints == null)
            {
                return(false);
            }

            m_Jobs = RigUtils.CreateAnimationJobs(animator, m_Constraints);

            return(isInitialized = true);
        }
Ejemplo n.º 4
0
        public bool Build()
        {
            Clear();
            var animator = GetComponent <Animator>();

            if (animator == null || layers.Count == 0)
            {
                return(false);
            }

            string graphName = gameObject.transform.name + "_Rigs";

            graph = PlayableGraph.Create(graphName);
            graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);

            // Create sync scene to stream layer
            var syncLayerOutput = AnimationPlayableOutput.Create(graph, "syncSceneToStreamOutput", animator);

            syncLayerOutput.SetAnimationStreamSource(AnimationStreamSource.PreviousInputs);

            // Create all rig layers
            m_RigLayerData = new List <LayerData>(layers.Count);
            List <JobTransform> allRigReferences = new List <JobTransform>();

            foreach (var layer in layers)
            {
                if (!layer.Initialize(animator))
                {
                    continue;
                }

                LayerData data = new LayerData();
                data.output = AnimationPlayableOutput.Create(graph, "rigOutput", animator);
                data.output.SetAnimationStreamSource(AnimationStreamSource.PreviousInputs);
                data.playables = BuildRigPlayables(graph, layer.rig, ref data.output);

                layer.data = m_RigLayerData.Count;
                m_RigLayerData.Add(data);

                // Gather all references used by rig
                var references = RigUtils.GetAllConstraintReferences(animator, layer.rig.constraints);
                if (references != null)
                {
                    allRigReferences.AddRange(references);
                }

                references = RigUtils.GetAllRigTransformReferences(layer.rig);
                if (references != null)
                {
                    allRigReferences.AddRange(references);
                }
            }

            // Create sync to stream job with all rig references
            m_SyncSceneToStreamJobData = RigUtils.CreateSyncSceneToStreamData(allRigReferences.ToArray());
            if (m_SyncSceneToStreamJobData.IsValid())
            {
                m_SyncSceneToStreamJob = RigUtils.syncSceneToStreamBinder.Create(animator, m_SyncSceneToStreamJobData);
                syncLayerOutput.SetSourcePlayable(RigUtils.syncSceneToStreamBinder.CreatePlayable(graph, m_SyncSceneToStreamJob));
            }
            graph.Play();

            return(true);
        }