private void CreateContextMenu() { contextMenu = new GenericMenu(); contextMenu.AddItem(JuicyEditorUtils.GetContent("Reset"), false, ResetFeedback); contextMenu.AddSeparator(string.Empty); contextMenu.AddItem(JuicyEditorUtils.GetContent("Copy"), false, CopyFeedback); if (FeedbackListCopyHelper.HasCopy) { contextMenu.AddItem(JuicyEditorUtils.GetContent("Paste"), false, PasteFeedback); } else { contextMenu.AddDisabledItem(JuicyEditorUtils.GetContent("Paste")); } contextMenu.AddSeparator(string.Empty); contextMenu.AddItem(JuicyEditorUtils.GetContent("Debug"), debugView.boolValue, DebugView); }
public static void Paste(SerializedProperty feedbacks, Action removeAll, Func <Type, JuicyFeedbackBase> addAction) { if (feedbacks == null) { return; } removeAll.Invoke(); foreach (FeedbackCopyData data in CopiedFeedbacks) { addAction.Invoke(data.type); } for (int i = 0; i < feedbacks.arraySize; i++) { SerializedProperty feedback = feedbacks.GetArrayElementAtIndex(i); JuicyFeedbackBase f = feedback.objectReferenceValue as JuicyFeedbackBase; FeedbackCopyData data = CopiedFeedbacks[i]; JuicyEditorUtils.PasteFeedback(feedback, f); foreach (var property in data.properties) { SerializedObject obj = new SerializedObject(f); obj.CopyFromSerializedProperty(property); obj.ApplyModifiedProperties(); } } CopiedFeedbacks.Clear(); }
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 Initialize(SerializedProperty property) { if (curve != null) { return; } string path = JuicyEditorUtils.GetPluginRootPath() + "Editor/EasingCurves.curves"; CacheProperty(ref curve, property, nameof(curve)); Object presetObject = AssetDatabase .LoadAssetAtPath <Object>(path); presets = new SerializedObject(presetObject) .FindProperty("m_Presets"); curves = new AnimationCurve[presets.arraySize]; names = new string[presets.arraySize]; for (int i = 0; i < presets.arraySize; i++) { SerializedProperty present = presets.GetArrayElementAtIndex(i); names[i] = BuildEaseMenu(present .FindPropertyRelative("m_Name").stringValue); curves[i] = new AnimationCurve(present .FindPropertyRelative("m_Curve").animationCurveValue.keys); } }
private void DrawFeedbackHeader() { feedbackListProp.isExpanded = JuicyEditorUtils.FoldoutHeader(feedbackListProp.isExpanded, $"Feedbacks ({feedbackListProp.arraySize})", () => { GUILayout.Space(8); using (new EditorGUILayout.HorizontalScope(JuicyStyles.RlHeaderBackground)) { GUILayout.Space(37); using (var check = new EditorGUI.ChangeCheckScope()) { toggleAll = GUILayout.Toggle(toggleAll, string.Empty); if (check.changed) { Toggle(); } } GUILayout.Space(18); GUILayout.Label("Type", EditorStyles.boldLabel); GUILayout.Space(27); GUILayout.Label("Description", EditorStyles.boldLabel); GUILayout.FlexibleSpace(); if (EditorGUILayout.DropdownButton(new GUIContent(JuicyStyles.PaneOptionsIcon), FocusType.Passive, JuicyStyles.IconButtonStyle)) { ShowListContextMenu(); } GUILayout.Space(2); } }); }
public override void OnGUI(Rect position) { EditorGUI.LabelField(new Rect(position) { height = EditorGUIUtility.singleLineHeight }, Attribute.Title, JuicyStyles.HeaderStyle); JuicyEditorUtils.DrawLine(position, EditorGUIUtility.singleLineHeight); }
public override void OnInspectorGUI() { serializedObject.Update(); if (timing != null) { timing.isExpanded = JuicyEditorUtils.FoldoutHeader(timing.isExpanded, "Timing", () => { EditorGUILayout.PropertyField(timing); }); } if (ContainsOnlyScriptAndTimingProperty()) { serializedObject.ApplyModifiedProperties(); return; } isExpanded.boolValue = JuicyEditorUtils.FoldoutHeader(isExpanded.boolValue, "Properties", () => { foreach (SerializedProperty child in GetChildren()) { if (FilterProperty(child)) { continue; } if (child.type.Contains("UnityEvent")) { using (new EditorGUILayout.HorizontalScope()) { GUILayout.Space(35); EditorGUILayout.PropertyField(child); } } else { if (SpecialFilterProperty(child)) { SpecialDraw(child); } else { EditorGUILayout.PropertyField(child); } } } // Draw ease always at the end if (ease != null) { EditorGUILayout.PropertyField(ease); } }); serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { serializedObject.Update(); timing.isExpanded = JuicyEditorUtils.FoldoutHeader(timing.isExpanded, "Timing", () => { EditorGUILayout.PropertyField(timing); }); isExpanded.boolValue = JuicyEditorUtils.FoldoutHeader(isExpanded.boolValue, "Properties", DrawProperties); serializedObject.ApplyModifiedProperties(); }
private void CreateAddFeedbackMenu() { addFeedbackMenu = new GenericMenu(); types = JuicyEditorUtils.GetAllSubtypes(typeof(JuicyFeedbackBase)); foreach (var type in types) { addFeedbackMenu.AddItem(JuicyEditorUtils.GetContent( FeedbackAttribute.GetPath(type) ), false, () => { AddFeedback(type); serializedObject.ApplyModifiedProperties(); }); } }
private void ShowElementContextMenu(int index) { SerializedProperty property = feedbackListProp.GetArrayElementAtIndex(index); JuicyFeedbackBase feedback = property.objectReferenceValue as JuicyFeedbackBase; var itemMenu = new GenericMenu(); itemMenu.AddItem(JuicyEditorUtils.GetContent("Remove|Remove feedback from List"), false, () => Remove(property, feedback, index)); itemMenu.AddItem(JuicyEditorUtils.GetContent("Reset|Resets the feedback to default"), false, () => ResetEditor(property, feedback)); itemMenu.AddSeparator(string.Empty); itemMenu.AddItem(JuicyEditorUtils.GetContent("Copy|Copy feedback values"), false, () => { FeedbackCopyHelper.CopyReference(feedback); JuicyEditorUtils.CopyFeedback(property, feedback); }); if (FeedbackCopyHelper.HasCopy) { itemMenu.AddItem(JuicyEditorUtils.GetContent("Paste|Paste feedback values"), false, () => JuicyEditorUtils.PasteFeedback(property, feedback)); itemMenu.AddItem(JuicyEditorUtils.GetContent("Paste as new|Paste copied feedback values as a new feedback"), false, PasteAsNew); itemMenu.AddItem(JuicyEditorUtils.GetContent("Paste Reference|Paste feedback reference"), false, () => { FeedbackCopyHelper.PasteReference(juicyFeedbackList.feedbackList); }); } else { itemMenu.AddDisabledItem(JuicyEditorUtils.GetContent("Paste")); } Rect menuRect = new Rect(Event.current.mousePosition, Vector2.zero); menuRect.y -= 10; itemMenu.DropDown(menuRect); }
private void CreateContextMenu() { var e = Event.current; Vector2 position = e.mousePosition; var menu = new GenericMenu(); for (int i = 0; i < names.Length; i++) { string name = names[i]; menu.AddItem( JuicyEditorUtils.GetContent(name), false, ChangeCurve, i); } menu.DropDown(new Rect(position, Vector2.zero)); e.Use(); }
private void CreateContextMenu() { var e = Event.current; Vector2 position = e.mousePosition; var menu = new GenericMenu(); bool isActive = targetIsSelf.boolValue; menu.AddItem( JuicyEditorUtils.GetContent("This"), isActive, SetTargetIsSelf, true); menu.AddItem( JuicyEditorUtils.GetContent("Other"), !isActive, SetTargetIsSelf, false); menu.DropDown(new Rect(position, Vector2.zero)); }
static JuicyStyles() { IconButtonStyle = new GUIStyle(GUI.skin.FindStyle("IconButton") ?? EditorGUIUtility .GetBuiltinSkin(EditorSkin.Inspector) .FindStyle("IconButton")) { margin = new RectOffset(0, 0, 2, 0) }; FeedbackEditorStyle = new GUIStyle { margin = new RectOffset(0, 17, 5, 5) }; BoxStyle = new GUIStyle(EditorStyles.toolbar) { padding = new RectOffset(3, 3, 4, 4), margin = new RectOffset(0, 3, 0, 0), stretchHeight = true, stretchWidth = true, fixedHeight = 0.0f }; FeedbackItemBoxStyle = new GUIStyle(EditorStyles.toolbar) { padding = new RectOffset(3, 3, 4, 4), margin = new RectOffset(0, 0, 0, 0), stretchHeight = true, stretchWidth = true, fixedHeight = 0.0f, }; IconJuicyStyle = new GUIStyle { margin = new RectOffset(10, 0, 0, 0), fixedWidth = EditorGUIUtility.singleLineHeight + 10, fixedHeight = EditorGUIUtility.singleLineHeight }; FeedbackIconStyle = new GUIStyle { margin = new RectOffset(0, 0, 4, 0), fixedWidth = EditorGUIUtility.singleLineHeight - 5, fixedHeight = EditorGUIUtility.singleLineHeight - 5, }; FoldoutStyle = new GUIStyle(EditorStyles.foldout) { //alignment = TextAnchor.MiddleLeft, wordWrap = true, //fontStyle = FontStyle.Bold, fontSize = 12 }; SmallToggle = new GUIStyle("ShurikenToggle") { fixedWidth = EditorGUIUtility.singleLineHeight, fixedHeight = EditorGUIUtility.singleLineHeight }; HeaderStyle = new GUIStyle(EditorStyles.boldLabel); HeaderToggleStyle = new GUIStyle(EditorStyles.toggle) { fontStyle = FontStyle.Bold }; HeaderFoldout = new GUIStyle(EditorStyles.foldoutHeader) { margin = new RectOffset(16, 7, 0, 0), fixedHeight = 25, fontSize = 11, fontStyle = FontStyle.Bold }; ToggleGroupStyle = new GUIStyle(EditorStyles.foldoutHeader) { fontSize = 10, fontStyle = FontStyle.Normal, }; ToggleGroupLabelStyle = new GUIStyle(EditorStyles.boldLabel) { padding = new RectOffset(-10, 0, 0, 0), fontSize = 10 }; ToggleGroupLabelSelectedStyle = new GUIStyle(ToggleGroupLabelStyle) { normal = { textColor = EditorStyles.linkLabel.normal.textColor }, }; IconJuicy = AssetDatabase .LoadAssetAtPath <Texture>(JuicyEditorUtils.GetPluginRootPath() + "Images/img_juicy.png"); DefaultFeedbackIcon = AssetDatabase .LoadAssetAtPath <Texture>(JuicyEditorUtils.GetPluginRootPath() + $"Images/img_feedback_default.png"); InvalidIcon = EditorGUIUtility.IconContent("console.erroricon.sml").image; ValidIcon = EditorGUIUtility.IconContent("Collab").image; }
private void DrawFeedbackElement(int index) { SerializedProperty property = feedbackListProp.GetArrayElementAtIndex(index); JuicyFeedbackBase feedback = property.objectReferenceValue as JuicyFeedbackBase; if (feedback == null) { return; } Undo.RecordObject(feedback, "Modified Feedback"); PrefabUtility.RecordPrefabInstancePropertyModifications(feedback); Rect contentRect; using (new EditorGUILayout.VerticalScope()) { string label = feedback.label; GUILayout.Space(3); property.isExpanded = JuicyEditorUtils.DrawHeader( index, ref label, property.isExpanded, ref feedback.isActive, feedback, out contentRect, showElementContextMenu, currentDraggedIndex); GUILayout.Space(3); feedback.label = label; using (new EditorGUI.DisabledScope(!feedback.enabled)) { DrawEditor(feedback, property.isExpanded); } } var e = Event.current; if (contentRect.Contains(e.mousePosition)) { if (currentDraggedIndex != index) { currentHoveredIndex = index; if (currentDraggedIndex != -1) { property.isExpanded = false; } } EventType eventType = e.type; switch (eventType) { case EventType.MouseDown when currentDraggedIndex == -1: currentDraggedIndex = index; property.isExpanded = false; e.Use(); break; case EventType.MouseUp: ReorderDraggedElement(); currentDraggedIndex = -1; currentHoveredIndex = -1; e.Use(); break; } } }