Beispiel #1
0
 protected void UndimAllPortraits(PortraitStage portraitStage)
 {
     portraitStage.dimPortraits = false;
     foreach (Character character in portraitStage.charactersOnStage)
     {
         Portrait.Undim(character, portraitStage);
     }
 }
Beispiel #2
0
        public override void DrawCommandGUI()
        {
            serializedObject.Update();

            Stage t = target as Stage;

            // Format Enum names
            string[] displayLabels = StringFormatter.formatEnumNames(t.display, "<None>");
            displayProp.enumValueIndex = EditorGUILayout.Popup("Display", (int)displayProp.enumValueIndex, displayLabels);

            string replaceLabel = "Portrait Stage";

            if (t.display == stageDisplayType.Swap)
            {
                CommandEditor.ObjectField <PortraitStage>(replacedPortraitStageProp,
                                                          new GUIContent("Replace", "Character to swap with"),
                                                          new GUIContent("<Default>"),
                                                          PortraitStage.activePortraitStages);
                replaceLabel = "With";
            }

            if (PortraitStage.activePortraitStages.Count > 1)
            {
                CommandEditor.ObjectField <PortraitStage>(portraitStageProp,
                                                          new GUIContent(replaceLabel, "Stage to display the character portraits on"),
                                                          new GUIContent("<Default>"),
                                                          PortraitStage.activePortraitStages);
            }

            bool          showOptionalFields = true;
            PortraitStage ps = t.portraitStage;

            // Only show optional portrait fields once required fields have been filled...
            if (t.portraitStage != null)                            // Character is selected
            {
                ps = t.GetFungusScript().defaultPortraitStage;;     // Try to get game's default portrait stage
                if (t.portraitStage == null)                        // If no default specified, try to get any portrait stage in the scene
                {
                    ps = GameObject.FindObjectOfType <PortraitStage>();
                }
                if (ps == null)
                {
                    EditorGUILayout.HelpBox("No portrait stage has been set. Please create a new portrait stage using [Game Object > Fungus > Portrait > Portrait Stage].", MessageType.Error);
                    showOptionalFields = false;
                }
            }
            if (t.display != stageDisplayType.NULL && showOptionalFields)
            {
                EditorGUILayout.PropertyField(useDefaultSettingsProp);
                if (!t.useDefaultSettings)
                {
                    EditorGUILayout.PropertyField(fadeDurationProp);
                }
                EditorGUILayout.PropertyField(waitUntilFinishedProp);
            }
            serializedObject.ApplyModifiedProperties();
        }
Beispiel #3
0
 protected void MoveToFront(PortraitStage portraitStage)
 {
     foreach (PortraitStage ps in PortraitStage.activePortraitStages)
     {
         if (ps == portraitStage)
         {
             ps.portraitCanvas.sortingOrder = 1;
         }
         else
         {
             ps.portraitCanvas.sortingOrder = 0;
         }
     }
 }
Beispiel #4
0
        public static void CreatePortraitObject(Character character, PortraitStage portraitStage)
        {
            GameObject portraitObj = new GameObject(character.name, typeof(RectTransform), typeof(CanvasRenderer), typeof(Image));

            portraitObj.transform.SetParent(portraitStage.portraitCanvas.transform, true);
            Image portraitImage = portraitObj.GetComponent <Image>();

            portraitImage.preserveAspect = true;
            portraitImage.sprite         = character.profileSprite;
            Material portraitMaterial = Instantiate(Resources.Load("Portrait")) as Material;

            portraitImage.material        = portraitMaterial;
            character.state.portraitObj   = portraitObj;
            character.state.portraitImage = portraitImage;
            character.state.portraitImage.material.SetFloat("_Alpha", 0);
        }
Beispiel #5
0
 public static void Undim(Character character, PortraitStage portraitStage)
 {
     if (character.state.dimmed == true)
     {
         character.state.dimmed = false;
         float fadeDuration = portraitStage.fadeDuration;
         if (fadeDuration == 0)
         {
             fadeDuration = float.Epsilon;
         }
         LeanTween.value(character.state.portraitObj, 0.5f, 1f, fadeDuration).setEase(portraitStage.fadeEaseType).setOnUpdate(
             (float tintAmount) => {
             Color tint = new Color(tintAmount, tintAmount, tintAmount, 1);
             character.state.portraitImage.material.SetColor("_Color", tint);
         }
             );
     }
 }
