示例#1
0
        /// <summary>
        /// Using the string of say parameters before the ':',
        /// set the current character, position and portrait if provided.
        /// </summary>
        /// <returns>The conversation item.</returns>
        /// <param name="sayParams">The list of say parameters.</param>
        /// <param name="text">The text for the character to say.</param>
        /// <param name="currentCharacter">The currently speaking character.</param>
        protected virtual ConversationItem CreateConversationItem(string[] sayParams, string text, Character currentCharacter)
        {
            var item = new ConversationItem();

            item.ClearPrev    = ClearPrev;
            item.FadeDone     = FadeDone;
            item.WaitForInput = WaitForInput;

            // Populate the story text to be written
            item.Text = text;

            if (WaitForSeconds > 0)
            {
                item.Text += "{w=" + WaitForSeconds.ToString() + "}";
            }

            if (sayParams == null || sayParams.Length == 0)
            {
                // Text only, no params - early out.
                return(item);
            }

            //TODO this needs a refactor
            for (int i = 0; i < sayParams.Length; i++)
            {
                if (string.Compare(sayParams[i], "clear", true) == 0)
                {
                    item.ClearPrev = true;
                }
                else if (string.Compare(sayParams[i], "noclear", true) == 0)
                {
                    item.ClearPrev = false;
                }
                else if (string.Compare(sayParams[i], "fade", true) == 0)
                {
                    item.FadeDone = true;
                }
                else if (string.Compare(sayParams[i], "nofade", true) == 0)
                {
                    item.FadeDone = false;
                }
                else if (string.Compare(sayParams[i], "wait", true) == 0)
                {
                    item.WaitForInput = true;
                }
                else if (string.Compare(sayParams[i], "nowait", true) == 0)
                {
                    item.WaitForInput = false;
                }
            }

            // try to find the character param first, since we need to get its portrait
            int characterIndex = -1;

            if (characters == null)
            {
                PopulateCharacterCache();
            }

            for (int i = 0; item.Character == null && i < sayParams.Length; i++)
            {
                for (int j = 0; j < characters.Length; j++)
                {
                    if (characters[j].NameStartsWith(sayParams[i]))
                    {
                        characterIndex = i;
                        item.Character = characters[j];
                        break;
                    }
                }
            }

            // Assume last used character if none is specified now
            if (item.Character == null)
            {
                item.Character = currentCharacter;
            }

            // Check if there's a Hide parameter
            int hideIndex = -1;

            if (item.Character != null)
            {
                for (int i = 0; i < sayParams.Length; i++)
                {
                    if (i != characterIndex &&
                        string.Compare(sayParams[i], "hide", true) == 0)
                    {
                        hideIndex = i;
                        item.Hide = true;
                        break;
                    }
                }
            }

            int flipIndex = -1;

            if (item.Character != null)
            {
                for (int i = 0; i < sayParams.Length; i++)
                {
                    if (i != characterIndex &&
                        i != hideIndex &&
                        (string.Compare(sayParams[i], ">>>", true) == 0 ||
                         string.Compare(sayParams[i], "<<<", true) == 0))
                    {
                        if (string.Compare(sayParams[i], ">>>", true) == 0)
                        {
                            item.FacingDirection = FacingDirection.Right;
                        }
                        if (string.Compare(sayParams[i], "<<<", true) == 0)
                        {
                            item.FacingDirection = FacingDirection.Left;
                        }
                        flipIndex = i;
                        item.Flip = true;
                        break;
                    }
                }
            }

            // Next see if we can find a portrait for this character
            int portraitIndex = -1;

            if (item.Character != null)
            {
                for (int i = 0; i < sayParams.Length; i++)
                {
                    if (item.Portrait == null &&
                        item.Character != null &&
                        i != characterIndex &&
                        i != hideIndex &&
                        i != flipIndex)
                    {
                        Sprite s = item.Character.GetPortrait(sayParams[i]);
                        if (s != null)
                        {
                            portraitIndex = i;
                            item.Portrait = s;
                            break;
                        }
                    }
                }
            }

            // Next check if there's a position parameter
            Stage stage = Stage.GetActiveStage();

            if (stage != null)
            {
                for (int i = 0; i < sayParams.Length; i++)
                {
                    if (i != characterIndex &&
                        i != portraitIndex &&
                        i != hideIndex)
                    {
                        RectTransform r = stage.GetPosition(sayParams[i]);
                        if (r != null)
                        {
                            item.Position = r;
                            break;
                        }
                    }
                }
            }

            return(item);
        }
