Tanoda
pb_SceneEditor.cs
Go to the documentation of this file.
1using UnityEngine;
4using System.Collections.Generic;
5
6namespace GILES
7{
13 [CreateAssetMenuAttribute(menuName = "Scene Editor", fileName = "RT Scene Editor", order = pb_Config.ASSET_MENU_ORDER)]
14 [System.Serializable]
15 public abstract class pb_SceneEditor : ScriptableObject
16 {
17#region Internal
18
19 readonly KeyCode SHORTCUT_TRANSLATE = KeyCode.W;
20 readonly KeyCode SHORTCUT_ROTATE = KeyCode.E;
21 readonly KeyCode SHORTCUT_SCALE = KeyCode.R;
22
23 internal pb_SelectionHandle handle { get { return pb_SelectionHandle.instance; } }
24
25 // If the mouse down occurred and AcceptMouseInput() returned false, don't send any further mouse events.
26 private bool ignoreMouse = false;
27
28 public bool skipOnGUI = false;
29
30 // Mouse position from last OnMouseDownEvent.
31 [SerializeField] Vector2 _mouseOrigin;
32
33 // Current mousePosition.
34 [SerializeField] Vector2 _mousePosition;
35
39 internal void Enable()
40 {
42 handle.OnHandleMove += OnHandleMove;
45
47 (Vector2 mpos) => {
48 return EventSystem.current != null && EventSystem.current.IsPointerOverGameObject();
49 });
50
51 OnEnable();
52 }
53
57 internal void Disable()
58 {
60 handle.OnHandleMove -= OnHandleMove;
61 handle.SetIsHidden(true);
62 OnDisabled();
63 }
64
65 internal void UpdateBase()
66 {
67 if(Input.GetMouseButtonUp(0))
68 {
69 if( !ignoreMouse ) // && !IsMouseInUse() )
70 {
71 OnMouseUp();
72 }
73
74 ignoreMouse = false;
75 }
76 else if (Input.GetMouseButtonDown(0))
77 {
78 if( IsMouseInUse() )
79 {
80 ignoreMouse = true;
81 }
82 else
83 {
84 ignoreMouse = false;
86 }
87 }
88 else if (Input.GetMouseButton(0) && !ignoreMouse)
89 {
90 // if( !IsMouseInUse() )
92 }
93
94 Update();
95 }
96
97 public void OnKeyDownBase()
98 {
99 if (!Input.GetMouseButton(0) && !Input.GetMouseButton(1))
100 {
101 if( Input.GetKey(SHORTCUT_TRANSLATE) )
102 handle.SetTool(Tool.Position);
103 else if( Input.GetKey(SHORTCUT_ROTATE) )
104 handle.SetTool(Tool.Rotate);
105 else if( Input.GetKey(SHORTCUT_SCALE) )
106 handle.SetTool(Tool.Scale);
107 else if( Input.GetKey(KeyCode.F))
109 }
110
111 OnKeyDown();
112 }
113#endregion
114
115#region Virtual
116
120 public virtual void Update() {}
121
125 public virtual void OnGUI() {}
126
131 public virtual void OnMouseDown() {}
132
137 public virtual void OnMouseMove() {}
138
143 public virtual void OnMouseUp() {}
144
149 public virtual void OnHandleBegin(pb_Transform transform) {}
150
155 public virtual void OnHandleMove(pb_Transform transform) {}
156
160 public virtual void OnHandleFinish() {}
161
165 public virtual void OnKeyDown() {}
166
171 public virtual void OnFrameSelection() {}
172
176 public virtual void OnEnable() {}
177
181 public virtual void OnDisabled() {}
182
187 public virtual void OnSelectionChange(IEnumerable<GameObject> added) {}
188
192 public virtual bool EnableCameraControls()
193 {
194 return Input.GetKey(KeyCode.LeftAlt);
195 }
196
203 public virtual bool IsMouseInUse()
204 {
206 }
207#endregion
208
209 }
210}
static bool IsMouseInUse()
static void AddMouseInUseDelegate(MouseInUse del)
virtual void OnFrameSelection()
virtual bool EnableCameraControls()
virtual void OnSelectionChange(IEnumerable< GameObject > added)
virtual void OnMouseUp()
virtual void Update()
virtual void OnDisabled()
virtual void OnHandleMove(pb_Transform transform)
virtual void OnMouseDown()
virtual void OnKeyDown()
virtual void OnMouseMove()
virtual bool IsMouseInUse()
virtual void OnGUI()
virtual void OnEnable()
virtual void OnHandleBegin(pb_Transform transform)
virtual void OnHandleFinish()
OnHandleFinishEvent OnHandleFinish
OnHandleMoveEvent OnHandleMove
void SetIsHidden(bool isHidden)
OnHandleBeginEvent OnHandleBegin
static void AddOnSelectionChangeListener(Callback< IEnumerable< GameObject > > del)
Definition: pb_Selection.cs:34
Tool
Definition: pb_Enum.cs:24