123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- using System;
- using UnityEngine;
- using UnityEngine.Events;
- public class CircleCommandUI : MonoBehaviour
- {
- public bool isClockwise
- {
- get
- {
- return this.m_IsClockwise;
- }
- set
- {
- this.m_IsClockwise = value;
- this.UpdateItemPosition();
- }
- }
- public uGUIListViewer listViewer
- {
- get
- {
- return this.m_ListViewer;
- }
- }
- public float circleRadius
- {
- get
- {
- return this.m_CircleRadius;
- }
- set
- {
- this.m_CircleRadius = value;
- this.UpdateItemPosition();
- }
- }
- public float offsetAngle
- {
- get
- {
- return this.m_OffsetAngle;
- }
- set
- {
- this.m_OffsetAngle = value;
- this.UpdateItemPosition();
- }
- }
- public CircleCommandUI.OnSelect onSelect
- {
- get
- {
- return this.m_OnSelect;
- }
- }
- public CircleCommandUI.OnDeselect onDeselect
- {
- get
- {
- return this.m_OnDeselect;
- }
- }
- public CircleCommandUI.OnDecide onDecide
- {
- get
- {
- return this.m_OnDecide;
- }
- }
- public Func<bool> funcDecide { get; set; }
- public GameObject lastSelectItem
- {
- get
- {
- return this.m_LastSelectItem;
- }
- private set
- {
- this.m_LastSelectItem = value;
- }
- }
- public GameObject nowSelectItem
- {
- get
- {
- return this.m_NowSelectItem;
- }
- private set
- {
- this.m_NowSelectItem = value;
- }
- }
- private void OnValidate()
- {
- if (!Application.isPlaying)
- {
- return;
- }
- if (this.isApplicationQuit)
- {
- return;
- }
- this.UpdateItemPosition();
- }
- private void OnApplicationQuit()
- {
- this.isApplicationQuit = true;
- }
- public void Show<T>(int itemCount, Action<int, T> callbackSetUp = null) where T : Component
- {
- this.m_ListViewer.Show<T>(itemCount, callbackSetUp);
- this.UpdateItemPosition();
- }
- private void UpdateItemPosition()
- {
- GameObject[] itemArray = this.m_ListViewer.ItemArray;
- if (itemArray == null)
- {
- return;
- }
- Transform parentItemArea = this.m_ListViewer.parentItemArea;
- float num = 360f / (float)itemArray.Length;
- float num2 = this.offsetAngle;
- if (this.isClockwise)
- {
- num *= -1f;
- }
- foreach (GameObject gameObject in itemArray)
- {
- Transform transform = gameObject.transform;
- Vector3 vector = Vector3.zero;
- vector.x = Mathf.Cos(num2 * 0.0174532924f);
- vector.y = Mathf.Sin(num2 * 0.0174532924f) * 0.75f;
- vector.Normalize();
- vector *= this.circleRadius;
- transform.localPosition = vector;
- num2 += num;
- }
- }
- private void Update()
- {
- if (this.funcDecide == null)
- {
- return;
- }
- if (this.funcDecide())
- {
- this.onDecide.Invoke(this.nowSelectItem);
- this.nowSelectItem = null;
- this.lastSelectItem = null;
- }
- }
- public void UpdateSelect(Vector2 axis)
- {
- GameObject[] itemArray = this.m_ListViewer.ItemArray;
- if (itemArray == null)
- {
- return;
- }
- Transform parentItemArea = this.m_ListViewer.parentItemArea;
- GameObject gameObject = null;
- Vector2 vector = Vector2.one * float.PositiveInfinity;
- foreach (GameObject gameObject2 in itemArray)
- {
- Vector2 a = gameObject2.transform.localPosition;
- Vector2 vector2 = a - axis;
- if (vector2.sqrMagnitude < vector.sqrMagnitude)
- {
- vector = vector2;
- gameObject = gameObject2;
- }
- }
- if (this.nowSelectItem != gameObject)
- {
- this.lastSelectItem = this.nowSelectItem;
- this.nowSelectItem = gameObject;
- this.onDeselect.Invoke(this.lastSelectItem);
- this.onSelect.Invoke(this.nowSelectItem);
- }
- }
- [SerializeField]
- private bool m_IsClockwise;
- [SerializeField]
- private uGUIListViewer m_ListViewer;
- [SerializeField]
- private float m_CircleRadius;
- [SerializeField]
- private float m_OffsetAngle;
- [SerializeField]
- private CircleCommandUI.OnSelect m_OnSelect = new CircleCommandUI.OnSelect();
- [SerializeField]
- private CircleCommandUI.OnDeselect m_OnDeselect = new CircleCommandUI.OnDeselect();
- [SerializeField]
- private CircleCommandUI.OnDecide m_OnDecide = new CircleCommandUI.OnDecide();
- private GameObject m_LastSelectItem;
- private GameObject m_NowSelectItem;
- private bool isApplicationQuit;
- [Serializable]
- public class OnSelect : UnityEvent<GameObject>
- {
- }
- [Serializable]
- public class OnDeselect : UnityEvent<GameObject>
- {
- }
- [Serializable]
- public class OnDecide : UnityEvent<GameObject>
- {
- }
- }
|