protected override void showBodyContextMenu(Event evt)
    {
        TimelineTrack itemTrack = TargetTrack.Behaviour as TimelineTrack;

        if (itemTrack == null)
        {
            return;
        }

        List <Type> trackTypes = itemTrack.GetAllowedCutsceneItems();
        GenericMenu createMenu = new GenericMenu();

        for (int i = 0; i < trackTypes.Count; i++)
        {
            ContextData data = getContextData(trackTypes[i]);
            data.Firetime = (evt.mousePosition.x - state.Translation.x) / state.Scale.x;
            createMenu.AddItem(new GUIContent(string.Format("Add New/{0}/{1}", data.Category, data.Label)), false, addCutsceneItem, data);
        }

        Behaviour    b            = DirectorCopyPaste.Peek();
        PasteContext pasteContext = new PasteContext(evt.mousePosition, itemTrack);

        if (b != null && DirectorHelper.IsTrackItemValidForTrack(b, itemTrack))
        {
            createMenu.AddItem(new GUIContent("Paste"), false, pasteItem, pasteContext);
        }
        else
        {
            createMenu.AddDisabledItem(new GUIContent("Paste"));
        }
        createMenu.ShowAsContext();
    }
    public void OnEnable()
    {
        enableBehaviour         = new SerializedObject(this.target);
        this.fireTime           = enableBehaviour.FindProperty("firetime");
        this.componentsProperty = enableBehaviour.FindProperty("Behaviour");
        this.editorRevert       = enableBehaviour.FindProperty("editorRevertMode");
        this.runtimeRevert      = enableBehaviour.FindProperty("runtimeRevertMode");
        Component currentComponent = componentsProperty.objectReferenceValue as Component;

        EnableBehaviour behaviour = (target as EnableBehaviour);

        if (behaviour == null || behaviour.ActorTrackGroup == null || behaviour.ActorTrackGroup.Actor == null)
        {
            return;
        }
        GameObject actor = behaviour.ActorTrackGroup.Actor.gameObject;

        Component[] components = DirectorHelper.getEnableableComponents(actor);
        for (int j = 0; j < components.Length; j++)
        {
            if (components[j] == currentComponent)
            {
                componentSelection = j;
            }
        }
    }
    public override void OnInspectorGUI()
    {
        enableBehaviour.Update();

        EnableBehaviour behaviour = (target as EnableBehaviour);
        GameObject      actor     = behaviour.ActorTrackGroup.Actor.gameObject;

        EditorGUILayout.PropertyField(this.fireTime, firetimeContent);

        List <GUIContent> componentSelectionList = new List <GUIContent>();

        Component[] components = DirectorHelper.getEnableableComponents(actor);
        for (int i = 0; i < components.Length; i++)
        {
            Component component = components[i];
            componentSelectionList.Add(new GUIContent(component.GetType().Name));
            if (componentsProperty.objectReferenceValue as Component == component)
            {
                componentSelection = i;
            }
        }
        componentSelection = EditorGUILayout.Popup(new GUIContent("Behaviour"), componentSelection, componentSelectionList.ToArray());
        componentsProperty.objectReferenceValue = components[componentSelection];

        EditorGUILayout.PropertyField(editorRevert);
        EditorGUILayout.PropertyField(runtimeRevert);

        enableBehaviour.ApplyModifiedProperties();
    }
Ejemplo n.º 4
0
    internal static AudioTrack CreateAudioTrack(DirectorGroup directorGroup)
    {
        string     name         = DirectorHelper.getCutsceneItemName(directorGroup.gameObject, AUDIO_TRACK_LABEL, typeof(AudioTrack));
        GameObject audioTrackGO = new GameObject(name, typeof(AudioTrack));

        audioTrackGO.transform.parent = directorGroup.transform;
        return(audioTrackGO.GetComponent <AudioTrack>());
    }
Ejemplo n.º 5
0
    internal static GlobalItemTrack CreateGlobalItemTrack(DirectorGroup directorGroup)
    {
        string     name          = DirectorHelper.getCutsceneItemName(directorGroup.gameObject, GLOBAL_TRACK_LABEL, typeof(GlobalItemTrack));
        GameObject globalTrackGO = new GameObject(name, typeof(GlobalItemTrack));

        globalTrackGO.transform.parent = directorGroup.transform;
        return(globalTrackGO.GetComponent <GlobalItemTrack>());
    }
Ejemplo n.º 6
0
        /// <summary>
        /// Fill _timeAtGrid, index in range [from, to], assuming constant BPM (bpm) starting from referenceIdx
        /// </summary>
        private void SetTimeAtGrid(int from, int to, double bpm, int referenceIdx)
        {
            var secondsPerSignature = DirectorHelper.BpmToSeconds(bpm);

            for (int i = from; i <= to; ++i)
            {
                var numGrids = i - referenceIdx;
                _timeAtGrid[i] = _timeAtGrid[referenceIdx] + numGrids * secondsPerSignature / GridPerSignature;
            }
        }
Ejemplo n.º 7
0
    /// <summary>
    /// Draws the GUI for the Timeline Window.
    /// </summary>
    protected void OnGUI()
    {
        Rect toolbarArea = new Rect(0, 0, base.position.width, TOOLBAR_HEIGHT);
        Rect controlArea = new Rect(0, TOOLBAR_HEIGHT, base.position.width, base.position.height - TOOLBAR_HEIGHT);

        updateToolbar(toolbarArea);
        cutsceneWrapper = DirectorHelper.UpdateWrapper(cutscene, cutsceneWrapper);
        directorControl.OnGUI(controlArea, cutsceneWrapper);
        DirectorHelper.ReflectChanges(cutscene, cutsceneWrapper);
    }
