10using System.Collections.Generic;
25#pragma warning disable 0414
26 private int _selectedGroup = 0;
27#pragma warning restore 0414
30 public readonly EditorApi editor;
32 [ContextMenu(
"Show all hidden objects (INTERNAL)")]
33 private void showAllHiddenObjects() {
34 foreach (var obj
in FindObjectsOfType<UnityEngine.Object>()) {
35 obj.hideFlags = HideFlags.None;
39 public class EditorApi {
43 private Hash _previousHierarchyHash;
47 InternalUtility.OnAnySave += onAnySave;
50 public void OnValidate() {
51 Assert.IsFalse(InternalUtility.IsPrefab(_renderer),
"Should never run editor validation on a prefab");
53 for (
int i = _renderer._groups.Count; i-- > 0;) {
54 if (_renderer._groups[i] ==
null) {
55 _renderer._groups.RemoveAt(i);
61 foreach (var group
in _renderer._groups) {
62 group.editor.OnValidate();
66 public void OnDestroy() {
67 InternalUtility.OnAnySave -= onAnySave;
69 foreach (var group
in _renderer._groups) {
70 group.editor.OnDestroy();
79 public void CreateGroup(Type rendererType) {
80 AssertHelper.AssertEditorOnly();
81 Assert.IsNotNull(rendererType);
85 _renderer._selectedGroup = _renderer._groups.Count;
86 _renderer._groups.Add(group);
93 public void DestroySelectedGroup() {
94 AssertHelper.AssertEditorOnly();
96 var toDestroy = _renderer._groups[_renderer._selectedGroup];
97 _renderer._groups.RemoveAt(_renderer._selectedGroup);
99 toDestroy.editor.OnDestroy();
101 if (_renderer._selectedGroup >= _renderer._groups.Count && _renderer._selectedGroup != 0) {
102 _renderer._selectedGroup--;
112 return _renderer._groups[_renderer._selectedGroup].renderingMethod;
123 public void ScheduleRebuild() {
124 AssertHelper.AssertEditorOnly();
127 _previousHierarchyHash++;
135 public void RebuildEditorPickingMeshes() {
137 if (InternalUtility.IsPrefab(_renderer)) {
141 if (!Application.isPlaying) {
142 if (_renderer._space !=
null) {
149 foreach (var group
in _renderer._groups) {
150 group.editor.ValidateGraphicList();
151 group.RebuildFeatureData();
152 group.RebuildFeatureSupportInfo();
153 group.editor.RebuildEditorPickingMeshes();
157 foreach (var group
in _renderer._groups) {
158 group.editor.RebuildEditorPickingMeshes();
166 public void ChangeRenderingMethodOfSelectedGroup(Type renderingMethod,
bool addFeatures) {
167 _renderer._groups[_renderer._selectedGroup].editor.ChangeRenderingMethod(renderingMethod, addFeatures);
174 public void AddFeatureToSelectedGroup(Type featureType) {
175 _renderer._groups[_renderer._selectedGroup].editor.AddFeature(featureType);
182 public void RemoveFeatureFromSelectedGroup(
int featureIndex) {
183 _renderer._groups[_renderer._selectedGroup].editor.RemoveFeature(featureIndex);
186 public void DoLateUpdateEditor() {
187 Undo.RecordObject(_renderer,
"Update graphic renderer.");
188 Assert.IsFalse(InternalUtility.IsPrefab(_renderer),
"Should never do editor updates for prefabs");
192 bool needsRebuild =
false;
195 foreach (var group
in _renderer._groups) {
197 if (!Application.isPlaying) {
198 group.editor.ValidateGraphicList();
202 foreach (var graphic
in group.graphics) {
203 if (graphic.isRepresentationDirty) {
209 foreach (var feature
in group.features) {
210 if (feature.isDirty) {
219 if (_renderer._space !=
null) {
223 if (_previousHierarchyHash != hierarchyHash) {
224 _previousHierarchyHash = hierarchyHash;
229 DoEditorUpdateLogic(needsRebuild);
232 public void DoEditorUpdateLogic(
bool fullRebuild) {
233 Undo.RecordObject(_renderer,
"Do Editor Update Logic");
235 Assert.IsFalse(InternalUtility.IsPrefab(_renderer),
"Should never do editor updates for prefabs");
242 if (_renderer._space !=
null) {
253 foreach (var group
in _renderer._groups) {
255 group.editor.ValidateGraphicList();
259 group.RebuildFeatureData();
263 group.RebuildFeatureSupportInfo();
267 group.editor.UpdateRendererEditor();
273 foreach (var group
in _renderer._groups) {
274 group.UpdateRenderer();
278 Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
281 private void onAnySave() {
282 if (_renderer ==
null || InternalUtility.IsPrefab(_renderer)) {
283 InternalUtility.OnAnySave -= onAnySave;
287 DoEditorUpdateLogic(fullRebuild:
true);
291 private List<LeapGraphic> _tempGraphicList =
new List<LeapGraphic>();
292 private void validateGraphics() {
293 Assert.IsFalse(InternalUtility.IsPrefab(_renderer),
"Should never validate graphics for prefabs");
295 _renderer.GetComponentsInChildren(includeInactive:
true, result: _tempGraphicList);
297 HashSet<LeapGraphic> graphicsInGroup = Pool<HashSet<LeapGraphic>>.Spawn();
299 foreach (var group
in _renderer._groups) {
301 for (
int i = group.graphics.Count; i-- != 0;) {
302 if (group.graphics[i] ==
null) {
303 group.graphics.RemoveAt(i);
305 graphicsInGroup.Add(group.graphics[i]);
309 foreach (var graphic
in _tempGraphicList) {
310 if (graphic.isAttachedToGroup) {
313 bool graphicThinksItsInGroup = graphic.attachedGroup == group;
314 bool isActuallyInGroup = graphicsInGroup.Contains(graphic);
317 if (graphicThinksItsInGroup != isActuallyInGroup ||
318 graphic.attachedGroup.renderer != _renderer) {
319 if (!group.TryRemoveGraphic(graphic)) {
321 graphic.OnDetachedFromGroup();
329 graphicsInGroup.Clear();
332 graphicsInGroup.Clear();
333 Pool<HashSet<LeapGraphic>>.Recycle(graphicsInGroup);
336 foreach (var graphic
in _tempGraphicList) {
337 if (graphic.isAttachedToGroup) {
342 if (graphic.anchor != anchor) {
343 var group = graphic.attachedGroup;
345 if (group.TryRemoveGraphic(graphic)) {
346 group.TryAddGraphic(graphic);
bool TryAddGraphic(LeapGraphic graphic)
Tries to add the given graphic to any group attached to this graphic. First, it will try to be attach...
void validateSpaceComponent()
static LeapSpaceAnchor GetAnchor(Transform root)
abstract Hash GetSettingHash()
Get a hash of all features in this space. This is useful if you want to know if anything has changed ...
void RecalculateTransformers()
Call to update all transformers in the space. Call this whenever any anchor or parent of an anchor ch...
void RebuildHierarchy()
Call to traverse the entire hierarchy and rebuild the relationship between anchors....
static Hash GetHierarchyHash(Transform root)
A utility struct for ease of use when you want to wrap a piece of code in a Profiler....