using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; public class hlight : MonoBehaviour, IPointerEnterHandler, IPointerDownHandler, IPointerExitHandler, IPointerUpHandler { [HideInInspector] public Manager manager; public static bool l=false; GameObject[] green; private Image[] img; private GameObject hintObj; public GameObject go; [SerializeField] private string t; void Start() { img = this.GetComponentsInChildren(); img[0].gameObject.SetActive(true); img[1].gameObject.SetActive(false); manager = GameObject.Find("Manager").GetComponent(); green = GameObject.FindGameObjectsWithTag("activezone"); } void OnColor() { foreach (GameObject gr in green) { if (l) { gr.GetComponent().ReplaceMaterialsWithActive(); } else { gr.GetComponent().RestoreChildrenMaterials(); } } } public void OnPointerUp(PointerEventData eventData) { l = !l; gameObject.GetComponentInChildren().color = (l) ? Color.green : Color.white; OnColor(); } public void OnPointerEnter(PointerEventData eventData) { img[0].gameObject.SetActive(false); img[1].gameObject.SetActive(true); gameObject.GetComponentInChildren().color = (l) ? Color.green : Color.white; /*if (manager.viewmode == 1) manager.ChangeLayerIgnore(); else if (manager.viewmode == 2) manager.ChangeLayerPassCabineIgnore();*/ var h = GameObject.Find("hintContainer"); if (h != null) { Destroy(h); } hintObj = OnHint(this.gameObject, go, t); //manager.mouseEnterUI(); } public void OnPointerDown(PointerEventData eventData) { gameObject.GetComponentInChildren().color = Color.green; } public void OnPointerExit(PointerEventData eventData) { img[0].gameObject.SetActive(true); img[1].gameObject.SetActive(false); gameObject.GetComponentInChildren().color = (l) ? Color.green : Color.white; /* if (manager.viewmode == 1) manager.ChangeLayerDefault(); else if (manager.viewmode == 2) manager.ChangeLayerPassCabineIgnore();*/ Destroy(hintObj); //manager.mouseExitUI(); } public GameObject OnHint(GameObject btn, GameObject objGo, string t) { Vector2 hintPos = new Vector2(btn.transform.localPosition.x + 15, btn.transform.localPosition.y + 55);//позиция хинта GameObject hint = Instantiate(objGo, btn.transform.parent);//создание хинта hint.name = "hintContainer"; hint.transform.localPosition = hintPos;//позиция хинта устанавливаем var hintBase = hint.GetComponentInChildren(); Text txt = hint.GetComponentInChildren(); txt.text = t; var s = txt.text.Length; //Debug.Log($"s = {s}"); RectTransform rectTransformText = txt.GetComponent(); rectTransformText.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, s * 10 + 20); RectTransform rectTransformBase = hintBase.GetComponent(); rectTransformBase.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, rectTransformText.rect.width + 35); if ((rectTransformBase.rect.width + hintBase.transform.position.x) > Screen.width) //1920 { hint.transform.localPosition = new Vector2(hint.transform.localPosition.x - rectTransformBase.rect.width/2 + 10, hint.transform.localPosition.y); var hintTr = hint.transform.GetChild(1).GetComponent(); hintTr.transform.localPosition = new Vector2(hintTr.transform.localPosition.x + rectTransformBase.rect.width/2 - 20, hintTr.transform.localPosition.y); //Debug.Log($"hintTr.name = {hintTr.name}"); } return hint; } }