Ejemplo n.º 8
0
    public Director()
    {
        state = new StateMachine<Director>(this);
        state.SetCurrentState(DirectorStateMachine1.Instance);

        entityManager = EntityManager<Actor>.CreateEntityManager();
        messageDispatcher = MessageDispatcher<Actor>.CreateMessageDispatcher(entityManager);
        helper = new DirectorHelper(this);
        helper.CreateActor();
    }
    private void addNewGlobalItem(GlobalItemTrack itemTrack)
    {
        GenericMenu createMenu = new GenericMenu();

        foreach (Type type in DirectorHelper.GetAllSubTypes(typeof(CinemaGlobalAction)))
        {
            string text     = string.Empty;
            string category = string.Empty;
            string label    = string.Empty;
            foreach (CutsceneItemAttribute attribute in type.GetCustomAttributes(typeof(CutsceneItemAttribute), true))
            {
                if (attribute != null)
                {
                    category = attribute.Category;
                    label    = attribute.Label;
                    text     = string.Format("{0}/{1}", attribute.Category, attribute.Label);
                    break;
                }
            }
            if (label != string.Empty)
            {
                TrackItemInfoContextData userData = new TrackItemInfoContextData {
                    Type = type, Label = label, Category = category
                };
                createMenu.AddItem(new GUIContent(text), false, new GenericMenu.MenuFunction2(AddGlobalAction), userData);
            }
        }

        foreach (Type type in DirectorHelper.GetAllSubTypes(typeof(CinemaGlobalEvent)))
        {
            string text     = string.Empty;
            string category = string.Empty;
            string label    = string.Empty;
            foreach (CutsceneItemAttribute attribute in type.GetCustomAttributes(typeof(CutsceneItemAttribute), true))
            {
                if (attribute != null)
                {
                    category = attribute.Category;
                    label    = attribute.Label;
                    text     = string.Format("{0}/{1}", attribute.Category, attribute.Label);
                    break;
                }
            }
            if (label != string.Empty)
            {
                TrackItemInfoContextData userData = new TrackItemInfoContextData {
                    Type = type, Label = label, Category = category
                };
                createMenu.AddItem(new GUIContent(text), false, new GenericMenu.MenuFunction2(AddGlobalEvent), userData);
            }
        }
        createMenu.ShowAsContext();
    }
Ejemplo n.º 10
0
    private void AddEvent(object userData)
    {
        ContextData data = userData as ContextData;

        if (data != null)
        {
            string     name       = DirectorHelper.getCutsceneItemName(data.Label, data.Type);
            GameObject trackEvent = new GameObject(name);
            trackEvent.AddComponent(data.Type);
            trackEvent.transform.parent = (this.target as GlobalItemTrack).transform;
        }
    }
    private void AddActorAction(object userData)
    {
        ContextData data = userData as ContextData;

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

            GameObject item = CutsceneItemFactory.CreateActorAction((TargetTrack.Behaviour as ActorItemTrack), data.Type, name, state.ScrubberPosition).gameObject;
            Undo.RegisterCreatedObjectUndo(item, string.Format("Created {0}", item.name));
        }
    }
Ejemplo n.º 12
0
        /// <summary>
        /// Show the "Add Track Group" context menu.
        /// </summary>
        /// <param name="cutscene">The current Cutscene that the track group will be added to.</param>
        public static void ShowAddTrackGroupContextMenu(Cutscene cutscene)
        {
            GenericMenu createMenu = new GenericMenu();

            foreach (Type type in DirectorHelper.GetAllSubTypes(typeof(TrackGroup)))
            {
                TrackGroupContextData userData = getContextDataFromType(cutscene, type);
                string text = string.Format(userData.Label);
                createMenu.AddItem(new GUIContent(text), false, new GenericMenu.MenuFunction2(AddTrackGroup), userData);
            }

            createMenu.ShowAsContext();
        }
    private void AddGlobalEvent(object userData)
    {
        TrackItemInfoContextData data = userData as TrackItemInfoContextData;

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

            float      firetime = state.IsInPreviewMode ? state.ScrubberPosition : 0f;
            GameObject item     = CutsceneItemFactory.CreateGlobalEvent((TargetTrack.Behaviour as GlobalItemTrack), data.Type, name, firetime).gameObject;
            Undo.RegisterCreatedObjectUndo(item, string.Format("Created {0}", item.name));
        }
    }
Ejemplo n.º 14
0
        private void UpdateTimeLength()
        {
            var  length      = 0.0;
            Note lastBpmNote = null;

            _timeAtGrid    = new double[TotalGridCount];
            _timeAtGrid[0] = StartTime;

            // find all BpmNotes and compute the length between them
            foreach (var note in Notes)
            {
                if (note.Type != NoteType.VariantBpm)
                {
                    continue;
                }

                if (lastBpmNote == null)
                {
                    // length between start and first BpmNote
                    length += DirectorHelper.BpmToSeconds(StartBpm) * note.IndexInGrid / GridPerSignature;
                    SetTimeAtGrid(1, note.IndexInGrid, StartBpm, 0);
                }
                else
                {
                    // length between prev BpmNote and current
                    var deltaGridCount = note.IndexInGrid - lastBpmNote.IndexInGrid;
                    length += DirectorHelper.BpmToSeconds(lastBpmNote.ExtraParams.NewBpm) * deltaGridCount / GridPerSignature;
                    SetTimeAtGrid(lastBpmNote.IndexInGrid + 1, note.IndexInGrid, lastBpmNote.ExtraParams.NewBpm, lastBpmNote.IndexInGrid);
                }

                lastBpmNote = note;
            }

            // length from the last BpmNote to end
            // if it's null, there is no BpmNote in the bar
            if (lastBpmNote != null)
            {
                length += DirectorHelper.BpmToSeconds(lastBpmNote.ExtraParams.NewBpm) * (TotalGridCount - lastBpmNote.IndexInGrid) / GridPerSignature;
                SetTimeAtGrid(lastBpmNote.IndexInGrid + 1, TotalGridCount - 1, lastBpmNote.ExtraParams.NewBpm, lastBpmNote.IndexInGrid);
            }
            else
            {
                length = DirectorHelper.BpmToSeconds(StartBpm) * Signature;
                for (int i = 0; i < TotalGridCount; ++i)
                {
                    _timeAtGrid[i] = StartTime + length * i / TotalGridCount;
                }
            }

            TimeLength = length;
        }
