/// <summary> /// Gets a reused speechbubble from the queue or, if no free ones exist already, creates /// a new one. /// </summary> /// <param name="type"></param> /// <returns></returns> private SpeechBubbleBehaviour GetBubble(SpeechbubbleType type = SpeechbubbleType.NORMAL) { SpeechBubbleBehaviour bubbleBehaviour; //Check to see if there is a free speechbuble of the right kind to reuse if (_speechBubbleQueueDict[type].Count == 0 || _speechBubbleQueueDict[type].Peek().gameObject.activeInHierarchy) { GameObject newBubble = (GameObject)GameObject.Instantiate(GetPrefab(type)); newBubble.transform.SetParent(transform); newBubble.transform.localScale = _sizeMultiplier * GetPrefab(type).transform.localScale; bubbleBehaviour = newBubble.GetComponent <SpeechBubbleBehaviour>(); //If this is not 2D then the speechbubble will need a world space canvas. if (!_is2D) { var canvas = newBubble.AddComponent <Canvas>(); canvas.renderMode = RenderMode.WorldSpace; canvas.overrideSorting = true; } } else { bubbleBehaviour = _speechBubbleQueueDict[type].Dequeue(); } //Set as last to always place latest on top (in case of screenspace ui that is..) bubbleBehaviour.transform.SetAsLastSibling(); return(bubbleBehaviour); }
/// <summary> /// Adds a speechbubble to a certain position /// </summary> /// <param name="position"></param> /// <param name="text"></param> /// <param name="type"></param> /// <param name="timeToLive"></param> /// <param name="color"></param> public void AddSpeechbubble(Vector3 position, string text, SpeechbubbleType type, float timeToLive, Color color) { SpeechbubbleBehaviour bubbleBehaviour = GetBubble(type); bubbleBehaviour.Setup(position, text, timeToLive, color); speechbubbleQueue[type].Enqueue(bubbleBehaviour); }
/// <summary> /// Adds a speechbubble that will follow a certain transform. /// It is recommended you use a character's head or mouth transform. /// </summary> /// <param name="objectToFollow"></param> /// <param name="text"></param> /// <param name="type"></param> /// <param name="timeToLive"></param> /// <param name="color"></param> /// <param name="offset"></param> public void AddSpeechbubble(Transform objectToFollow, string text, SpeechbubbleType type, float timeToLive, Color color, Vector3 offset) { SpeechbubbleBehaviour bubbleBehaviour = GetBubble(type); bubbleBehaviour.Setup(objectToFollow, offset, text, timeToLive, color); speechbubbleQueue[type].Enqueue(bubbleBehaviour); }
/// <summary> /// Adds a speechbubble to a certain position /// </summary> /// <param name="position"></param> /// <param name="text"></param> /// <param name="type"></param> /// <param name="timeToLive"></param> /// <param name="color"></param> public SpeechBubbleBehaviour AddSpeechBubble(Vector3 position, string text, SpeechbubbleType type = SpeechbubbleType.NORMAL, float timeToLive = 0, Color color = default(Color)) { if (timeToLive == 0) { timeToLive = _defaultTimeToLive; } if (color == default(Color)) { color = _defaultColor; } SpeechBubbleBehaviour bubbleBehaviour = GetBubble(type); bubbleBehaviour.Setup(position, text, timeToLive, color, Cam); _speechBubbleQueueDict[type].Enqueue(bubbleBehaviour); return(bubbleBehaviour); }
/// <summary> /// Gets a reused speechbubble from the queue or, if no free ones exist already, creates /// a new one. /// </summary> /// <param name="type"></param> /// <returns></returns> private SpeechBubbleBase GetBubble(SpeechbubbleType type = SpeechbubbleType.NORMAL) { SpeechBubbleBase bubbleBehaviour; //Check to see if there is a free speechbuble of the right kind to reuse if (_speechBubbleQueueDict[type].Count == 0 || _speechBubbleQueueDict[type].Peek().gameObject.activeInHierarchy) { bubbleBehaviour = CreateNewSpeechBubble(type); } else { bubbleBehaviour = _speechBubbleQueueDict[type].Dequeue(); } //Set as last to always place latest on top (in case of screenspace ui that is..) bubbleBehaviour.transform.SetAsLastSibling(); return(bubbleBehaviour); }
private SpeechBubbleBase CreateNewSpeechBubble(SpeechbubbleType type) { var newBubble = Instantiate(GetPrefab(type)); newBubble.transform.SetParent(transform); newBubble.transform.localScale = _sizeMultiplier * GetPrefab(type).transform.localScale; //If this is not 2D then the speechbubble will need a world space canvas. if (!_is2D) { var canvas = newBubble.gameObject.AddComponent <Canvas>(); canvas.renderMode = RenderMode.WorldSpace; canvas.overrideSorting = true; } newBubble.SpeechBubbleFinishedEvent += OnSpeechBubbleFinished; return(newBubble); }
private GameObject GetPrefab(SpeechbubbleType type) { return(_prefabsDict[type]); }
/// <summary> /// Adds a speechbubble that will follow a certain transform. /// It is recommended you use a character's head or mouth transform. /// /// The speech bubble will be delayed and will only show up after the delay, making it possiblew to add a whole monologue or conversation between characters at once. /// If objectToFollow should be destroyed then no speech bubble will show up. /// </summary> /// <param name="delay"></param> /// <param name="objectToFollow"></param> /// <param name="text"></param> /// <param name="type"></param> /// <param name="timeToLive"></param> /// <param name="color"></param> /// <param name="offset"></param> public void AddDelayedSpeechBubble(float delay, Transform objectToFollow, string text, SpeechbubbleType type = SpeechbubbleType.NORMAL, float timeToLive = 0, Color color = default(Color), Vector3 offset = new Vector3()) { StartCoroutine(DelaySpeechBubble(delay, objectToFollow, text, type, timeToLive, color, offset)); }
/// <summary> /// Adds a speechbubble that will follow a certain transform. /// It is recommended you use a character's head or mouth transform. /// </summary> /// <param name="objectToFollow"></param> /// <param name="text"></param> /// <param name="type"></param> /// <param name="timeToLive">if 0 then will use default time to live</param> /// <param name="color">Color to tint, default will be white</param> /// <param name="offset">Offset from objectToFollow</param> public SpeechBubbleBehaviour AddSpeechBubble(Transform objectToFollow, string text, SpeechbubbleType type = SpeechbubbleType.NORMAL, float timeToLive = 0, Color color = default(Color), Vector3 offset = new Vector3()) { if (timeToLive == 0) { timeToLive = _defaultTimeToLive; } if (color == default(Color)) { color = _defaultColor; } SpeechBubbleBehaviour bubbleBehaviour = GetBubble(type); bubbleBehaviour.Setup(objectToFollow, offset, text, timeToLive, color, Cam); _speechBubbleQueueDict[type].Enqueue(bubbleBehaviour); return(bubbleBehaviour); }
private IEnumerator DelaySpeechBubble(float delay, Transform objectToFollow, string text, SpeechbubbleType type, float timeToLive, Color color, Vector3 offset) { yield return(new WaitForSeconds(delay)); if (objectToFollow) { AddSpeechBubble(objectToFollow, text, type, timeToLive, color, offset); } }
/// <summary> /// Adds a speechbubble to a certain position /// </summary> /// <param name="position"></param> /// <param name="text"></param> /// <param name="type"></param> public void AddSpeechbubble(Vector3 position, string text, SpeechbubbleType type = SpeechbubbleType.NORMAL) { AddSpeechbubble(position, text, type, defaultTimeToLive, Color.white); }
/// <summary> /// Adds a speechbubble that will follow a certain transform. /// It is recommended you use a character's head or mouth transform. /// </summary> /// <param name="objectToFollow"></param> /// <param name="text"></param> /// <param name="type"></param> public void AddSpeechbubble(Transform objectToFollow, string text, SpeechbubbleType type = SpeechbubbleType.NORMAL) { AddSpeechbubble(objectToFollow, text, type, defaultTimeToLive, Color.white, Vector3.zero); }
private SpeechBubbleBase GetPrefab(SpeechbubbleType type) { return(_prefabsDict[type]); }