Inheritance: UnityEngine.MonoBehaviour, ILocalizable
Exemplo n.º 1
0
Arquivo: NPC.cs Projeto: Fuinaru/Game
 void Start()
 {
     if (transform.tag == "chart")
     {
         flowchart = GetComponent <Fungus.Flowchart>();
         character = m_character;
         if (m_img != null)
         {
             img = m_img;
         }
     }
 }
Exemplo n.º 2
0
        protected SayDialog GetSayDialog(Character character)
        {
            SayDialog sayDialog = null;
            if (character != null)
            {
                if (character.setSayDialog != null)
                {
                    sayDialog = character.setSayDialog;
                }
            }

            if (sayDialog == null)
            {
                sayDialog = SayDialog.GetSayDialog();
            }

            return sayDialog;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Contains all options to run a portrait command.
        /// </summary>
        /// <param name="useDefaultSettings">Will use stage default times for animation and fade</param>
        public PortraitOptions(bool useDefaultSettings = true)
        {
            character = null;
            replacedCharacter = null;
            portrait = null;
            display = DisplayType.None;
            offset = PositionOffset.None;
            fromPosition = null;
            toPosition = null;
            facing = FacingDirection.None;
            shiftOffset = new Vector2(0, 0);
            move = false;
            shiftIntoPlace = false;
            waitUntilFinished = false;
            onComplete = null;

            // Special values that can be overridden
            fadeDuration = 0.5f;
            moveDuration = 1f;
            this.useDefaultSettings = useDefaultSettings;
        }
Exemplo n.º 4
0
		public void SetCharacter(Character character)
		{
			if (character == null)
			{
				if (characterImage != null)
					characterImage.enabled = false;
				if (nameText != null)
					nameText.text = "";
			}
			else
			{
				SetCharacterImage(character.profileSprite);

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

				SetCharacterName(characterName, character.nameColor);
			}
		}
Exemplo n.º 5
0
 protected void UpdateTweens(Character character, RectTransform fromPosition, RectTransform toPosition)
 {
     if (fadeDuration == 0) fadeDuration = float.Epsilon;
     LeanTween.value(character.state.portraitObj,0,1,fadeDuration).setEase(stage.fadeEaseType).setOnComplete(OnComplete).setOnUpdate(
         (float fadeAmount)=>{
         character.state.portraitImage.material.SetFloat("_Fade", fadeAmount);
     }
     );
     float moveDuration = (Vector3.Distance(fromPosition.anchoredPosition,toPosition.anchoredPosition)/moveSpeed);
     if (moveSpeed == 0) moveDuration = float.Epsilon;
     LeanTween.value(character.state.portraitObj,fromPosition.anchoredPosition,toPosition.anchoredPosition,moveDuration).setEase(stage.moveEaseType).setOnComplete(OnComplete).setOnUpdate(
         (Vector3 updatePosition)=>{
         character.state.portraitImage.rectTransform.anchoredPosition = updatePosition;
     }
     );
 }
Exemplo n.º 6
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 = "";
				}
				speakingCharacter = 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.SetDimmed(c, s, true);
								}
								else
								{
									Portrait.SetDimmed(c, s, false);
								}
							}
						}
					}
				}
				
				string characterName = character.nameText;
				
				if (characterName == "")
				{
					// Use game object name as default
					characterName = character.name;
				}
				
				if (flowchart != null)
				{
					characterName = flowchart.SubstituteVariables(characterName);
				}
				
				SetCharacterName(characterName, character.nameColor);
			}
		}