Ejemplo n.º 15
0
    protected override void showContextMenu(Behaviour behaviour)
    {
        CinemaActorClipCurve clipCurve = behaviour as CinemaActorClipCurve;

        if (clipCurve == null)
        {
            return;
        }

        List <KeyValuePair <string, string> > currentCurves = new List <KeyValuePair <string, string> >();
        {
            var __list1      = clipCurve.CurveData;
            var __listCount1 = __list1.Count;
            for (int __i1 = 0; __i1 < __listCount1; ++__i1)
            {
                var data = (MemberClipCurveData)__list1[__i1];
                {
                    KeyValuePair <string, string> curveStrings = new KeyValuePair <string, string>(data.Type, data.PropertyName);
                    currentCurves.Add(curveStrings);
                }
            }
        }
        GenericMenu createMenu = new GenericMenu();

        if (clipCurve.Actor != null)
        {
            Component[] components = DirectorHelper.getValidComponents(clipCurve.Actor.gameObject);

            for (int i = 0; i < components.Length; i++)
            {
                Component    component = components[i];
                MemberInfo[] members   = DirectorHelper.getValidMembers(component);
                for (int j = 0; j < members.Length; j++)
                {
                    AddCurveContext context = new AddCurveContext();
                    context.clipCurve  = clipCurve;
                    context.component  = component;
                    context.memberInfo = members[j];
                    if (!currentCurves.Contains(new KeyValuePair <string, string>(component.GetType().Name, members[j].Name)))
                    {
                        createMenu.AddItem(new GUIContent(string.Format("Add Curve/{0}/{1}", component.GetType().Name, DirectorHelper.GetUserFriendlyName(component, members[j]))), false, addCurve, context);
                    }
                }
            }
            createMenu.AddSeparator(string.Empty);
        }
        createMenu.AddItem(new GUIContent("Copy"), false, copyItem, behaviour);
        createMenu.AddSeparator(string.Empty);
        createMenu.AddItem(new GUIContent("Clear"), false, deleteItem, clipCurve);
        createMenu.ShowAsContext();
    }
Ejemplo n.º 16
0
        /// <summary>
        /// Show the "Add Track Group" context menu.
        /// </summary>
        /// <param name="cutscene">The current Cutscene that the track group will be added to.</param>
        public static void ShowAddTrackGroupContextMenu(TimelineManager cutscene)
        {
            GenericMenu createMenu = new GenericMenu();

            Type[] subTypes = DirectorHelper.GetAllSubTypes(typeof(TrackGroup));
            for (int i = 0; i < subTypes.Length; i++)
            {
                TrackGroupContextData userData = getContextDataFromType(cutscene, subTypes[i]);
                string text = string.Format(userData.Label);
                createMenu.AddItem(new GUIContent(text), false, new GenericMenu.MenuFunction2(AddTrackGroup), userData);
            }

            createMenu.ShowAsContext();
        }
Ejemplo n.º 17
0
    /// <summary>
    /// Update and Draw the inspector
    /// </summary>
    public override void OnInspectorGUI()
    {
        audioTrack.Update();

        foreach (CinemaAudio audio in (target as AudioTrack).AudioClips)
        {
            EditorGUILayout.ObjectField(audio.name, audio, typeof(CinemaAudio), true);
        }

        if (GUILayout.Button(addAudio))
        {
            string     label     = DirectorHelper.getCutsceneItemName("Audio Item", typeof(CinemaAudio));
            GameObject audioItem = new GameObject(label, new System.Type[] { typeof(CinemaAudio), typeof(AudioSource) });
            audioItem.transform.parent = (this.target as AudioTrack).transform;
        }

        audioTrack.ApplyModifiedProperties();
    }
Ejemplo n.º 18
0
    /// <summary>
    /// Draws the GUI for the Timeline Window.
    /// </summary>
    protected void OnGUI()
    {
        Rect controlArea = new Rect(0, TOOLBAR_HEIGHT, position.width, position.height - TOOLBAR_HEIGHT);

        updateToolbar();

        cutsceneWrapper = DirectorHelper.UpdateWrapper(cutscene, cutsceneWrapper);
        switch (Event.current.keyCode)
        {
        case KeyCode.RightArrow:
            cutscene.RunningTime += 0.01f;
            break;

        case KeyCode.LeftArrow:
            cutscene.RunningTime -= 0.01f;
            break;
        }
        directorControl.OnGUI(controlArea, cutsceneWrapper, position);
        DirectorHelper.ReflectChanges(cutscene, cutsceneWrapper);
    }
Ejemplo n.º 19
0
        /// <summary>
        /// Show the "Add Track Group" context menu.
        /// </summary>
        /// <param name="cutscene">The current Cutscene that the track group will be added to.</param>
        public static void ShowAddTrackGroupContextMenu(Cutscene cutscene)
        {
            GenericMenu createMenu = new GenericMenu();

            {
                // foreach(var type in DirectorHelper.GetAllSubTypes(typeof(TrackGroup)))
                var __enumerator1 = (DirectorHelper.GetAllSubTypes(typeof(TrackGroup))).GetEnumerator();
                while (__enumerator1.MoveNext())
                {
                    var type = (Type)__enumerator1.Current;
                    {
                        TrackGroupContextData userData = getContextDataFromType(cutscene, type);
                        string text = string.Format(userData.Label);
                        createMenu.AddItem(new GUIContent(text), false, new GenericMenu.MenuFunction2(AddTrackGroup), userData);
                    }
                }
            }

            createMenu.ShowAsContext();
        }
Ejemplo n.º 20
0
    internal static CinemaAudio CreateCinemaAudio(AudioTrack track, AudioClip clip, float firetime)
    {
        string      name        = DirectorHelper.getCutsceneItemName(track.gameObject, AUDIO_CLIP_NAME_DEFAULT, typeof(CinemaAudio));
        GameObject  item        = new GameObject(name);
        CinemaAudio cinemaAudio = item.AddComponent <CinemaAudio>();
        AudioSource source      = item.AddComponent <AudioSource>();

        source.clip = clip;

        SortedDictionary <float, CinemaAudio> sortedClips = new SortedDictionary <float, CinemaAudio>();

        foreach (CinemaAudio a in track.AudioClips)
        {
            sortedClips.Add(a.Firetime, a);
        }

        float latestTime = firetime;

        float length = source.clip.length;

        foreach (CinemaAudio a in sortedClips.Values)
        {
            if (!(latestTime < a.Firetime && latestTime + length <= a.Firetime))
            {
                latestTime = a.Firetime + a.Duration;
            }
        }

        cinemaAudio.Firetime   = latestTime;
        cinemaAudio.Duration   = length;
        cinemaAudio.InTime     = 0;
        cinemaAudio.OutTime    = length;
        cinemaAudio.ItemLength = length;
        source.playOnAwake     = false;
        item.transform.parent  = track.transform;

        return(cinemaAudio);
    }
    private void addNewActorItem(ActorItemTrack itemTrack)
    {
        GenericMenu createMenu = new GenericMenu();

        Type actorActionType = typeof(CinemaActorAction);

        foreach (Type type in DirectorHelper.GetAllSubTypes(actorActionType))
        {
            ContextData userData = getContextDataFromType(type);
            string      text     = string.Format("{0}/{1}", userData.Category, userData.Label);
            createMenu.AddItem(new GUIContent(text), false, new GenericMenu.MenuFunction2(AddActorAction), userData);
        }

        Type actorEventType = typeof(CinemaActorEvent);

        foreach (Type type in DirectorHelper.GetAllSubTypes(actorEventType))
        {
            ContextData userData = getContextDataFromType(type);
            string      text     = string.Format("{0}/{1}", userData.Category, userData.Label);
            createMenu.AddItem(new GUIContent(text), false, new GenericMenu.MenuFunction2(AddActorEvent), userData);
        }
        createMenu.ShowAsContext();
    }
