using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; namespace TBTK{ public static class UI { public static float GetScaleFactor(){ return UIControl.GetScaleReferenceWidth()/Screen.width; } //inputID=-1 - mouse cursor, inputID>=0 - touch finger index public static bool IsCursorOnUI(int inputID=-1){ EventSystem eventSystem = EventSystem.current; return ( eventSystem.IsPointerOverGameObject( inputID ) ); } public static GameObject Clone(GameObject srcObj, string name="", Vector3 posOffset=default(Vector3)) { GameObject newObj=(GameObject)MonoBehaviour.Instantiate(srcObj); newObj.name=name=="" ? srcObj.name : name ; newObj.transform.SetParent(srcObj.transform.parent); newObj.transform.localPosition=srcObj.transform.localPosition+posOffset; newObj.transform.localScale=srcObj.transform.localScale; return newObj; } //0 - bottom left //1 - top left //2 - top right //3 - bottom right public static Vector3 GetCorner(RectTransform rectT, int corner=0){ Vector3[] fourCornersArray=new Vector3[4]; rectT.GetWorldCorners(fourCornersArray); return fourCornersArray[corner]; } public static void SetPivot(int pivotCorner, RectTransform rect){ if(pivotCorner==0) rect.pivot=new Vector3(0, 0); if(pivotCorner==1) rect.pivot=new Vector3(0, 1); if(pivotCorner==2) rect.pivot=new Vector3(1, 1); if(pivotCorner==3) rect.pivot=new Vector3(1, 0); } public static string HLTxt(string txt){ return ""+txt+""; } public static string ColorTxt(string txt){ return ""+txt+""; } //255, 150, 64 public static int GetIdxFromList(List buttonList, GameObject butObj, int idx=0){ for(int i=0; i buttonList, GameObject butObj, int idx=0){ for(int i=0; i