| | |
| | | using UnityEngine; |
| | | using UnityEngine.UI; |
| | | using UnityEngine.EventSystems; |
| | | using vnxbqy.UI; |
| | | |
| | | |
| | | |
| | | public static class UIUtility |
| | |
| | | |
| | | public static GameObject CreateWidget(string _sourceName, string _name) |
| | | { |
| | | var prefab = ResManager.Instance.LoadAsset<GameObject>("UI", _sourceName); |
| | | var prefab = UILoader.LoadPrefab(_sourceName); |
| | | if (prefab == null) |
| | | { |
| | | return null; |
| | |
| | | |
| | | public static Vector2 GetMaxWorldPosition(this RectTransform _rectTransform) |
| | | { |
| | | Vector2 max; |
| | | var offsetY = (1 - _rectTransform.pivot.y) * _rectTransform.rect.height; |
| | | var offsetX = (1 - _rectTransform.pivot.x) * _rectTransform.rect.width; |
| | | max = _rectTransform.TransformPoint(offsetX, offsetY, 0); |
| | | |
| | | return max; |
| | | Vector3[] cornors = new Vector3[4]; |
| | | _rectTransform.GetWorldCorners(cornors); |
| | | return cornors[2]; |
| | | } |
| | | |
| | | public static Vector2 GetMinWorldPosition(this RectTransform _rectTransform) |
| | | { |
| | | Vector2 min; |
| | | var offsetY = -_rectTransform.pivot.y * _rectTransform.rect.height; |
| | | var offsetX = -_rectTransform.pivot.x * _rectTransform.rect.width; |
| | | min = _rectTransform.TransformPoint(offsetX, offsetY, 0); |
| | | |
| | | return min; |
| | | Vector3[] cornors = new Vector3[4]; |
| | | _rectTransform.GetWorldCorners(cornors); |
| | | return cornors[0]; |
| | | } |
| | | |
| | | public static Vector2 GetMaxReferencePosition(this RectTransform _rectTransform, Transform _reference) |
| | |
| | | vertexHelper.AddTriangle(currentVertCount, currentVertCount + 1, currentVertCount + 2); |
| | | } |
| | | |
| | | // public static string GetUIElementRelativePath(UIRoot _root, Transform _transform) |
| | | // { |
| | | // List<Transform> parents = new List<Transform>() { _transform }; |
| | | // GetParents(_transform, ref parents); |
| | | |
| | | // if (parents.Contains(_root.transform)) |
| | | // { |
| | | // parents.Remove(_root.transform); |
| | | // } |
| | | |
| | | // var names = new string[parents.Count]; |
| | | // for (int i = 0; i < names.Length; i++) |
| | | // { |
| | | // names[i] = parents[i].gameObject.name; |
| | | // } |
| | | |
| | | // return string.Join("/", names); |
| | | // } |
| | | |
| | | public static void GetParents(Transform _transform, ref List<Transform> _parents) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | public static string GetUIElementRelativePath(Transform _root, Transform _transform) |
| | | { |
| | | List<Transform> parents = new List<Transform>() { _transform }; |
| | | GetParents(_transform, ref parents); |
| | | |
| | | if (parents.Contains(_root)) |
| | | { |
| | | parents.Remove(_root); |
| | | } |
| | | |
| | | var names = new string[parents.Count]; |
| | | for (int i = 0; i < names.Length; i++) |
| | | { |
| | | names[i] = parents[i].gameObject.name; |
| | | } |
| | | |
| | | return string.Join("/", names); |
| | | } |
| | | } |