Exemplo n.º 7
0
 protected void SetupPortrait(Character character, RectTransform fromPosition)
 {
     SetRectTransform(character.state.portraitImage.rectTransform, fromPosition);
     character.state.portraitImage.material.SetFloat("_Fade",0);
     character.state.portraitImage.material.SetTexture("_MainTex", character.profileSprite.texture);
     Texture2D blankTexture = new Texture2D(1, 1, TextureFormat.ARGB32, false);
     blankTexture.SetPixel(0, 0, new Color(0f,0f,0f,0f));
     blankTexture.Apply();
     character.state.portraitImage.material.SetTexture("_TexStart", blankTexture as Texture);
     character.state.portraitImage.material.SetTexture("_TexEnd", blankTexture as Texture);
     if (character.state.facing != character.portraitsFace)
     {
         character.state.portraitImage.material.SetFloat("_FlipStart",1);
     }
     else
     {
         character.state.portraitImage.material.SetFloat("_FlipStart",0);
     }
     if (facing != character.portraitsFace)
     {
         character.state.portraitImage.material.SetFloat("_FlipEnd",1);
     }
     else
     {
         character.state.portraitImage.material.SetFloat("_FlipEnd",0);
     }
     character.state.portraitImage.material.SetFloat("_Alpha",1);
 }
Exemplo n.º 8
0
 protected void Show(Character character, RectTransform fromPosition, RectTransform toPosition)
 {
     if (shiftIntoPlace)
     {
         fromPosition = Instantiate(toPosition) as RectTransform;
         if (offset == PositionOffset.OffsetLeft)
         {
             fromPosition.anchoredPosition = new Vector2(fromPosition.anchoredPosition.x-Mathf.Abs(shiftOffset.x), fromPosition.anchoredPosition.y-Mathf.Abs(shiftOffset.y));
         }
         else if (offset == PositionOffset.OffsetRight)
         {
             fromPosition.anchoredPosition = new Vector2(fromPosition.anchoredPosition.x+Mathf.Abs(shiftOffset.x), fromPosition.anchoredPosition.y+Mathf.Abs(shiftOffset.y));
         }
         else
         {
             fromPosition.anchoredPosition = new Vector2(fromPosition.anchoredPosition.x, fromPosition.anchoredPosition.y);
         }
     }
     SetupPortrait(character, fromPosition);
     if (character.state.display != DisplayType.None && character.state.display != DisplayType.Hide)
     {
         character.state.portraitImage.material.SetTexture("_TexStart", character.state.portrait.texture);
     }
     character.state.portraitImage.material.SetTexture("_TexEnd", portrait.texture);
     UpdateTweens(character, fromPosition, toPosition);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Shows character at a named position in the stage
        /// </summary>
        /// <param name="character"></param>
        /// <param name="position">Named position on stage</param>
        public void Show(Character character, string position)
        {
            PortraitOptions options = new PortraitOptions(true);
            options.character = character;
            options.fromPosition = options.toPosition = stage.GetPosition(position);

            Show(options);
        }
Exemplo n.º 10
0
 protected void Hide(Character character, RectTransform fromPosition, RectTransform toPosition)
 {
     if (character.state.display == DisplayType.None)
     {
         return;
     }
     SetupPortrait(character, fromPosition);
     character.state.portraitImage.material.SetTexture("_TexStart", character.state.portrait.texture);
     UpdateTweens(character, fromPosition, toPosition);
 }
Exemplo n.º 11
0
		protected void MoveToFront(Character character)
		{
			character.state.portraitImage.transform.SetSiblingIndex(character.state.portraitImage.transform.parent.childCount);
		}
Exemplo n.º 12
0
		protected void Show(Character character, RectTransform fromPosition, RectTransform toPosition) 
		{
			if (shiftIntoPlace)
			{
				fromPosition = Instantiate(toPosition) as RectTransform;
				if (offset == PositionOffset.OffsetLeft)
				{
					fromPosition.anchoredPosition = new Vector2(fromPosition.anchoredPosition.x - Mathf.Abs(shiftOffset.x), fromPosition.anchoredPosition.y - Mathf.Abs(shiftOffset.y));
				}
				else if (offset == PositionOffset.OffsetRight)
				{
					fromPosition.anchoredPosition = new Vector2(fromPosition.anchoredPosition.x + Mathf.Abs(shiftOffset.x), fromPosition.anchoredPosition.y + Mathf.Abs(shiftOffset.y));
				}
				else
				{
					fromPosition.anchoredPosition = new Vector2(fromPosition.anchoredPosition.x, fromPosition.anchoredPosition.y);
				}
			}

			SetupPortrait(character, fromPosition);

			// LeanTween doesn't handle 0 duration properly
			float duration = (fadeDuration > 0f) ? fadeDuration : float.Epsilon;
			
			// Fade out a duplicate of the existing portrait image
			if (character.state.portraitImage != null)
			{
				GameObject tempGO = GameObject.Instantiate(character.state.portraitImage.gameObject);
				tempGO.transform.SetParent(character.state.portraitImage.transform, false);
				tempGO.transform.localPosition = Vector3.zero;
				Image tempImage = tempGO.GetComponent<Image>();
				tempImage.sprite = character.state.portraitImage.sprite;
				tempImage.preserveAspect = true;
				tempImage.color = character.state.portraitImage.color;

				LeanTween.alpha(tempImage.rectTransform, 0f, duration).setEase(stage.fadeEaseType).setOnComplete(() => {
					Destroy(tempGO);
				});
			}

			// Fade in the new sprite image
			character.state.portraitImage.sprite = portrait;
			character.state.portraitImage.color = new Color(1f, 1f, 1f, 0f);
			LeanTween.alpha(character.state.portraitImage.rectTransform, 1f, duration).setEase(stage.fadeEaseType);

			DoMoveTween(character, fromPosition, toPosition);
		}
Exemplo n.º 13
0
        /// <summary>
        /// Move the character to a position then hide it
        /// </summary>
        /// <param name="character"></param>
        /// <param name="toPosition">Where the character will disapear to</param>
        public void Hide(Character character, string toPosition)
        {
            PortraitOptions options = new PortraitOptions(true);
            options.character = character;
            options.toPosition = stage.GetPosition(toPosition);
            options.move = true;

            Hide(options);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Using the string of say parameters before the ':',
        /// set the current character, position and portrait if provided.
        /// </summary>
        /// <param name="sayParams">The list of say parameters</param>
        protected virtual ConversationItem CreateConversationItem(string[] sayParams, string text, Character currentCharacter)
        {
            var item = new ConversationItem();

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

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

            // 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;
                    }
                }
            }
                
            // 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) 
                    {
                        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;
        }
