Bootstrap

一些独立功能工具脚本集合

目录

 1.获取物体在Hierarchy下的完整层级,从最上级开始

2.多个UI选中的高亮

3.获取Box的八个顶点

4.Tab建切换UI的选中

5.显示帧数

6.判断屏幕边界


 1.获取物体在Hierarchy下的完整层级,从最上级开始

 using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GetPath: MonoBehaviour
{
    public string path;

    private void OnValidate()
    {
       
    }

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.S))
        {
            path = GetHierarchyPath(transform);
        }
    }
    private string GetHierarchyPath(Transform transform)//5   
    {
     
        if (!transform.parent)
        {
   
            return transform.name;

        }
        return GetHierarchyPath(transform.parent) + "/" + transform.name;
    }

}

2.多个UI选中的高亮

这里写了一个基类,把脚挂载在所有需要选中的UI父级上面

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UISelectHighlight<T> : MonoBehaviour where T: Selectable
{
    public List<T> tList = new List<T>();
    internal virtual void Awake()
    {
        T[] ts = transform.GetComponentsInChildren<T>(true);
        for (int i = 0; i < ts.Length; i++)
        {
            if (!tList.Contains(ts[i]))
            {
                tList.Add(ts[i]);
            }
        }
    }

    internal virtual void HighlightEvent(T t)
    {
        if (t == null)
        {
            foreach (T item in tList)
            {
                item.image.sprite= item.spriteState.disabledSprite;
            }

            return;
        }
        if (tList.Count > 0)
        {
            for (int i = 0; i < tList.Count; i++)
            {
                if (tList[i] == t)
                {
                    tList[i].image.sprite = tList[i].spriteState.selectedSprite;
                }
                else
                {
                    tList[i].image.sprite = tList[i].spriteState.disabledSprite;
                }
            }
        }
    }
    internal virtual void OnDisable()
    {
        HighlightEvent(null);
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ButtonSelectHighlight : UISelectHighlight<Button>
{

    p
;