public void OnAfterDeserialize() { if (_renderingMethod.Value == null || renderer == null) { Debug.LogWarning("The rendering group did not find the needed data! If you have a variable of type " + "LeapGraphicGroup make sure to annotate it with a [NonSerialized] attribute, or else " + "Unity will automatically create invalid instances of the class."); } else { ILeapInternalRenderingMethod renderingMethodInternal = _renderingMethod.Value; renderingMethodInternal.group = this; renderingMethodInternal.renderer = renderer; } }
/// <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(); }