private JuicyFeedbackBase AddFeedback(Type type) { GameObject gameObject = ((JuicyFeedbackList)target).gameObject; JuicyFeedbackBase newFeedback = Undo.AddComponent(gameObject, type) as JuicyFeedbackBase; if (newFeedback == null) { return(null); } newFeedback.label = FeedbackAttribute.GetName(newFeedback.GetType()); newFeedback.hideFlags = debugView.boolValue ? HideFlags.None : HideFlags.HideInInspector; AddEditor(newFeedback); feedbackListProp.arraySize++; feedbackListProp .GetArrayElementAtIndex(feedbackListProp.arraySize - 1) .objectReferenceValue = newFeedback; return(newFeedback); }
private void ResetEditor(SerializedProperty property, JuicyFeedbackBase feedback) { int referenceCount = feedback.referenceCount; if (PrefabUtility.IsPartOfAnyPrefab(property.objectReferenceValue)) { PrefabUtility.RevertObjectOverride(feedback, InteractionMode.UserAction); feedback.referenceCount = referenceCount; return; } // Create a temporary feedback and copy the values JuicyFeedbackBase tmpFeedback = AddFeedback(feedback.GetType()); int index = feedbackListProp.arraySize - 1; tmpFeedback.referenceCount = referenceCount; SerializedProperty tmp = feedbackListProp .GetArrayElementAtIndex(index); JuicyEditorUtils.CopyFeedback(tmp, tmpFeedback); JuicyEditorUtils.PasteFeedback(property, feedback); FeedbackCopyHelper.ClearCache(); RemoveFeedback(tmp, tmpFeedback, index); serializedObject.ApplyModifiedProperties(); }
private void DrawEditor(JuicyFeedbackBase feedback, bool isExpanded) { if (!isExpanded) { return; } using (new EditorGUI.DisabledScope(!feedback.isActive)) { using (new EditorGUILayout.VerticalScope(JuicyStyles.FeedbackEditorStyle)) { if (!editors.ContainsKey(feedback)) { AddEditor(feedback); } Editor editor = editors[feedback]; CreateCachedEditor(feedback, feedback.GetType(), ref editor); editor.OnInspectorGUI(); } } }
internal static bool DrawHeader( int index, ref string title, bool isExpanded, ref bool isActive, JuicyFeedbackBase target, out Rect contentRect, Action <int> showMenu, int draggedIndex) { var position = GUILayoutUtility.GetRect(1f, EditorGUIUtility.singleLineHeight); position.x += 5; if (index == draggedIndex) { position.y = Event.current.mousePosition.y; } Texture2D menuIcon = JuicyStyles.PaneOptionsIcon; Rect dragRect = new Rect(position) { y = position.y + menuIcon.height / 2f - 1, width = 12, height = 12 }; Rect foldoutRect = new Rect(position) { x = dragRect.x + dragRect.width + 4, width = 16 }; Rect enabledRect = new Rect(position) { x = foldoutRect.x + foldoutRect.width, width = 16 }; Rect textureRect = new Rect(position) { x = enabledRect.x + enabledRect.width + 4, y = position.y + 2, width = 14, height = 14 }; Rect labelRect = new Rect(position) { x = textureRect.x + textureRect.width + 6, y = position.y + 1, width = 60, }; Rect menuRect = new Rect(position) { x = position.width, y = position.y + 1, width = menuIcon.width }; Rect textfieldRect = new Rect(position) { xMin = labelRect.x + labelRect.width, xMax = menuRect.x - 4 }; contentRect = position; contentRect.x = 23f; contentRect.width -= 23f; // Background //EditorGUI.DrawRect(labelRect, Color.red); //EditorGUI.DrawRect(contentRect, new Color(1,1,1, 0.5f)); if (Event.current.type == EventType.Repaint) { JuicyStyles.RlDraggingHandle.Draw(dragRect, false, false, false, false); } using (new EditorGUI.DisabledScope(!isActive)) { Texture t = GetIcon(FeedbackAttribute.GetIcon(target.GetType())); if (t != null) { GUI.DrawTexture(textureRect, t, ScaleMode.ScaleAndCrop); } bool isReference = target.referenceCount > 0; EditorGUI.LabelField(labelRect, new GUIContent( $"{FeedbackAttribute.GetName(target.GetType())} {(isReference ? "*" : string.Empty)}", $"{(isReference ? "Is a reference" : "")}"), new GUIStyle(EditorStyles.label) { padding = new RectOffset(0, 0, 0, 3) }); Color c = GUI.backgroundColor; if (isReference) { GUI.backgroundColor = JuicyStyles.ReferenceColor; } title = EditorGUI.TextField(textfieldRect, GUIContent.none, title); GUI.backgroundColor = c; } isExpanded = GUI.Toggle(foldoutRect, isExpanded, GUIContent.none, EditorStyles.foldout); isActive = GUI.Toggle(enabledRect, isActive, GUIContent.none); if (EditorGUI.DropdownButton(menuRect, new GUIContent(JuicyStyles.PaneOptionsIcon), FocusType.Passive, JuicyStyles.IconButtonStyle)) { if (Event.current.type != EventType.Repaint) { showMenu.Invoke(index); Event.current.Use(); } } return(isExpanded); }