Exemple #1
0
        protected virtual IEnumerator WaitForInput(Action onInput)
        {
            while (!wasPointerClicked)
            {
                yield return(null);
            }
            wasPointerClicked = false;

            if (onInput != null)
            {
                // Stop all tweening portraits
                foreach (Character c in Character.activeCharacters)
                {
                    if (c.state.portraitImage != null)
                    {
                        if (LeanTween.isTweening(c.state.portraitObj))
                        {
                            LeanTween.cancel(c.state.portraitObj, true);
                            c.state.portraitImage.material.SetFloat("_Fade", 1);
                            Portrait.SetRectTransform(c.state.portraitImage.rectTransform, c.state.position);
                            if (c.state.dimmed == true)
                            {
                                c.state.portraitImage.material.SetColor("_Color", new Color(0.5f, 0.5f, 0.5f, 1f));
                            }
                            else
                            {
                                c.state.portraitImage.material.SetColor("_Color", new Color(1f, 1f, 1f, 1f));
                            }
                        }
                    }
                }
                onInput();
            }
        }
Exemple #2
0
        public virtual void SetCharacter(Character character, Flowchart flowchart = null)
        {
            if (character == null)
            {
                if (characterImage != null)
                {
                    characterImage.gameObject.SetActive(false);
                }
                if (nameText != null)
                {
                    nameText.text = "";
                }
                characterTypingSound = null;
            }
            else
            {
                Character prevSpeakingCharacter = speakingCharacter;
                speakingCharacter = character;

                // Dim portraits of non-speaking characters
                foreach (Stage s in Stage.activeStages)
                {
                    if (s.dimPortraits)
                    {
                        foreach (Character c in s.charactersOnStage)
                        {
                            if (prevSpeakingCharacter != speakingCharacter)
                            {
                                if (c != speakingCharacter)
                                {
                                    Portrait.Dim(c, s);
                                }
                                else
                                {
                                    Portrait.Undim(c, s);
                                }
                            }
                        }
                    }
                }

                string characterName = character.nameText;

                if (characterName == "")
                {
                    // Use game object name as default
                    characterName = character.name;
                }

                if (flowchart != null)
                {
                    characterName = flowchart.SubstituteVariables(characterName);
                }

                characterTypingSound = character.soundEffect;

                SetCharacterName(characterName, character.nameColor);
            }
        }
 protected void UndimAllPortraits(Stage stage)
 {
     stage.dimPortraits = false;
     foreach (Character character in stage.charactersOnStage)
     {
         Portrait.SetDimmed(character, stage, false);
     }
 }
Exemple #4
0
 protected void UndimAllPortraits(PortraitStage portraitStage)
 {
     portraitStage.dimPortraits = false;
     foreach (Character character in portraitStage.charactersOnStage)
     {
         Portrait.Undim(character, portraitStage);
     }
 }
Exemple #5
0
        public virtual void SetCharacter(Character character, FungusScript fungusScript = null)
        {
            if (character == null)
            {
                if (characterImage != null)
                {
                    characterImage.enabled = false;
                }
                if (nameText != null)
                {
                    nameText.text = "";
                }
                characterTypingSound = null;
            }
            else
            {
                Character prevSpeakingCharacter = speakingCharacter;
                speakingCharacter = character;

                // Dim portraits of non-speaking characters
                foreach (PortraitStage ps in PortraitStage.activePortraitStages)
                {
                    if (ps.dimPortraits)
                    {
                        foreach (Character c in ps.charactersOnStage)
                        {
                            if (prevSpeakingCharacter != speakingCharacter)
                            {
                                if (c != speakingCharacter)
                                {
                                    Portrait.Dim(c, ps);
                                }
                                else
                                {
                                    Portrait.Undim(c, ps);
                                }
                            }
                        }
                    }
                }

                string characterName = character.nameText;
                if (characterName == "")
                {
                    // Use game object name as default
                    characterName = character.name;
                }

                if (fungusScript != null)
                {
                    characterName = fungusScript.SubstituteVariables(characterName);
                }

                characterTypingSound = character.soundEffect;

                SetCharacterName(characterName, character.nameColor);
            }
        }