示例#2
0
        /// <summary>
        /// Parse and execute a conversation string.
        /// </summary>
        public virtual IEnumerator DoConversation(string conv)
        {
            if (string.IsNullOrEmpty(conv))
            {
                yield break;
            }

            var conversationItems = Parse(conv);

            if (conversationItems.Count == 0)
            {
                yield break;
            }

            // Track the current and previous parameter values
            Character     currentCharacter  = null;
            Sprite        currentPortrait   = null;
            RectTransform currentPosition   = null;
            Character     previousCharacter = null;

            // Play the conversation
            for (int i = 0; i < conversationItems.Count; ++i)
            {
                ConversationItem item = conversationItems[i];

                if (item.Character != null)
                {
                    currentCharacter = item.Character;
                }

                currentPortrait = item.Portrait;
                currentPosition = item.Position;

                var sayDialog = GetSayDialog(currentCharacter);

                if (sayDialog == null)
                {
                    // Should never happen
                    yield break;
                }

                if (currentCharacter != null &&
                    currentCharacter != previousCharacter)
                {
                    sayDialog.SetCharacter(currentCharacter);
                }

                //Handle stage changes
                var stage = Stage.GetActiveStage();

                if (currentCharacter != null &&
                    !currentCharacter.State.onScreen &&
                    currentPortrait == null)
                {
                    // No call to show portrait of hidden character
                    // so keep hidden
                    item.Hide = true;
                }

                if (stage != null && currentCharacter != null &&
                    (currentPortrait != currentCharacter.State.portrait ||
                     currentPosition != currentCharacter.State.position))
                {
                    var portraitOptions = new PortraitOptions(true);
                    portraitOptions.display      = item.Hide ? DisplayType.Hide : DisplayType.Show;
                    portraitOptions.character    = currentCharacter;
                    portraitOptions.fromPosition = currentCharacter.State.position;
                    portraitOptions.toPosition   = currentPosition;
                    portraitOptions.portrait     = currentPortrait;

                    //Flip option - Flip the opposite direction the character is currently facing
                    if (item.Flip)
                    {
                        portraitOptions.facing = item.FacingDirection;
                    }

                    // Do a move tween if the character is already on screen and not yet at the specified position
                    if (currentCharacter.State.onScreen &&
                        currentPosition != currentCharacter.State.position)
                    {
                        portraitOptions.move = true;
                    }

                    if (item.Hide)
                    {
                        stage.Hide(portraitOptions);
                    }
                    else
                    {
                        stage.Show(portraitOptions);
                    }
                }

                if (stage == null &&
                    currentPortrait != null)
                {
                    sayDialog.SetCharacterImage(currentPortrait);
                }

                previousCharacter = currentCharacter;

                if (!string.IsNullOrEmpty(item.Text))
                {
                    exitSayWait = false;
                    sayDialog.Say(item.Text, item.ClearPrev, item.WaitForInput, item.FadeDone, true, false, null, () => {
                        exitSayWait = true;
                    });

                    while (!exitSayWait)
                    {
                        yield return(null);
                    }
                    exitSayWait = false;
                }
            }
        }
 protected virtual void Awake()
 {
     stage = GetComponentInParent<Stage>();
 }
        public override void OnEnter()
        {
            // If no display specified, do nothing
            if (IsDisplayNone(display))
            {
                Continue();
                return;
            }

            // Selected "use default Portrait Stage"
            if (stage == null)
            {
                // If no default specified, try to get any portrait stage in the scene
                stage = FindObjectOfType <Stage>();

                // If portrait stage does not exist, do nothing
                if (stage == null)
                {
                    Continue();
                    return;
                }
            }

            // Selected "use default Portrait Stage"
            if (display == StageDisplayType.Swap) // Default portrait stage selected
            {
                if (replacedStage == null)        // If no default specified, try to get any portrait stage in the scene
                {
                    replacedStage = GameObject.FindObjectOfType <Stage>();
                }
                // If portrait stage does not exist, do nothing
                if (replacedStage == null)
                {
                    Continue();
                    return;
                }
            }
            // Use default settings
            if (useDefaultSettings)
            {
                fadeDuration = stage.FadeDuration;
            }
            switch (display)
            {
            case (StageDisplayType.Show):
                Show(stage, true);
                break;

            case (StageDisplayType.Hide):
                Show(stage, false);
                break;

            case (StageDisplayType.Swap):
                Show(stage, true);
                Show(replacedStage, false);
                break;

            case (StageDisplayType.MoveToFront):
                MoveToFront(stage);
                break;

            case (StageDisplayType.UndimAllPortraits):
                UndimAllPortraits(stage);
                break;

            case (StageDisplayType.DimNonSpeakingPortraits):
                DimNonSpeakingPortraits(stage);
                break;
            }

            if (!waitUntilFinished)
            {
                Continue();
            }
        }
