/// <summary> /// Called by the system when this graphic is attached to a group. This method is /// invoked both at runtime and at edit time. /// </summary> public virtual void OnAttachedToGroup(LeapGraphicGroup group, LeapSpaceAnchor anchor) { #if UNITY_EDITOR editor.OnAttachedToGroup(group, anchor); #endif isRepresentationDirty = true; _willBeAttached = false; _groupToBeAttachedTo = null; _favoriteGroupName = group.name; _attachedRenderer = group.renderer; _attachedGroupIndex = _attachedRenderer.groups.IndexOf(group); _anchor = anchor; patchReferences(); if (OnAttachedToGroupEvent != null) { OnAttachedToGroupEvent(group); } }
public LeapGuiGroupEditor(LeapGraphicRenderer renderer, SerializedObject serializedObject) { _renderer = renderer; _serializedObject = serializedObject; var allTypes = Assembly.GetAssembly(typeof(LeapGraphicRenderer)).GetTypes(); var allRenderingMethods = allTypes.Query(). Where(t => !t.IsAbstract && !t.IsGenericType && t.IsSubclassOf(typeof(LeapRenderingMethod))); _addRenderingMethodMenu = new GenericMenu(); foreach (var renderingMethod in allRenderingMethods) { _addRenderingMethodMenu.AddItem(new GUIContent(LeapGraphicTagAttribute.GetTagName(renderingMethod)), false, () => { serializedObject.ApplyModifiedProperties(); Undo.RecordObject(_renderer, "Changed rendering method"); EditorUtility.SetDirty(_renderer); _renderer.editor.ChangeRenderingMethodOfSelectedGroup(renderingMethod, addFeatures: false); serializedObject.Update(); _renderer.editor.ScheduleRebuild(); _serializedObject.SetIsDifferentCacheDirty(); }); } var allFeatures = allTypes.Query(). Where(t => !t.IsAbstract && !t.IsGenericType && t.IsSubclassOf(typeof(LeapGraphicFeatureBase))).ToList(); allFeatures.Sort((a, b) => { var tagA = LeapGraphicTagAttribute.GetTag(a); var tagB = LeapGraphicTagAttribute.GetTag(b); var orderA = tagA == null ? 0 : tagA.order; var orderB = tagB == null ? 0 : tagB.order; return(orderA - orderB); }); _addFeatureMenu = new GenericMenu(); foreach (var item in allFeatures.Query().WithPrevious(includeStart: true)) { var tag = LeapGraphicTagAttribute.GetTag(item.value); var order = tag == null ? 0 : tag.order; if (item.hasPrev) { var prevTag = LeapGraphicTagAttribute.GetTag(item.prev); var prevOrder = prevTag == null ? 0 : prevTag.order; if ((prevOrder / 100) != (order / 100)) { _addFeatureMenu.AddSeparator(""); } } _addFeatureMenu.AddItem(new GUIContent(tag.name), false, () => { if (item.value.ImplementsInterface(typeof(ICustomChannelFeature)) && LeapGraphicPreferences.promptWhenAddCustomChannel) { int result = EditorUtility.DisplayDialogComplex("Adding Custom Channel", "Custom channels can only be utilized by writing custom shaders, are you sure you want to continue?", "Add it", "Cancel", "Add it from now on"); switch (result) { case 0: break; case 1: return; case 2: LeapGraphicPreferences.promptWhenAddCustomChannel = false; break; } } serializedObject.ApplyModifiedProperties(); Undo.RecordObject(_renderer, "Added feature"); EditorUtility.SetDirty(_renderer); _renderer.editor.AddFeatureToSelectedGroup(item.value); _serializedObject.Update(); _serializedObject.SetIsDifferentCacheDirty(); }); } }
public EditorApi(LeapGraphicRenderer renderer) { _renderer = renderer; InternalUtility.OnAnySave += onAnySave; }