/// <summary>
            /// Force a rebuild of all editor picking meshes for all graphics attached to all
            /// groups.  Editor picking meshes are what allow graphics to be accurately picked
            /// in the scene view even if they are in a curved space.
            /// </summary>
            public void RebuildEditorPickingMeshes()
            {
                //No picking meshes for prefabs
                if (InternalUtility.IsPrefab(_renderer))
                {
                    return;
                }

                if (!Application.isPlaying)
                {
                    if (_renderer._space != null)
                    {
                        _renderer._space.RebuildHierarchy();
                        _renderer._space.RecalculateTransformers();
                    }

                    validateGraphics();

                    foreach (var group in _renderer._groups)
                    {
                        group.editor.ValidateGraphicList();
                        group.RebuildFeatureData();
                        group.RebuildFeatureSupportInfo();
                        group.editor.RebuildEditorPickingMeshes();
                    }
                }

                foreach (var group in _renderer._groups)
                {
                    group.editor.RebuildEditorPickingMeshes();
                }
            }
Пример #2
0
        protected virtual void OnEnable()
        {
#if UNITY_EDITOR
            if (InternalUtility.IsPrefab(this))
            {
                return;
            }

            if (Application.isPlaying)
            {
#endif
            //If we are not attached, and if we are about not about to become attached
            if (!isAttachedToGroup && !_willBeAttached)
            {
                var parentRenderer = GetComponentInParent <LeapGraphicRenderer>();
                if (parentRenderer != null)
                {
                    parentRenderer.TryAddGraphic(this);
                }
            }

            patchReferences();
#if UNITY_EDITOR
        }
#endif
        }
            private void onAnySave()
            {
                if (_renderer == null || InternalUtility.IsPrefab(_renderer))
                {
                    InternalUtility.OnAnySave -= onAnySave;
                    return;
                }

                DoEditorUpdateLogic(fullRebuild: true);
            }
Пример #4
0
            public void DoLateUpdateEditor()
            {
                Undo.RecordObject(_renderer, "Update graphic renderer.");
                Assert.IsFalse(InternalUtility.IsPrefab(_renderer), "Should never do editor updates for prefabs");

                _renderer.validateSpaceComponent();

                bool needsRebuild = false;

                using (new ProfilerSample("Calculate Should Rebuild"))
                {
                    foreach (var group in _renderer._groups)
                    {
#if UNITY_EDITOR
                        if (!Application.isPlaying)
                        {
                            group.editor.ValidateGraphicList();
                        }
#endif

                        foreach (var graphic in group.graphics)
                        {
                            if (graphic.isRepresentationDirty)
                            {
                                needsRebuild = true;
                                break;
                            }
                        }

                        foreach (var feature in group.features)
                        {
                            if (feature.isDirty)
                            {
                                needsRebuild = true;
                                break;
                            }
                        }
                    }

                    Hash hierarchyHash = Hash.GetHierarchyHash(_renderer.transform);

                    if (_renderer._space != null)
                    {
                        hierarchyHash.Add(_renderer._space.GetSettingHash());
                    }

                    if (_previousHierarchyHash != hierarchyHash)
                    {
                        _previousHierarchyHash = hierarchyHash;
                        needsRebuild           = true;
                    }
                }

                DoEditorUpdateLogic(needsRebuild);
            }
            public void DoEditorUpdateLogic(bool fullRebuild)
            {
                Undo.RecordObject(_renderer, "Do Editor Update Logic");

                Assert.IsFalse(InternalUtility.IsPrefab(_renderer), "Should never do editor updates for prefabs");

                using (new ProfilerSample("Validate Space Component")) {
                    _renderer.validateSpaceComponent();
                }

                if (fullRebuild)
                {
                    if (_renderer._space != null)
                    {
                        using (new ProfilerSample("Rebuild Space")) {
                            _renderer._space.RebuildHierarchy();
                            _renderer._space.RecalculateTransformers();
                        }
                    }

                    using (new ProfilerSample("Validate graphics")) {
                        validateGraphics();
                    }

                    foreach (var group in _renderer._groups)
                    {
                        using (new ProfilerSample("Validate Graphic List")) {
                            group.editor.ValidateGraphicList();
                        }

                        using (new ProfilerSample("Rebuild Feature Data")) {
                            group.RebuildFeatureData();
                        }

                        using (new ProfilerSample("Rebuild Feature Support Info")) {
                            group.RebuildFeatureSupportInfo();
                        }

                        using (new ProfilerSample("Update Renderer Editor")) {
                            group.editor.UpdateRendererEditor();
                        }
                    }
                }

                using (new ProfilerSample("Update Renderer")) {
                    foreach (var group in _renderer._groups)
                    {
                        group.UpdateRenderer();
                    }
                }

                Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
            }