示例#5
0
 public static void Undim(Character character, Stage stage)
 {
     if (character.state.dimmed == true)
     {
         character.state.dimmed = false;
         float fadeDuration = stage.fadeDuration;
         if (fadeDuration == 0) fadeDuration = float.Epsilon;
         LeanTween.value(character.state.portraitObj,0.5f,1f,fadeDuration).setEase(stage.fadeEaseType).setOnUpdate(
             (float tintAmount)=>{
             Color tint = new Color(tintAmount,tintAmount,tintAmount,1);
             character.state.portraitImage.material.SetColor("_Color", tint);
         }
         );
     }
 }
示例#6
0
		public static void SetDimmed(Character character, Stage stage, bool dimmedState)
		{
			if (character.state.dimmed == dimmedState)
			{
				return;
			}

			character.state.dimmed = dimmedState;

			Color targetColor = dimmedState ? new Color(0.5f, 0.5f, 0.5f, 1f) : Color.white;

			// LeanTween doesn't handle 0 duration properly
			float duration = (stage.fadeDuration > 0f) ? stage.fadeDuration : float.Epsilon;
			
			LeanTween.color(character.state.portraitImage.rectTransform, targetColor, duration).setEase(stage.fadeEaseType);
		}
示例#7
0
        public override void OnEnter()
        {
            // If no display specified, do nothing
            if (display == StageDisplayType.None)
            {
                Continue();
                return;
            }
            // Selected "use default Portrait Stage"
            if (stage == null)            // Default portrait stage selected
            {
                if (stage == null)        // If no default specified, try to get any portrait stage in the scene
                {
                    stage = GameObject.FindObjectOfType<Stage>();
                }
            }
            // If portrait stage does not exist, do nothing
            if (stage == null)
            {
                Continue();
                return;
            }
            // Selected "use default Portrait Stage"
            if (display == StageDisplayType.Swap)            // Default portrait stage selected
            {
                if (replacedStage == null)        // If no default specified, try to get any portrait stage in the scene
                {
                    replacedStage = GameObject.FindObjectOfType<Stage>();
                }
                // If portrait stage does not exist, do nothing
                if (replacedStage == null)
                {
                    Continue();
                    return;
                }
            }
            // Use default settings
            if (useDefaultSettings)
            {
                fadeDuration = stage.fadeDuration;
            }
            switch(display)
            {
            case (StageDisplayType.Show):
                Show(stage);
                break;
            case (StageDisplayType.Hide):
                Hide(stage);
                break;
            case (StageDisplayType.Swap):
                Show(stage);
                Hide(replacedStage);
                break;
            case (StageDisplayType.MoveToFront):
                MoveToFront(stage);
                break;
            case (StageDisplayType.UndimAllPortraits):
                UndimAllPortraits(stage);
                break;
            case (StageDisplayType.DimNonSpeakingPortraits):
                DimNonSpeakingPortraits(stage);
                break;
            }

            if (!waitUntilFinished)
            {
                Continue();
            }
        }