Ejemplo n.º 22
0
    /// <summary>
    /// Update and Draw the inspector
    /// </summary>
    public override void OnInspectorGUI()
    {
        audioTrack.Update();
        {
            var __array1       = (target as AudioTrack).AudioClips;
            var __arrayLength1 = __array1.Length;
            for (int __i1 = 0; __i1 < __arrayLength1; ++__i1)
            {
                var audio = (CinemaAudio)__array1[__i1];
                {
                    EditorGUILayout.ObjectField(audio.name, audio, typeof(CinemaAudio), true);
                }
            }
        }
        if (GUILayout.Button(addAudio))
        {
            string     label     = DirectorHelper.getCutsceneItemName("Audio Item", typeof(CinemaAudio));
            GameObject audioItem = new GameObject(label, new System.Type[] { typeof(CinemaAudio), typeof(AudioSource) });
            audioItem.transform.parent = (this.target as AudioTrack).transform;
        }

        audioTrack.ApplyModifiedProperties();
    }
Ejemplo n.º 23
0
    public static CinemaShot CreateNewShot(ShotTrack shotTrack)
    {
        string     name   = DirectorHelper.getCutsceneItemName(shotTrack.gameObject, SHOT_NAME_DEFAULT, typeof(CinemaShot));
        GameObject shotGO = new GameObject(name);

        shotGO.transform.parent = shotTrack.transform;

        SortedDictionary <float, CinemaShot> sortedShots = new SortedDictionary <float, CinemaShot>();

        foreach (CinemaShot s in shotTrack.TimelineItems)
        {
            sortedShots.Add(s.CutTime, s);
        }

        float latestTime = 0;
        float length     = DEFAULT_SHOT_LENGTH;

        foreach (CinemaShot s in sortedShots.Values)
        {
            if (latestTime >= s.CutTime)
            {
                latestTime = Mathf.Max(latestTime, s.CutTime + s.Duration);
            }
            else
            {
                length = s.CutTime - latestTime;
                break;
            }
        }

        CinemaShot shot = shotGO.AddComponent <CinemaShot>();

        shot.CutTime    = latestTime;
        shot.ShotLength = length;

        return(shot);
    }
Ejemplo n.º 24
0
    internal static CinemaMultiActorCurveClip CreateMultiActorClipCurve(MultiCurveTrack multiCurveTrack)
    {
        string     name = DirectorHelper.getCutsceneItemName(multiCurveTrack.gameObject, CURVE_CLIP_NAME_DEFAULT, typeof(CinemaMultiActorCurveClip));
        GameObject item = new GameObject(name);

        item.transform.parent = multiCurveTrack.transform;
        CinemaMultiActorCurveClip clip = item.AddComponent <CinemaMultiActorCurveClip>();

        SortedDictionary <float, CinemaMultiActorCurveClip> sortedItems = new SortedDictionary <float, CinemaMultiActorCurveClip>();

        foreach (CinemaMultiActorCurveClip c in multiCurveTrack.TimelineItems)
        {
            sortedItems.Add(c.Firetime, c);
        }

        float latestTime = 0;
        float length     = DEFAULT_CURVE_LENGTH;

        foreach (CinemaMultiActorCurveClip c in sortedItems.Values)
        {
            if (latestTime >= c.Firetime)
            {
                latestTime = Mathf.Max(latestTime, c.Firetime + c.Duration);
            }
            else
            {
                length = c.Firetime - latestTime;
                break;
            }
        }

        clip.Firetime = latestTime;
        clip.Duration = length;

        return(clip);
    }
Ejemplo n.º 25
0
        private static double CalculateTimingPeriodBetweenNotes(List <DelesteBeatmapEntry> entries, DelesteBasicNote currentBasicFlickNote, DelesteBasicNote lastBasicFlickNote, int fullLength)
        {
            double timeDiff;
            double timePerBeat;
            DelesteBeatmapEntry entry;

            if (currentBasicFlickNote.Entry.MeasureIndex != lastBasicFlickNote.Entry.MeasureIndex)
            {
                var startIndex = entries.IndexOf(lastBasicFlickNote.Entry);
                var endIndex   = entries.IndexOf(currentBasicFlickNote.Entry, startIndex + 1);

                entry       = lastBasicFlickNote.Entry;
                timePerBeat = DirectorHelper.BpmToSeconds(entry.BPM);
                timeDiff    = timePerBeat * entry.Signature * (1 - (float)lastBasicFlickNote.IndexInMeasure / lastBasicFlickNote.Entry.FullLength);
                for (var i = startIndex + 1; i < endIndex; ++i)
                {
                    entry = entries[i];
                    if (entry.IsCommand)
                    {
                        continue;
                    }
                    timePerBeat = DirectorHelper.BpmToSeconds(entry.BPM);
                    timeDiff   += timePerBeat * entry.Signature;
                }
                entry       = currentBasicFlickNote.Entry;
                timePerBeat = DirectorHelper.BpmToSeconds(entry.BPM);
                timeDiff   += timePerBeat * entry.Signature * ((float)currentBasicFlickNote.IndexInMeasure / fullLength);
            }
            else
            {
                entry       = currentBasicFlickNote.Entry;
                timePerBeat = DirectorHelper.BpmToSeconds(entry.BPM);
                timeDiff    = timePerBeat * entry.Signature * ((float)currentBasicFlickNote.IndexInMeasure / fullLength - (float)lastBasicFlickNote.IndexInMeasure / lastBasicFlickNote.Entry.FullLength);
            }
            return(timeDiff);
        }
