// Update is called once per frame
        private void populateAnimation(FabulaClip clip)
        {
            // 3 game objects
            agent              = GameObject.Find(clip.gameobject_name);
            location           = GameObject.Find(clip.startingPos_string);
            animTimelineObject = GameObject.Find(clip.animation_string);

            // control track
            control_track_clip             = ctrack.CreateDefaultClip();
            control_track_clip.start       = clip.start + (float)0.12;
            control_track_clip.duration    = clip.duration - (float)0.12;
            control_track_clip.displayName = clip.Name;
            controlAnim = control_track_clip.asset as ControlPlayableAsset;
            AnimateBind(controlAnim, animTimelineObject);

            // nav track
            nav_track_clip             = ntrack.CreateClip <LerpMoveObjectAsset>();
            nav_track_clip.start       = clip.start;
            nav_track_clip.displayName = clip.Name;
            nav_track_clip.duration    = 0.11;
            LerpMoveObjectAsset tp_obj = nav_track_clip.asset as LerpMoveObjectAsset;

            TransformBind(tp_obj, agent, agent.transform, makeCustomizedTransform(location.transform.position, clip.orientation).transform);
            //setClipOffset(animTimelineObject, anim_loc, anim_rot);
        }
예제 #2
0
    private void populateNavVirtual(DiscourseClip clip)
    {
        // Make a copy of virtual camera and set aim and follow target

        string name     = clip.Name;
        float  start    = clip.start + 0.06f;
        float  duration = clip.duration - 0.06f;
        float  fov      = clip.fov;

        float fab_start = clip.fabulaStart;

        GameObject starting_loc = GameObject.Find(clip.startingPos_string);
        float      start_offset = clip.start_dist_offset;
        GameObject ending_loc   = GameObject.Find(clip.endingPos_string);
        float      end_offset   = clip.end_dist_offset;

        GameObject virtualCamOriginal = GameObject.Find(clip.virtualCamName);
        GameObject virtualCam         = Instantiate(virtualCamOriginal);
        CinemachineVirtualCamera cva  = virtualCam.GetComponent <CinemachineVirtualCamera>();

        if (clip.aimTarget != null)
        {
            agent = GameObject.Find(clip.aimTarget);

            cva.m_LookAt           = agent.transform;
            cva.m_Lens.FieldOfView = clip.fov;
        }

        bool has_fab_switch = false;

        if (clip.fabulaStart >= 0f)
        {
            has_fab_switch = true;
            GameObject ttravel = Instantiate(Resources.Load("time_travel", typeof(GameObject))) as GameObject;
            ttravel.transform.parent = virtualCam.transform;
            ttravel.GetComponent <timeStorage>().fab_time = clip.fabulaStart;
            TimelineClip tc = ctrack.CreateDefaultClip();
            tc.start       = clip.start;
            tc.duration    = clip.duration;
            tc.displayName = "Time Travel";
            var time_travel_clip = tc.asset as ControlPlayableAsset;
            AnimateBind(time_travel_clip, ttravel);
        }

        film_track_clip = ftrack.CreateDefaultClip();
        if (has_fab_switch)
        {
            start    = clip.start + (float)0.06;
            duration = clip.duration;
        }
        film_track_clip.start       = start;
        film_track_clip.duration    = duration;
        film_track_clip.displayName = clip.Name;

        // specialize and bind
        var cinemachineShot = film_track_clip.asset as CinemachineShot;

        CamBind(cinemachineShot, cva);
    }
    // Use this for initialization
    void Awake()
    {
        List <List <string> > clipList = readDiscourse();

        foreach (List <string> clipItem in clipList)
        {
            Debug.Log("Clip:");
            foreach (string item in clipItem)
            {
                Debug.Log(item);
            }
        }
        main_camera_object = GameObject.Find("Main Camera");

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

        PlayableDirector director = GetComponent <PlayableDirector>();

        TrackAsset track  = timeline.CreateTrack <CinemachineTrack>(null, "trackname");
        TrackAsset ctrack = timeline.CreateTrack <ControlTrack>(null, "control_track");

        foreach (List <string> clipitem_list in clipList)
        {
            string name         = clipitem_list[0];
            string type         = clipitem_list[1];
            float  start        = float.Parse(clipitem_list[2]);
            float  dur          = float.Parse(clipitem_list[3]);
            string gameobj_name = clipitem_list[4];

            if (type.Equals("cam"))
            {
                var clip = track.CreateDefaultClip();
                clip.start       = start;
                clip.duration    = dur;
                clip.displayName = name;

                CinemachineVirtualCamera new_cam = GameObject.Find(gameobj_name).GetComponent <CinemachineVirtualCamera>();
                var cinemachineShot = clip.asset as CinemachineShot;
                cinemachineShot.VirtualCamera.exposedName = UnityEditor.GUID.Generate().ToString();
                director.SetReferenceValue(cinemachineShot.VirtualCamera.exposedName, new_cam);
            }
            else // assume control track
            {
                var clip = ctrack.CreateDefaultClip();
                clip.start       = start;
                clip.duration    = dur;
                clip.displayName = name;
                GameObject new_cam     = GameObject.Find(gameobj_name);
                var        controlshot = clip.asset as ControlPlayableAsset;
                controlshot.sourceGameObject.exposedName = UnityEditor.GUID.Generate().ToString();
                director.SetReferenceValue(controlshot.sourceGameObject.exposedName, new_cam);
            }
        }

        // Set cinemachine brain as track's game object
        director.SetGenericBinding(track, main_camera_object);

        // Set it to play when ready.
        director.Play(timeline);
    }