示例#8
0
        /// <summary>
        /// Convert a Moonsharp table to portrait options
        /// If the table returns a null for any of the parameters, it should keep the defaults
        /// </summary>
        /// <param name="table">Moonsharp Table</param>
        /// <param name="stage">Stage</param>
        /// <returns></returns>
        public static PortraitOptions ConvertTableToPortraitOptions(Table table, Stage stage)
        {
            PortraitOptions options = new PortraitOptions(true);

            // If the table supplies a nil, keep the default
            options.character = table.Get("character").ToObject<Character>() 
                ?? options.character;

            options.replacedCharacter = table.Get("replacedCharacter").ToObject<Character>()
                ?? options.replacedCharacter;

            if (!table.Get("portrait").IsNil())
            {
                options.portrait = options.character.GetPortrait(table.Get("portrait").CastToString());
            }

            if (!table.Get("display").IsNil())
            {
                options.display = table.Get("display").ToObject<DisplayType>();
            }
            
            if (!table.Get("offset").IsNil())
            {
                options.offset = table.Get("offset").ToObject<PositionOffset>();
            }

            if (!table.Get("fromPosition").IsNil())
            {
                options.fromPosition = stage.GetPosition(table.Get("fromPosition").CastToString());
            }

            if (!table.Get("toPosition").IsNil())
            {
                options.toPosition = stage.GetPosition(table.Get("toPosition").CastToString());
            }

            if (!table.Get("facing").IsNil())
            {
                options.facing = table.Get("facing").ToObject<FacingDirection>();
            }

            if (!table.Get("useDefaultSettings").IsNil())
            {
                options.useDefaultSettings = table.Get("useDefaultSettings").CastToBool();
            }

            if (!table.Get("fadeDuration").IsNil())
            {
                options.fadeDuration = table.Get("fadeDuration").ToObject<float>();
            }

            if (!table.Get("moveDuration").IsNil())
            {
                options.moveDuration = table.Get("moveDuration").ToObject<float>();
            }

            if (!table.Get("move").IsNil())
            {
                options.move = table.Get("move").CastToBool();
            }
            else if (options.fromPosition != options.toPosition)
            {
                options.move = true;
            }

            if (!table.Get("shiftIntoPlace").IsNil())
            {
                options.shiftIntoPlace = table.Get("shiftIntoPlace").CastToBool();
            }

            //TODO: Make the next lua command wait when this options is true
            if (!table.Get("waitUntilFinished").IsNil())
            {
                options.waitUntilFinished = table.Get("waitUntilFinished").CastToBool();
            }

            return options;
        }
示例#9
0
        protected void Show(Stage stage)
        {
            if (fadeDuration == 0)
            {
                fadeDuration = float.Epsilon;
            }

            LeanTween.value(gameObject,0,1,fadeDuration).setOnUpdate(
                (float fadeAmount)=>{
                foreach ( Character c in stage.charactersOnStage)
                {
                    c.state.portraitImage.material.SetFloat("_Alpha",fadeAmount);
                }
            }
            ).setOnComplete(
                ()=>{
                foreach ( Character c in stage.charactersOnStage)
                {
                    c.state.portraitImage.material.SetFloat("_Alpha",1);
                }
                OnComplete();
            }
            );
        }
示例#10
0
 protected void UndimAllPortraits(Stage stage)
 {
     stage.dimPortraits = false;
     foreach (Character character in stage.charactersOnStage)
     {
         Portrait.Undim(character, stage);
     }
 }
示例#11
0
 protected void MoveToFront(Stage stage)
 {
     foreach (Stage s in Stage.activeStages)
     {
         if (s == stage)
         {
             s.portraitCanvas.sortingOrder = 1;
         }
         else
         {
             s.portraitCanvas.sortingOrder = 0;
         }
     }
 }
示例#12
0
 protected void DimNonSpeakingPortraits(Stage stage)
 {
     stage.dimPortraits = true;
 }
		protected void Show(Stage stage, bool visible) 
		{
			float duration = (fadeDuration == 0) ? float.Epsilon : fadeDuration;
			float targetAlpha = visible ? 1f : 0f;

			CanvasGroup canvasGroup = stage.GetComponentInChildren<CanvasGroup>();
			if (canvasGroup == null)
			{
				Continue();
				return;
			}
			
			LeanTween.value(canvasGroup.gameObject, canvasGroup.alpha, targetAlpha, duration).setOnUpdate( (float alpha) => {
				canvasGroup.alpha = alpha;
			}).setOnComplete( () => {
				OnComplete();
			});
		}
