Exemple #1
0
 void Update()
 {
     if (_audioIsPlaying && _stopTime <= EditorApplication.timeSinceStartup)
     {
         EditorAudioPlayer.Stop();
         _audioIsPlaying = false;
     }
 }
Exemple #2
0
        public override void OnInspectorGUI()
        {
            EditorGUI.BeginChangeCheck();

            if (_textArea == null)
            {
                _textArea          = new GUIStyle(GUI.skin.textArea);
                _textArea.wordWrap = true;
            }

            TextNode myTarget = (TextNode)target;

            // NPC Details
            EditorGUIExtension.SimpleBox("", 5, "", delegate()
            {
                myTarget.ActorName = EditorGUILayout.TextField(new GUIContent("Actor Name*", "Name of the Actor who 'says' the text. If no value is set, the system uses the name you defined in the Dialogue Behaviour Component."), myTarget.ActorName);

                EditorGUI.BeginChangeCheck();
                myTarget.Portrait = (Sprite)EditorGUILayout.ObjectField("Portrait", myTarget.Portrait, typeof(Sprite), false);

                if (EditorGUI.EndChangeCheck())
                {
                    _portraitWarning = CheckSpriteProblem(myTarget.Portrait);
                }

                if (_portraitWarning)
                {
                    EditorGUILayout.HelpBox(
                        "The visual editor can't visualize this sprite right above the node." +
                        "To fix this, please set the Read/Write enable in the sprite import settings." +
                        "\n This issue is not affects runtime functionality! ",
                        MessageType.Warning);
                }
            });

            EditorGUILayout.Space();

            EditorGUIExtension.SimpleBox("Text", 5, "", delegate()
            {
                myTarget.Text = EditorGUILayout.TextArea(myTarget.Text, _textArea, GUILayout.Height(100));

                EditorGUILayout.Space();

                _answers.Draw();
            });



            EditorGUILayout.Space();

            // AUDIO
            EditorGUIExtension.FoldoutBox("Audio", ref myTarget.AudioFoldout, (myTarget.Audio != null) ? 1 : 0, delegate()
            {
                EditorGUI.indentLevel--;
                EditorGUILayout.Space();

                EditorGUI.BeginChangeCheck();
                myTarget.Audio = (AudioClip)EditorGUILayout.ObjectField("Audio Clip", myTarget.Audio, typeof(AudioClip), false);
                if (EditorGUI.EndChangeCheck())
                {
                    myTarget.AudioDelay     = 0;
                    myTarget.AudioEndTime   = (myTarget.Audio != null) ? myTarget.Audio.length : 0;
                    myTarget.AudioStartTime = 0;
                }

                EditorGUI.indentLevel++;

                if (myTarget.Audio != null)
                {
                    myTarget.AudioDelay = EditorGUILayout.FloatField(new GUIContent("Play delay", "Seconds after the audio clip started to play after the textnode is appeared."), myTarget.AudioDelay);

                    GUILayout.Space(10);

                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label(new GUIContent("Playback (seconds)", "Seconds of the audio clip where it should start"));

                    myTarget.AudioStartTime = EditorGUILayout.FloatField(myTarget.AudioStartTime, GUILayout.Width(75));

                    EditorGUILayout.MinMaxSlider(ref myTarget.AudioStartTime, ref myTarget.AudioEndTime, 0, myTarget.Audio.length);

                    myTarget.AudioEndTime = EditorGUILayout.FloatField(myTarget.AudioEndTime, GUILayout.Width(75));

                    EditorGUILayout.EndHorizontal();

                    GUILayout.Space(10);

                    if (!_audioIsPlaying && GUILayout.Button(EditorGUIUtility.FindTexture("PlayButton")))
                    {
                        int start = (int)System.Math.Ceiling(myTarget.Audio.samples * (myTarget.AudioStartTime / myTarget.Audio.length));
                        EditorAudioPlayer.Play(myTarget.Audio, start);
                        _audioIsPlaying = true;
                        _stopTime       = EditorApplication.timeSinceStartup + myTarget.AudioEndTime;
                    }

                    if (_audioIsPlaying && GUILayout.Button(EditorGUIUtility.FindTexture("PlayButton On")))
                    {
                        EditorAudioPlayer.Stop();
                        _audioIsPlaying = false;
                    }
                }

                EditorGUILayout.Space();
            });

            EditorGUILayout.Space();

            // CAMERA
            string title = "Custom Camera";

            if (myTarget.CustomCameraEnable)
            {
                title += " [index: " + myTarget.CameraIndex + "]";
            }

            EditorGUIExtension.FoldoutBox(title, ref myTarget.CameraFoldout, (myTarget.CustomCameraEnable) ? 1 : 0, delegate()
            {
                EditorGUI.indentLevel--;
                EditorGUILayout.Space();

                myTarget.CustomCameraEnable = EditorGUILayout.Toggle("Enable", myTarget.CustomCameraEnable);
                if (myTarget.CustomCameraEnable)
                {
                    myTarget.CameraIndex = EditorGUILayout.IntField("Camera Index", myTarget.CameraIndex);
                }

                EditorGUILayout.Space();
                EditorGUI.indentLevel++;
            });


            // ADVANCED
            EditorGUIExtension.FoldoutBox("Advanced Settings", ref myTarget.AdvancedSettingsFoldout, -1, delegate()
            {
                EditorGUI.indentLevel--;
                EditorGUILayout.Space();

                myTarget.CustomSkinEnable = EditorGUILayout.Toggle("Use Custom Skin", myTarget.CustomSkinEnable);
                if (myTarget.CustomSkinEnable)
                {
                    // NAME
                    if (_skinNames.DrawGUI())
                    {
                        myTarget.Skin = SkinDatabase.Instance.Skins[_skinNames.Index].Name;
                    }
                }

                EditorGUILayout.Space();
                EditorGUI.indentLevel++;
            });

            if (EditorGUI.EndChangeCheck())
            {
                myTarget.HasChanges = true;
            }
        }