mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/MI-38.git
synced 2026-01-24 02:25:38 +03:00
106 lines
3.8 KiB
C#
106 lines
3.8 KiB
C#
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
public class hintUI : MonoBehaviour, IPointerEnterHandler, IPointerDownHandler, IPointerExitHandler, IPointerUpHandler
|
|
{
|
|
|
|
[HideInInspector] public Manager manager;
|
|
public bool isGreen = true;
|
|
public Image[] img;
|
|
[HideInInspector]
|
|
private GameObject hintObj;
|
|
public GameObject go;
|
|
[SerializeField]
|
|
private string t;
|
|
//RectTransform rectTransform;
|
|
public void Start()
|
|
{
|
|
if (img.Length != 2)
|
|
img = this.GetComponentsInChildren<Image>();
|
|
OnGreen(img, 0);
|
|
manager = GameObject.Find("Manager").GetComponent<Manager>();
|
|
//rectTransform = GetComponent<RectTransform>();
|
|
//t = "Внешний вид";
|
|
}
|
|
private void OnGreen(Image[] img, int k=-1)
|
|
{
|
|
//if(img.Length != 2)
|
|
// img = this.GetComponentsInChildren<Image>();
|
|
|
|
for (var i = 0; i < img.Length; i++)
|
|
{
|
|
if(img[i].color != Color.gray)
|
|
img[i].color = (isGreen) ? Color.green : Color.white;
|
|
if(k >= 0 && i != k)
|
|
img[i].gameObject.SetActive(false);
|
|
}
|
|
if(k >= 0 && k < img.Length) img[k].gameObject.SetActive(true);
|
|
}
|
|
public void OnPointerUp(PointerEventData eventData)
|
|
{
|
|
OnGreen(img);
|
|
}
|
|
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
OnGreen(img, 1);
|
|
var h = GameObject.Find("hintContainer");
|
|
if (h != null)
|
|
{
|
|
Destroy(h);
|
|
}
|
|
hintObj = OnHint(this.gameObject, go, t);
|
|
}
|
|
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)
|
|
{
|
|
hint.transform.localPosition = new Vector2(hint.transform.localPosition.x - rectTransformBase.rect.width/2 - 20, 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 + 15, hintTr.transform.localPosition.y);
|
|
//Debug.Log($"hintTr.name = {hintTr.name}");
|
|
}
|
|
return hint;
|
|
|
|
}
|
|
public void OnPointerDown(PointerEventData eventData)
|
|
{
|
|
isGreen = true;
|
|
OnParentGreenOff();
|
|
OnGreen(img);
|
|
}
|
|
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
OnGreen(img, 0);
|
|
Destroy(hintObj);
|
|
}
|
|
void OnParentGreenOff()
|
|
{
|
|
var btn = gameObject.transform.parent.GetComponentsInChildren<hintUI>();
|
|
for(var i=0; i<btn.Length; i++)
|
|
{
|
|
if (btn[i] != this)
|
|
{
|
|
btn[i].isGreen = false;
|
|
btn[i].OnGreen(btn[i].img,0);
|
|
}
|
|
}
|
|
}
|
|
}
|