mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/MI-38.git
synced 2026-01-24 02:35:38 +03:00
110 lines
4.1 KiB
C#
110 lines
4.1 KiB
C#
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<Image>();
|
|
img[0].gameObject.SetActive(true);
|
|
img[1].gameObject.SetActive(false);
|
|
manager = GameObject.Find("Manager").GetComponent<Manager>();
|
|
green = GameObject.FindGameObjectsWithTag("activezone");
|
|
|
|
}
|
|
|
|
void OnColor()
|
|
{
|
|
foreach (GameObject gr in green)
|
|
{
|
|
if (l)
|
|
{
|
|
gr.GetComponent<MakeActive>().ReplaceMaterialsWithActive();
|
|
}
|
|
else
|
|
{
|
|
gr.GetComponent<MakeActive>().RestoreChildrenMaterials();
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public void OnPointerUp(PointerEventData eventData)
|
|
{
|
|
l = !l;
|
|
gameObject.GetComponentInChildren<Image>().color = (l) ? Color.green : Color.white;
|
|
OnColor();
|
|
}
|
|
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
img[0].gameObject.SetActive(false);
|
|
img[1].gameObject.SetActive(true);
|
|
gameObject.GetComponentInChildren<Image>().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<Image>().color = Color.green;
|
|
|
|
}
|
|
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
img[0].gameObject.SetActive(true);
|
|
img[1].gameObject.SetActive(false);
|
|
gameObject.GetComponentInChildren<Image>().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<Image>();
|
|
Text txt = hint.GetComponentInChildren<Text>();
|
|
txt.text = t;
|
|
var s = txt.text.Length;
|
|
//Debug.Log($"s = {s}");
|
|
RectTransform rectTransformText = txt.GetComponent<RectTransform>();
|
|
rectTransformText.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, s * 10 + 20);
|
|
RectTransform rectTransformBase = hintBase.GetComponent<RectTransform>();
|
|
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<Image>();
|
|
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;
|
|
|
|
}
|
|
}
|