| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- using System;
- using UnityEngine;
- namespace UnityEditor.U2D.Path.GUIFramework
- {
- public abstract class Control
- {
- private string m_Name;
- private int m_NameHashCode;
- private int m_ID;
- private LayoutData m_LayoutData;
- private int m_ActionID = -1;
- private LayoutData m_HotLayoutData;
- public string name
- {
- get { return m_Name; }
- }
- public int ID
- {
- get { return m_ID; }
- }
- public int actionID
- {
- get { return m_ActionID; }
- }
- public LayoutData layoutData
- {
- get { return m_LayoutData; }
- set { m_LayoutData = value; }
- }
- public LayoutData hotLayoutData
- {
- get { return m_HotLayoutData; }
- }
- public Control(string name)
- {
- m_Name = name;
- m_NameHashCode = name.GetHashCode();
- }
- public void GetControl(IGUIState guiState)
- {
- m_ID = guiState.GetControlID(m_NameHashCode, FocusType.Passive);
- }
- internal void SetActionID(int actionID)
- {
- m_ActionID = actionID;
- m_HotLayoutData = m_LayoutData;
- }
- public void BeginLayout(IGUIState guiState)
- {
- Debug.Assert(guiState.eventType == EventType.Layout);
- m_LayoutData = OnBeginLayout(LayoutData.zero, guiState);
- }
- public void Layout(IGUIState guiState)
- {
- Debug.Assert(guiState.eventType == EventType.Layout);
- for (var i = 0; i < GetCount(); ++i)
- {
- if (guiState.hotControl == actionID && hotLayoutData.index == i)
- continue;
- var layoutData = new LayoutData()
- {
- index = i,
- position = GetPosition(guiState, i),
- distance = GetDistance(guiState, i),
- forward = GetForward(guiState, i),
- up = GetUp(guiState, i),
- right = GetRight(guiState, i),
- userData = GetUserData(guiState, i)
- };
- m_LayoutData = LayoutData.Nearest(m_LayoutData, layoutData);
- }
- }
- public void EndLayout(IGUIState guiState)
- {
- Debug.Assert(guiState.eventType == EventType.Layout);
- OnEndLayout(guiState);
- }
- public void Repaint(IGUIState guiState)
- {
- for (var i = 0; i < GetCount(); ++i)
- OnRepaint(guiState, i);
- }
- protected virtual LayoutData OnBeginLayout(LayoutData data, IGUIState guiState)
- {
- return data;
- }
- protected virtual void OnEndLayout(IGUIState guiState)
- {
-
- }
- protected virtual void OnRepaint(IGUIState guiState, int index)
- {
-
- }
- protected virtual int GetCount()
- {
- return 1;
- }
- protected virtual Vector3 GetPosition(IGUIState guiState, int index)
- {
- return Vector3.zero;
- }
- protected virtual Vector3 GetForward(IGUIState guiState, int index)
- {
- return Vector3.forward;
- }
- protected virtual Vector3 GetUp(IGUIState guiState, int index)
- {
- return Vector3.up;
- }
- protected virtual Vector3 GetRight(IGUIState guiState, int index)
- {
- return Vector3.right;
- }
- protected virtual float GetDistance(IGUIState guiState, int index)
- {
- return layoutData.distance;
- }
- protected virtual object GetUserData(IGUIState guiState, int index)
- {
- return null;
- }
- }
- }
|