private void ResizeButton (RectTransform _rect) { float screenX = 800; float screenY = 480; float rectWidth = (_rect.sizeDelta.x / screenX) * Screen.width; float rectHeight = (_rect.sizeDelta.y / screenY) * Screen.height; _rect.sizeDelta = new Vector2 (rectWidth, rectHeight); float rectX = (_rect.anchoredPosition.x / screenX) * Screen.width; float rectY = (_rect.anchoredPosition.y / screenY) * Screen.height; _rect.anchoredPosition = new Vector2 (rectX, rectY); int size = _rect.GetComponentInChildren<Text> ().fontSize; _rect.GetComponentInChildren<Text> ().fontSize = (int)(size * (Screen.width / screenX)); }
public void ShowTextError(string Text) { ErrorText.gameObject.SetActive(true); var t = ErrorText.GetComponentInChildren <UnityEngine.UI.Text>(); t.text = Text; StartCoroutine("DoHideError", ErrorDisplayDuration); }
//summon activates whenever a card is played. All spells (at least for now) target a specific tile. public override Transform Summon(RectTransform location, Transform hand) { if (location.GetComponent<Tile_Component>().unit != null) location.GetComponentInChildren<BaseUnit_Component>().TakeDamage(5); else { hand.GetComponent<ResourceManager>().AddResources(cost); hand.GetComponent<Hand_Component>().AddCard(0003); } return transform; }
void Start() { healthBarCanvas = GameObject.Find("Health Bar Canvas").transform; hpSource = this.GetComponent<IHealth>(); _healthBarInstance = GameObject.Instantiate(healthBarPrefab); _healthBarInstance.SetParent(healthBarCanvas, false); healthBarSlider = _healthBarInstance.GetComponentInChildren<Slider>(); healthBarPos = this.transform.position; healthBarPos.y += healthBarHeight; _healthBarInstance.anchoredPosition = Camera.main.WorldToScreenPoint(healthBarPos); }
void Awake() { m_TextMeshPro = gameObject.GetComponent<TextMeshProUGUI>(); m_Canvas = gameObject.GetComponentInParent<Canvas>(); // Get a reference to the camera if Canvas Render Mode is not ScreenSpace Overlay. if (m_Canvas.renderMode == RenderMode.ScreenSpaceOverlay) m_Camera = null; else m_Camera = m_Canvas.worldCamera; // Create pop-up text object which is used to show the link information. m_TextPopup_RectTransform = Instantiate(TextPopup_Prefab_01) as RectTransform; m_TextPopup_RectTransform.SetParent(m_Canvas.transform, false); m_TextPopup_TMPComponent = m_TextPopup_RectTransform.GetComponentInChildren<TextMeshProUGUI>(); m_TextPopup_RectTransform.gameObject.SetActive(false); }
void Start() { currentStep = PlayerHistoryStep.HELLCIRCLE; HistorySelection = GetComponent<Canvas> (); HistoChoiceDescription = HistorySelection.GetComponentInChildren<RectTransform> (); ChoiceDisplay = HistoChoiceDescription.GetComponentInChildren<GridLayoutGroup> (); for (int i=0; i<9; i++) { Choice [i] = ChoiceDisplay.GetComponentsInChildren<Button> () [i]; } for (int i=0; i<10; i++) { HistoryChoiceDisplay [i] = HistorySelection.GetComponentInChildren<Mask> ().GetComponentsInChildren<Text> () [i]; } for (int i=0; i<9; i++) { HistoryChoiceImage [i] = HistorySelection.GetComponentInChildren<Mask> ().GetComponentsInChildren<Image> () [i + 1]; } GetHistoryUIButtons (); HistorySelection.enabled = false; }
private IEnumerator LoadCoroutine() { int i = 0; foreach (FileInfo f in info) { item = Instantiate(prefab) as RectTransform; item.SetParent(transform, false); Text titleText = item.GetComponentInChildren<Text>(); titleText.text = f.Name.Substring(0, f.Name.Length - 5); item.gameObject.GetComponent<LoadButtonParam>().Number = i++; _loadButtonParam = item.gameObject.GetComponent<LoadButtonParam>(); string folderPath = ""; try { if (Application.platform != RuntimePlatform.WindowsEditor) { folderPath = Application.persistentDataPath + "/" + titleText.text + ".png"; } else if(Application.platform == RuntimePlatform.OSXEditor) { folderPath = Application.dataPath + "/../" + titleText.text + ".png"; }else { folderPath = Application.dataPath + "/../" + titleText.text + ".png"; } byte[] by = File.ReadAllBytes(folderPath); Texture2D tex = new Texture2D(0, 0); tex.LoadImage(by); GameObject sun = item.transform.FindChild("ScreenShot").gameObject; Image image = sun.GetComponent<Image>(); image.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height),Vector2.zero); } catch (Exception e) { print(e.Message); } yield return null; } }
private void UpdateSubroutineButtonText(RectTransform r, string compositeName) { r.GetComponentInChildren<Text>().text = compositeName; }
void setPlayersNames(GameModel game, RectTransform gameCanvas) { PlayerLeftNameScript playerLeftName; PlayerRightNameScript playerRightName; // set players names playerLeftName = gameCanvas.GetComponentInChildren<PlayerLeftNameScript>(); if (playerLeftName != null) { playerLeftName.setName(game.players.challenger.username); } playerRightName = gameCanvas.GetComponentInChildren<PlayerRightNameScript>(); if (playerRightName != null) { playerRightName.setName(game.players.challenged.username); } }
void setTurn(GameModel game, RectTransform gameCanvas) { GameTurnUpdateScript turnDisplay; // set players names turnDisplay = gameCanvas.GetComponentInChildren<GameTurnUpdateScript>(); turnDisplay.setTurn (game.turn); }
void setPayload(GameModel game, RectTransform gameCanvas) { GamePayloadScript gamePayload; // set players names gamePayload = gameCanvas.GetComponentInChildren<GamePayloadScript>(); gamePayload.gameId = game._id; }
void Awake() { _textField = GetComponent<Text>(); _windowTransform = GameObject.FindGameObjectWithTag("ConsoleWindow").GetComponent<RectTransform>(); _scrollbar = _windowTransform.GetComponentInChildren<Scrollbar>(); }
private void AddButton(Action onClick, RectTransform buttonInst) { var image = buttonInst.GetComponentInChildren<Image>(); image.gameObject.SetActive(false); Buttons.Add(new ButtonData() { Trans = (RectTransform)buttonInst.transform, HightlighEffect = image, OnClick = onClick, }); }
void Start() { PreDefinedSelection = GetComponent<Canvas> (); data.Load(CSVSource); HistoChoiceDescription = PreDefinedSelection.GetComponentInChildren<RectTransform> (); ChoiceDisplay = HistoChoiceDescription.GetComponentInChildren<GridLayoutGroup> (); for (int i=0; i<9; i++) { Choice [i] = ChoiceDisplay.GetComponentsInChildren<Button> () [i]; } for (int i=0; i<9; i++) { HistoryChoiceImage [i] = PreDefinedSelection.GetComponentInChildren<Mask> ().GetComponentsInChildren<Image> () [i + 1]; } for (int i = 0; i < 9; i++) GetPreDefinedUIButtons (); PreDefinedSelection.enabled = false; }
private void Update() { if (m_LastEnabled != m_Interactable) { m_LastEnabled = m_Interactable; if (canvasGroup != null) { if (m_LastEnabled) { canvasGroup.blocksRaycasts = true; canvasGroup.alpha = 1f; if (m_DisabledPanel != null) { Destroy(m_DisabledPanel.gameObject); } } else { canvasGroup.blocksRaycasts = false; canvasGroup.alpha = 0.15f; if (m_ShowDisabledPanel) { m_DisabledPanel = PrefabManager.InstantiateGameObject(PrefabManager.ResourcePrefabs.disabledPanel, rectTransform).GetComponent<RectTransform>(); m_DisabledPanel.anchoredPosition = Vector2.zero; m_DisabledPanel.sizeDelta = Vector2.zero; Color backgroundColor = tabView.GetComponent<Image>().color; m_DisabledPanel.GetComponent<Image>().color = backgroundColor; m_DisabledPanel.GetComponentInChildren<Text>().color = (backgroundColor.r + backgroundColor.g + backgroundColor.b) / 3 > 0.8f ? MaterialColor.textDark : MaterialColor.textLight; } } } } }