/// <summary> /// Schedules a full editor rebuild of all graphic groups and their representations. /// This method only schedules the rebuild, it does not actually execute it. The /// rebuild will happen on during the next editor tick. /// /// This is an editor-only api. During runtime rebuilding is handled automatically, /// and full rebuilds do not occur. /// </summary> public void ScheduleRebuild() { AssertHelper.AssertEditorOnly(); //Dirty the hash by changing it to something else _previousHierarchyHash++; }
/// <summary> /// Creates a new group for this graphic renderer, and assigns it the /// given rendering method. This is an editor only api, as creating new /// groups cannot be done at runtime. /// </summary> public void CreateGroup(Type rendererType) { AssertHelper.AssertEditorOnly(); Assert.IsNotNull(rendererType); var group = new LeapGraphicGroup(_renderer, rendererType); _renderer._selectedGroup = _renderer._groups.Count; _renderer._groups.Add(group); }
public LeapGraphicGroup(LeapGraphicRenderer renderer, Type renderingMethodType) { _groupName = LeapGraphicTagAttribute.GetTagName(renderingMethodType); AssertHelper.AssertEditorOnly(); Assert.IsNotNull(renderer); Assert.IsNotNull(renderingMethodType); _renderer = renderer; editor = new EditorApi(this); editor.ChangeRenderingMethod(renderingMethodType, addFeatures: true); }
/// <summary> /// Removes the feature at the given index. This is an editor only api, as features /// cannot be added/removed at runtime. /// </summary> public void RemoveFeature(int featureIndex) { AssertHelper.AssertEditorOnly(); Undo.RecordObject(_group.renderer, "Removed feature"); _group._features.RemoveAt(featureIndex); _group.RebuildFeatureData(); _group.RebuildFeatureSupportInfo(); _group._renderer.editor.ScheduleRebuild(); }
/// <summary> /// Destroys the currently selected group. This is an editor-only api, /// as destroying groups cannot be done at runtime. /// </summary> public void DestroySelectedGroup() { AssertHelper.AssertEditorOnly(); var toDestroy = _renderer._groups[_renderer._selectedGroup]; _renderer._groups.RemoveAt(_renderer._selectedGroup); toDestroy.editor.OnDestroy(); if (_renderer._selectedGroup >= _renderer._groups.Count && _renderer._selectedGroup != 0) { _renderer._selectedGroup--; } }
/// <summary> /// Adds a feature of a specific type to this group. Even if the feature is not /// a supported feature it will still be added, it will just not be supported and /// will show up in red in the inspector. /// /// This is an editor only api, as features cannot be added/removed at runtime. /// </summary> public LeapGraphicFeatureBase AddFeature(Type featureType) { AssertHelper.AssertEditorOnly(); _group._renderer.editor.ScheduleRebuild(); Undo.RecordObject(_group.renderer, "Added feature"); var feature = Activator.CreateInstance(featureType) as LeapGraphicFeatureBase; _group._features.Add(feature); _group.RebuildFeatureData(); _group.RebuildFeatureSupportInfo(); return(feature); }
/// <summary> /// This method changes the rendering method used for this group. You must provide the type /// of the rendering method to switch to, as well as if features should be added to match /// the existing feature data objects present in the graphics that are attached. /// /// This is an editor only method, as rendering types cannot be changed at runtime! /// </summary> public void ChangeRenderingMethod(Type renderingMethodType, bool addFeatures) { AssertHelper.AssertEditorOnly(); Assert.IsNotNull(renderingMethodType); if (_group._renderingMethod.Value != null) { _group._renderingMethod.Value.OnDisableRendererEditor(); _group._renderingMethod.Value = null; } _group._renderingMethod.Value = Activator.CreateInstance(renderingMethodType) as LeapRenderingMethod; Assert.IsNotNull(_group._renderingMethod.Value); ILeapInternalRenderingMethod renderingMethodInternal = _group._renderingMethod.Value; renderingMethodInternal.renderer = _group._renderer; renderingMethodInternal.group = _group; if (addFeatures) { List <Type> dataObjTypes = new List <Type>(); var allGraphics = _group.renderer.GetComponentsInChildren <LeapGraphic>(); foreach (var graphic in allGraphics) { if (_group._renderingMethod.Value.IsValidGraphic(graphic)) { List <Type> types = new List <Type>(); for (int i = 0; i < graphic.featureData.Count; i++) { var dataObj = graphic.featureData[i]; var dataType = dataObj.GetType(); if (!dataObjTypes.Contains(dataType)) { types.Add(dataType); } } foreach (var type in types) { if (dataObjTypes.Query().Count(t => t == type) < types.Query().Count(t => t == type)) { dataObjTypes.Add(type); } } } } foreach (var type in dataObjTypes) { var featureType = LeapFeatureData.GetFeatureType(type); if (featureType != null) { AddFeature(featureType); } } } _group._renderingMethod.Value.OnEnableRendererEditor(); OnValidate(); }
public void UpdateRendererEditor() { AssertHelper.AssertEditorOnly(); _group._renderingMethod.Value.OnUpdateRendererEditor(); }