public override Playable CreatePlayable(PlayableGraph graph, GameObject go)
        {
            ScriptPlayable <HvrActor_AssetBehavior> playable = ScriptPlayable <HvrActor_AssetBehavior> .Create(graph);

            HvrActor_AssetBehavior playableBehaviour = playable.GetBehaviour();

            playableBehaviour.dataGUID = dataGUID;

            return(playable);
        }
Beispiel #2
0
        public override void ProcessFrame(Playable playable, FrameData info, object playerData)
        {
            if (m_Clips == null)
            {
                return;
            }

            HvrActor actor = playerData as HvrActor;

            if (actor == null)
            {
                return;
            }

            // Allow for the previous asset that was assigned to the HvrActor to
            // be set back when this graph ends
            if (actor != null &&
                !m_firstFrameHappened)
            {
                m_firstFrameHappened            = true;
                m_trackBindingActor             = actor;
                m_originalAssetInterface        = actor.assetInterface;
                m_originalActorRenderMethodType = actor.renderMethodType;
            }

            Interface.AssetInterface current_asset = null;
            float greatestWeight = 0;

            int inputPort = 0;

            foreach (TimelineClip clip in m_Clips)
            {
                float inputWeight = playable.GetInputWeight(inputPort);
                ScriptPlayable <HvrActor_AssetBehavior> scriptPlayable = (ScriptPlayable <HvrActor_AssetBehavior>)playable.GetInput(inputPort);
                HvrActor_AssetBehavior hvrAssetBehavior = scriptPlayable.GetBehaviour();

                if (hvrAssetBehavior != null)
                {
                    double preloadTime = Math.Max(0.0, hvrAssetBehavior.preloadTime);

                    if (m_Director.time >= clip.start + clip.duration ||
                        m_Director.time <= clip.start - preloadTime)
                    {
                        hvrAssetBehavior.StopAsset();
                    }
                    else if (m_Director.time > clip.start - preloadTime)
                    {
                        hvrAssetBehavior.PrepareAsset();
                    }

                    // If this behavior is within the range of the clip, then take it's asset and
                    // overwrite the activeAsset in order to ensure that only one asset is assigned per
                    // evaluation to the target HvrActor
                    // this assumes that the order of clips remain in a consistent order between frames
                    if (m_Director.time >= clip.start &&
                        m_Director.time <= clip.end)
                    {
                        if (inputWeight >= greatestWeight)
                        {
                            greatestWeight = inputWeight;
                            current_asset  = hvrAssetBehavior.asset;
                        }
                    }
                }

                ++inputPort;
            }

            if (!string.IsNullOrEmpty(m_originalActorRenderMethodType) &&
                m_originalActorRenderMethodType != actor.renderMethodType)
            {
                // TODO Remove this warning once this bug is fixed - Tom
                Debug.LogError("HvrActor RenderMethod changed while a Timeline Clip was playing. This behavior is unsupported");
                return;
            }

            if (actor.actorInterface != null &&
                actor.assetInterface != current_asset)
            {
                actor.SetAssetInterface(current_asset);
            }
        }