/// <summary> /// Helper method to only support the first element in a list. /// </summary> public static void OnlySupportFirstFeature <T>(List <SupportInfo> info) { for (int i = 1; i < info.Count; i++) { info[i] = SupportInfo.Error("Only the first " + LeapGraphicTagAttribute.GetTagName(typeof(T)) + " is supported."); } }
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); }
private void drawFeatureCallback(Rect rect, int index, bool isActive, bool isFocused) { var featureProperty = _cachedPropertyList[index]; rect = rect.SingleLine(); string featureName = LeapGraphicTagAttribute.GetTagName(featureProperty.type); int lastIndexOf = featureName.LastIndexOf('/'); if (lastIndexOf >= 0) { featureName = featureName.Substring(lastIndexOf + 1); } GUIContent featureLabel = new GUIContent(featureName); Color originalColor = GUI.color; if (!EditorApplication.isPlaying && index < _supportInfo.arraySize) { var supportInfo = _supportInfo.GetArrayElementAtIndex(index); var supportProperty = supportInfo.FindPropertyRelative("support"); var messageProperty = supportInfo.FindPropertyRelative("message"); switch ((SupportType)supportProperty.intValue) { case SupportType.Warning: GUI.color = Color.yellow; featureLabel.tooltip = messageProperty.stringValue; break; case SupportType.Error: GUI.color = Color.red; featureLabel.tooltip = messageProperty.stringValue; break; } } Vector2 size = EditorStyles.label.CalcSize(featureLabel); Rect labelRect = rect; labelRect.width = size.x; GUI.Box(labelRect, ""); EditorGUI.LabelField(labelRect, featureLabel); GUI.color = originalColor; rect = rect.NextLine().Indent(); EditorGUI.PropertyField(rect, featureProperty, includeChildren: true); }
protected override void OnEnable() { base.OnEnable(); if (target == null) { return; } _renderer = target as LeapGraphicRenderer; _selectedGroup = serializedObject.FindProperty("_selectedGroup"); var allTypes = Assembly.GetAssembly(typeof(LeapGraphicRenderer)).GetTypes(); var allRenderingMethods = allTypes.Query(). Where(t => !t.IsAbstract && !t.IsGenericType && t.IsSubclassOf(typeof(LeapRenderingMethod))); _addGroupMenu = new GenericMenu(); foreach (var renderingMethod in allRenderingMethods) { _addGroupMenu.AddItem(new GUIContent(LeapGraphicTagAttribute.GetTagName(renderingMethod)), false, () => { serializedObject.ApplyModifiedProperties(); Undo.RecordObject(_renderer, "Created group"); EditorUtility.SetDirty(_renderer); _renderer.editor.CreateGroup(renderingMethod); serializedObject.Update(); updateGroupProperty(); }); } _groupEditor = new LeapGuiGroupEditor(target, serializedObject); }
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(); }); } }
protected void drawFeatureData(LeapGraphicGroup sharedGroup) { using (new ProfilerSample("Draw Leap Gui Graphic Editor")) { if (targets.Length == 0) { return; } var mainGraphic = targets[0]; if (mainGraphic.featureData.Count == 0) { return; } if (mainGraphic.attachedGroup != null) { SpriteAtlasUtil.ShowInvalidSpriteWarning(mainGraphic.attachedGroup.features); } int maxGraphics = LeapGraphicPreferences.graphicMax; if (targets.Query().Any(e => e.attachedGroup != null && e.attachedGroup.graphics.IndexOf(e) >= maxGraphics)) { string noun = targets.Length == 1 ? "This graphic" : "Some of these graphics"; string rendererName = targets.Length == 1 ? "its renderer" : "their renderers"; EditorGUILayout.HelpBox(noun + " may not be properly displayed because there are too many graphics on " + rendererName + ". " + "Either lower the number of graphics or increase the maximum graphic count by visiting " + "Edit->Preferences.", MessageType.Warning); } //If we are not all attached to the same group we cannot show features if (!targets.Query().Select(g => g.attachedGroup).AllEqual()) { return; } EditorGUILayout.Space(); using (new GUILayout.HorizontalScope()) { EditorGUILayout.LabelField("Feature Data: ", EditorStyles.boldLabel); if (sharedGroup != null) { var meshRendering = sharedGroup.renderingMethod as LeapMesherBase; if (meshRendering != null && meshRendering.IsAtlasDirty && !EditorApplication.isPlaying) { if (GUILayout.Button("Refresh Atlas", GUILayout.MaxHeight(EditorGUIUtility.singleLineHeight))) { meshRendering.RebuildAtlas(new ProgressBar()); sharedGroup.renderer.editor.ScheduleRebuild(); } } } } for (int i = 0; i < _featureTable.arraySize; i++) { var idIndex = _featureTable.GetArrayElementAtIndex(i); var dataProp = MultiTypedListUtil.GetReferenceProperty(_featureList, idIndex); EditorGUILayout.LabelField(LeapGraphicTagAttribute.GetTagName(dataProp.type)); if (mainGraphic.attachedGroup != null) { currentFeature = mainGraphic.attachedGroup.features[i]; } EditorGUI.indentLevel++; EditorGUILayout.PropertyField(dataProp, includeChildren: true); EditorGUI.indentLevel--; currentFeature = null; } serializedObject.ApplyModifiedProperties(); } }