Exemplo n.º 15
0
        /// <summary>
        /// Simple character hide command
        /// </summary>
        /// <param name="character">Character to hide</param>
        public void Hide(Character character)
        {
            PortraitOptions options = new PortraitOptions(true);
            options.character = character;

            Hide(options);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Simple show command that shows the character with an available named portrait
        /// </summary>
        /// <param name="character">Character to show</param>
        /// <param name="portrait">Named portrait to show for the character, i.e. "angry", "happy", etc</param>
        public void ShowPortrait(Character character, string portrait)
        {
            PortraitOptions options = new PortraitOptions(true);
            options.character = character;
            options.portrait = character.GetPortrait(portrait);

            if (character.state.position == null)
            {
                options.toPosition = options.fromPosition = stage.GetPosition("middle");
            }
            else
            {
                options.fromPosition = options.toPosition = character.state.position;
            }

            Show(options);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Shows character moving from a position to a position
        /// </summary>
        /// <param name="character"></param>
        /// <param name="portrait"></param>
        /// <param name="fromPosition">Where the character will appear</param>
        /// <param name="toPosition">Where the character will move to</param>
        public void Show(Character character, string portrait, string fromPosition, string toPosition)
        {
            PortraitOptions options = new PortraitOptions(true);
            options.character = character;
            options.portrait = character.GetPortrait(portrait);
            options.fromPosition = stage.GetPosition(fromPosition);
            options.toPosition = stage.GetPosition(toPosition);
            options.move = true;

            Show(options);
        }
Exemplo n.º 18
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;
		}
Exemplo n.º 19
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);
		}
