private void AddActorEvent(object userData)
    {
        ContextData data = userData as ContextData;

        if (data != null)
        {
            string name = DirectorHelper.getCutsceneItemName(data.Label, data.Type);

            float      firetime = state.IsInPreviewMode ? state.ScrubberPosition : 0f;
            GameObject item     = CutsceneItemFactory.CreateActorEvent((TargetTrack.Behaviour as ActorItemTrack), data.Type, name, firetime).gameObject;
            Undo.RegisterCreatedObjectUndo(item, string.Format("Created {0}", item.name));
        }
    }
示例#2
0
        public static void CreateCutscene(List <Sequence.FrameInfo> Frames, float DurationPerFrame)
        {
            string cutsceneName = DirectorHelper.getCutsceneItemName("New Cutscene", typeof(Cutscene));

            GameObject cutsceneGO = new GameObject(cutsceneName);
            Cutscene   cutscene   = cutsceneGO.AddComponent <Cutscene>();

            GameObject framesGO = new GameObject("Frames");

            framesGO.transform.SetParent(cutsceneGO.transform);

            GameObject triggersGO = new GameObject("Triggers");

            triggersGO.transform.SetParent(cutsceneGO.transform);

            List <Transform> frameTransforms = new List <Transform>();
            float            time            = 0;

            for (int i = 0; i < Frames.Count; i++)
            {
                if (Frames[i].m_Source == null)
                {
                    time += DurationPerFrame * Frames[i].Duration;
                    continue;
                }
                var frameGO = GameObject.Instantiate(Frames[i].m_Source) as GameObject;
                frameGO.name = Frames[i].m_Source.name;
                frameGO.transform.SetParent(framesGO.transform);
                frameGO.transform.localPosition    = Vector3.zero;
                frameGO.transform.localEulerAngles = Vector3.zero;
                frameGO.transform.localScale       = Vector3.one;
                frameGO.SetActive(false);
                frameTransforms.Add(frameGO.transform);
                var group = CutsceneItemFactory.CreateActorTrackGroup(cutscene, frameGO.transform) as ActorTrackGroup;
                group.transform.SetParent(triggersGO.transform);
                var track  = CutsceneItemFactory.CreateActorItemTrack(group);
                var action = CutsceneItemFactory.CreateActorAction(track, typeof(EnableGameObjectAction),
                                                                   "Temporary Enable", time) as EnableGameObjectAction;
                action.Firetime = time;
                action.Duration = DurationPerFrame * Frames[i].Duration;
                time           += action.Duration;

                CutsceneItemFactory.CreateActorEvent(track, typeof(DisableGameObject), "Disable", 0);
            }

            cutscene.Duration    = time;
            cutscene.IsLooping   = true;
            cutscene.IsSkippable = false;

            // Cutscene trigger
            GameObject cutsceneTriggerGO = new GameObject("Cutscene Trigger");

            cutsceneTriggerGO.transform.SetParent(cutsceneGO.transform);
            CutsceneTrigger cutsceneTrigger = cutsceneTriggerGO.AddComponent <CutsceneTrigger>();

            cutsceneTrigger.StartMethod = StartMethod.OnStart;
            cutsceneTrigger.Cutscene    = cutscene;

            int undoIndex = Undo.GetCurrentGroup();

            Undo.RegisterCreatedObjectUndo(cutsceneGO, "Created New Cutscene");
            Undo.CollapseUndoOperations(undoIndex);

            Selection.activeTransform = cutsceneGO.transform;

            // Open director
            DirectorWindow window = EditorWindow.GetWindow(typeof(DirectorWindow)) as DirectorWindow;

            window.FocusCutscene(cutscene);
        }