示例#14
0
        /// <summary>
        /// Convert a Moonsharp table to portrait options
        /// If the table returns a null for any of the parameters, it should keep the defaults
        /// </summary>
        /// <param name="table">Moonsharp Table</param>
        /// <param name="stage">Stage</param>
        /// <returns></returns>
        public static PortraitOptions ConvertTableToPortraitOptions(Table table, Stage stage)
        {
            PortraitOptions options = new PortraitOptions(true);

            // If the table supplies a nil, keep the default
            options.character = table.Get("character").ToObject <Character>()
                                ?? options.character;

            options.replacedCharacter = table.Get("replacedCharacter").ToObject <Character>()
                                        ?? options.replacedCharacter;

            if (!table.Get("portrait").IsNil())
            {
                options.portrait = options.character.GetPortrait(table.Get("portrait").CastToString());
            }

            if (!table.Get("display").IsNil())
            {
                options.display = table.Get("display").ToObject <DisplayType>();
            }

            if (!table.Get("offset").IsNil())
            {
                options.offset = table.Get("offset").ToObject <PositionOffset>();
            }

            if (!table.Get("fromPosition").IsNil())
            {
                options.fromPosition = stage.GetPosition(table.Get("fromPosition").CastToString());
            }

            if (!table.Get("toPosition").IsNil())
            {
                options.toPosition = stage.GetPosition(table.Get("toPosition").CastToString());
            }

            if (!table.Get("facing").IsNil())
            {
                var      facingDirection = FacingDirection.None;
                DynValue v = table.Get("facing");
                if (v.Type == DataType.String)
                {
                    if (string.Compare(v.String, "left", true) == 0)
                    {
                        facingDirection = FacingDirection.Left;
                    }
                    else if (string.Compare(v.String, "right", true) == 0)
                    {
                        facingDirection = FacingDirection.Right;
                    }
                }
                else
                {
                    facingDirection = table.Get("facing").ToObject <FacingDirection>();
                }

                options.facing = facingDirection;
            }

            if (!table.Get("useDefaultSettings").IsNil())
            {
                options.useDefaultSettings = table.Get("useDefaultSettings").CastToBool();
            }

            if (!table.Get("fadeDuration").IsNil())
            {
                options.fadeDuration = table.Get("fadeDuration").ToObject <float>();
            }

            if (!table.Get("moveDuration").IsNil())
            {
                options.moveDuration = table.Get("moveDuration").ToObject <float>();
            }

            if (!table.Get("move").IsNil())
            {
                options.move = table.Get("move").CastToBool();
            }
            else if (options.fromPosition != options.toPosition)
            {
                options.move = true;
            }

            if (!table.Get("shiftIntoPlace").IsNil())
            {
                options.shiftIntoPlace = table.Get("shiftIntoPlace").CastToBool();
            }

            if (!table.Get("waitUntilFinished").IsNil())
            {
                options.waitUntilFinished = table.Get("waitUntilFinished").CastToBool();
            }

            return(options);
        }
        /// <summary>
        /// Convert a Moonsharp table to portrait options
        /// If the table returns a null for any of the parameters, it should keep the defaults
        /// </summary>
        /// <param name="table">Moonsharp Table</param>
        /// <param name="stage">Stage</param>
        /// <returns></returns>
        public static PortraitOptions ConvertTableToPortraitOptions(Table table, Stage stage)
        {
            PortraitOptions options = new PortraitOptions(true);

            // If the table supplies a nil, keep the default
            options.character = table.Get("character").ToObject<Character>() 
                ?? options.character;

            options.replacedCharacter = table.Get("replacedCharacter").ToObject<Character>()
                ?? options.replacedCharacter;

            if (!table.Get("portrait").IsNil())
            {
                options.portrait = options.character.GetPortrait(table.Get("portrait").CastToString());
            }

            if (!table.Get("display").IsNil())
            {
                options.display = table.Get("display").ToObject<DisplayType>();
            }

            if (!table.Get("offset").IsNil())
            {
                options.offset = table.Get("offset").ToObject<PositionOffset>();
            }

            if (!table.Get("fromPosition").IsNil())
            {
                options.fromPosition = stage.GetPosition(table.Get("fromPosition").CastToString());
            }

            if (!table.Get("toPosition").IsNil())
            {
                options.toPosition = stage.GetPosition(table.Get("toPosition").CastToString());
            }

            if (!table.Get("facing").IsNil())
            {
                var facingDirection = FacingDirection.None;
                DynValue v = table.Get("facing");
                if (v.Type == DataType.String)
                {
                    if (string.Compare(v.String, "left", true) == 0)
                    {
                        facingDirection = FacingDirection.Left;
                    }
                    else if (string.Compare(v.String, "right", true) == 0)
                    {
                        facingDirection = FacingDirection.Right;
                    }
                }
                else
                {
                    facingDirection = table.Get("facing").ToObject<FacingDirection>();
                }

                options.facing = facingDirection;
            }

            if (!table.Get("useDefaultSettings").IsNil())
            {
                options.useDefaultSettings = table.Get("useDefaultSettings").CastToBool();
            }

            if (!table.Get("fadeDuration").IsNil())
            {
                options.fadeDuration = table.Get("fadeDuration").ToObject<float>();
            }

            if (!table.Get("moveDuration").IsNil())
            {
                options.moveDuration = table.Get("moveDuration").ToObject<float>();
            }

            if (!table.Get("move").IsNil())
            {
                options.move = table.Get("move").CastToBool();
            }
            else if (options.fromPosition != options.toPosition)
            {
                options.move = true;
            }

            if (!table.Get("shiftIntoPlace").IsNil())
            {
                options.shiftIntoPlace = table.Get("shiftIntoPlace").CastToBool();
            }

            if (!table.Get("waitUntilFinished").IsNil())
            {
                options.waitUntilFinished = table.Get("waitUntilFinished").CastToBool();
            }

            return options;
        }