Exemplo n.º 20
0
		protected void SetupPortrait(Character character, RectTransform fromPosition)
		{
			SetRectTransform(character.state.portraitImage.rectTransform, fromPosition);

			if (character.state.facing != character.portraitsFace)
			{
				character.state.portraitImage.rectTransform.localScale = new Vector3(-1f, 1f, 1f);
			}
			else
			{
				character.state.portraitImage.rectTransform.localScale = new Vector3(1f, 1f, 1f);
			}

			if (facing != character.portraitsFace)
			{
				character.state.portraitImage.rectTransform.localScale = new Vector3(-1f, 1f, 1f);
			}
			else
			{
				character.state.portraitImage.rectTransform.localScale = new Vector3(1f, 1f, 1f);
			}
		}
Exemplo n.º 21
0
        /// <summary>
        /// Moves Character in front of other characters on stage
        /// </summary>
        /// <param name="character"></param>
        public void MoveToFront(Character character)
        {
            PortraitOptions options = new PortraitOptions(true);
            options.character = character;

            MoveToFront(CleanPortraitOptions(options));
        }
Exemplo n.º 22
0
		protected void Hide(Character character, RectTransform fromPosition, RectTransform toPosition)
		{
			if (character.state.display == DisplayType.None)
			{
				return;
			}

			SetupPortrait(character, fromPosition);

			// LeanTween doesn't handle 0 duration properly
			float duration = (fadeDuration > 0f) ? fadeDuration : float.Epsilon;
			
			LeanTween.alpha(character.state.portraitImage.rectTransform, 0f, duration).setEase(stage.fadeEaseType);

			DoMoveTween(character, fromPosition, toPosition);
		}
Exemplo n.º 23
0
        public void DoMoveTween(Character character, RectTransform fromPosition, RectTransform toPosition, float moveDuration, Boolean waitUntilFinished)
        {
            PortraitOptions options = new PortraitOptions(true);
            options.character = character;
            options.fromPosition = fromPosition;
            options.toPosition = toPosition;
            options.moveDuration = moveDuration;
            options.waitUntilFinished = waitUntilFinished;

            DoMoveTween(options);
        }
Exemplo n.º 24
0
		protected void DoMoveTween(Character character, RectTransform fromPosition, RectTransform toPosition) 
		{
			// LeanTween doesn't handle 0 duration properly
			float duration = (moveDuration > 0f) ? moveDuration : float.Epsilon;

			// LeanTween.move uses the anchoredPosition, so all position images must have the same anchor position
			LeanTween.move(character.state.portraitImage.gameObject, toPosition.position, duration).setEase(stage.fadeEaseType);
			if (waitUntilFinished)
			{
				waitTimer = duration;
			}
		}
Exemplo n.º 25
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);
 }
Exemplo n.º 26
0
        /// <summary>
        /// Sets the active speaking character.
        /// </summary>
        /// <param name="character">The active speaking character.</param>
        public virtual void SetCharacter(Character character)
        {
            if (character == null)
            {
                if (characterImage != null)
                {
                    characterImage.gameObject.SetActive(false);
                }
                if (nameText != null)
                {
                    nameText.text = "";
                }
                speakingCharacter = null;
            }
            else
            {
                var prevSpeakingCharacter = speakingCharacter;
                speakingCharacter = character;

                // Dim portraits of non-speaking characters
                var activeStages = Stage.ActiveStages;
                for (int i = 0; i < activeStages.Count; i++)
                {
                    var stage = activeStages[i];
                    if (stage.DimPortraits)
                    {
                        var charactersOnStage = stage.CharactersOnStage;
                        for (int j = 0; j < charactersOnStage.Count; j++)
                        {
                            var c = charactersOnStage[j];
                            if (prevSpeakingCharacter != speakingCharacter)
                            {
                                if (c != null && !c.Equals(speakingCharacter))
                                {
                                    stage.SetDimmed(c, true);
                                }
                                else
                                {
                                    stage.SetDimmed(c, false);
                                }
                            }
                        }
                    }
                }

                string characterName = character.NameText;

                if (characterName == "")
                {
                    // Use game object name as default
                    characterName = character.GetObjectName();
                }
                    
                SetCharacterName(characterName, character.NameColor);
            }
        }
Exemplo n.º 27
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);
         }
         );
     }
 }