Пример #6
0
        private void OnValidate()
        {
#if UNITY_EDITOR
            if (!InternalUtility.IsPrefab(this))
            {
                if (!Application.isPlaying)
                {
                    editor.ScheduleRebuild();
                }
                editor.OnValidate();
            }
#endif
        }
Пример #7
0
        private void LateUpdate()
        {
#if UNITY_EDITOR
            //No updates for prefabs!
            if (InternalUtility.IsPrefab(this))
            {
                return;
            }

            if (!Application.isPlaying)
            {
                editor.DoLateUpdateEditor();
            }
            else
#endif
            {
                doLateUpdateRuntime();
            }
        }
            public void OnValidate()
            {
                Assert.IsFalse(InternalUtility.IsPrefab(_renderer), "Should never run editor validation on a prefab");

                for (int i = _renderer._groups.Count; i-- > 0;)
                {
                    if (_renderer._groups[i] == null)
                    {
                        _renderer._groups.RemoveAt(i);
                    }
                }

                _renderer.validateSpaceComponent();

                foreach (var group in _renderer._groups)
                {
                    group.editor.OnValidate();
                }
            }
Пример #9
0
        protected virtual void OnDisable()
        {
#if UNITY_EDITOR
            if (InternalUtility.IsPrefab(this))
            {
                return;
            }

            if (Application.isPlaying)
            {
#endif
            if (isAttachedToGroup)
            {
                attachedGroup.TryRemoveGraphic(this);
            }
            else if (_willBeAttached)
            {
                _groupToBeAttachedTo.TryRemoveGraphic(this);
            }
#if UNITY_EDITOR
        }
#endif
        }
            private void validateGraphics()
            {
                Assert.IsFalse(InternalUtility.IsPrefab(_renderer), "Should never validate graphics for prefabs");

                _renderer.GetComponentsInChildren(includeInactive: true, result: _tempGraphicList);

                HashSet <LeapGraphic> graphicsInGroup = Pool <HashSet <LeapGraphic> > .Spawn();

                try {
                    foreach (var group in _renderer._groups)
                    {
                        for (int i = group.graphics.Count; i-- != 0;)
                        {
                            if (group.graphics[i] == null)
                            {
                                group.graphics.RemoveAt(i);
                            }
                            else
                            {
                                graphicsInGroup.Add(group.graphics[i]);
                            }
                        }

                        foreach (var graphic in _tempGraphicList)
                        {
                            if (graphic.isAttachedToGroup)
                            {
                                //If the graphic claims it is attached to this group, but it really isn't, remove
                                //it and re-add it.
                                bool graphicThinksItsInGroup = graphic.attachedGroup == group;
                                bool isActuallyInGroup       = graphicsInGroup.Contains(graphic);

                                //Also re add it if it is attached to a completely different renderer!
                                if (graphicThinksItsInGroup != isActuallyInGroup ||
                                    graphic.attachedGroup.renderer != _renderer)
                                {
                                    if (!group.TryRemoveGraphic(graphic))
                                    {
                                        //If we fail, detach using force!!
                                        graphic.OnDetachedFromGroup();
                                    }

                                    group.TryAddGraphic(graphic);
                                }
                            }
                        }

                        graphicsInGroup.Clear();
                    }
                } finally {
                    graphicsInGroup.Clear();
                    Pool <HashSet <LeapGraphic> > .Recycle(graphicsInGroup);
                }

                foreach (var graphic in _tempGraphicList)
                {
                    if (graphic.isAttachedToGroup)
                    {
                        //procede to validate

                        //If the graphic is anchored to the wrong anchor, detach and reattach
                        var anchor = _renderer._space == null ? null : LeapSpaceAnchor.GetAnchor(graphic.transform);
                        if (graphic.anchor != anchor)
                        {
                            var group = graphic.attachedGroup;

                            if (group.TryRemoveGraphic(graphic))
                            {
                                group.TryAddGraphic(graphic);
                            }
                        }
                    }
                }
            }