示例#16
0
 void Awake()
 {
     stage = GetComponentInParent<Stage>();
     stage.CachePositions();
 }
示例#17
0
        public override void OnEnter()
        {
            // If no display specified, do nothing
            if (display == DisplayType.None)
            {
                Continue();
                return;
            }

            // If no character specified, do nothing
            if (character == null)
            {
                Continue();
                return;
            }

            // If Replace and no replaced character specified, do nothing
            if (display == DisplayType.Replace && replacedCharacter == null)
            {
                Continue();
                return;
            }

            // Selected "use default Portrait Stage"
            if (stage == null)                        // Default portrait stage selected
            {
                if (stage == null)                    // If no default specified, try to get any portrait stage in the scene
                {
                    stage = GameObject.FindObjectOfType <Stage>();
                }
            }

            // If portrait stage does not exist, do nothing
            if (stage == null)
            {
                Continue();
                return;
            }

            // Use default settings
            if (useDefaultSettings)
            {
                fadeDuration = stage.fadeDuration;
                moveDuration = stage.moveDuration;
                shiftOffset  = stage.shiftOffset;
            }

            if (character.state.portraitImage == null)
            {
                CreatePortraitObject(character, stage);
            }

            // 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 = stage.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 = stage.defaultPosition.rectTransform;
                }
            }

            // If swapping, use replaced character's position
            if (display == DisplayType.Replace)
            {
                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.None)
            {
                character.state.facing = character.portraitsFace;
            }

            // Selected "use previous facing direction"
            if (facing == FacingDirection.None)
            {
                facing = character.state.facing;
            }

            switch (display)
            {
            case (DisplayType.Show):
                Show(character, fromPosition, toPosition);
                character.state.onScreen = true;
                if (!stage.charactersOnStage.Contains(character))
                {
                    stage.charactersOnStage.Add(character);
                }
                break;

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

            case (DisplayType.Replace):
                Show(character, fromPosition, toPosition);
                Hide(replacedCharacter, replacedCharacter.state.position, replacedCharacter.state.position);
                character.state.onScreen         = true;
                replacedCharacter.state.onScreen = false;
                stage.charactersOnStage.Add(character);
                stage.charactersOnStage.Remove(replacedCharacter);
                break;

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

            if (display == DisplayType.Replace)
            {
                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;

            waitTimer = 0f;
            if (!waitUntilFinished)
            {
                Continue();
            }
            else
            {
                StartCoroutine(WaitUntilFinished(fadeDuration));
            }
        }
示例#18
0
 public static void CreatePortraitObject(Character character, Stage stage)
 {
     GameObject portraitObj = new GameObject(character.name, typeof(RectTransform), typeof(CanvasRenderer), typeof(Image));
     portraitObj.transform.SetParent(stage.portraitCanvas.transform, true);
     Image portraitImage = portraitObj.GetComponent<Image>();
     portraitImage.preserveAspect = true;
     portraitImage.sprite = character.profileSprite;
     // Workaround for bug #92. Tiled switches off an internal quad cropping optimisation.
     portraitImage.type = Image.Type.Tiled;
     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);
 }