Ejemplo n.º 26
0
    protected override void showBodyContextMenu(Event evt)
    {
        ShotTrack itemTrack = TargetTrack.Behaviour as ShotTrack;

        if (itemTrack == null)
        {
            return;
        }

        Behaviour b = DirectorCopyPaste.Peek();

        PasteContext pasteContext = new PasteContext(evt.mousePosition, itemTrack);
        GenericMenu  createMenu   = new GenericMenu();

        if (b != null && DirectorHelper.IsTrackItemValidForTrack(b, itemTrack))
        {
            createMenu.AddItem(new GUIContent("Paste"), false, pasteItem, pasteContext);
        }
        else
        {
            createMenu.AddDisabledItem(new GUIContent("Paste"));
        }
        createMenu.ShowAsContext();
    }
Ejemplo n.º 27
0
    /// <summary>
    /// Update and Draw the inspector
    /// </summary>
    public override void OnInspectorGUI()
    {
        eventTrack.Update();
        ActorItemTrack track = base.serializedObject.targetObject as ActorItemTrack;

        CinemaActorAction[] actions     = track.ActorActions;
        CinemaActorEvent[]  actorEvents = track.ActorEvents;

        if (actions.Length > 0 || actorEvents.Length > 0)
        {
            actionFoldout = EditorGUILayout.Foldout(actionFoldout, actionContent);
            if (actionFoldout)
            {
                EditorGUI.indentLevel++;

                foreach (CinemaActorAction action in actions)
                {
                    EditorGUILayout.ObjectField(action.name, action, typeof(CinemaActorAction), true);
                }
                foreach (CinemaActorEvent actorEvent in actorEvents)
                {
                    EditorGUILayout.ObjectField(actorEvent.name, actorEvent, typeof(CinemaActorEvent), true);
                }
                EditorGUI.indentLevel--;
            }
        }

        if (GUILayout.Button(addActionContent))
        {
            GenericMenu createMenu = new GenericMenu();

            Type actorActionType = typeof(CinemaActorAction);
            foreach (Type type in DirectorHelper.GetAllSubTypes(actorActionType))
            {
                string text     = string.Empty;
                string category = string.Empty;
                string label    = string.Empty;
                foreach (CutsceneItemAttribute attribute in type.GetCustomAttributes(typeof(CutsceneItemAttribute), true))
                {
                    if (attribute != null)
                    {
                        category = attribute.Category;
                        label    = attribute.Label;
                        text     = string.Format("{0}/{1}", category, label);
                        break;
                    }
                }
                ContextData userData = new ContextData {
                    type = type, label = label, category = category
                };
                createMenu.AddItem(new GUIContent(text), false, new GenericMenu.MenuFunction2(AddEvent), userData);
            }

            Type actorEventType = typeof(CinemaActorEvent);
            foreach (Type type in DirectorHelper.GetAllSubTypes(actorEventType))
            {
                string text     = string.Empty;
                string category = string.Empty;
                string label    = string.Empty;
                foreach (CutsceneItemAttribute attribute in type.GetCustomAttributes(typeof(CutsceneItemAttribute), true))
                {
                    if (attribute != null)
                    {
                        category = attribute.Category;
                        label    = attribute.Label;
                        text     = string.Format("{0}/{1}", attribute.Category, attribute.Label);
                        break;
                    }
                }
                ContextData userData = new ContextData {
                    type = type, label = label, category = category
                };
                createMenu.AddItem(new GUIContent(text), false, new GenericMenu.MenuFunction2(AddEvent), userData);
            }
            createMenu.ShowAsContext();
        }

        eventTrack.ApplyModifiedProperties();
    }
