/// <summary> /// send a new event, to create a new floating text /// </summary> public GameObject NewText(string text, HUDType hudType, Transform trans, Color color, int size, float speed, float yAcceleration, float yAccelerationScaleFactor, bl_Guidance movement) { GameObject t = Instantiate(TextPrefab) as GameObject; //Create new text info to instatiate bl_Text item = t.GetComponent <bl_Text>(); item.m_Speed = speed; item.m_Color = color; item.m_Transform = trans; // text = ""; item.m_text = ""; item.m_Size = size; item.movement = movement; item.Yquickness = yAcceleration; item.YquicknessScaleFactor = yAccelerationScaleFactor; t.transform.SetParent(CanvasParent, false); // t.GetComponent<RectTransform>().anchoredPosition = Vector2.zero; texts.Add(item); HUDImage hudImage = t.GetComponent <HUDImage>(); hudImage.Show(text, hudType); return(item.gameObject); }
public void SetText() { for (int i = 0; i < texts.Count; i++) { //Convert Word Position in screen position for UI int mov = ScreenPosition(texts[i].m_Transform); bl_Text m_Text = texts[i]; m_Text.Yquickness += Time.deltaTime * texts[i].YquicknessScaleFactor;; //Get center up of target Vector3 position = texts[i].m_Transform.GetComponent <Collider>().bounds.center + (((Vector3.up * texts[i].m_Transform.GetComponent <Collider>().bounds.size.y) * 0.5f)); Vector3 front = position - MCamera.transform.position; //its in camera view if ((front.magnitude <= HideDistance) && (Vector3.Angle(MCamera.transform.forward, position - MCamera.transform.position) <= MaxViewAngle)) { //Convert position to view port Vector2 v = MCamera.WorldToViewportPoint(position); //configure each text texts[i].m_Text.fontSize = ((int)(((mov / 2) * 1)) + texts[i].m_Size) / 2; texts[i].m_Text.text = texts[i].m_text; Vector2 size = new Vector2(0, 0); //Calculate the movement Vector2 v2 = new Vector2((v.x - size.x * 0.5f) + texts[i].Xcountervail, -((v.y - size.y) - texts[i].Ycountervail)); //Apply to Text texts[i].Rect.anchorMax = v; texts[i].Rect.anchorMin = v; texts[i].Rect.anchoredPosition = v2; texts[i].m_Text.color = texts[i].m_Color; } } }
/// <summary> /// send a new event, to create a new floating text /// </summary> public void NewText(HUDTextInfo info) { //override animation type TextAnimationType tat = (info.AnimationType == TextAnimationType.None) ? m_TextAnimationType : info.AnimationType; if (CanReuse && HaveUtil(info.CacheTransform) != null) { bl_Text t = HaveUtil(info.CacheTransform); //check for new lines //if you want add a new line to the current text simple send a text with the subfix '\n' in the end string text = t.m_text + info.Text; bool hasOtherLine = false; int containCount = 0; if (info.Text.Contains("\n") && !string.IsNullOrEmpty(t.m_text)) { string[] tArray = text.Split('\n'); containCount = tArray.Length; hasOtherLine = true; text = string.Join("\n", tArray); } t.m_text = (hasOtherLine) ? text : info.Text; t.m_Color = info.Color; t.FadeSpeed = (info.FadeSpeed > 0) ? info.FadeSpeed : FadeSpeed; t.VerticalPositionOffset = (hasOtherLine) ? 2.2f * containCount : t.VerticalPositionOffset; t.Delay = (Time.time + (DelayStay / 2)) + info.ExtraDelayTime; t.FloatSpeed = (FloatingSpeed + info.ExtraFloatSpeed); t.Uses++; t.PlayAnimation((int)tat, info.AnimationSpeed); return; } GameObject prefab = (info.TextPrefab == null) ? TextPrefab : info.TextPrefab; //Create new text info to instantiate GameObject go = Instantiate(prefab) as GameObject; bl_Text item = go.GetComponent <bl_Text>(); item.m_Speed = info.Speed; item.FadeSpeed = (info.FadeSpeed > 0) ? info.FadeSpeed : FadeSpeed; item.m_Color = info.Color; item.m_Transform = info.CacheTransform; item.m_text = info.Text; item.m_Size = info.Size; item.movement = info.Side; item.FloatSpeed = (FloatingSpeed + info.ExtraFloatSpeed); item.VerticalPositionOffset = info.VerticalPositionOffset; item.Yquickness = info.VerticalAceleration; item.YquicknessScaleFactor = info.VerticalFactorScale; item.Delay = (Time.time + DelayStay) + info.ExtraDelayTime; item.PlayAnimation((int)tat, info.AnimationSpeed); go.transform.SetParent(CanvasParent, false); go.GetComponent <RectTransform>().anchoredPosition = Vector2.zero; texts.Add(item); }
/// <summary> /// send a new event, to create a new floating text /// </summary> public void NewText(string text, Transform trans, Color color, int size, float speed, float yAcceleration, float yAccelerationScaleFactor, bl_Guidance movement) { GameObject t = Instantiate(TextPrefab) as GameObject; //Create new text info to instatiate bl_Text item = t.GetComponent <bl_Text>(); item.m_Speed = speed; item.m_Color = color; item.m_Transform = trans; item.m_text = text; item.m_Size = size; item.movement = movement; item.Yquickness = yAcceleration; item.YquicknessScaleFactor = yAccelerationScaleFactor; print(1); t.transform.SetParent(CanvasParent, false); //t.GetComponent<RectTransform>().anchoredPosition = Vector2.zero; texts.Add(item); }
/// <summary> /// /// </summary> void OnGUI() { if (m_Cam == null) { return; } if (Event.current.type == EventType.Repaint) { for (int i = 0; i < texts.Count; i++) { //when target is destroyed then remove it from list. if (texts[i].m_Transform == null) { //When player / Object death, destroy all last text. if (DestroyTextOnDeath) { Destroy(texts[i].Rect.gameObject); texts[i] = null; } texts.Remove(texts[i]); return; } bl_Text temporal = texts[i]; //fade text temporal.m_Color -= new Color(0f, 0f, 0f, (Time.deltaTime * FadeSpeed) / 100f); //if Text have more than a target graphic //add a canvas group in the root for fade all if (texts[i].LayoutRoot != null) { texts[i].LayoutRoot.alpha = texts[i].m_Color.a; } //if complete fade remove and destroy text if (texts[i].m_Color.a <= 0f) { Destroy(texts[i].Rect.gameObject); texts[i] = null; texts.Remove(texts[i]); } else//if UI visible { //Convert Word Position in screen position for UI int mov = ScreenPosition(texts[i].m_Transform); bl_Text m_Text = texts[i]; m_Text.Yquickness += Time.deltaTime * texts[i].YquicknessScaleFactor;; switch (texts[i].movement) { case bl_Guidance.Up: m_Text.Ycountervail += (((Time.deltaTime * FloatingSpeed) * mov) * 0.25f) * texts[i].Yquickness; break; case bl_Guidance.Down: m_Text.Ycountervail -= (((Time.deltaTime * FloatingSpeed) * mov) * 0.25f) * texts[i].Yquickness; break; case bl_Guidance.Left: m_Text.Xcountervail -= ((Time.deltaTime * FloatingSpeed) * mov) * 0.25f; break; case bl_Guidance.Right: m_Text.Ycountervail += ((Time.deltaTime * FloatingSpeed) * mov) * 0.25f; break; case bl_Guidance.RightUp: m_Text.Ycountervail += (((Time.deltaTime * FloatingSpeed) * mov) * 0.25f) * texts[i].Yquickness; m_Text.Xcountervail += ((Time.deltaTime * FloatingSpeed) * mov) * 0.25f; break; case bl_Guidance.RightDown: m_Text.Ycountervail -= (((Time.deltaTime * FloatingSpeed) * mov) * 0.25f) * texts[i].Yquickness; m_Text.Xcountervail += ((Time.deltaTime * FloatingSpeed) * mov) * 0.25f; break; case bl_Guidance.LeftUp: m_Text.Ycountervail += (((Time.deltaTime * FloatingSpeed) * mov) * 0.25f) * texts[i].Yquickness; m_Text.Xcountervail -= ((Time.deltaTime * FloatingSpeed) * mov) * 0.25f; break; case bl_Guidance.LeftDown: m_Text.Ycountervail -= (((Time.deltaTime * FloatingSpeed) * mov) * 0.25f) * texts[i].Yquickness; m_Text.Xcountervail -= ((Time.deltaTime * FloatingSpeed) * mov) * 0.25f; break; } //Get center up of target Vector3 position = texts[i].m_Transform.GetComponent <Collider>().bounds.center + (((Vector3.up * texts[i].m_Transform.GetComponent <Collider>().bounds.size.y) * 0.5f)); Vector3 front = position - MCamera.transform.position; //its in camera view if ((front.magnitude <= HideDistance) && (Vector3.Angle(MCamera.transform.forward, position - MCamera.transform.position) <= MaxViewAngle)) { //Convert position to view port Vector2 v = MCamera.WorldToViewportPoint(position); //configure each text texts[i].m_Text.fontSize = ((int)(((mov / 2) * 1)) + texts[i].m_Size) / 2; texts[i].m_Text.text = texts[i].m_text; Vector2 size = GUI.skin.label.CalcSize(new GUIContent(texts[i].m_text)); //Calculate the movement Vector2 v2 = new Vector2((v.x - size.x * 0.5f) + texts[i].Xcountervail, -((v.y - size.y) - texts[i].Ycountervail)); //Apply to Text texts[i].Rect.anchorMax = v; texts[i].Rect.anchorMin = v; texts[i].Rect.anchoredPosition = v2; texts[i].m_Text.color = texts[i].m_Color; } } } } }
/// <summary> /// /// </summary> void HudTextControl() { for (int i = 0; i < texts.Count; i++) { //cache the current text bl_Text temporal = texts[i]; if (temporal == null) { texts.RemoveAt(i); return; } //when target is destroyed then remove it from list. if (temporal.m_Transform == null) { //When player / Object death, destroy all last text. if (DestroyTextOnDeath && temporal.Rect.gameObject != null) { Destroy(temporal.Rect.gameObject); texts[i] = null; } texts.Remove(temporal); return; } //Wait for delay time, if this is pass, then is not more util and can move. temporal.isUtil = (Time.time < temporal.Delay && temporal.Uses < MaxUses); if (!temporal.isUtil) { float alpha = FadeCurve.Evaluate(temporal.fadeCurveTime); temporal.fadeCurveTime += ((Time.deltaTime * temporal.FadeSpeed) / 100); //fade text Color _color = temporal.m_Color; _color.a = alpha; temporal.m_Color = _color; } //if Text have more than a target graphic //add a canvas group in the root for fade all if (temporal.LayoutRoot != null) { temporal.LayoutRoot.alpha = texts[i].m_Color.a; } //if complete fade, remove and destroy text. if (texts[i].m_Color.a <= FadeCurve.keys[FadeCurve.keys.Length - 1].value) { Destroy(texts[i].Rect.gameObject); texts[i] = null; texts.Remove(texts[i]); } else//if UI visible { //Convert Word Position in screen position for UI int mov = ScreenPosition(texts[i].m_Transform); //only move is already pass the daly time if (!temporal.isUtil) { bl_Text m_Text = texts[i]; m_Text.Yquickness += Time.deltaTime * temporal.YquicknessScaleFactor; float floatSpeed = temporal.FloatSpeed; switch (texts[i].movement) { case bl_Guidance.Up: m_Text.Ycountervail += (((Time.deltaTime * floatSpeed) * mov) * FactorMultiplier) * temporal.Yquickness; break; case bl_Guidance.Down: m_Text.Ycountervail -= (((Time.deltaTime * floatSpeed) * mov) * FactorMultiplier) * temporal.Yquickness; break; case bl_Guidance.Left: m_Text.Xcountervail -= ((Time.deltaTime * floatSpeed) * mov) * FactorMultiplier; break; case bl_Guidance.Right: m_Text.Xcountervail += ((Time.deltaTime * floatSpeed) * mov) * FactorMultiplier; break; case bl_Guidance.RightUp: m_Text.Ycountervail += (((Time.deltaTime * floatSpeed) * mov) * FactorMultiplier) * temporal.Yquickness; m_Text.Xcountervail += ((Time.deltaTime * floatSpeed) * mov) * FactorMultiplier; break; case bl_Guidance.RightDown: m_Text.Ycountervail -= (((Time.deltaTime * floatSpeed) * mov) * FactorMultiplier) * temporal.Yquickness; m_Text.Xcountervail += ((Time.deltaTime * floatSpeed) * mov) * FactorMultiplier; break; case bl_Guidance.LeftUp: m_Text.Ycountervail += (((Time.deltaTime * floatSpeed) * mov) * FactorMultiplier) * temporal.Yquickness; m_Text.Xcountervail -= ((Time.deltaTime * floatSpeed) * mov) * FactorMultiplier; break; case bl_Guidance.LeftDown: m_Text.Ycountervail -= (((Time.deltaTime * floatSpeed) * mov) * FactorMultiplier) * temporal.Yquickness; m_Text.Xcountervail -= ((Time.deltaTime * floatSpeed) * mov) * FactorMultiplier; break; } } //Get center up of target Vector3 position = Vector3.zero; if (m_Type == GameType.Mode3D) { position = temporal.m_Transform.GetComponent <Collider>().bounds.center + (((Vector3.up * temporal.m_Transform.GetComponent <Collider>().bounds.size.y) * 0.5f)); } else { Collider2D c = temporal.m_Transform.GetComponent <Collider2D>(); position = c.bounds.center + (((Vector3.up * c.bounds.size.y) * 0.5f)); } position.y += temporal.VerticalPositionOffset; Vector3 front = position - MCamera.transform.position; //its in camera view if ((front.magnitude <= HideDistance) && (Vector3.Angle(MCamera.transform.forward, position - MCamera.transform.position) <= MaxViewAngle)) { //Convert position to view port Vector2 v = MCamera.WorldToViewportPoint(position); //Calculate font size depend of distance. int fontSize = ((int)((mov / 4) * 1) + temporal.m_Size) / 2; //Clamp size for avoid problems of failed to generate dynamic font texture. fontSize = Mathf.Clamp(fontSize, 1, 100); temporal.m_Text.fontSize = fontSize; temporal.m_Text.text = temporal.m_text; //Calculate the movement Vector2 v2 = new Vector2((v.x * 0.5f) + temporal.Xcountervail, -((v.y) - temporal.Ycountervail)); //Apply to Text temporal.Rect.anchorMax = v; temporal.Rect.anchorMin = v; temporal.Rect.anchoredPosition = v2; temporal.m_Text.color = texts[i].m_Color; } else { temporal.m_Color -= new Color(0f, 0f, 0f, (Time.deltaTime * temporal.FadeSpeed) / 25f); } } } }