Beispiel #6
0
 protected void Hide(PortraitStage portraitStage)
 {
     if (fadeDuration == 0)
     {
         fadeDuration = float.Epsilon;
     }
     LeanTween.value(gameObject, 1, 0, fadeDuration).setOnUpdate(
         (float fadeAmount) => {
         foreach (Character c in portraitStage.charactersOnStage)
         {
             c.state.portraitImage.material.SetFloat("_Alpha", fadeAmount);
         }
     }
         ).setOnComplete(
         () => {
         foreach (Character c in portraitStage.charactersOnStage)
         {
             c.state.portraitImage.material.SetFloat("_Alpha", 0);
         }
         OnComplete();
     }
         );
 }
Beispiel #7
0
        public override void OnEnter()
        {
            // If no display specified, do nothing
            if (display == displayType.NULL)
            {
                Continue();
                return;
            }
            // If no character specified, do nothing
            if (character == null)
            {
                Continue();
                return;
            }
            // If Swap and no replaced character specified, do nothing
            if (display == displayType.Swap && replacedCharacter == null)
            {
                Continue();
                return;
            }
            // Selected "use default Portrait Stage"
            if (portraitStage == null)                                   // Default portrait stage selected
            {
                portraitStage = GetFungusScript().defaultPortraitStage;; // Try to get game's default portrait stage
                if (portraitStage == null)                               // If no default specified, try to get any portrait stage in the scene
                {
                    portraitStage = GameObject.FindObjectOfType <PortraitStage>();
                }
            }
            // If portrait stage does not exist, do nothing
            if (portraitStage == null)
            {
                Continue();
                return;
            }

            if (character.state.portraitImage == null)
            {
                CreatePortraitObject(character, portraitStage);
            }
            // if no previous portrait, use default portrait
            if (character.state.portrait == null)
            {
                character.state.portrait = character.profileSprite;
            }
            // Selected "use previous portrait"
            if (portrait == null)
            {
                portrait = character.state.portrait;
            }
            // if no previous position, use default position
            if (character.state.position == null)
            {
                character.state.position = portraitStage.defaultPosition.rectTransform;
            }
            // Selected "use previous position"
            if (toPosition == null)
            {
                toPosition = character.state.position;
            }
            if (replacedCharacter != null)
            {
                // if no previous position, use default position
                if (replacedCharacter.state.position == null)
                {
                    replacedCharacter.state.position = portraitStage.defaultPosition.rectTransform;
                }
            }
            // If swapping, use replaced character's position
            if (display == displayType.Swap)
            {
                toPosition = replacedCharacter.state.position;
            }
            // Selected "use previous position"
            if (fromPosition == null)
            {
                fromPosition = character.state.position;
            }
            // if portrait not moving, use from position is same as to position
            if (!move)
            {
                fromPosition = toPosition;
            }
            if (display == displayType.Hide)
            {
                fromPosition = character.state.position;
            }
            // if no previous facing direction, use default facing direction
            if (character.state.facing == facingDirection.NULL)
            {
                character.state.facing = character.portraitsFace;
            }
            // Selected "use previous facing direction"
            if (facing == facingDirection.NULL)
            {
                facing = character.state.facing;
            }
            // Use default settings
            if (useDefaultSettings)
            {
                fadeDuration = portraitStage.fadeDuration;
                moveSpeed    = portraitStage.moveSpeed;
                shiftOffset  = portraitStage.shiftOffset;
            }
            switch (display)
            {
            case (displayType.Show):
                Show(character, fromPosition, toPosition);
                character.state.onScreen = true;
                portraitStage.charactersOnStage.Add(character);
                break;

            case (displayType.Hide):
                Hide(character, fromPosition, toPosition);
                character.state.onScreen = false;
                portraitStage.charactersOnStage.Remove(character);
                break;

            case (displayType.Swap):
                Show(character, fromPosition, toPosition);
                Hide(replacedCharacter, replacedCharacter.state.position, replacedCharacter.state.position);
                character.state.onScreen         = true;
                replacedCharacter.state.onScreen = false;
                portraitStage.charactersOnStage.Add(character);
                portraitStage.charactersOnStage.Remove(replacedCharacter);
                break;

            case (displayType.MoveToFront):
                MoveToFront(character);
                break;
            }

            if (display == displayType.Swap)
            {
                character.state.display         = displayType.Show;
                replacedCharacter.state.display = displayType.Hide;
            }
            else
            {
                character.state.display = display;
            }
            character.state.portrait = portrait;
            character.state.facing   = facing;
            character.state.position = toPosition;
            if (!waitUntilFinished)
            {
                Continue();
            }
        }
