예제 #1
0
    /// <summary>
    /// Plays a quote from the narrator.
    /// </summary>
    /// <param name="_quote">Quote to play.</param>
    public void PlayNarratorQuote(TDS_NarratorQuote _quote)
    {
        if (narratorCoroutine != null)
        {
            StopCoroutine(narratorCoroutine);
        }

        narratorCoroutine = StartCoroutine(PlayNarratorQuoteCoroutine(_quote));
    }
예제 #2
0
    /// <summary>
    /// Plays a quote from the narrator.
    /// </summary>
    /// <param name="_quote">Quote to play.</param>
    /// <returns></returns>
    private IEnumerator PlayNarratorQuoteCoroutine(TDS_NarratorQuote _quote)
    {
        TDS_UIManager.Instance.ActivateNarratorBox(_quote.Quote);

        // If an audio track is linked, play it
        if (_quote.AudioTrack)
        {
            TDS_SoundManager.Instance.PlayNarratorQuote(_quote.AudioTrack);
            yield return(new WaitForSeconds(_quote.AudioTrack.length));
        }
        else
        {
            yield return(new WaitForSeconds(_quote.Quote.Length / 15));
        }

        TDS_UIManager.Instance.DesactivateNarratorBox();

        narratorCoroutine = null;
    }
    /// <summary>
    /// Draws the editor for the events.
    /// </summary>
    public void DrawEvents(SerializedProperty _events, ref bool[] _foldouts)
    {
        // Button to add a new event
        GUI.backgroundColor = TDS_EditorUtility.BoxLightColor;
        GUI.color           = Color.green;

        if (TDS_EditorUtility.Button("+", "Add a new event", EditorStyles.miniButton))
        {
            _events.InsertArrayElementAtIndex(0);
            _events.GetArrayElementAtIndex(0).FindPropertyRelative("Name").stringValue = "New Event";

            bool[] _newFoldouts = new bool[_foldouts.Length + 1];
            Array.Copy(_foldouts, 0, _newFoldouts, 1, _foldouts.Length);
            _foldouts = _newFoldouts;
        }

        GUI.color           = Color.white;
        GUI.backgroundColor = TDS_EditorUtility.BoxDarkColor;

        for (int _i = 0; _i < _events.arraySize; _i++)
        {
            GUILayout.Space(5);

            GUI.backgroundColor = TDS_EditorUtility.BoxLightColor;
            EditorGUILayout.BeginVertical("Box");

            SerializedProperty _event     = _events.GetArrayElementAtIndex(_i);
            SerializedProperty _eventName = _event.FindPropertyRelative("Name");

            EditorGUILayout.BeginHorizontal();

            // Button to show or not this event
            if (TDS_EditorUtility.Button(_eventName.stringValue, "Wrap / unwrap this event", TDS_EditorUtility.HeaderStyle))
            {
                _foldouts[_i] = !_foldouts[_i];
            }

            GUILayout.FlexibleSpace();

            // BUttons to change the event position in the list
            if ((_i > 0) && TDS_EditorUtility.Button("▲", "Move this element up", EditorStyles.miniButton))
            {
                _events.MoveArrayElement(_i, _i - 1);
            }
            if ((_i < _events.arraySize - 1) && TDS_EditorUtility.Button("▼", "Move this element down", EditorStyles.miniButton))
            {
                _events.MoveArrayElement(_i, _i + 1);
            }

            // Button to delete this event
            GUI.color = Color.red;
            if (TDS_EditorUtility.Button("X", "Delete this event", EditorStyles.miniButton))
            {
                _events.DeleteArrayElementAtIndex(_i);

                bool[] _newFoldouts = new bool[_foldouts.Length - 1];
                Array.Copy(_foldouts, 0, _newFoldouts, 0, _i);
                Array.Copy(_foldouts, _i + 1, _newFoldouts, _i, _foldouts.Length - (_i + 1));
                _foldouts = _newFoldouts;
                break;
            }

            GUI.color = Color.white;
            EditorGUILayout.EndHorizontal();

            // If unfolded, draws this event
            if (_foldouts[_i])
            {
                SerializedProperty _eventType     = _event.FindPropertyRelative("eventType");
                SerializedProperty _doRequireType = _event.FindPropertyRelative("doRequireSpecificPlayerType");

                TDS_EditorUtility.TextField("Name", "Name of this event", _eventName);

                GUILayout.Space(3);

                TDS_EditorUtility.PropertyField("Event Type", "Type of this event", _eventType);
                CustomEventType _eventTypeValue = (CustomEventType)_eventType.enumValueIndex;
                if (_eventType.enumValueIndex > 7)
                {
                    _eventTypeValue += 13;
                }

                TDS_EditorUtility.FloatField("Delay", "Delay before starting this event", _event.FindPropertyRelative("delay"));

                GUILayout.Space(3);

                TDS_EditorUtility.Toggle("Require specific Player type", "Should this event require a specific player type to be triggered", _doRequireType);
                if (_doRequireType.boolValue)
                {
                    TDS_EditorUtility.PropertyField("Required type of Player", "Required type of player to trigger this event", _event.FindPropertyRelative("playerType"));
                }

                GUILayout.Space(5);

                switch (_eventTypeValue)
                {
                case CustomEventType.CameraMovement:
                    TDS_EditorUtility.PropertyField("Target", "Target to make the camera look ", _event.FindPropertyRelative("eventTransform"));

                    TDS_EditorUtility.FloatField("Duration", "Time to look at the target", _event.FindPropertyRelative("cameraWaitTime"));

                    TDS_EditorUtility.FloatField("Speed Coef", "Coefficient applied to the speed of the camera.", _event.FindPropertyRelative("eventFloat"));
                    break;

                case CustomEventType.DesactiveInfoBox:
                    break;

                case CustomEventType.DisplayInfoBox:
                    TDS_EditorUtility.TextField("Text ID", "ID of the text to use for the Info Box", _event.FindPropertyRelative("eventString"));
                    break;

                case CustomEventType.Instantiate:
                    TDS_EditorUtility.PropertyField("Prefab", "Prefab to instantiate", _event.FindPropertyRelative("prefab"));

                    TDS_EditorUtility.PropertyField("Instantiation transform reference", "Transform to use as reference for position & rotation for the transform of the instantiated object", _event.FindPropertyRelative("eventTransform"));
                    break;

                case CustomEventType.InstantiatePhoton:
                    TDS_EditorUtility.PropertyField("Prefab", "Prefab to instantiate", _event.FindPropertyRelative("prefab"));

                    TDS_EditorUtility.PropertyField("Instantiation transform reference", "Transform to use as reference for position & rotation for the transform of the instantiated object", _event.FindPropertyRelative("eventTransform"));
                    break;

                case CustomEventType.MovePlayerAroundPoint:
                    TDS_EditorUtility.PropertyField("Position", "Where to move te player around", _event.FindPropertyRelative("eventTransform"));
                    break;

                case CustomEventType.Narrator:
                    TDS_EditorUtility.PropertyField("Quote", "Narrator quote to play", _event.FindPropertyRelative("quote"));

                    GUILayout.BeginHorizontal();
                    GUILayout.FlexibleSpace();

                    Color _originalColor = GUI.color;
                    GUI.color = new Color(.7f, .35f, .75f);
                    if (GUILayout.Button(new GUIContent("Load Quote", "Loads the quote with the ID entered as Text ID"), GUILayout.Width(150)))
                    {
                        FieldInfo _fieldInfo = typeof(TDS_Event).GetField("quote", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
                        if (_fieldInfo != null)
                        {
                            TDS_NarratorQuote _quote = ((TDS_NarratorManager)Resources.Load(TDS_NarratorManager.FILE_PATH)).Quotes.FirstOrDefault(q => q.Name == _event.FindPropertyRelative("quote").FindPropertyRelative("Name").stringValue);

                            if (_quote != null)
                            {
                                TDS_Event[] _objectEvents = (TDS_Event[])typeof(TDS_EventsSystem).GetField(_events.name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(target);

                                typeof(TDS_Event).GetField("quote", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).SetValue(_objectEvents[_i], _quote);
                            }
                        }
                    }

                    GUI.color = _originalColor;
                    GUILayout.EndHorizontal();
                    break;

                case CustomEventType.PlayMusic:
                    _event.FindPropertyRelative("eventInt").intValue = EditorGUILayout.IntPopup("Music", _event.FindPropertyRelative("eventInt").intValue, Enum.GetNames(typeof(Music)), (int[])Enum.GetValues(typeof(Music)));

                    TDS_EditorUtility.FloatField("Fade Duration", "Time during which the previous music will fade out before the new one starts.", _event.FindPropertyRelative("eventFloat"));
                    break;

                case CustomEventType.WaitForObjectDeath:
                    TDS_EditorUtility.PropertyField("Object Tag", "Tag waiting for an object with dies", _event.FindPropertyRelative("eventString"));
                    TDS_EditorUtility.PropertyField("Amount", "Amount of object with this tag to wait for death", _event.FindPropertyRelative("eventInt"));
                    break;

                case CustomEventType.WaitForSpawnAreaDesactivation:
                    TDS_EditorUtility.PropertyField("Amount", "Amount of spawn area to wait for desactivation", _event.FindPropertyRelative("eventInt"));
                    break;

                case CustomEventType.UnityEventLocal:
                    TDS_EditorUtility.PropertyField("Unity Event", "Associated Unity Event to this event", _event.FindPropertyRelative("unityEvent"));
                    break;

                case CustomEventType.UnityEventOnline:
                    TDS_EditorUtility.PropertyField("Unity Event", "Associated Unity Event to this event", _event.FindPropertyRelative("unityEvent"));
                    break;

                case CustomEventType.WaitForAction:
                    TDS_EditorUtility.PropertyField("Action to wait", "Action to wait the player to perform", _event.FindPropertyRelative("actionType"));
                    break;

                case CustomEventType.WaitForEveryone:
                    TDS_EditorUtility.PropertyField("Bound min X", "Transform to use for minimum bound X value to wait", _event.FindPropertyRelative("eventTransform"));
                    break;

                default:
                    // Mhmm...
                    break;
                }

                // Button to add a new event
                GUI.color = Color.green;

                if (TDS_EditorUtility.Button("+", "Add a new event", EditorStyles.miniButton))
                {
                    _events.InsertArrayElementAtIndex(_i);

                    bool[] _newFoldouts = new bool[_foldouts.Length + 1];
                    Array.Copy(_foldouts, 0, _newFoldouts, 0, _i + 1);
                    Array.Copy(_foldouts, _i + 1, _newFoldouts, _i + 2, _foldouts.Length - (_i + 1));
                    _foldouts = _newFoldouts;
                }

                GUI.color = Color.white;
            }

            EditorGUILayout.EndVertical();
        }
    }