Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// The enemy information UI if clicked on enemy
- /// </summary>
- public GameObject hoverGUI;
- public static void SpawnHoverGUI_Enemy(Tile tile) {
- // Enable canvas
- GamePlay.EnableCanvas(instance.hoverGUI.GetComponent<Canvas>());
- // Config
- int width = 400;
- int fontSize = 20;
- // Remove appended gameobjects
- foreach (Transform child in instance.hoverGUI.GetComponent<HoverGUI_Components>().GetHoverElement().transform) {
- if (child.name == "Appended") {
- GameObject.Destroy(child.gameObject);
- }
- }
- // START Description
- // Activate before making a copy
- instance.hoverGUI.GetComponent<HoverGUI_Components>().GetTemplateText().SetActive(true);
- // Make copy of text object and parent it
- GameObject EnemyTextObject = Instantiate(instance.hoverGUI.GetComponent<HoverGUI_Components>().GetTemplateText());
- EnemyTextObject.transform.SetParent(instance.hoverGUI.GetComponent<HoverGUI_Components>().GetHoverElement().transform);
- EnemyTextObject.name = "Appended";
- // Adjust size of hover element
- EnemyTextObject.GetComponentInChildren<TextMeshProUGUI>().GetComponent<RectTransform>().sizeDelta = new Vector2(width,
- EnemyTextObject.GetComponentInChildren<TextMeshProUGUI>().GetComponent<RectTransform>().sizeDelta.y);
- // Adjust font size
- EnemyTextObject.GetComponentInChildren<TextMeshProUGUI>().fontSize = fontSize;
- // Set description
- EnemyTextObject.GetComponentInChildren<TextMeshProUGUI>().text = tile.current_enemy.GetDescription();
- // END Description
- // START Effects
- // Activate before making a copy
- instance.hoverGUI.GetComponent<HoverGUI_Components>().GetTemplateGrid().SetActive(true);
- // Make copy of grid object and parent it
- GameObject EnemyGridObject_1 = Instantiate(instance.hoverGUI.GetComponent<HoverGUI_Components>().GetTemplateGrid());
- EnemyGridObject_1.transform.SetParent(instance.hoverGUI.GetComponent<HoverGUI_Components>().GetHoverElement().transform);
- EnemyGridObject_1.name = "Appended";
- // Append effects to grid
- for (int i = 0; i < tile.current_enemy.GetNegativeEffects().Count; i++) {
- GameObject button = (GameObject)Instantiate(GamePlay.GetEffectsButtonPrefab());
- button.transform.SetParent(EnemyGridObject_1.GetComponent<GridLayoutGroup>().transform);
- button.GetComponent<Image>().sprite = tile.current_enemy.GetNegativeEffects()[i].GetSprite();
- button.GetComponentsInChildren<TextMeshProUGUI>()[1].text = tile.current_enemy.GetNegativeEffects()[i].GetFloorDuration().ToString();
- button.GetComponentsInChildren<TextMeshProUGUI>()[0].text = tile.current_enemy.GetNegativeEffects()[i].GetRoundDuration().ToString();
- }
- // TO DO Same with positive effects
- // END Effects
- Canvas.ForceUpdateCanvases();
- // Positioning the hover GUI
- // The offset is used to postion the GUI on the right of the enemy tile.
- float offSet = (instance.hoverGUI.GetComponent<HoverGUI_Components>().GetHoverElement().GetComponent<RectTransform>().rect.width / 2 + (tile.GetComponent<RectTransform>().rect.width / 2)) + 10;
- RectTransform hoverOverRect = tile.GetComponent<RectTransform>();
- instance.hoverGUI.GetComponent<HoverGUI_Components>().GetHoverElement().GetComponent<RectTransform>().position = new Vector3(hoverOverRect.position.x + offSet, hoverOverRect.position.y,
- hoverOverRect.position.z);
- Canvas.ForceUpdateCanvases();
- // Correct positioning if out of bounds
- RectTransform hoverElementRect = instance.hoverGUI.GetComponent<HoverGUI_Components>().GetHoverElement().GetComponent<RectTransform>();
- Debug.Log(hoverElementRect.sizeDelta);
- /*float canvasBounds_y = instance.hoverGUI.GetComponent<Canvas>().GetComponent<RectTransform>().localPosition.y / 2;
- float pos_top_bound = instance.hoverGUI.GetComponent<HoverGUI_Components>().GetHoverElement().GetComponent<RectTransform>().localPosition.y +
- (instance.hoverGUI.GetComponent<HoverGUI_Components>().GetHoverElement().GetComponent<RectTransform>().rect.height / 2);
- Debug.Log(canvasBounds_y);
- Debug.Log(pos_top_bound);
- LayoutRebuilder.ForceRebuildLayoutImmediate(instance.hoverGUI.GetComponent<HoverGUI_Components>().GetHoverElement().GetComponent<RectTransform>());
- instance.hoverGUI.GetComponent<HoverGUI_Components>().GetHoverElement().GetComponent<RectTransform>().ForceUpdateRectTransforms();
- Debug.Log(instance.hoverGUI.GetComponent<HoverGUI_Components>().GetHoverElement().GetComponent<RectTransform>().localPosition.y);
- Debug.Log(instance.hoverGUI.GetComponent<HoverGUI_Components>().GetHoverElement().GetComponent<RectTransform>().sizeDelta.y);
- if (instance.hoverGUI.GetComponent<HoverGUI_Components>().GetHoverElement().GetComponent<RectTransform>().localPosition.y > canvasBounds_y) {
- Debug.Log("is bigger");
- float difference_y = instance.hoverGUI.GetComponent<HoverGUI_Components>().GetHoverElement().GetComponent<RectTransform>().localPosition.y - canvasBounds_y;
- Debug.Log(difference_y);
- instance.hoverGUI.GetComponent<HoverGUI_Components>().GetHoverElement().GetComponent<RectTransform>().position = new Vector3(hoverOverRect.position.x + offSet, hoverOverRect.position.y - difference_y - 30,
- hoverOverRect.position.z);
- } else if (instance.hoverGUI.GetComponent<HoverGUI_Components>().GetHoverElement().GetComponent<RectTransform>().localPosition.y < -canvasBounds_y) {
- Debug.Log("is smaller");
- float difference_y = instance.hoverGUI.GetComponent<HoverGUI_Components>().GetHoverElement().GetComponent<RectTransform>().localPosition.y + canvasBounds_y;
- Debug.Log(difference_y);
- instance.hoverGUI.GetComponent<HoverGUI_Components>().GetHoverElement().GetComponent<RectTransform>().position = new Vector3(hoverOverRect.position.x + offSet, hoverOverRect.position.y + difference_y + 30,
- hoverOverRect.position.z);
- }*/
- //Debug.Log(canvasBounds_y);
- // Deactivate template objects
- instance.hoverGUI.GetComponent<HoverGUI_Components>().GetTemplateText().SetActive(false);
- instance.hoverGUI.GetComponent<HoverGUI_Components>().GetTemplateGrid().SetActive(false);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement