protected void CreateButtonText(RectTransform buttonTransform, string textContent, ref GameObject textObject, ref RectTransform textTransform, ref SpritedStringUI textComponent, bool replicateScale) { RectTransform areaParentTrans = null; if ((buttonTransform != null) && (textContent != null)) { areaParentTrans = (RectTransform)buttonTransform.parent; if (areaParentTrans != null) { textObject = new GameObject("ButtonText", typeof(RectTransform)); textTransform = textObject.GetComponent <RectTransform>(); textTransform.SetParent(areaParentTrans, false); textComponent = textObject.AddComponent <SpritedStringUI>(); textComponent.SetSymbolSource(font); textComponent.SetValue(textContent); textComponent.ToggleRaycastTargeting(false); textTransform.anchoredPosition = buttonTransform.anchoredPosition; if (replicateScale) { textTransform.localScale = buttonTransform.localScale; } } } }
protected void CreateTextDisplayObject(string objectName, string objectContent, Vector2 scaleChange, Vector2 positionRates, TextAlignment anchorAlign, ref GameObject newObject, ref RectTransform newTransform, ref SpritedStringUI newText) { Vector2 originalUIDimensions = Vector2.zero; if (font != null) { newObject = new GameObject(objectName, typeof(RectTransform)); newTransform = newObject.GetComponent <RectTransform>(); newText = newObject.AddComponent <SpritedStringUI>(); newText.SetSymbolSource(font); newText.SetValue(objectContent); newText.ToggleRaycastTargeting(false); originalUIDimensions = newText.GetUIDimensions(); PlaceTransformProperly(newTransform, originalUIDimensions, scaleChange, positionRates, anchorAlign); } }
private bool AddCanvasText(string textString, SymbolDatabase textFont, Color textColor, Vector4 textColorGradient, int textEvolution, Transform originTransform, Vector2 originWorldPosition, bool workDuringPause) { GameObject textObject = null; RectTransform textTrans = null; SpritedStringUI text = null; int textIndex = -1; Vector3 completeWorldPos = Vector3.zero; Vector2 currentWorldPos = Vector2.zero; Vector2 canvasPosition = Vector2.zero; Vector2 textSpeed = Vector2.zero; Vector2 textIncreasedScale = Vector2.zero; Color textGeneralColor = Color.white; float textDurationShow = 0f; float textDurationPlain = 0f; float textDurationHide = 0f; int textStage = INVALID_TEXT_STAGE; if (originTransform != null) { completeWorldPos = originTransform.position; currentWorldPos = new Vector2(completeWorldPos.x, completeWorldPos.y); /*halmeida - in case there is an origin transform, the originWorldPosition vector is interpreted as an offset * from the transform's position.*/ currentWorldPos += originWorldPosition; } else { currentWorldPos = originWorldPosition; } if (TransformWorldToCanvasPosition(currentWorldPos, ref canvasPosition)) { textIndex = (textObjects == null) ? 0 : textObjects.Length; textObject = new GameObject("UIText" + textIndex, typeof(RectTransform)); if (textObject != null) { textTrans = textObject.GetComponent <RectTransform>(); text = textObject.AddComponent <SpritedStringUI>(); if (text != null) { text.SetSymbolSource(textFont); text.ToggleRaycastTargeting(false); text.SetValue(textString); textTrans.SetParent(interfaceCanvasTrans, false); textTrans.anchoredPosition = canvasPosition; switch (textEvolution) { case TEXT_EVOLUTION_ASCENT: textSpeed.y = TEXT_ASCENT_SPEED; textGeneralColor = text.GetGeneralColor(); textGeneralColor.a = 0f; text.SetGeneralColor(textGeneralColor); textStage = TEXT_STAGE_SHOW; textIncreasedScale = new Vector2(TEXT_ASCENT_START_SCALE_X, TEXT_ASCENT_START_SCALE_Y); textTrans.localScale = new Vector3(textIncreasedScale.x, textIncreasedScale.y, 1f); textDurationShow = TEXT_ASCENT_DURATION_SHOW; textDurationPlain = TEXT_ASCENT_DURATION_PLAIN; textDurationHide = TEXT_ASCENT_DURATION_HIDE; break; case TEXT_EVOLUTION_STAY: textGeneralColor = text.GetGeneralColor(); textGeneralColor.a = 0f; text.SetGeneralColor(textGeneralColor); textStage = TEXT_STAGE_SHOW; textIncreasedScale = new Vector2(TEXT_STAY_START_SCALE_X, TEXT_STAY_START_SCALE_Y); textTrans.localScale = new Vector3(textIncreasedScale.x, textIncreasedScale.y, 1f); textDurationShow = TEXT_STAY_DURATION_SHOW; textDurationPlain = TEXT_STAY_DURATION_PLAIN; textDurationHide = TEXT_STAY_DURATION_HIDE; break; case TEXT_EVOLUTION_NONE_WAIT: case TEXT_EVOLUTION_NONE_GO: textGeneralColor = text.GetGeneralColor(); textGeneralColor.a = 0f; text.SetGeneralColor(textGeneralColor); textStage = TEXT_STAGE_SHOW; textIncreasedScale = new Vector2(TEXT_NONE_START_SCALE_X, TEXT_NONE_START_SCALE_Y); textTrans.localScale = new Vector3(textIncreasedScale.x, textIncreasedScale.y, 1f); textDurationShow = TEXT_NONE_DURATION_SHOW; textDurationPlain = TEXT_NONE_DURATION_PLAIN; textDurationHide = TEXT_NONE_DURATION_HIDE; break; } text.SetColor(textColor, textColorGradient); UsefulFunctions.IncreaseArray <GameObject>(ref textObjects, textObject); UsefulFunctions.IncreaseArray <RectTransform>(ref textTransforms, textTrans); UsefulFunctions.IncreaseArray <SpritedStringUI>(ref texts, text); UsefulFunctions.IncreaseArray <int>(ref textEvolutions, textEvolution); UsefulFunctions.IncreaseArray <Transform>(ref textOriginTransforms, originTransform); UsefulFunctions.IncreaseArray <Vector2>(ref textOriginPositions, originWorldPosition); UsefulFunctions.IncreaseArray <Vector2>(ref textSpeeds, textSpeed); UsefulFunctions.IncreaseArray <Vector2>(ref textIncreasedScales, textIncreasedScale); UsefulFunctions.IncreaseArray <float>(ref textDurationsShow, textDurationShow); UsefulFunctions.IncreaseArray <float>(ref textDurationsPlain, textDurationPlain); UsefulFunctions.IncreaseArray <float>(ref textDurationsHide, textDurationHide); UsefulFunctions.IncreaseArray <int>(ref textStages, textStage); UsefulFunctions.IncreaseArray <float>(ref textStageElapseds, 0f); UsefulFunctions.IncreaseArray <float>(ref textElapseds, 0f); UsefulFunctions.IncreaseArray <bool>(ref textPauseds, workDuringPause); return(true); } } textTrans = null; if (textObject != null) { Destroy(textObject); } } return(false); }