示例#19
0
 protected virtual void Awake()
 {
     stage = GetComponentInParent <Stage>();
 }
示例#20
0
		protected virtual void CreatePortraitObject(Character character, Stage stage)
		{
			// Create a new portrait object
			GameObject portraitObj = new GameObject(character.name, 
			                                        typeof(RectTransform), 
			                                        typeof(CanvasRenderer), 
			                                        typeof(Image));

			// Set it to be a child of the stage
			portraitObj.transform.SetParent(stage.portraitCanvas.transform, true);

			// Configure the portrait image
			Image portraitImage = portraitObj.GetComponent<Image>();
			portraitImage.preserveAspect = true;
			portraitImage.sprite = character.profileSprite;
			portraitImage.color = new Color(1f, 1f, 1f, 0f);

			// LeanTween doesn't handle 0 duration properly
			float duration = (fadeDuration > 0f) ? fadeDuration : float.Epsilon;

			// Fade in character image (first time)
			LeanTween.alpha(portraitImage.transform as RectTransform, 1f, duration).setEase(stage.fadeEaseType);

			// Tell character about portrait image
			character.state.portraitImage = portraitImage;
		}
示例#21
0
 protected virtual void DimNonSpeakingPortraits(Stage stage)
 {
     stage.DimPortraits = true;
 }
示例#22
0
		public override void OnEnter()
		{
			// If no display specified, do nothing
			if (display == DisplayType.None)
			{
				Continue();
				return;
			}

			// If no character specified, do nothing
			if (character == null)
			{
				Continue();
				return;
			}

			// If Replace and no replaced character specified, do nothing
			if (display == DisplayType.Replace && replacedCharacter == null)
			{
				Continue();
				return;
			}

			// Selected "use default Portrait Stage"
			if (stage == null)            // Default portrait stage selected
			{
				if (stage == null)        // If no default specified, try to get any portrait stage in the scene
				{
					stage = GameObject.FindObjectOfType<Stage>();
				}
			}

			// If portrait stage does not exist, do nothing
			if (stage == null)
			{
				Continue();
				return;
			}

			// Use default settings
			if (useDefaultSettings)
			{
				fadeDuration = stage.fadeDuration;
				moveDuration = stage.moveDuration;
				shiftOffset = stage.shiftOffset;
			}

			if (character.state.portraitImage == null)
			{
				CreatePortraitObject(character, stage);
			}

			// 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 = stage.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 = stage.defaultPosition.rectTransform;
				}
			}

			// If swapping, use replaced character's position
			if (display == DisplayType.Replace)
			{
				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.None) 
			{
				character.state.facing = character.portraitsFace;
			}

			// Selected "use previous facing direction"
			if (facing == FacingDirection.None)
			{
				facing = character.state.facing;
			}

			switch(display)
			{
			case (DisplayType.Show):
				Show(character, fromPosition, toPosition);
				character.state.onScreen = true;
				if (!stage.charactersOnStage.Contains(character))
				{
					stage.charactersOnStage.Add(character);
				}
				break;

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

			case (DisplayType.Replace):
				Show(character, fromPosition, toPosition);
				Hide(replacedCharacter, replacedCharacter.state.position, replacedCharacter.state.position);
				character.state.onScreen = true;
				replacedCharacter.state.onScreen = false;
				stage.charactersOnStage.Add(character);
				stage.charactersOnStage.Remove(replacedCharacter);
				break;

			case (DisplayType.MoveToFront):
				MoveToFront(character);
				break;
			}
			
			if (display == DisplayType.Replace)
			{
				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;

			waitTimer = 0f;
			if (!waitUntilFinished)
			{
				Continue();
			}
			else
			{
				StartCoroutine(WaitUntilFinished(fadeDuration));
			}
		}
示例#23
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();
        }