Beispiel #8
0
        public override void OnEnter()
        {
            // If no display specified, do nothing
            if (display == stageDisplayType.NULL)
            {
                Continue();
                return;
            }
            // Selected "use default Portrait Stage"
            if (portraitStage == null)                                   // Default portrait stage selected
            {
                portraitStage = GetFungusScript().defaultPortraitStage;; // Try to get game's default portrait stage
                if (portraitStage == null)                               // If no default specified, try to get any portrait stage in the scene
                {
                    portraitStage = GameObject.FindObjectOfType <PortraitStage>();
                }
            }
            // If portrait stage does not exist, do nothing
            if (portraitStage == null)
            {
                Continue();
                return;
            }
            // Selected "use default Portrait Stage"
            if (display == stageDisplayType.Swap)                                // Default portrait stage selected
            {
                replacedPortraitStage = GetFungusScript().defaultPortraitStage;; // Try to get game's default portrait stage
                if (replacedPortraitStage == null)                               // If no default specified, try to get any portrait stage in the scene
                {
                    replacedPortraitStage = GameObject.FindObjectOfType <PortraitStage>();
                }
                // If portrait stage does not exist, do nothing
                if (replacedPortraitStage == null)
                {
                    Continue();
                    return;
                }
            }
            // Use default settings
            if (useDefaultSettings)
            {
                fadeDuration = portraitStage.fadeDuration;
            }
            switch (display)
            {
            case (stageDisplayType.Show):
                Show(portraitStage);
                break;

            case (stageDisplayType.Hide):
                Hide(portraitStage);
                break;

            case (stageDisplayType.Swap):
                Show(portraitStage);
                Hide(replacedPortraitStage);
                break;

            case (stageDisplayType.MoveToFront):
                MoveToFront(portraitStage);
                break;

            case (stageDisplayType.UndimAllPortraits):
                UndimAllPortraits(portraitStage);
                break;

            case (stageDisplayType.DimNonSpeakingPortraits):
                DimNonSpeakingPortraits(portraitStage);
                break;
            }

            if (!waitUntilFinished)
            {
                Continue();
            }
        }
Beispiel #9
0
 protected void DimNonSpeakingPortraits(PortraitStage portraitStage)
 {
     portraitStage.dimPortraits = true;
 }
        public override void DrawCommandGUI()
        {
            serializedObject.Update();

            Portrait t = target as Portrait;

            if (PortraitStage.activePortraitStages.Count > 1)
            {
                CommandEditor.ObjectField <PortraitStage>(portraitStageProp,
                                                          new GUIContent("Portrait Stage", "Stage to display the character portraits on"),
                                                          new GUIContent("<Default>"),
                                                          PortraitStage.activePortraitStages);
            }
            // 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.Swap)
            {
                CommandEditor.ObjectField <Character>(replacedCharacterProp,
                                                      new GUIContent("Replace", "Character to swap with"),
                                                      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;
            PortraitStage ps = t.portraitStage;

            // 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.portraitStage == null)                            // If default portrait stage selected
                {
                    ps = t.GetFungusScript().defaultPortraitStage;;     // Try to get game's default portrait stage
                    if (t.portraitStage == null)                        // If no default specified, try to get any portrait stage in the scene
                    {
                        ps = GameObject.FindObjectOfType <PortraitStage>();
                    }
                }
                if (ps == null)
                {
                    EditorGUILayout.HelpBox("No portrait stage has been set. Please create a new portrait stage using [Game Object > Fungus > Portrait > Portrait Stage].", MessageType.Error);
                    showOptionalFields = false;
                }
            }
            if (t.display != displayType.NULL && 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.NULL)
                    {
                        // 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.NULL;
                    }
                }
                else
                {
                    t.portrait = null;
                    t.facing   = facingDirection.NULL;
                }
                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.NULL;
                            // FROM POSITION
                            CommandEditor.ObjectField <RectTransform>(fromPositionProp,
                                                                      new GUIContent("From Position", "Move the portrait to this position"),
                                                                      new GUIContent("<Previous>"),
                                                                      ps.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>"),
                                                              ps.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(moveSpeedProp);
                        }
                        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)
                {
                    EditorGUILayout.Separator();

                    Texture2D       characterTexture = t.portrait.texture;
                    float           aspect           = (float)characterTexture.width / (float)characterTexture.height;
                    Rect            previewRect      = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(100), GUILayout.ExpandWidth(true));
                    CharacterEditor characterEditor  = Editor.CreateEditor(t.character) as CharacterEditor;
                    characterEditor.DrawPreview(previewRect, characterTexture);
                    DestroyImmediate(characterEditor);
                }
                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();
        }