Exemplo n.º 1
0
    /// <summary>
    /// 设置人物动画轨道,相机轨道
    /// </summary>
    /// <param name="director">播放器</param>
    /// <param name="animator">人物动画</param>
    /// <param name="brain">主相机</param>
    /// <param name="cameras">机位列表</param>
    private void SetCinemachineTrack(PlayableDirector director, CinemachineBrain brain, params CinemachineVirtualCameraBase[] cameras)
    {
        bool cinemachineFinded = false;
        bool animatorFinded    = false;

        foreach (PlayableBinding binding in director.playableAsset.outputs)
        {
            if (binding.streamName.Equals("CinemachineTrack"))
            {
                director.SetGenericBinding(binding.sourceObject, brain);

                int index = 0;

                CinemachineTrack track = (CinemachineTrack)binding.sourceObject;
                foreach (TimelineClip clip in track.GetClips())
                {
                    CinemachineShot cameraShot = clip.asset as CinemachineShot;

                    director.SetReferenceValue(cameraShot.VirtualCamera.exposedName, cameras != null && index < cameras.Length ? cameras[index] : null);

                    index++;
                }
                cinemachineFinded = true;
            }

            if (cinemachineFinded && animatorFinded)
            {
                break;
            }
        }
    }
Exemplo n.º 2
0
    public override Playable CreateTrackMixer(
        PlayableGraph graph, GameObject go, int inputCount)
    {
        // Hack to set the display name of the clip to match the vcam
        foreach (var c in GetClips())
        {
            CinemachineShot shot = (CinemachineShot)c.asset;
            CinemachineVirtualCameraBase vcam = shot.VirtualCamera.Resolve(graph.GetResolver());
            if (vcam != null)
            {
                c.displayName = vcam.Name;
            }
        }

        var mixer = ScriptPlayable <CinemachineMixer> .Create(graph);

        mixer.SetInputCount(inputCount);
        return(mixer);
    }
Exemplo n.º 3
0
    // triggered when the generated button is clicked
    public void OnGenerateClicked()
    {
        storyCreator.storyManager.CreateNewBranch("new", 0.0);
        storyCreator.storyManager.DoChoice(0);
        storyCreator.timelineManager.AddTrack(new AnimationTrack(), storyCreator.actor);
        CinemachineTrack cameraTrack = storyCreator.timelineManager.AddTrack(new CinemachineTrack(), "Camera") as CinemachineTrack;
        CinemachineShot  cameraClip  = storyCreator.timelineManager.AddCustomClipWithInitialTime(cameraTrack, 0) as CinemachineShot;


        storyCreator.ResetActioPosition();
        for (int i = 0; i < operationPanel.childCount - 2; i++)
        {
            int option = operationPanel.GetChild(i).GetComponent <Dropdown>().value;
            if (animationList[option] != "None")
            {
                storyCreator.timelineManager.AddAnimationClip(TSEiAResourceManager.GetAnimation(animationList[option]),
                                                              storyCreator.actor, -0.1, false);
            }
        }
        storyCreator.timelineManager.StartTimeline();
    }
Exemplo n.º 4
0
    bool Process(TimelineInfo timelineInfo)
    {
        var  timelineState  = EntityManager.GetComponentData <TimelineState>(timelineInfo.Owner);
        bool isCanInterrupt = timelineState.InterruptStatus == TimelineState.InterruptState.Allow;

        if (!isCanInterrupt)
        {
            return(false);
        }
        ResourceManager.GetInstance().LoadAsset <PlayableAsset>(timelineInfo.ResPath, delegate(UnityEngine.Object[] objs)
        {
            if (objs == null || objs.Length <= 0)
            {
                return;
            }
            var entity         = timelineInfo.Owner;
            var playerDirector = EntityManager.GetComponentObject <PlayableDirector>(entity);
            playerDirector.Stop();
            playerDirector.playableAsset = objs[0] as PlayableAsset;
            var looksInfo = EntityManager.GetComponentData <LooksInfo>(entity);
            if (looksInfo.CurState != LooksInfo.State.Loaded)
            {
                return;
            }
            var looksEntity = looksInfo.LooksEntity;
            var animator    = EntityManager.GetComponentObject <Animator>(looksEntity);
            foreach (var at in playerDirector.playableAsset.outputs)
            {
                if (at.sourceObject.GetType() == typeof(AnimationTrack))
                {
                    playerDirector.SetGenericBinding(at.sourceObject, animator);
                }
                else if (at.sourceObject.GetType() == typeof(CinemachineTrack))
                {
                    CinemachineBrain mainCamBrian = SceneMgr.Instance.MainCameraTrans.GetComponent <Cinemachine.CinemachineBrain>();//将主摄像机传入
                    playerDirector.SetGenericBinding(at.sourceObject, mainCamBrian);
                    CinemachineTrack cinemachineTrack = (CinemachineTrack)at.sourceObject;
                    int idx = 0;
                    try
                    {
                        foreach (var c in cinemachineTrack.GetClips())
                        {
                            CinemachineShot shot = (CinemachineShot)c.asset;
                            // playerDirector.SetReferenceValue(shot.VirtualCamera.exposedName, vCams[idx++]);
                        }
                    }
                    catch (Exception)
                    {
                        Debug.LogError("Clip Num InEqual Cam Num");
                    }
                }
                else if (at.streamName.StartsWith("ParticleTrack"))
                {
                    var nameParts     = at.streamName.Split('_');
                    var hangPointName = "root";
                    if (nameParts.Length > 1)
                    {
                        hangPointName = nameParts[1];
                    }
                    var ct             = at.sourceObject as ControlTrack;
                    var looksTrans     = EntityManager.GetComponentObject <Transform>(looksEntity);
                    var particleParent = looksTrans.Find(hangPointName);
                    foreach (var info in ct.GetClips())
                    {
                        var cpa = info.asset as ControlPlayableAsset;
                        playerDirector.SetReferenceValue(cpa.sourceGameObject.exposedName, particleParent.gameObject);
                    }
                }
                // Debug.Log("timelineInfo.Param != null : "+(timelineInfo.Param != null).ToString());
                if (timelineInfo.Param != null)
                {
                    var nameParts = at.streamName.Split('_');
                    // Debug.Log("nameParts : "+nameParts[0]);
                    if (timelineInfo.Param.ContainsKey(nameParts[0]))
                    {
                        var ta = at.sourceObject as TrackAsset;
                        foreach (var info in ta.GetClips())
                        {
                            // var cpa = info.asset as ScriptPlayable<>;
                            var cpa = info.asset as ParamPlayableAsset;
                            Debug.Log("cpa != null : " + (cpa != null).ToString());
                            if (cpa != null)
                            {
                                cpa.Param = timelineInfo.Param[nameParts[0]];
                            }
                            else
                            {
                                Debug.LogError("error : trying to set param with no param playable asset name : " + at.streamName);
                            }
                        }
                    }
                }
            }
            playerDirector.Play();
        });
        return(true);
    }
Exemplo n.º 5
0
 public void CamBind(CinemachineShot cshot, CinemachineVirtualCamera vcam)
 {
     cshot.VirtualCamera.exposedName = UnityEditor.GUID.Generate().ToString();
     director.SetReferenceValue(cshot.VirtualCamera.exposedName, vcam);
 }