/// <summary> /// Tries to damage the building if unlucky. /// </summary> private void CheckForDisaster() { //Creates a list of potential disasters List <BuildingDistaster> disasters = new List <BuildingDistaster>(); disasters.AddRange(thisBuilding.potentialDisasters); disasters.AddRange(tile.properties.environmentalDisaster); foreach (BuildingDistaster disaster in disasters) { // If the building isn't already broken and the risk returns true a disaster occurs. if (durability > 0 && SoulTycoon.AttemptRisk(disaster.risk)) { //Gameplay implications int damageDealt = (int)SoulTycoon.VariableValue(disaster.damageBase, disaster.damageVariance); durability = Mathf.Max(durability - damageDealt, 0); //Play particle effects SmokeParticles.Emit(15); if (durability <= 0) { SmokeParticles.Play(); } //Create a notifiaction about the disaster. GameObject go = Instantiate(Resources.Load <GameObject>("Disaster"), transform.position - new Vector3(0, 0, 1), Quaternion.identity); TMPro.TextMeshPro textMesh = go.GetComponent <TMPro.TextMeshPro>(); textMesh.SetText(string.Format(durability > 0 ? "{0}!\nIntegrity {2}%" : "{0}\nRepairs needed!", disaster.name, damageDealt, Mathf.Max((float)durability / thisBuilding.durability * 100, 0).ToString("N1"))); textMesh.color = new Color(1f, 0.7f, 0.7f); //Only one disaster can occur per hour so we stop running through the foreach loop here. break; } } }
// Start is called before the first frame update void Start() { tmProh = GetComponent <TextMeshPro>() ?? gameObject.AddComponent <TextMeshPro>(); tmpText.text = "LOADING..."; tmProh.text = tmpText.text; Debug.Log(tmProh.text); //// MQTT stuff //client = new MqttClient(broker); //// register to message received //client.MqttMsgPublishReceived += client_MqttMsgPublishReceived; //string clientId = System.Guid.NewGuid().ToString(); //goodDownload = false; //try //{ // client.Connect(clientId); // Debug.Log("CONNECTED!!"); // goodDownload = true; //} //catch (System.Exception e) //{ // Debug.LogError("Connection error: " + e); //} //// subscribe to the topic //client.Subscribe(new string[] { "topic/EV3ARProject" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE }); StartCoroutine(GetRequest()); }
public void Init(TMPro.TextMeshPro scoreTextField) { if (m_FirstInit) { m_SplinePointsWorld = new Vector3[kSplineMax]; m_MeshFilter = gameObject.GetComponent <MeshFilter>(); m_Material = gameObject.GetComponent <MeshRenderer>().material; m_InitialColor = m_Material.color; m_Score = 0; m_FirstInit = false; } m_SplineN = 2; m_SplinePointsWorld[0] = transform.position; m_SplinePointsWorld[1] = transform.position; m_Mode = Mode.Menu; distanceFromCenter = .5f; m_Speed = 0.2f; m_RotationSpeed = 180; m_SpeedFactor = 1.0f; m_SnakeLength = m_SnakeLengthMax = 0.2f; m_SnakeRadius = 0.5f; m_Material.color = m_InitialColor; m_ScoreTextField = scoreTextField; m_BonusScoreOverage = 0; bonusMode = false; }
public void SetPrivates(Character character, System.Func <bool> sceneUpdateAction, bool isInventoryAvailable, int tabId) { _title = transform.Find("Title").GetComponent <TMPro.TextMeshPro>(); _character = character; _sceneUpdateAction = sceneUpdateAction; _currentTab = tabId; _resetTabPosition = new Vector3(-10.0f, 10.0f, 0.0f); _currentTabPosition = transform.position; _tabs = new List <GameObject>(); _buttonsTabs = new List <ButtonBhv>(); _instantiator = GameObject.Find(Constants.GoSceneBhvName).GetComponent <SceneBhv>().Instantiator; for (int i = 0; i < 5; ++i) { _tabs.Add(transform.Find("Tab" + i).gameObject); _buttonsTabs.Add(transform.Find("ButtonTab" + i).GetComponent <ButtonBhv>()); if (i == _currentTab) { BringTabFront(_tabs[i]); } else { UnpressButton(_buttonsTabs[i].gameObject); BringTabBack(_tabs[i], i); } } _skinContainerBhv = _tabs[0].transform.Find("SkinContainer").GetComponent <SkinContainerBhv>(); SetButtons(isInventoryAvailable); DisplayStatsCharacter(); DisplayStatsWeapon(_tabs[1], _character.Weapons[0], "SkinContainerWeapon0", "StatsList1"); DisplayStatsWeapon(_tabs[2], _character.Weapons[1], "SkinContainerWeapon1", "StatsList2"); DisplayStatsSkill(_tabs[3], _character.Skills[0], "SkinContainerSkill0", "StatsList3"); DisplayStatsSkill(_tabs[4], _character.Skills[1], "SkinContainerSkill1", "StatsList4"); }
/// <summary> /// Function returning the index of the character at the given position (if any). /// </summary> /// <param name="text">A reference to the TextMeshPro UGUI component.</param> /// <param name="position">Position to check for intersection.</param> /// <param name="camera"></param> /// <param name="visibleOnly">Only check for visible characters.</param> /// <returns></returns> public static int FindIntersectingCharacter(TextMeshPro text, Vector3 position, Camera camera, bool visibleOnly) { Transform textTransform = text.transform; // Convert position into Worldspace coordinates ScreenPointToWorldPointInRectangle(textTransform, position, camera, out position); for (int i = 0; i < text.textInfo.characterCount; i++) { // Get current character info. TMP_CharacterInfo cInfo = text.textInfo.characterInfo[i]; if (visibleOnly && !cInfo.isVisible) continue; // Get Bottom Left and Top Right position of the current character Vector3 bl = textTransform.TransformPoint(cInfo.bottomLeft); Vector3 tl = textTransform.TransformPoint(new Vector3(cInfo.bottomLeft.x, cInfo.topRight.y, 0)); Vector3 tr = textTransform.TransformPoint(cInfo.topRight); Vector3 br = textTransform.TransformPoint(new Vector3(cInfo.topRight.x, cInfo.bottomLeft.y, 0)); if (PointIntersectRectangle(position, bl, tl, tr, br)) return i; } return -1; }
void Awake() { if (!enabled) return; m_camera = Camera.main; //Debug.Log("w:" + Screen.width + " h:" + Screen.height); GameObject frameCounter = new GameObject("Frame Counter"); m_frameCounter_transform = frameCounter.transform; m_frameCounter_transform.parent = m_camera.transform; m_frameCounter_transform.localRotation = Quaternion.identity; m_TextMeshPro = frameCounter.AddComponent<TextMeshPro>(); m_TextMeshPro.font = Resources.Load("Fonts/ARIAL SDF", typeof(TextMeshProFont)) as TextMeshProFont; m_TextMeshPro.fontSharedMaterial = Resources.Load("Fonts/ARIAL SDF Overlay", typeof(Material)) as Material; m_TextMeshPro.fontSize = 48; //m_TextMeshPro.FontColor = new Color32(255, 255, 255, 128); //m_TextMeshPro.edgeWidth = .15f; m_TextMeshPro.isOverlay = true; //m_TextMeshPro.FaceColor = new Color32(255, 128, 0, 0); //m_TextMeshPro.EdgeColor = new Color32(0, 255, 0, 255); //m_TextMeshPro.FontMaterial.renderQueue = 4000; //m_TextMeshPro.CreateSoftShadowClone(new Vector2(1f, -1f)); Set_FrameCounter_Position(AnchorPosition); last_AnchorPosition = AnchorPosition; }
static int SetMask(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 3) { TMPro.TextMeshPro obj = (TMPro.TextMeshPro)ToLua.CheckObject <TMPro.TextMeshPro>(L, 1); TMPro.MaskingTypes arg0 = (TMPro.MaskingTypes)ToLua.CheckObject(L, 2, typeof(TMPro.MaskingTypes)); UnityEngine.Vector4 arg1 = ToLua.ToVector4(L, 3); obj.SetMask(arg0, arg1); return(0); } else if (count == 5) { TMPro.TextMeshPro obj = (TMPro.TextMeshPro)ToLua.CheckObject <TMPro.TextMeshPro>(L, 1); TMPro.MaskingTypes arg0 = (TMPro.MaskingTypes)ToLua.CheckObject(L, 2, typeof(TMPro.MaskingTypes)); UnityEngine.Vector4 arg1 = ToLua.ToVector4(L, 3); float arg2 = (float)LuaDLL.luaL_checknumber(L, 4); float arg3 = (float)LuaDLL.luaL_checknumber(L, 5); obj.SetMask(arg0, arg1, arg2, arg3); return(0); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: TMPro.TextMeshPro.SetMask")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int UpdateVertexData(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 1) { TMPro.TextMeshPro obj = (TMPro.TextMeshPro)ToLua.CheckObject <TMPro.TextMeshPro>(L, 1); obj.UpdateVertexData(); return(0); } else if (count == 2) { TMPro.TextMeshPro obj = (TMPro.TextMeshPro)ToLua.CheckObject <TMPro.TextMeshPro>(L, 1); TMPro.TMP_VertexDataUpdateFlags arg0 = (TMPro.TMP_VertexDataUpdateFlags)ToLua.CheckObject(L, 2, typeof(TMPro.TMP_VertexDataUpdateFlags)); obj.UpdateVertexData(arg0); return(0); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: TMPro.TextMeshPro.UpdateVertexData")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int ClearMesh(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 1) { TMPro.TextMeshPro obj = (TMPro.TextMeshPro)ToLua.CheckObject <TMPro.TextMeshPro>(L, 1); obj.ClearMesh(); return(0); } else if (count == 2) { TMPro.TextMeshPro obj = (TMPro.TextMeshPro)ToLua.CheckObject <TMPro.TextMeshPro>(L, 1); bool arg0 = LuaDLL.luaL_checkboolean(L, 2); obj.ClearMesh(arg0); return(0); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: TMPro.TextMeshPro.ClearMesh")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public void SetPrivates(OverBlendType overBlendType, string message, float?constantLoadingSpeed, System.Func <bool, object> resultAction, bool reverse) { Constants.InputLocked = true; DontDestroyOnLoad(gameObject); _overBlendType = overBlendType; _loadPercent = 0; if (reverse) { _sourcePosition = new Vector3(-6.0f, 0.0f, 0.0f); } else { _sourcePosition = new Vector3(6.0f, 0.0f, 0.0f); } _activePosition = new Vector3(0.0f, 0.0f, 0.0f); _endPosition = new Vector3(-_sourcePosition.x, 0.0f, 0.0f); _state = 0; _constantLoadingSpeed = constantLoadingSpeed; _resultAction = resultAction; _spriteRenderer = gameObject.GetComponent <SpriteRenderer>(); _spriteRenderer.color = Constants.ColorPlainTransparent; _loading = transform.Find("Loading").gameObject; _halfSpriteSize = _loading.GetComponent <SpriteRenderer>().size.x / 2; AddLoadingPercent(0.0f); _message = transform.Find("Message").GetComponent <TMPro.TextMeshPro>(); _message.text = message; _midActionDone = false; transform.position = _sourcePosition; }
private void Awake() { // Get components _collider = GetComponent <Collider>(); text = GetComponentInChildren <TMPro.TextMeshPro>(); SetLetter(character); }
void Start() { if (SpawnType == 0) { //Debug.Log("Spawning TextMesh Pro Objects."); // TextMesh Pro Implementation m_textMeshPro = m_floatingText.AddComponent<TextMeshPro>(); //m_textMeshPro.FontAsset = Resources.Load("Fonts/JOKERMAN SDF", typeof(TextMeshProFont)) as TextMeshProFont; // User should only provide a string to the resource. m_textMeshPro.anchor = AnchorPositions.Bottom; m_textMeshPro.color = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), 255); m_textMeshPro.fontSize = 16; m_textMeshPro.text = string.Empty; StartCoroutine(DisplayTextMeshProFloatingText()); } else { //Debug.Log("Spawning TextMesh Objects."); m_textMesh = m_floatingText.AddComponent<TextMesh>(); m_textMesh.font = Resources.Load("Fonts/ARIAL", typeof(Font)) as Font; // User should only provide a string to the resource. m_textMesh.renderer.sharedMaterial = m_textMesh.font.material; m_textMesh.color = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), 255); m_textMesh.anchor = TextAnchor.LowerCenter; m_textMesh.fontSize = 16; StartCoroutine(DisplayTextMeshFloatingText()); } }
protected override void SetPrivates() { base.SetPrivates(); OnRootPreviousScene = Constants.SoulTreeScene; _characterName = GameObject.Find("CharacterName").GetComponent <TMPro.TextMeshPro>(); _skinContainer = GameObject.Find("SkinContainer"); _raceTextMesh = GameObject.Find("RaceText").GetComponent <TMPro.TextMeshPro>(); _gender = (CharacterGender)Random.Range(0, 1); _race = CharacterRace.Human; _rightButtons = new List <ButtonBhv>(); _leftButtons = new List <ButtonBhv>(); var allButtons = GameObject.FindGameObjectsWithTag(Constants.TagButton); foreach (var button in allButtons) { if (button.name.Contains("Right")) { _rightButtons.Add(button.GetComponent <ButtonBhv>()); } if (button.name.Contains("Left")) { _leftButtons.Add(button.GetComponent <ButtonBhv>()); } } }
public GameField() { gameObject = create(Program.I().new_ocgcore_field, getGoodPosition(), Vector3.zero, false, Program.ui_container_3d, false); UIHelper.getByName(gameObject, "obj_0").transform.localScale = Vector3.zero; UIHelper.getByName(gameObject, "obj_1").transform.localScale = Vector3.zero; Phase = gameObject.GetComponentInChildren <phaser>(); Phase.bpAction = onBP; Phase.epAction = onEP; Phase.mp2Action = onMP; leftT = UIHelper.getByName <UITexture>(gameObject, "leftT"); midT = UIHelper.getByName <UITexture>(gameObject, "midT"); rightT = UIHelper.getByName <UITexture>(gameObject, "rightT"); phaseTexure = UIHelper.getByName <UITexture>(gameObject, "phaseT"); midT.border = new Vector4(0, 500, 0, 230); leftT.mainTexture = null; midT.mainTexture = null; rightT.mainTexture = null; phaseTexure.mainTexture = null; me_left_p_num = create(Program.I().mod_ocgcore_number); me_right_p_num = create(Program.I().mod_ocgcore_number); op_left_p_num = create(Program.I().mod_ocgcore_number); op_right_p_num = create(Program.I().mod_ocgcore_number); Program.I().ocgcore.AddUpdateAction_s(Update); gameHiddenButtons.Add(new gameHiddenButton(game_location.LOCATION_DECK, 0)); gameHiddenButtons.Add(new gameHiddenButton(game_location.LOCATION_EXTRA, 0)); gameHiddenButtons.Add(new gameHiddenButton(game_location.LOCATION_GRAVE, 0)); gameHiddenButtons.Add(new gameHiddenButton(game_location.LOCATION_REMOVED, 0)); gameHiddenButtons.Add(new gameHiddenButton(game_location.LOCATION_DECK, 1)); gameHiddenButtons.Add(new gameHiddenButton(game_location.LOCATION_EXTRA, 1)); gameHiddenButtons.Add(new gameHiddenButton(game_location.LOCATION_GRAVE, 1)); gameHiddenButtons.Add(new gameHiddenButton(game_location.LOCATION_REMOVED, 1)); LOCATION_DECK_0 = create(Program.I().new_ui_textMesh, Vector3.zero, new Vector3(60, 0, 0)).GetComponent <TMPro.TextMeshPro>(); LOCATION_EXTRA_0 = create(Program.I().new_ui_textMesh, Vector3.zero, new Vector3(60, 0, 0)).GetComponent <TMPro.TextMeshPro>(); LOCATION_GRAVE_0 = create(Program.I().new_ui_textMesh, Vector3.zero, new Vector3(60, 0, 0)).GetComponent <TMPro.TextMeshPro>(); LOCATION_REMOVED_0 = create(Program.I().new_ui_textMesh, Vector3.zero, new Vector3(60, 0, 0)).GetComponent <TMPro.TextMeshPro>(); LOCATION_DECK_1 = create(Program.I().new_ui_textMesh, Vector3.zero, new Vector3(60, 0, 0)).GetComponent <TMPro.TextMeshPro>(); LOCATION_EXTRA_1 = create(Program.I().new_ui_textMesh, Vector3.zero, new Vector3(60, 0, 0)).GetComponent <TMPro.TextMeshPro>(); LOCATION_GRAVE_1 = create(Program.I().new_ui_textMesh, Vector3.zero, new Vector3(60, 0, 0)).GetComponent <TMPro.TextMeshPro>(); LOCATION_REMOVED_1 = create(Program.I().new_ui_textMesh, Vector3.zero, new Vector3(60, 0, 0)).GetComponent <TMPro.TextMeshPro>(); label = create(Program.I().mod_simple_ngui_text, new Vector3(0, 0, -14.5f), new Vector3(60, 0, 0), false, Program.ui_container_3d, false).GetComponent <UILabel>(); label.fontSize = 40; label.overflowMethod = UILabel.Overflow.ShrinkContent; label.alignment = NGUIText.Alignment.Left; label.width = 800; label.height = 40; label.transform.localScale = new Vector3(0.03f, 0.03f, 0.03f); label.text = ""; overCount = 0; }
private GameObject createLoadButton() { GameObject button = Instantiate(Resources.Load("Tournament_Cell", typeof(GameObject))) as GameObject; button.transform.SetParent(tournamentsPanel.transform); button.transform.localScale = Vector3.one; button.transform.position = new Vector3(-500f, -500f, -500f); button.name = "Load_Button"; var text = button.transform.Find("Text").GetComponent <TMPro.TextMeshPro>(); text.text = "Reload Tournaments"; text.fontStyle = TMPro.FontStyles.Bold; text.alignment = TMPro.TextAlignmentOptions.Center; TMPro.TextMeshPro matryxBountyTMP = button.transform.Find("MTX_Amount").GetComponent <TMPro.TextMeshPro>(); matryxBountyTMP.text = ""; scroll.addObject(button.transform); joyStickAggregator.AddForwarder(button.GetComponentInChildren <JoyStickForwarder>()); // Add this action to the panel tournamentsPanel.AddAction(button.GetComponent <FlexButtonComponent>()); return(button); }
void Start() { _spriteRenderer = GetComponent <SpriteRenderer>(); SetSpriteSortingLayerOrder(Constants.InputLayer); _textMesh = GetComponent <TMPro.TextMeshPro>(); SetTextSortingLayerOrder(Constants.InputLayer); }
void Start() { _textMesh = transform.Find(gameObject.name + "Text").GetComponent <TMPro.TextMeshPro>(); _content = transform.Find(gameObject.name + "Mask").Find(gameObject.name + "Content").gameObject; _subContent = transform.Find(gameObject.name + "Mask").Find(gameObject.name + "SubContent").gameObject; _height = _content.GetComponent <SpriteRenderer>().sprite.rect.size.y *Constants.Pixel; }
public void SetPrivates(string text, string imagePath, System.Func <bool, object> resultAction, Direction mainDirection, Direction secondaryDirection) { _startPosition = new Vector3(0.0f, 0.0f, 0.0f); AddDirection(mainDirection); if (secondaryDirection != Direction.None) { AddDirection(secondaryDirection); } _endPosition = new Vector3(-_startPosition.x, -_startPosition.y, 0.0f); var slidingBit = 0.01f; _slideStartPosition = new Vector3(_startPosition.x * slidingBit, _startPosition.y * slidingBit, 0.0f); _slideEndPosition = new Vector3(_endPosition.x * slidingBit, _endPosition.y * slidingBit, 0.0f); _state = 0; _resultAction = resultAction; _spriteRenderer = gameObject.GetComponent <SpriteRenderer>(); _spriteRenderer.sprite = Helper.GetSpriteFromSpriteSheet(imagePath); _spriteRenderer.color = Constants.ColorPlainTransparent; _backgroundRenderer = transform.Find("Background").GetComponent <SpriteRenderer>(); _backgroundPlain = _backgroundRenderer.color; _backgroundTransparent = new Color(_backgroundPlain.r, _backgroundPlain.g, _backgroundPlain.b, 0.0f); _backgroundRenderer.color = _backgroundTransparent; _title = transform.Find("Title").GetComponent <TMPro.TextMeshPro>(); _title.text = text; _moveSpeed = 0.15f; _slideSpeed = 0.05f; _fadeSpeed = 0.2f; transform.position = _startPosition; }
IEnumerator IncreaseScore(int score, GameObject targetCanvas, TMPro.TextMeshPro scoreText) { yield return(StartCoroutine(GameOverTriggered())); targetCanvas.SetActive(true); int displayScore = 0; int scoreIncrement = (int)((float)score / (4f * 60f)); countSource.Play(); while (displayScore < score) { displayScore = Mathf.Min(displayScore + scoreIncrement, score); if (scoreIncrement == 0) { displayScore = score; } scoreText.text = "" + displayScore; yield return(null); } countSource.Stop(); yield return(null); }
//private FpsCounterAnchorPositions last_AnchorPosition; void Awake() { if (!enabled) return; m_camera = Camera.main; GameObject frameCounter = new GameObject("Frame Counter"); m_frameCounter_transform = frameCounter.transform; m_frameCounter_transform.parent = m_camera.transform; m_frameCounter_transform.localRotation = Quaternion.identity; m_TextMeshPro = frameCounter.AddComponent<TextMeshPro>(); m_TextMeshPro.font = Resources.Load("Fonts/ARIAL SDF", typeof(TextMeshProFont)) as TextMeshProFont; m_TextMeshPro.fontSharedMaterial = Resources.Load("Fonts/ARIAL SDF Overlay", typeof(Material)) as Material; m_TextMeshPro.fontSize = 30; m_TextMeshPro.isOverlay = true; m_TextMeshPro.alignment = AlignmentTypes.Right; Set_FrameCounter_Position(AnchorPosition); //last_AnchorPosition = AnchorPosition; m_TextMeshPro.text = instructions; }
public void DisplayTrimResults(ref TotalResultsModel _trModel, TMPro.TextMeshPro _totalSubtext) { int counter = 0; _totalSubtext.text = ""; //get the last 35 characters of the string and just display that. //see the most recent calculations of the last few throws of dice. if (_trModel.preText.Length >= _trModel.maxSubtextChars) { for (int i = _trModel.preText.Length - _trModel.maxSubtextChars; i < _trModel.preText.Length; i++) { if (counter < 3) { _totalSubtext.text += "."; ++counter; } else { _totalSubtext.text += _trModel.preText[i]; } } } else { _totalSubtext.text = _trModel.preText; } }
void Start() { // get renderer renderer = gameObject.GetComponent <Renderer>(); // store the original color originalColor = renderer.material.color; // get the HSV and reduce saturation Color.RGBToHSV(originalColor, out float h, out float s, out float v); s *= (1f - percentageOfUnsaturation); // convert back to RGB and store it unsaturatedColor = Color.HSVToRGB(h, s, v); // text properties text = GetComponentInChildren <TMPro.TextMeshPro>(); if (text) { textOriginalColor = text.color; textUnsaturatedColor = Color.grey; } // change the state of the object to unsaturated color ChangeColorToUnsaturated(); }
public static IEnumerator LerpColorRoutine(TMPro.TextMeshPro textMesh, Color targetColor, float duration, bool ignoreTimeScale, AnimationCurve animationCurve = null) { Color startingColor = textMesh.color; float progress = 0f; int steps = Mathf.RoundToInt(duration / Time.fixedDeltaTime); if (ignoreTimeScale) { float increment = duration / (float)steps; for (int i = 0; i < steps; i++) { progress = Remap(i, 0, steps - 1, 0f, 1f); if (animationCurve != null) { progress = animationCurve.Evaluate(progress); } textMesh.color = Color.Lerp(startingColor, targetColor, progress); yield return(new WaitForSecondsRealtime(increment)); } } else { for (int i = 0; i < steps; i++) { progress = Remap(i, 0, steps - 1, 0f, 1f); if (animationCurve != null) { progress = animationCurve.Evaluate(progress); } textMesh.color = Color.Lerp(startingColor, targetColor, progress); yield return(new WaitForFixedUpdate()); } } }
public void AssignMirrors(int goalMirror, List <MirrorPositionInfo> mirrors, GameObject circle, GameObject square, GameObject diamond, List <MirrorProperties> props, GameObject player) { for (int i = 0; i < mirrors.Count; i++) { string color = props[i].color; string shape = props[i].shape; string number = props[i].number; GameObject newMirror = CreateMirror(circleMirror, square, diamond, shape); PrepareNewMirror(newMirror, mirrors[i]); ChangeColor(newMirror, color); GameObject textComp = newMirror.transform.GetChild(4).gameObject; TMPro.TextMeshPro textMesh = textComp.GetComponent <TMPro.TextMeshPro>(); textMesh.text = number; GameObject collideArea = newMirror.transform.GetChild(5).gameObject; Interact interactObject = collideArea.GetComponent <Interact>(); interactObject.player = player; interactObject.goal = false; if (i == goalMirror) { interactObject.goal = true; } } }
void Start() { var playerGameObject = GameObject.FindGameObjectWithTag("Player"); Player = playerGameObject.GetComponent <Player>(); PlayerController = playerGameObject.GetComponent <PlayerController>(); _text = GetComponentInChildren <TMPro.TextMeshPro>(includeInactive: true); _frame = gameObject.transform.Find("Frame").gameObject; _frame.SetActive(true); // For Find() below _button = GameObject.Find("SkipButton"); _frame.SetActive(false); _menu = gameObject.transform.Find("Menu").gameObject; _text.enabled = false; //_frame.SetActive(false); _button.SetActive(false); _menu.SetActive(false); // Get base scene (always loaded) _baseScene = SceneManager.GetSceneByName("BaseScene"); // Ensure start level scene is loaded and active { var co = LoadStartLevel(); StartCoroutine(co); } }
private void OnEnable() { TextObj = transform.GetChild(1).transform; ChampName = TextObj.GetComponent <TextMeshPro>(); var playerObject = GameObject.FindGameObjectWithTag("Player"); if (playerObject == null) { return; } LocalPos = playerObject.transform.position; PhotonNetwork.OnEventCall += FindSender; if (MyEventGroup.Equals(0)) // 이벤트 코드 초기화 { if (PhotonNetwork.player.IsLocal) { if (PhotonNetwork.player.GetTeam().ToString().Equals("red")) { MyEventGroup = 30; } else { MyEventGroup = 40; } } } }
public void SetPrivates(Character character, System.Func <bool> sceneUpdateAction, System.Func <bool, object> afterManageAction, InventoryItem loot) { _character = character; _sceneUpdateAction = sceneUpdateAction; _afterManageAction = afterManageAction; _loot = loot; _selectedItem = 0; _selectedSprite = transform.Find("SelectedSprite").gameObject; _resetTabPosition = new Vector3(-10.0f, -10.0f, 0.0f); _currentTabPosition = transform.position; _tabs = new List <GameObject>(); _instantiator = GameObject.Find(Constants.GoSceneBhvName).GetComponent <SceneBhv>().Instantiator; for (int i = 0; i < 3; ++i) { _tabs.Add(transform.Find("Tab" + ((InventoryItemType)i).ToString()).gameObject); } _buttons = new List <GameObject>(); _buttons.Add(transform.Find("ButtonPositive").GetComponent <ButtonBhv>().gameObject); _buttons.Add(transform.Find("ButtonNegative").GetComponent <ButtonBhv>().gameObject); _buttonsText = new List <TMPro.TextMeshPro>(); _buttonsText.Add(_buttons[0].transform.GetChild(0).GetComponent <TMPro.TextMeshPro>()); _buttonsText.Add(_buttons[1].transform.GetChild(0).GetComponent <TMPro.TextMeshPro>()); _weightText = transform.Find("Weight").GetComponent <TMPro.TextMeshPro>(); _buttonsPosition = new List <Vector3>(); _buttonsPosition.Add(_buttons[0].transform.position); _buttonsPosition.Add(_buttons[1].transform.position); SetButtons(); }
public override IEnumerator applyToText(TMPro.TextMeshPro text, int startIndex, int length, string param) { int i; /* * Old cuttoff for character name was determined by grabbing the character's name from the beginning of the text. * This for some reason doesn't work for Oculus Quest due to [BUG 0005] * for(i = 0; i < text.text.Length; i++) * { * if(text.text[i] == ':') * { * break; * } * } */ // New cutoff requires that the sound files are named starting with the character's name and then either a - or a _ for (i = 0; i < param.Length; i++) { if (param[i] == '-' || param[i] == '_') { break; } } string char_name = param.Substring(0, i); Debug.Log(char_name); GameObject.Find("GameManager").GetComponent <GameManager>().PlaySoundOnChar(char_name, param); yield return(new WaitForSeconds(0.0f)); }
// Use this for initialization public override void Start() { menuMute = GetComponentInChildren <avatarMenuMute>(); menuMute.AvatarMenu = this; avatarName = transform.FindDeepChild("slam_av_name").GetComponent <TextMeshPro>(); mutelabel = transform.FindDeepChild("slam_av_mute_lbl").gameObject; mutebutton = transform.FindDeepChild("slam_av_mute").gameObject; }
void Update() { movesMadeText = GameObject.Find("MoveNumber").GetComponent<TMPro.TextMeshPro>(); movesMadeText.text = movesMade.ToString(); movesLeftText = GameObject.Find("MoveLeftNumber").GetComponent<TMPro.TextMeshPro>(); movesLeftText.text = movesLeft.ToString(); }
private static void relocateTextMesh(TMPro.TextMeshPro obj, uint con, CardLocation loc, Vector3 poi) { obj.transform.position = UIHelper.getCamGoodPosition(Program.I().ocgcore.get_point_worldposition(new GPS { controller = con, location = (UInt32)loc }) + poi, -2); }
// Start is called before the first frame update void Start() { cursorOn = false; ableToChoose = false; textMesh = GetComponentInChildren <TMPro.TextMeshPro>(); gameManager = GameObject.FindObjectOfType <GameManager>(); textMesh.text = code; chosen = false; }
public void ScheduleObjectForUpdate(TextMeshPro obj) { //Debug.Log("Text Object ID:" + obj.GetInstanceID() + " has been scheduled for update. Object visibility is:" + obj.renderer.isVisible); if (m_objectList == null) m_objectList = new List<TextMeshPro>(); m_objectList.Add(obj); }
public void SetText(string text) { if (_text == null) { _text = GetComponentInChildren <TMPro.TextMeshPro>(); } _text.text = text; }
/// <inheritdoc /> public override void Init(GameObject host, ThemeDefinition settings) { mesh = host.GetComponent <TextMesh>(); text = host.GetComponent <Text>(); meshPro = host.GetComponent <TextMeshPro>(); meshProUGUI = host.GetComponent <TextMeshProUGUI>(); base.Init(host, settings); }
void Awake() { // Make sure I have the thigs I need to get the data to deform text if (m_TextComponent == null) m_TextComponent = gameObject.GetComponent<TextMeshPro>(); if (vertexCurve == null) vertexCurve = gameObject.GetComponent<BezierSpline>(); UpdateTextPosition(); }
void Awake() { Debug.Log("Advanced Layout Component was added."); m_renderer = renderer; //m_meshFilter = GetComponent<MeshFilter>(); //m_mesh = m_meshFilter.sharedMesh; m_sharedMaterial = m_renderer.sharedMaterial; // Get Reference to the TextMeshPro Component m_textMeshProComponent = GetComponent<TextMeshPro>(); m_textMeshProComponent.isAdvancedLayoutComponentPresent = true; }
void OnEnable() { if (m_TextMeshPro == null) m_TextMeshPro = gameObject.GetComponent<TextMeshPro>(); if (m_TextMeshProUI == null) m_TextMeshProUI = gameObject.GetComponent<TextMeshProUGUI>(); m_uiVertex = new UIVertex[4]; #if UNITY_EDITOR TMPro_EventManager.SPRITE_ASSET_PROPERTY_EVENT.Add(ON_SPRITE_ASSET_PROPERTY_CHANGED); #endif LoadSpriteAsset(m_spriteAsset); }
void OnEnable() { if (m_TextMeshPro == null) m_TextMeshPro = gameObject.GetComponent<TextMeshPro>(); if (m_TextMeshProUI == null) m_TextMeshProUI = gameObject.GetComponent<TextMeshProUGUI>(); m_uiVertex = new UIVertex[4]; #if UNITY_EDITOR TMPro_EventManager.SPRITE_ASSET_PROPERTY_EVENT += ON_SPRITE_ASSET_PROPERTY_CHANGED; #endif LoadSpriteAsset(m_spriteAsset); //m_inlineGraphic.material.renderQueue = 3000; }
void Start() { damageSplatGo = transform.FindChild("Text").gameObject; damageSplatText = damageSplatGo.GetComponent<TextMeshPro>(); damageSplatBonusGo = transform.FindChild("Bonus").gameObject; damageSplatBonusText = damageSplatBonusGo.GetComponent<TextMeshPro>(); //damage vs heal if (change <= 0) { damageSplatText.color = damageColor; damageSplatBonusText.color = damageColor; damageSplatText.colorGradient = new VertexGradient(Color.white, Color.white, damageColorBot, damageColorBot); damageSplatBonusText.colorGradient = new VertexGradient(Color.white, Color.white, damageColorBot, damageColorBot); } else { damageSplatText.color = healColor; damageSplatBonusText.color = healColor; damageSplatText.colorGradient = new VertexGradient(Color.white, Color.white, healColorBot, healColorBot); damageSplatBonusText.colorGradient = new VertexGradient(Color.white, Color.white, healColorBot, healColorBot); } damageSplatText.text = string.Format("{0:+#;-#;0}", change); if (bonus.HasValue && bonus != 0) { damageSplatBonusText.text = Math.Abs(bonus.Value).ToString(); //+ " " + bonusText; } else { damageSplatBonusText.text = ""; } if (animate) { iTweenExtensions.PunchScale(gameObject, punchSize, 0.3f, 0); //iTweenExtensions.ScaleTo(gameObject, Vector3.zero, 1.0f, 0.5f); iTweenExtensions.ColorTo(damageSplatGo, transparent, 1f, 0.0f); iTweenExtensions.ColorTo(damageSplatBonusGo, transparent, 1.5f, 0.0f); iTweenExtensions.MoveToLocal(gameObject, Vector3.up, 3.5f, 0.0f); } }
void Start() { // Add new TextMesh Pro Component m_textMeshPro = gameObject.AddComponent<TextMeshPro>(); //m_textContainer = GetComponent<TextContainer>(); // Load the Font Asset to be used. m_FontAsset = Resources.Load("Fonts & Materials/ARIAL SDF", typeof(TextMeshProFont)) as TextMeshProFont; m_textMeshPro.font = m_FontAsset; // Assign Material to TextMesh Pro Component //m_textMeshPro.fontSharedMaterial = Resources.Load("Fonts & Materials/ARIAL SDF Bevel", typeof(Material)) as Material; //m_textMeshPro.fontSharedMaterial.EnableKeyword("BEVEL_ON"); // Set various font settings. m_textMeshPro.fontSize = 48; //m_textMeshPro.anchor = AnchorPositions.Center; m_textMeshPro.alignment = TextAlignmentOptions.Center; m_textMeshPro.anchorDampening = true; //m_textMeshPro.enableAutoSizing = true; //textMeshPro.lineJustification = LineJustificationTypes.Center; //textMeshPro.characterSpacing = 0.2f; //m_textMeshPro.enableCulling = true; //textMeshPro.enableWordWrapping = true; //textMeshPro.lineLength = 60; //textMeshPro.fontColor = new Color32(255, 255, 255, 255); /* for (int i = 0; i <= 1000000; i++) { m_textMeshPro.SetText(label, i % 1000); // Example to test the .char function. //m_chars = (i % 100).ToString().ToCharArray(); //textMeshPro.chars = m_chars; yield return new WaitForSeconds(0.1f); } */ }
protected override void Awake() { //Debug.Log("TextContainer Awake() called."); m_rectTransform = this.rectTransform; if (m_rectTransform == null) { Vector2 oldPivot = m_pivot; m_rectTransform = gameObject.AddComponent<RectTransform>(); m_pivot = oldPivot; } m_textMeshPro = GetComponent(typeof(TextMeshPro)) as TextMeshPro; if (m_rect.width == 0 || m_rect.height == 0) { // Handling of Legacy lineLength property if (m_textMeshPro != null && m_textMeshPro.anchor != TMP_Compatibility.AnchorPositions.None) { Debug.LogWarning("Converting from using anchor and lineLength properties to Text Container.", this); m_isDefaultHeight = true; int anchor = (int)m_textMeshPro.anchor; // Special Handling if Baseline Anchor was used on the old object. if (anchor == 9) { switch (m_textMeshPro.alignment) { case TextAlignmentOptions.TopLeft: // Left m_textMeshPro.alignment = TextAlignmentOptions.BaselineLeft; break; case TextAlignmentOptions.Top: // Center m_textMeshPro.alignment = TextAlignmentOptions.Baseline; break; case TextAlignmentOptions.TopRight: // Right m_textMeshPro.alignment = TextAlignmentOptions.BaselineRight; break; case TextAlignmentOptions.TopJustified: // Left m_textMeshPro.alignment = TextAlignmentOptions.BaselineJustified; break; } anchor = 3; // left } m_anchorPosition = (TextContainerAnchors)anchor; m_pivot = GetPivot(m_anchorPosition); if (m_textMeshPro.lineLength == 72) { m_rect.size = m_textMeshPro.GetPreferredValues(m_textMeshPro.text); } else { m_rect.width = m_textMeshPro.lineLength; m_rect.height = m_textMeshPro.GetPreferredValues(m_rect.width, Mathf.Infinity).y; } } else // if (m_rectTransform.sizeDelta == new Vector2(100, 100)) { m_isDefaultWidth = true; m_isDefaultHeight = true; m_pivot = GetPivot(m_anchorPosition); m_rect.width = 20; m_rect.height = 5; m_rectTransform.sizeDelta = this.size; } m_margins = new Vector4(0, 0, 0, 0); UpdateCorners(); } }
/// <summary> /// Function returning the index of the word at the given position (if any). /// </summary> /// <param name="text">A reference to the TextMeshPro UGUI component.</param> /// <param name="position"></param> /// <param name="camera"></param> /// <returns></returns> public static int FindNearestLink(TextMeshPro text, Vector3 position, Camera camera) { Transform textTransform = text.transform; // Convert position into Worldspace coordinates ScreenPointToWorldPointInRectangle(textTransform, position, camera, out position); float distanceSqr = Mathf.Infinity; int closest = 0; for (int i = 0; i < text.textInfo.linkCount; i++) { TMP_LinkInfo linkInfo = text.textInfo.linkInfo[i]; bool isBeginRegion = false; Vector3 bl = Vector3.zero; Vector3 tl = Vector3.zero; Vector3 br = Vector3.zero; Vector3 tr = Vector3.zero; // Iterate through each character of the word for (int j = 0; j < linkInfo.linkTextLength; j++) { int characterIndex = linkInfo.linkTextfirstCharacterIndex + j; TMP_CharacterInfo currentCharInfo = text.textInfo.characterInfo[characterIndex]; int currentLine = currentCharInfo.lineNumber; if (isBeginRegion == false) { isBeginRegion = true; bl = textTransform.TransformPoint(new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.descender, 0)); tl = textTransform.TransformPoint(new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.ascender, 0)); //Debug.Log("Start Word Region at [" + currentCharInfo.character + "]"); // If Word is one character if (linkInfo.linkTextLength == 1) { isBeginRegion = false; br = textTransform.TransformPoint(new Vector3(currentCharInfo.topRight.x, currentCharInfo.descender, 0)); tr = textTransform.TransformPoint(new Vector3(currentCharInfo.topRight.x, currentCharInfo.ascender, 0)); // Check for Intersection if (PointIntersectRectangle(position, bl, tl, tr, br)) return i; //Debug.Log("End Word Region at [" + currentCharInfo.character + "]"); } } // Last Character of Word if (isBeginRegion && j == linkInfo.linkTextLength - 1) { isBeginRegion = false; br = textTransform.TransformPoint(new Vector3(currentCharInfo.topRight.x, currentCharInfo.descender, 0)); tr = textTransform.TransformPoint(new Vector3(currentCharInfo.topRight.x, currentCharInfo.ascender, 0)); // Check for Intersection if (PointIntersectRectangle(position, bl, tl, tr, br)) return i; //Debug.Log("End Word Region at [" + currentCharInfo.character + "]"); } // If Word is split on more than one line. else if (isBeginRegion && currentLine != text.textInfo.characterInfo[characterIndex + 1].lineNumber) { isBeginRegion = false; br = textTransform.TransformPoint(new Vector3(currentCharInfo.topRight.x, currentCharInfo.descender, 0)); tr = textTransform.TransformPoint(new Vector3(currentCharInfo.topRight.x, currentCharInfo.ascender, 0)); // Check for Intersection if (PointIntersectRectangle(position, bl, tl, tr, br)) return i; //Debug.Log("End Word Region at [" + currentCharInfo.character + "]"); } } // Find the closest line segment to position. float dbl = DistanceToLine(bl, tl, position); float dtl = DistanceToLine(tl, tr, position); float dtr = DistanceToLine(tr, br, position); float dbr = DistanceToLine(br, bl, position); float d = dbl < dtl ? dbl : dtl; d = d < dtr ? d : dtr; d = d < dbr ? d : dbr; if (distanceSqr > d) { distanceSqr = d; closest = i; } //Debug.Log("Word at Index: " + i + " is located at (" + bl + ", " + tl + ", " + tr + ", " + br + ")."); } return closest; }
public static void ON_TEXTMESHPRO_PROPERTY_CHANGED(bool isChanged, TextMeshPro obj) { TEXTMESHPRO_PROPERTY_EVENT.Call(isChanged, obj); }
public void AddInlineGraphicsChild() { if (m_inlineGraphic != null) { //Debug.LogWarning("A child Inline Graphics object already exists."); return; } GameObject inlineGraphicObj = new GameObject("Inline Graphic"); m_inlineGraphic = inlineGraphicObj.AddComponent<InlineGraphic>(); m_inlineGraphicRectTransform = inlineGraphicObj.GetComponent<RectTransform>(); m_inlineGraphicCanvasRenderer = inlineGraphicObj.GetComponent<CanvasRenderer>(); m_inlineGraphicRectTransform.SetParent(transform, false); m_inlineGraphicRectTransform.localPosition = Vector3.zero; m_inlineGraphicRectTransform.anchoredPosition3D = Vector3.zero; m_inlineGraphicRectTransform.sizeDelta = Vector2.zero; m_inlineGraphicRectTransform.anchorMin = Vector2.zero; m_inlineGraphicRectTransform.anchorMax = Vector2.one; m_TextMeshPro = gameObject.GetComponent<TextMeshPro>(); m_TextMeshProUI = gameObject.GetComponent<TextMeshProUGUI>(); }
// Event received when custom material editor properties are changed. void ON_MATERIAL_PROPERTY_CHANGED(bool isChanged, Material mat) { //Debug.Log("*** ON_MATERIAL_PROPERTY_CHANGED ***"); // Filter events and return if the affected material is not this object's material. if (mat.GetInstanceID() != m_sharedMaterial.GetInstanceID()) return; if (m_TextComponent == null) m_TextComponent = GetComponentInParent<TextMeshPro>(); m_padding = GetPaddingForMaterial(); m_TextComponent.havePropertiesChanged = true; m_TextComponent.SetVerticesDirty(); }
// Event received when UNDO / REDO Event alters the properties of the object. void ON_TEXTMESHPRO_PROPERTY_CHANGED(bool isChanged, TextMeshPro obj) { if (obj == this) { //Debug.Log("Undo / Redo Event Received by Object ID:" + GetInstanceID()); m_havePropertiesChanged = true; m_isInputParsingRequired = true; m_padding = GetPaddingForMaterial(); SetVerticesDirty(); } }
void Awake() { // Make sure this component is attached to an object which contains a TextMeshPro or TextMeshPro UI Component. if (gameObject.GetComponent<TextMeshPro>() == null && gameObject.GetComponent<TextMeshProUGUI>() == null) Debug.LogWarning("The InlineGraphics Component must be attached to a TextMesh Pro Object"); // Add a Child GameObject to the TextMeshPro Object if one is not already present. if (m_inlineGraphic == null) { GameObject inlineGraphicObj = new GameObject("Inline Graphic"); m_inlineGraphic = inlineGraphicObj.AddComponent<InlineGraphic>(); m_inlineGraphicRectTransform = inlineGraphicObj.GetComponent<RectTransform>(); m_inlineGraphicCanvasRenderer = inlineGraphicObj.GetComponent<CanvasRenderer>(); m_inlineGraphicRectTransform.SetParent(transform, false); m_inlineGraphicRectTransform.localPosition = Vector3.zero; m_inlineGraphicRectTransform.anchoredPosition3D = Vector3.zero; m_inlineGraphicRectTransform.sizeDelta = Vector2.zero; m_inlineGraphicRectTransform.anchorMin = Vector2.zero; m_inlineGraphicRectTransform.anchorMax = Vector2.one; m_TextMeshPro = gameObject.GetComponent<TextMeshPro>(); m_TextMeshProUI = gameObject.GetComponent<TextMeshProUGUI>(); } }
// Event received when UNDO / REDO Event alters the properties of the object. void ON_TEXTMESHPRO_PROPERTY_CHANGED(bool isChanged, TextMeshPro obj) { if (obj == this) { //Debug.Log("Undo / Redo Event Received by Object ID:" + GetInstanceID()); m_havePropertiesChanged = true; isInputParsingRequired = true; /* ScheduleUpdate(); */ } }
/// <summary> /// Function to find the nearest character to position. /// </summary> /// <param name="text">A reference to the TextMeshPro UGUI component.</param> /// <param name="position">Position to check for intersection.</param> /// <param name="camera"></param> /// <param name="visibleOnly">Only check for visible characters.</param> /// <returns></returns> public static int FindNearestCharacter(TextMeshPro text, Vector3 position, Camera camera, bool visibleOnly) { Transform textTransform = text.transform; float distanceSqr = Mathf.Infinity; int closest = 0; // Convert position into Worldspace coordinates ScreenPointToWorldPointInRectangle(textTransform, position, camera, out position); for (int i = 0; i < text.textInfo.characterCount; i++) { // Get current character info. TMP_CharacterInfo cInfo = text.textInfo.characterInfo[i]; if (visibleOnly && !cInfo.isVisible) continue; // Get Bottom Left and Top Right position of the current character Vector3 bl = textTransform.TransformPoint(cInfo.bottomLeft); Vector3 tl = textTransform.TransformPoint(new Vector3(cInfo.bottomLeft.x, cInfo.topRight.y, 0)); Vector3 tr = textTransform.TransformPoint(cInfo.topRight); Vector3 br = textTransform.TransformPoint(new Vector3(cInfo.topRight.x, cInfo.bottomLeft.y, 0)); if (PointIntersectRectangle(position, bl, tl, tr, br)) return i; // Find the closest corner to position. float dbl = DistanceToLine(bl, tl, position); // (position - bl).sqrMagnitude; float dtl = DistanceToLine(tl, tr, position); // (position - tl).sqrMagnitude; float dtr = DistanceToLine(tr, br, position); // (position - tr).sqrMagnitude; float dbr = DistanceToLine(br, bl, position); // (position - br).sqrMagnitude; float d = dbl < dtl ? dbl : dtl; d = d < dtr ? d : dtr; d = d < dbr ? d : dbr; if (distanceSqr > d) { distanceSqr = d; closest = i; } } //Debug.Log("Returning nearest character at index: " + closest); return closest; }
/// <summary> /// /// </summary> protected override void OnEnable() { //Debug.Log("Text Container OnEnable() called."); if (m_transform == null) m_transform = this.transform; if (m_textMeshPro == null) m_textMeshPro = GetComponent<TextMeshPro>(); OnContainerChanged(); }
IEnumerator Start () { if (BenchmarkType == 0) // TextMesh Pro Component { m_textMeshPro = gameObject.AddComponent<TextMeshPro>(); m_textMeshPro.anchorDampening = true; if (TMProFont != null) m_textMeshPro.font = TMProFont; //m_textMeshPro.font = Resources.Load("Fonts/IMPACT SDF", typeof(TextMeshProFont)) as TextMeshProFont; // Make sure the IMPACT SDF exists before calling this... //m_textMeshPro.fontSharedMaterial = Resources.Load("Fonts/IMPACT SDF", typeof(Material)) as Material; // Same as above make sure this material exists. m_textMeshPro.fontSize = 48; m_textMeshPro.anchor = AnchorPositions.Center; m_textMeshPro.extraPadding = true; //m_textMeshPro.outlineWidth = 0.25f; //m_textMeshPro.fontSharedMaterial.SetFloat("_OutlineWidth", 0.2f); //m_textMeshPro.fontSharedMaterial.EnableKeyword("UNDERLAY_ON"); //m_textMeshPro.lineJustification = LineJustificationTypes.Center; //m_textMeshPro.enableWordWrapping = true; //m_textMeshPro.lineLength = 60; //m_textMeshPro.characterSpacing = 0.2f; //m_textMeshPro.fontColor = new Color32(255, 255, 255, 255); m_material01 = m_textMeshPro.font.material; m_material02 = Resources.Load("Fonts/ARIAL SDF BEVEL", typeof(Material)) as Material; // Make sure the IMPACT SDF exists before calling this... } else if (BenchmarkType == 1) // TextMesh { m_textMesh = gameObject.AddComponent<TextMesh>(); if (TextMeshFont != null) { m_textMesh.font = TextMeshFont; m_textMesh.renderer.sharedMaterial = m_textMesh.font.material; } else { m_textMesh.font = Resources.Load("Fonts/ARIAL", typeof(Font)) as Font; m_textMesh.renderer.sharedMaterial = m_textMesh.font.material; } m_textMesh.fontSize = 48; m_textMesh.anchor = TextAnchor.MiddleCenter; //m_textMesh.color = new Color32(255, 255, 0, 255); } for (int i = 0; i <= 1000000; i++) { if (BenchmarkType == 0) { m_textMeshPro.SetText(label01, i % 1000); if (i % 1000 == 999) m_textMeshPro.fontSharedMaterial = m_textMeshPro.fontSharedMaterial == m_material01 ? m_textMeshPro.fontSharedMaterial = m_material02 : m_textMeshPro.fontSharedMaterial = m_material01; } else if (BenchmarkType == 1) m_textMesh.text = label02 + (i % 1000).ToString(); yield return null; } yield return null; }
public static void ON_TEXTMESHPRO_PROPERTY_CHANGED(bool isChanged, TextMeshPro obj) { if (TEXTMESHPRO_PROPERTY_EVENT != null) TEXTMESHPRO_PROPERTY_EVENT(isChanged, obj); }
protected override void Start() { model = piece.gameObject.transform.FindChild("Model").gameObject; faceCameraContainer = piece.gameObject.transform.FindChild("FaceCameraContainer").gameObject; hpBarContainer = faceCameraContainer.transform.FindChild("HpBarContainer").gameObject; hpBar = hpBarContainer.transform.FindChild("hpbar").gameObject; hpBarfill = hpBarContainer.transform.FindChild("HpBarFill").gameObject; hpBarFillRenderer = hpBarfill.GetComponent<MeshRenderer>(); hpBarSvgRenderer = hpBar.GetComponent<SVGRenderer>(); hpBarSvgEnemy = loader.Load<SVGAsset>("UI/hpbar enemy"); hpBarSvg = loader.Load<SVGAsset>("UI/hpbar"); textContainer = hpBarContainer.transform.FindChild("TextContainer").gameObject; attackGO = textContainer.transform.FindChild("Attack").gameObject; healthGO = textContainer.transform.FindChild("Health").gameObject; armorGO = textContainer.transform.FindChild("Armor").gameObject; attackText = attackGO.GetComponent<TextMeshPro>(); healthText = healthGO.GetComponent<TextMeshPro>(); armorText = armorGO.GetComponent<TextMeshPro>(); shield = faceCameraContainer.transform.FindChild("Shield").gameObject; cloak = faceCameraContainer.transform.FindChild("Cloak").gameObject; paralyze = faceCameraContainer.transform.FindChild("Paralyze").gameObject; root = faceCameraContainer.transform.FindChild("Root").gameObject; armorBG = faceCameraContainer.transform.FindChild("Armor").gameObject; eventIconContainer = faceCameraContainer.transform.FindChild("EventIconContainer").gameObject; circleBg = eventIconContainer.transform.FindChild("CircleBg").gameObject; eventIcon = eventIconContainer.transform.FindChild("Event").gameObject; deathIcon = eventIconContainer.transform.FindChild("Death").gameObject; rangeIcon = eventIconContainer.transform.FindChild("Range").gameObject; meshRenderer = model.GetComponentInChildren<MeshRenderer>(); highlight = model.GetComponentInChildren<Highlighter>(); attackText.text = piece.attack.ToString(); healthText.text = piece.health.ToString(); circleBg.SetActive(false); deathIcon.SetActive(false); eventIcon.SetActive(false); rangeIcon.SetActive(false); //rotate to model direction model.gameObject.transform.rotation = Quaternion.Euler(DirectionAngle.angle[piece.direction]); //find top of the mesh and adjust the hpbar to be just above it Vector3[] verts = model.GetComponentInChildren<MeshFilter>().sharedMesh.vertices; Vector3 topVertex = new Vector3(0, float.NegativeInfinity, 0); for (int i = 0; i < verts.Length; i++) { //Vector3 vert = transform.TransformPoint(verts[i]); Vector3 vert = verts[i]; if (vert.y > topVertex.y) { topVertex = vert; } } hpBarContainer.transform.localPosition = hpBarContainer.transform.localPosition.SetY( topVertex.y * 1.5f + 0.9f ); UpdateHpBar(); }
/// <summary> /// Function returning the index of the word at the given position (if any). /// </summary> /// <param name="text">A reference to the TextMeshPro UGUI component.</param> /// <param name="position"></param> /// <param name="camera"></param> /// <returns></returns> public static int FindIntersectingWord(TextMeshPro text, Vector3 position, Camera camera) { Transform textTransform = text.transform; // Convert position into Worldspace coordinates ScreenPointToWorldPointInRectangle(textTransform, position, camera, out position); for (int i = 0; i < text.textInfo.wordCount; i++) { TMP_WordInfo wInfo = text.textInfo.wordInfo[i]; bool isBeginRegion = false; Vector3 bl = Vector3.zero; Vector3 tl = Vector3.zero; Vector3 br = Vector3.zero; Vector3 tr = Vector3.zero; float maxAscender = -Mathf.Infinity; float minDescender = Mathf.Infinity; // Iterate through each character of the word for (int j = 0; j < wInfo.characterCount; j++) { int characterIndex = wInfo.firstCharacterIndex + j; TMP_CharacterInfo currentCharInfo = text.textInfo.characterInfo[characterIndex]; int currentLine = currentCharInfo.lineNumber; bool isCharacterVisible = characterIndex > text.maxVisibleCharacters || currentCharInfo.lineNumber > text.maxVisibleLines || (text.OverflowMode == TextOverflowModes.Page && currentCharInfo.pageNumber + 1 != text.pageToDisplay) ? false : true; // Track maximum Ascender and minimum Descender for each word. maxAscender = Mathf.Max(maxAscender, currentCharInfo.ascender); minDescender = Mathf.Min(minDescender, currentCharInfo.descender); if (isBeginRegion == false && isCharacterVisible) { isBeginRegion = true; bl = new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.descender, 0); tl = new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.ascender, 0); //Debug.Log("Start Word Region at [" + currentCharInfo.character + "]"); // If Word is one character if (wInfo.characterCount == 1) { isBeginRegion = false; br = new Vector3(currentCharInfo.topRight.x, currentCharInfo.descender, 0); tr = new Vector3(currentCharInfo.topRight.x, currentCharInfo.ascender, 0); // Transform coordinates to be relative to transform and account min descender and max ascender. bl = textTransform.TransformPoint(new Vector3(bl.x, minDescender, 0)); tl = textTransform.TransformPoint(new Vector3(tl.x, maxAscender, 0)); tr = textTransform.TransformPoint(new Vector3(tr.x, maxAscender, 0)); br = textTransform.TransformPoint(new Vector3(br.x, minDescender, 0)); // Check for Intersection if (PointIntersectRectangle(position, bl, tl, tr, br)) return i; //Debug.Log("End Word Region at [" + currentCharInfo.character + "]"); } } // Last Character of Word if (isBeginRegion && j == wInfo.characterCount - 1) { isBeginRegion = false; br = new Vector3(currentCharInfo.topRight.x, currentCharInfo.descender, 0); tr = new Vector3(currentCharInfo.topRight.x, currentCharInfo.ascender, 0); // Transform coordinates to be relative to transform and account min descender and max ascender. bl = textTransform.TransformPoint(new Vector3(bl.x, minDescender, 0)); tl = textTransform.TransformPoint(new Vector3(tl.x, maxAscender, 0)); tr = textTransform.TransformPoint(new Vector3(tr.x, maxAscender, 0)); br = textTransform.TransformPoint(new Vector3(br.x, minDescender, 0)); // Check for Intersection if (PointIntersectRectangle(position, bl, tl, tr, br)) return i; //Debug.Log("End Word Region at [" + currentCharInfo.character + "]"); } // If Word is split on more than one line. else if (isBeginRegion && currentLine != text.textInfo.characterInfo[characterIndex + 1].lineNumber) { isBeginRegion = false; br = new Vector3(currentCharInfo.topRight.x, currentCharInfo.descender, 0); tr = new Vector3(currentCharInfo.topRight.x, currentCharInfo.ascender, 0); // Transform coordinates to be relative to transform and account min descender and max ascender. bl = textTransform.TransformPoint(new Vector3(bl.x, minDescender, 0)); tl = textTransform.TransformPoint(new Vector3(tl.x, maxAscender, 0)); tr = textTransform.TransformPoint(new Vector3(tr.x, maxAscender, 0)); br = textTransform.TransformPoint(new Vector3(br.x, minDescender, 0)); // Reset maxAscender and minDescender for next word segment. maxAscender = -Mathf.Infinity; minDescender = Mathf.Infinity; // Check for Intersection if (PointIntersectRectangle(position, bl, tl, tr, br)) return i; //Debug.Log("End Word Region at [" + currentCharInfo.character + "]"); } } } return -1; }
void Awake() { m_transform = GetComponent(typeof(Transform)) as Transform; m_textMeshPro = GetComponent(typeof(TextMeshPro)) as TextMeshPro; //Debug.Log("TextContainer Awake() called."); if (m_rect.width == 0 || m_rect.height == 0) { // Handling of Legacy lineLength property if (m_textMeshPro != null && m_textMeshPro.lineLength != 72) { Debug.LogWarning("Converting from using anchor and lineLength properties to Text Container.", this); m_isDefaultHeight = true; int anchor = (int)m_textMeshPro.anchor; m_anchorPosition = (TextContainerAnchors)anchor; m_pivot = GetPivot(m_anchorPosition); m_rect.width = m_textMeshPro.lineLength; } else { m_isDefaultWidth = true; m_isDefaultHeight = true; m_pivot = GetPivot(m_anchorPosition); m_rect.width = 0; m_rect.height = 0; } m_margins = new Vector4(0, 0, 0, 0); UpdateCorners(); } }
void Start() { if (SpawnType == 0) { //Debug.Log("Spawning TextMesh Pro Objects."); // TextMesh Pro Implementation m_textMeshPro = m_floatingText.AddComponent<TextMeshPro>(); m_textContainer = m_floatingText.GetComponent<TextContainer>(); m_textContainer.isAutoFitting = false; //m_textMeshPro.fontAsset = Resources.Load("Fonts & Materials/JOKERMAN SDF", typeof(TextMeshProFont)) as TextMeshProFont; // User should only provide a string to the resource. //m_textMeshPro.fontSharedMaterial = Resources.Load("Fonts & Materials/ARIAL SDF 1", typeof(Material)) as Material; //m_textContainer.anchorPosition = TextContainerAnchors.Bottom; m_textMeshPro.alignment = TextAlignmentOptions.Center; m_textMeshPro.color = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), 255); m_textMeshPro.fontSize = 24; //m_textMeshPro.enableExtraPadding = true; //m_textMeshPro.enableShadows = false; m_textMeshPro.text = string.Empty; StartCoroutine(DisplayTextMeshProFloatingText()); } else { //Debug.Log("Spawning TextMesh Objects."); m_textMesh = m_floatingText.AddComponent<TextMesh>(); m_textMesh.font = Resources.Load("Fonts/ARIAL", typeof(Font)) as Font; m_textMesh.GetComponent<Renderer>().sharedMaterial = m_textMesh.font.material; m_textMesh.color = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), 255); m_textMesh.anchor = TextAnchor.LowerCenter; m_textMesh.fontSize = 24; StartCoroutine(DisplayTextMeshFloatingText()); } }
public static TMP_SubMesh AddSubTextObject(TextMeshPro textComponent, MaterialReference materialReference) { GameObject go = new GameObject("TMP SubMesh [" + materialReference.material.name + "]"); TMP_SubMesh subMesh = go.AddComponent<TMP_SubMesh>(); go.transform.SetParent(textComponent.transform, false); go.transform.localPosition = Vector3.zero; go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one; go.layer = textComponent.gameObject.layer; subMesh.m_meshFilter = go.GetComponent<MeshFilter>(); subMesh.m_TextComponent = textComponent; subMesh.m_fontAsset = materialReference.fontAsset; subMesh.m_spriteAsset = materialReference.spriteAsset; subMesh.m_isDefaultMaterial = materialReference.isDefaultMaterial; subMesh.SetSharedMaterial(materialReference.material); subMesh.renderer.sortingLayerID = textComponent.renderer.sortingLayerID; subMesh.renderer.sortingOrder = textComponent.renderer.sortingOrder; return subMesh; }
protected override void Awake() { //Debug.Log("TextContainer Awake() called."); m_rectTransform = this.rectTransform; if (m_rectTransform == null) { //m_isAddingRectTransform = true; m_rectTransform = gameObject.AddComponent<RectTransform>(); //m_isAddingRectTransform = false; } m_textMeshPro = GetComponent(typeof(TextMeshPro)) as TextMeshPro; if (m_rect.width == 0 || m_rect.height == 0) { // Handling of Legacy lineLength property if (m_textMeshPro != null && m_textMeshPro.lineLength != 72) { Debug.LogWarning("Converting from using anchor and lineLength properties to Text Container.", this); m_isDefaultHeight = true; int anchor = (int)m_textMeshPro.anchor; m_anchorPosition = (TextContainerAnchors)anchor; m_pivot = GetPivot(m_anchorPosition); m_rect.width = m_textMeshPro.lineLength; } else // if (m_rectTransform.sizeDelta == new Vector2(100, 100)) { m_isDefaultWidth = true; m_isDefaultHeight = true; m_pivot = GetPivot(m_anchorPosition); m_rect.width = 20; m_rect.height = 5; m_rectTransform.sizeDelta = this.size; } m_margins = new Vector4(0, 0, 0, 0); UpdateCorners(); } }
/// <summary> /// Function returning the index of the Link at the given position (if any). /// </summary> /// <param name="text">A reference to the TextMeshPro UGUI component.</param> /// <param name="position"></param> /// <param name="camera"></param> /// <returns></returns> public static int FindIntersectingLink(TextMeshPro text, Vector3 position, Camera camera) { Transform textTransform = text.transform; // Convert position into Worldspace coordinates ScreenPointToWorldPointInRectangle(textTransform, position, camera, out position); for (int i = 0; i < text.textInfo.linkCount; i++) { TMP_LinkInfo linkInfo = text.textInfo.linkInfo[i]; bool isBeginRegion = false; Vector3 bl = Vector3.zero; Vector3 tl = Vector3.zero; Vector3 br = Vector3.zero; Vector3 tr = Vector3.zero; // Iterate through each character of the word for (int j = 0; j < linkInfo.characterCount; j++) { int characterIndex = linkInfo.firstCharacterIndex + j; TMP_CharacterInfo currentCharInfo = text.textInfo.characterInfo[characterIndex]; int currentLine = currentCharInfo.lineNumber; if (isBeginRegion == false) { isBeginRegion = true; bl = textTransform.TransformPoint(new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.bottomLine, 0)); tl = textTransform.TransformPoint(new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.topLine, 0)); //Debug.Log("Start Word Region at [" + currentCharInfo.character + "]"); // If Word is one character if (linkInfo.characterCount == 1) { isBeginRegion = false; br = textTransform.TransformPoint(new Vector3(currentCharInfo.topRight.x, currentCharInfo.bottomLine, 0)); tr = textTransform.TransformPoint(new Vector3(currentCharInfo.topRight.x, currentCharInfo.topLine, 0)); // Check for Intersection if (PointIntersectRectangle(position, bl, tl, tr, br)) return i; //Debug.Log("End Word Region at [" + currentCharInfo.character + "]"); } } // Last Character of Word if (isBeginRegion && j == linkInfo.characterCount - 1) { isBeginRegion = false; br = textTransform.TransformPoint(new Vector3(currentCharInfo.topRight.x, currentCharInfo.bottomLine, 0)); tr = textTransform.TransformPoint(new Vector3(currentCharInfo.topRight.x, currentCharInfo.topLine, 0)); // Check for Intersection if (PointIntersectRectangle(position, bl, tl, tr, br)) return i; //Debug.Log("End Word Region at [" + currentCharInfo.character + "]"); } // If Word is split on more than one line. else if (isBeginRegion && currentLine != text.textInfo.characterInfo[characterIndex + 1].lineNumber) { isBeginRegion = false; br = textTransform.TransformPoint(new Vector3(currentCharInfo.topRight.x, currentCharInfo.bottomLine, 0)); tr = textTransform.TransformPoint(new Vector3(currentCharInfo.topRight.x, currentCharInfo.topLine, 0)); // Check for Intersection if (PointIntersectRectangle(position, bl, tl, tr, br)) return i; //Debug.Log("End Word Region at [" + currentCharInfo.character + "]"); } } //Debug.Log("Word at Index: " + i + " is located at (" + bl + ", " + tl + ", " + tr + ", " + br + ")."); } return -1; }