예제 #4
0
    public void GenerateMoveClip(PlayableDirector director, int trackIndex)
    {
        List <CurvePoint> points = GetPointsInScene();

        if (points.Count <= 0)
        {
            return;
        }
        string        errorLog = "";
        TimelineAsset asset    = director.playableAsset as TimelineAsset;
        TrackAsset    track    = asset.GetOutputTrack(trackIndex);

        if (track == null)
        {
            errorLog = "Track Index Error";
        }
        if (!(track is RoleMoveTrack))
        {
            errorLog = "Track 类型错误,不是RoleMoveTrack";
        }
        if (string.IsNullOrEmpty(errorLog))
        {
            List <Vector3> pointsPos = points.Select(point => point.transform.position).ToList();
            TimelineClip   clip      = track.CreateDefaultClip();
            RoleMoveClip   moveclip  = clip.asset as RoleMoveClip;
            moveclip.points   = pointsPos;
            moveclip.roleData = director.GetGenericBinding(track) as RoleData;
        }
        else
        {
            Debug.LogError(errorLog);
        }
    }
        /// <summary>
        /// Adds a given animation clip to the specified timeline track
        /// </summary>
        /// <param name="track">the timeline track to add the clip to</param>
        /// <param name="clip">the animation clip to add</param>
        public static void AddClipToAnimationTrack(TrackAsset track, AnimationClip clip)
        {
            var newClip = track.CreateDefaultClip();

            newClip.duration    = clip.length;
            newClip.displayName = clip.name;
            var animAsset = newClip.asset as AnimationPlayableAsset;

            animAsset.clip = clip;
        }
        public TimelineClip CreateClip(float start, float duration, string displayName)
        {
            TimelineClip tc;

            tc = currentTrack.CreateDefaultClip();

            tc.start       = start + .015f;// .06f;
            tc.duration    = duration;
            tc.displayName = displayName;


            TimelineClips.Add(tc);
            return(tc);
        }
        public virtual TimelineClip CreateClip(float start, float duration, string displayName)
        {
            TimelineClip tc;

            if (FreeInterval(start, start + duration, TimelineClips))
            {
                tc = currentTrack.CreateDefaultClip();
            }
            else
            {
                trackNum++;
                currentTrack  = timeline.CreateTrack <ControlTrack>(null, name + trackNum.ToString());
                TimelineClips = new List <TimelineClip>();
                tc            = currentTrack.CreateDefaultClip();
            }

            tc.start       = start;
            tc.duration    = duration;
            tc.displayName = displayName;

            TimelineClips.Add(tc);
            return(tc);
        }
    // 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);
    }