Ejemplo n.º 28
0
    /// <summary>
    /// Draw and update the toolbar for the director control
    /// </summary>
    /// <param name="toolbarArea">The area for the toolbar</param>
    private void updateToolbar(Rect toolbarArea)
    {
        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);

        // If there are no cutscenes, then only give option to create a new cutscene.
        if (GUILayout.Button(CREATE, EditorStyles.toolbarDropDown, GUILayout.Width(60)))
        {
            GenericMenu createMenu = new GenericMenu();
            createMenu.AddItem(new_cutscene, false, openCutsceneCreatorWindow);
            createMenu.AddItem(default_cutscene, false, createDefaultCutscene);
            createMenu.AddItem(empty_cutscene, false, createEmptyCutscene);


            if (cutscene != null)
            {
                createMenu.AddSeparator(string.Empty);
                createMenu.AddItem(new_cutscene_trigger, false, createCutsceneTrigger);
                createMenu.AddSeparator(string.Empty);

                Type[] subTypes = DirectorHelper.GetAllSubTypes(typeof(TrackGroup));
                for (int i = 0; i < subTypes.Length; i++)
                {
                    TrackGroupContextData userData = getContextDataFromType(subTypes[i]);
                    string text = string.Format(userData.Label);
                    createMenu.AddItem(new GUIContent(text), false, new GenericMenu.MenuFunction2(AddTrackGroup), userData);
                }
            }

            createMenu.DropDown(new Rect(5, TOOLBAR_HEIGHT, 0, 0));
        }

        // Cutscene selector
        cachedCutscenes = GameObject.FindObjectsOfType <Cutscene>();
        if (cachedCutscenes != null && cachedCutscenes.Length > 0)
        {
            // Get cutscene names
            GUIContent[] cutsceneNames = new GUIContent[cachedCutscenes.Length];
            for (int i = 0; i < cachedCutscenes.Length; i++)
            {
                cutsceneNames[i] = new GUIContent(cachedCutscenes[i].name);
            }

            // Sort alphabetically
            Array.Sort(cutsceneNames, delegate(GUIContent content1, GUIContent content2)
            {
                return(string.Compare(content1.text, content2.text));
            });

            int count = 1;
            // Resolve duplicate names
            for (int i = 0; i < cutsceneNames.Length - 1; i++)
            {
                int next = i + 1;
                while (next < cutsceneNames.Length && string.Compare(cutsceneNames[i].text, cutsceneNames[next].text) == 0)
                {
                    cutsceneNames[next].text = string.Format("{0} (duplicate {1})", cutsceneNames[next].text, count++);
                    next++;
                }
                count = 1;
            }

            Array.Sort(cachedCutscenes, delegate(Cutscene c1, Cutscene c2)
            {
                return(string.Compare(c1.name, c2.name));
            });

            // Find the currently selected cutscene.
            for (int i = 0; i < cachedCutscenes.Length; i++)
            {
                if (cutscene != null && cutscene.GetInstanceID() == cachedCutscenes[i].GetInstanceID())
                {
                    popupSelection = i;
                }
            }

            // Show the popup
            int tempPopup = EditorGUILayout.Popup(popupSelection, cutsceneNames, EditorStyles.toolbarPopup);
            if (cutscene == null || tempPopup != popupSelection || cutsceneInstanceID != cachedCutscenes[Math.Min(tempPopup, cachedCutscenes.Length - 1)].GetInstanceID())
            {
                popupSelection = tempPopup;
                popupSelection = Math.Min(popupSelection, cachedCutscenes.Length - 1);
                FocusCutscene(cachedCutscenes[popupSelection]);
            }
        }
        if (cutscene != null)
        {
            if (GUILayout.Button(pickerImage, EditorStyles.toolbarButton, GUILayout.Width(24)))
            {
                Selection.activeObject = cutscene;
            }
            if (GUILayout.Button(refreshImage, EditorStyles.toolbarButton, GUILayout.Width(24)))
            {
                cutscene.Refresh();
            }

            if (Event.current.control && Event.current.keyCode == KeyCode.Space)
            {
                cutscene.Refresh();
                Event.current.Use();
            }
        }
        GUILayout.FlexibleSpace();

        if (betaFeaturesEnabled)
        {
            Texture resizeTexture = cropImage;
            if (directorControl.ResizeOption == DirectorEditor.ResizeOption.Scale)
            {
                resizeTexture = scaleImage;
            }
            Rect resizeRect = GUILayoutUtility.GetRect(new GUIContent(resizeTexture), EditorStyles.toolbarDropDown, GUILayout.Width(32));
            if (GUI.Button(resizeRect, new GUIContent(resizeTexture, "Resize Option"), EditorStyles.toolbarDropDown))
            {
                GenericMenu resizeMenu = new GenericMenu();

                string[] names = Enum.GetNames(typeof(DirectorEditor.ResizeOption));

                for (int i = 0; i < names.Length; i++)
                {
                    resizeMenu.AddItem(new GUIContent(names[i]), directorControl.ResizeOption == (DirectorEditor.ResizeOption)i, chooseResizeOption, i);
                }

                resizeMenu.DropDown(new Rect(resizeRect.x, TOOLBAR_HEIGHT, 0, 0));
            }
        }

        bool tempSnapping = GUILayout.Toggle(isSnappingEnabled, snapImage, EditorStyles.toolbarButton, GUILayout.Width(24));

        if (tempSnapping != isSnappingEnabled)
        {
            isSnappingEnabled = tempSnapping;
            directorControl.IsSnappingEnabled = isSnappingEnabled;
        }

        //GUILayout.Button(rollingEditImage, EditorStyles.toolbarButton, GUILayout.Width(24));
        GUILayout.Space(10f);

        if (GUILayout.Button(rescaleImage, EditorStyles.toolbarButton, GUILayout.Width(24)))
        {
            directorControl.Rescale();
        }
        if (GUILayout.Button(new GUIContent(zoomInImage, "Zoom In"), EditorStyles.toolbarButton, GUILayout.Width(24)))
        {
            directorControl.ZoomIn();
        }
        if (GUILayout.Button(zoomOutImage, EditorStyles.toolbarButton, GUILayout.Width(24)))
        {
            directorControl.ZoomOut();
        }
        GUILayout.Space(10f);

        Color temp = GUI.color;

        GUI.color = directorControl.InPreviewMode ? Color.red : temp;
        directorControl.InPreviewMode = GUILayout.Toggle(directorControl.InPreviewMode, PREVIEW_MODE, EditorStyles.toolbarButton, GUILayout.Width(150));
        GUI.color = temp;
        GUILayout.Space(10);

        if (GUILayout.Button(settingsImage, EditorStyles.toolbarButton, GUILayout.Width(30)))
        {
            EditorWindow.GetWindow <DirectorSettingsWindow>();
        }
        // Check if the Welcome Window exists and if so, show an icon for it.
        var helpWindowType = Type.GetType("CinemaSuite.CinemaSuiteWelcome");

        if (helpWindowType != null)
        {
            if (GUILayout.Button(new GUIContent("?", "Help"), EditorStyles.toolbarButton))
            {
                EditorWindow.GetWindow(helpWindowType);
            }
        }
        EditorGUILayout.EndHorizontal();
    }