Exemple #6
0
        public static void StopPortraitTweens()
        {
            // Stop all tweening portraits
            foreach (Character c in Character.activeCharacters)
            {
                if (c.state.portraitImage != null)
                {
                    if (LeanTween.isTweening(c.state.portraitImage.gameObject))
                    {
                        LeanTween.cancel(c.state.portraitImage.gameObject, true);

                        Portrait.SetRectTransform(c.state.portraitImage.rectTransform, c.state.position);
                        if (c.state.dimmed == true)
                        {
                            c.state.portraitImage.color = new Color(0.5f, 0.5f, 0.5f, 1f);
                        }
                        else
                        {
                            c.state.portraitImage.color = Color.white;
                        }
                    }
                }
            }
        }
Exemple #7
0
        public override void DrawCommandGUI()
        {
            serializedObject.Update();

            Portrait t = target as Portrait;

            if (Stage.activeStages.Count > 1)
            {
                CommandEditor.ObjectField <Stage>(stageProp,
                                                  new GUIContent("Portrait Stage", "Stage to display the character portraits on"),
                                                  new GUIContent("<Default>"),
                                                  Stage.activeStages);
            }
            else
            {
                t.stage = null;
            }
            // Format Enum names
            string[] displayLabels = StringFormatter.FormatEnumNames(t.display, "<None>");
            displayProp.enumValueIndex = EditorGUILayout.Popup("Display", (int)displayProp.enumValueIndex, displayLabels);

            string characterLabel = "Character";

            if (t.display == DisplayType.Replace)
            {
                CommandEditor.ObjectField <Character>(replacedCharacterProp,
                                                      new GUIContent("Replace", "Character to replace"),
                                                      new GUIContent("<None>"),
                                                      Character.activeCharacters);
                characterLabel = "With";
            }

            CommandEditor.ObjectField <Character>(characterProp,
                                                  new GUIContent(characterLabel, "Character to display"),
                                                  new GUIContent("<None>"),
                                                  Character.activeCharacters);

            bool  showOptionalFields = true;
            Stage s = t.stage;

            // Only show optional portrait fields once required fields have been filled...
            if (t.character != null)                  // Character is selected
            {
                if (t.character.portraits == null ||  // Character has a portraits field
                    t.character.portraits.Count <= 0) // Character has at least one portrait
                {
                    EditorGUILayout.HelpBox("This character has no portraits. Please add portraits to the character's prefab before using this command.", MessageType.Error);
                    showOptionalFields = false;
                }
                if (t.stage == null)            // If default portrait stage selected
                {
                    if (t.stage == null)        // If no default specified, try to get any portrait stage in the scene
                    {
                        s = GameObject.FindObjectOfType <Stage>();
                    }
                }
                if (s == null)
                {
                    EditorGUILayout.HelpBox("No portrait stage has been set.", MessageType.Error);
                    showOptionalFields = false;
                }
            }
            if (t.display != DisplayType.None && t.character != null && showOptionalFields)
            {
                if (t.display != DisplayType.Hide && t.display != DisplayType.MoveToFront)
                {
                    // PORTRAIT
                    CommandEditor.ObjectField <Sprite>(portraitProp,
                                                       new GUIContent("Portrait", "Portrait representing character"),
                                                       new GUIContent("<Previous>"),
                                                       t.character.portraits);
                    if (t.character.portraitsFace != FacingDirection.None)
                    {
                        // FACING
                        // Display the values of the facing enum as <-- and --> arrows to avoid confusion with position field
                        string[] facingArrows = new string[]
                        {
                            "<Previous>",
                            "<--",
                            "-->",
                        };
                        facingProp.enumValueIndex = EditorGUILayout.Popup("Facing", (int)facingProp.enumValueIndex, facingArrows);
                    }
                    else
                    {
                        t.facing = FacingDirection.None;
                    }
                }
                else
                {
                    t.portrait = null;
                    t.facing   = FacingDirection.None;
                }
                string toPositionPrefix = "";
                if (t.move)
                {
                    // MOVE
                    EditorGUILayout.PropertyField(moveProp);
                }
                if (t.move)
                {
                    if (t.display != DisplayType.Hide)
                    {
                        // START FROM OFFSET
                        EditorGUILayout.PropertyField(shiftIntoPlaceProp);
                    }
                }
                if (t.move)
                {
                    if (t.display != DisplayType.Hide)
                    {
                        if (t.shiftIntoPlace)
                        {
                            t.fromPosition = null;
                            // OFFSET
                            // Format Enum names
                            string[] offsetLabels = StringFormatter.FormatEnumNames(t.offset, "<Previous>");
                            offsetProp.enumValueIndex = EditorGUILayout.Popup("From Offset", (int)offsetProp.enumValueIndex, offsetLabels);
                        }
                        else
                        {
                            t.offset = PositionOffset.None;
                            // FROM POSITION
                            CommandEditor.ObjectField <RectTransform>(fromPositionProp,
                                                                      new GUIContent("From Position", "Move the portrait to this position"),
                                                                      new GUIContent("<Previous>"),
                                                                      s.positions);
                        }
                    }
                    toPositionPrefix = "To ";
                }
                else
                {
                    t.shiftIntoPlace = false;
                    t.fromPosition   = null;
                    toPositionPrefix = "At ";
                }
                if (t.display == DisplayType.Show || (t.display == DisplayType.Hide && t.move))
                {
                    // TO POSITION
                    CommandEditor.ObjectField <RectTransform>(toPositionProp,
                                                              new GUIContent(toPositionPrefix + "Position", "Move the portrait to this position"),
                                                              new GUIContent("<Previous>"),
                                                              s.positions);
                }
                else
                {
                    t.toPosition = null;
                }
                if (!t.move && t.display != DisplayType.MoveToFront)
                {
                    // MOVE
                    EditorGUILayout.PropertyField(moveProp);
                }
                if (t.display != DisplayType.MoveToFront)
                {
                    EditorGUILayout.Separator();

                    // USE DEFAULT SETTINGS
                    EditorGUILayout.PropertyField(useDefaultSettingsProp);
                    if (!t.useDefaultSettings)
                    {
                        // FADE DURATION
                        EditorGUILayout.PropertyField(fadeDurationProp);
                        if (t.move)
                        {
                            // MOVE SPEED
                            EditorGUILayout.PropertyField(moveDurationProp);
                        }
                        if (t.shiftIntoPlace)
                        {
                            // SHIFT OFFSET
                            EditorGUILayout.PropertyField(shiftOffsetProp);
                        }
                    }
                }
                else
                {
                    t.move = false;
                    t.useDefaultSettings = true;
                    EditorGUILayout.Separator();
                }

                EditorGUILayout.PropertyField(waitUntilFinishedProp);


                if (t.portrait != null && t.display != DisplayType.Hide)
                {
                    Texture2D characterTexture = t.portrait.texture;

                    float aspect      = (float)characterTexture.width / (float)characterTexture.height;
                    Rect  previewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(100), GUILayout.ExpandWidth(true));

                    if (characterTexture != null)
                    {
                        GUI.DrawTexture(previewRect, characterTexture, ScaleMode.ScaleToFit, true, aspect);
                    }
                }

                if (t.display != DisplayType.Hide)
                {
                    string portraitName = "<Previous>";
                    if (t.portrait != null)
                    {
                        portraitName = t.portrait.name;
                    }
                    string   portraitSummary = " " + portraitName;
                    int      toolbarInt      = 1;
                    string[] toolbarStrings  = { "<--", portraitSummary, "-->" };
                    toolbarInt = GUILayout.Toolbar(toolbarInt, toolbarStrings, GUILayout.MinHeight(20));
                    int portraitIndex = -1;

                    if (toolbarInt != 1)
                    {
                        for (int i = 0; i < t.character.portraits.Count; i++)
                        {
                            if (portraitName == t.character.portraits[i].name)
                            {
                                portraitIndex = i;
                            }
                        }
                    }

                    if (toolbarInt == 0)
                    {
                        if (portraitIndex > 0)
                        {
                            t.portrait = t.character.portraits[--portraitIndex];
                        }
                        else
                        {
                            t.portrait = null;
                        }
                    }
                    if (toolbarInt == 2)
                    {
                        if (portraitIndex < t.character.portraits.Count - 1)
                        {
                            t.portrait = t.character.portraits[++portraitIndex];
                        }
                    }
                }
            }
            serializedObject.ApplyModifiedProperties();
        }