Ejemplo n.º 29
0
    /// <summary>
    /// Draws the Director GUI
    /// </summary>
    protected void OnGUI()
    {
        scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
        {
            txtCutsceneName = EditorGUILayout.TextField(NameContentCutscene, txtCutsceneName);
            EditorGUILayout.BeginHorizontal();
            txtDuration = EditorGUILayout.FloatField(DurationContentCutscene, txtDuration);
            timeEnum    = (DirectorHelper.TimeEnum)EditorGUILayout.EnumPopup(timeEnum);
            EditorGUILayout.EndHorizontal();

            isLooping   = EditorGUILayout.Toggle(LoopingContentCutscene, isLooping);
            isSkippable = EditorGUILayout.Toggle(SkippableContentCutscene, isSkippable);
            StartMethod = (StartMethod)EditorGUILayout.EnumPopup(new GUIContent("开始方法"), StartMethod);

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("轨道组", EditorStyles.boldLabel);

            // Director Group
            directorTrackGroupsSelection = EditorGUILayout.Popup(AddDirectorGroupContent, directorTrackGroupsSelection, intValues1.ToArray());

            if (directorTrackGroupsSelection > 0)
            {
                EditorGUI.indentLevel++;

                // Shot Tracks
                shotTrackSelection = EditorGUILayout.Popup(AddShotTracksContent, shotTrackSelection, intValues1.ToArray());

                // Audio Tracks
                audioTrackSelection = EditorGUILayout.Popup(AddAudioTracksContent, audioTrackSelection, intValues4.ToArray());

                // Global Item Tracks
                globalItemTrackSelection = EditorGUILayout.Popup(AddGlobalTracksContent, globalItemTrackSelection, intValues10.ToArray());

                EditorGUI.indentLevel--;
            }

            EditorGUILayout.Space();

            // Actor Track Groups
            int actorCount = EditorGUILayout.Popup(new GUIContent("主角轨道群组"), actorTrackGroupsSelection, intValues10.ToArray());

            if (actorCount != actorTrackGroupsSelection)
            {
                actorTrackGroupsSelection = actorCount;

                Transform[] tempActors = new Transform[actors.Length];
                Array.Copy(actors, tempActors, actors.Length);

                actors = new Transform[actorCount];
                int amount = Math.Min(actorCount, tempActors.Length);
                Array.Copy(tempActors, actors, amount);
            }

            EditorGUI.indentLevel++;
            for (int i = 1; i <= actorTrackGroupsSelection; i++)
            {
                actors[i - 1] = EditorGUILayout.ObjectField(new GUIContent(string.Format("主角 {0}", i)), actors[i - 1], typeof(Transform), true) as Transform;
            }
            EditorGUI.indentLevel--;

            EditorGUILayout.Space();
            // Multi Actor Track Groups
            multiActorTrackGroupsSelection = EditorGUILayout.Popup(new GUIContent("多主角轨道群组"), multiActorTrackGroupsSelection, intValues10.ToArray());
            EditorGUI.indentLevel++;
            EditorGUI.indentLevel--;
            Add(ref characters, ref characterTrackGroupsSelection, "ActorTrackGroups");
            for (int i = 1; i <= characterTrackGroupsSelection; i++)
            {
                characters[i - 1] = EditorGUILayout.ObjectField(new GUIContent(string.Format("角色 {0}", i)), characters[i - 1], typeof(Transform), true) as Transform;
            }
            EditorGUI.indentLevel--;
        }

        EditorGUILayout.EndScrollView();

        EditorGUILayout.BeginHorizontal();
        {
            if (GUILayout.Button("I'm Feeling Lucky"))
            {
                List <Transform> interestingActors = UnitySceneEvaluator.GetHighestRankedGameObjects(10);

                actorTrackGroupsSelection = interestingActors.Count;
                actors = interestingActors.ToArray();
            }

            if (GUILayout.Button("创建剧情"))
            {
                string cutsceneName = DirectorHelper.getCutsceneItemName(txtCutsceneName, typeof(Cutscene));

                GameObject cutsceneGO = new GameObject(cutsceneName);
                Cutscene   cutscene   = cutsceneGO.AddComponent <Cutscene>();
                for (int i = 0; i < directorTrackGroupsSelection; i++)
                {
                    DirectorGroup dg = CutsceneItemFactory.CreateDirectorGroup(cutscene);
                    dg.Ordinal = 0;
                    for (int j = 0; j < shotTrackSelection; j++)
                    {
                        CutsceneItemFactory.CreateShotTrack(dg);
                    }
                    for (int j = 0; j < audioTrackSelection; j++)
                    {
                        CutsceneItemFactory.CreateAudioTrack(dg);
                    }
                    for (int j = 0; j < globalItemTrackSelection; j++)
                    {
                        CutsceneItemFactory.CreateGlobalItemTrack(dg);
                    }
                }

                for (int i = 0; i < actorTrackGroupsSelection; i++)
                {
                    CutsceneItemFactory.CreateActorTrackGroup(cutscene, actors[i]);
                }

                for (int i = 0; i < multiActorTrackGroupsSelection; i++)
                {
                    CutsceneItemFactory.CreateMultiActorTrackGroup(cutscene);
                }

                for (int i = 0; i < characterTrackGroupsSelection; i++)
                {
                    CutsceneItemFactory.CreateCharacterTrackGroup(cutscene, characters[i]);
                }
                float duration = txtDuration;
                if (timeEnum == DirectorHelper.TimeEnum.Minutes)
                {
                    duration *= 60;
                }
                cutscene.Duration = duration;

                int undoIndex = Undo.GetCurrentGroup();

                if (StartMethod != StartMethod.None)
                {
                    GameObject      cutsceneTriggerGO = new GameObject("Cutscene Trigger");
                    CutsceneTrigger cutsceneTrigger   = cutsceneTriggerGO.AddComponent <CutsceneTrigger>();
                    if (StartMethod == StartMethod.OnTrigger)
                    {
                        cutsceneTriggerGO.AddComponent <BoxCollider>();
                    }
                    cutsceneTrigger.StartMethod = StartMethod;
                    cutsceneTrigger.Cutscene    = cutscene;
                    Undo.RegisterCreatedObjectUndo(cutsceneTriggerGO, string.Format("Created {0}", txtCutsceneName));
                }

                Undo.RegisterCreatedObjectUndo(cutsceneGO, string.Format("Created {0}", txtCutsceneName));
                Undo.CollapseUndoOperations(undoIndex);
                Selection.activeTransform = cutsceneGO.transform;
            }
        }
        EditorGUILayout.EndHorizontal();
    }
    public override void OnInspectorGUI()
    {
        actorClipCurve.Update();
        CinemaActorClipCurve clipCurveGameObject = (target as CinemaActorClipCurve);

        if (clipCurveGameObject == null || clipCurveGameObject.Actor == null)
        {
            EditorGUILayout.HelpBox(ERROR_MSG, UnityEditor.MessageType.Error);
            return;
        }

        GameObject actor = clipCurveGameObject.Actor.gameObject;

        List <KeyValuePair <string, string> > currentCurves = new List <KeyValuePair <string, string> >();

        EditorGUILayout.PropertyField(editorRevert);
        EditorGUILayout.PropertyField(runtimeRevert);

        SerializedProperty curveData = actorClipCurve.FindProperty("curveData");

        if (curveData.arraySize > 0)
        {
            isDataFolded = EditorGUILayout.Foldout(isDataFolded, dataContent);
            if (isDataFolded)
            {
                for (int i = 0; i < curveData.arraySize; i++)
                {
                    SerializedProperty member         = curveData.GetArrayElementAtIndex(i);
                    SerializedProperty typeProperty   = member.FindPropertyRelative("Type");
                    SerializedProperty memberProperty = member.FindPropertyRelative("PropertyName");

                    KeyValuePair <string, string> curveStrings = new KeyValuePair <string, string>(typeProperty.stringValue, memberProperty.stringValue);
                    currentCurves.Add(curveStrings);

                    Component c = actor.GetComponent(typeProperty.stringValue);

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(new GUIContent(string.Format("{0}.{1}", typeProperty.stringValue, DirectorHelper.GetUserFriendlyName(typeProperty.stringValue, memberProperty.stringValue)), EditorGUIUtility.ObjectContent(c, c.GetType()).image));
                    if (GUILayout.Button("-", GUILayout.Width(24f)))
                    {
                        curveData.DeleteArrayElementAtIndex(i);
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
            GUILayout.Space(5);
        }

        isNewCurveFolded = EditorGUILayout.Foldout(isNewCurveFolded, addContent);

        if (isNewCurveFolded)
        {
            List <GUIContent> componentSelectionList = new List <GUIContent>();
            List <GUIContent> propertySelectionList  = new List <GUIContent>();

            Component[] components = DirectorHelper.getValidComponents(actor);
            for (int i = 0; i < components.Length; i++)
            {
                Component component = components[i];

                if (component != null)
                {
                    componentSelectionList.Add(new GUIContent(component.GetType().Name));
                }
            }

            componentSeletion = EditorGUILayout.Popup(new GUIContent("Component"), componentSeletion, componentSelectionList.ToArray());
            MemberInfo[]      members    = DirectorHelper.getValidMembers(components[componentSeletion]);
            List <MemberInfo> newMembers = new List <MemberInfo>();
            for (int i = 0; i < members.Length; i++)
            {
                MemberInfo memberInfo = members[i];
                if (!currentCurves.Contains(new KeyValuePair <string, string>(components[componentSeletion].GetType().Name, memberInfo.Name)))
                {
                    newMembers.Add(memberInfo);
                }
            }
            members = newMembers.ToArray();

            for (int i = 0; i < members.Length; i++)
            {
                MemberInfo memberInfo = members[i];
                string     name       = DirectorHelper.GetUserFriendlyName(components[componentSeletion], memberInfo);
                propertySelectionList.Add(new GUIContent(name));
            }
            propertySelection = EditorGUILayout.Popup(new GUIContent("Property"), propertySelection, propertySelectionList.ToArray());

            if (GUILayout.Button("Add Curve") && members.Length > 0)
            {
                Type         t          = null;
                PropertyInfo property   = members[propertySelection] as PropertyInfo;
                FieldInfo    field      = members[propertySelection] as FieldInfo;
                bool         isProperty = false;
                if (property != null)
                {
                    t          = property.PropertyType;
                    isProperty = true;
                }
                else if (field != null)
                {
                    t          = field.FieldType;
                    isProperty = false;
                }
                clipCurveGameObject.AddClipCurveData(components[componentSeletion], members[propertySelection].Name, isProperty, t);
            }
        }



        actorClipCurve.ApplyModifiedProperties();
    }
Ejemplo n.º 31
0
    /// <summary>
    /// Update and Draw the inspector
    /// </summary>
    public override void OnInspectorGUI()
    {
        eventTrack.Update();
        GlobalItemTrack track = base.serializedObject.targetObject as GlobalItemTrack;

        CinemaGlobalAction[] actions = track.Actions;
        CinemaGlobalEvent[]  events  = track.Events;

        if (actions.Length > 0 || events.Length > 0)
        {
            actionFoldout = EditorGUILayout.Foldout(actionFoldout, actionContent);
            if (actionFoldout)
            {
                EditorGUI.indentLevel++;

                for (int i = 0; i < actions.Length; i++)
                {
                    EditorGUILayout.ObjectField(actions[i].name, actions[i], typeof(CinemaGlobalAction), true);
                }
                for (int i = 0; i < events.Length; i++)
                {
                    EditorGUILayout.ObjectField(events[i].name, events[i], typeof(CinemaGlobalEvent), true);
                }
                EditorGUI.indentLevel--;
            }
        }

        if (GUILayout.Button(addActionContent))
        {
            GenericMenu createMenu = new GenericMenu();

            Type[] actionSubTypes = DirectorHelper.GetAllSubTypes(typeof(CinemaGlobalAction));
            for (int i = 0; i < actionSubTypes.Length; i++)
            {
                string   text     = string.Empty;
                string   category = string.Empty;
                string   label    = string.Empty;
                object[] attrs    = actionSubTypes[i].GetCustomAttributes(typeof(CutsceneItemAttribute), true);
                for (int j = 0; j < attrs.Length; j++)
                {
                    CutsceneItemAttribute attribute = attrs[j] as CutsceneItemAttribute;
                    if (attribute != null)
                    {
                        category = attribute.Category;
                        label    = attribute.Label;
                        text     = string.Format("{0}/{1}", attribute.Category, attribute.Label);
                        break;
                    }
                }
                if (label != string.Empty)
                {
                    ContextData userData = new ContextData {
                        Type = actionSubTypes[i], Label = label, Category = category
                    };
                    createMenu.AddItem(new GUIContent(text), false, new GenericMenu.MenuFunction2(AddEvent), userData);
                }
            }

            Type[] eventSubTypes = DirectorHelper.GetAllSubTypes(typeof(CinemaGlobalEvent));
            for (int i = 0; i < eventSubTypes.Length; i++)
            {
                string   text     = string.Empty;
                string   category = string.Empty;
                string   label    = string.Empty;
                object[] attrs    = eventSubTypes[i].GetCustomAttributes(typeof(CutsceneItemAttribute), true);
                for (int j = 0; j < attrs.Length; j++)
                {
                    CutsceneItemAttribute attribute = attrs[j] as CutsceneItemAttribute;
                    if (attribute != null)
                    {
                        category = attribute.Category;
                        label    = attribute.Label;
                        text     = string.Format("{0}/{1}", attribute.Category, attribute.Label);
                        break;
                    }
                }
                if (label != string.Empty)
                {
                    ContextData userData = new ContextData {
                        Type = eventSubTypes[i], Label = label, Category = category
                    };
                    createMenu.AddItem(new GUIContent(text), false, new GenericMenu.MenuFunction2(AddEvent), userData);
                }
            }
            createMenu.ShowAsContext();
        }

        eventTrack.ApplyModifiedProperties();
    }