private void RemoveFeedbackItems()
        {
            for (int i = 0; i < feedbackListProp.arraySize; i++)
            {
                SerializedProperty item = feedbackListProp.GetArrayElementAtIndex(i);

                JuicyFeedbackBase feedback = item.objectReferenceValue as JuicyFeedbackBase;
                if (feedback == null)
                {
                    continue;
                }

                Undo.DestroyObjectImmediate(feedback);

                if (item.objectReferenceValue != null)
                {
                    item.objectReferenceValue = null;
                }

                feedbackListProp.DeleteArrayElementAtIndex(i);
            }

            for (int i = feedbackListProp.arraySize - 1; i >= 0; i--)
            {
                if (feedbackListProp.GetArrayElementAtIndex(i).objectReferenceValue == null)
                {
                    feedbackListProp.DeleteArrayElementAtIndex(i);
                }
            }

            juicyFeedbackList.feedbackList.Clear();
        }
Exemple #2
0
 public static void PasteReference(List <JuicyFeedbackBase> list)
 {
     Properties.Clear();
     list.Add(copyReference);
     copyReference.referenceCount++;
     copyReference = null;
 }
        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 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);
        }
Exemple #5
0
        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();
        }
Exemple #6
0
        public static void PasteFeedback(SerializedProperty property,
                                         JuicyFeedbackBase feedback)
        {
            SerializedObject serialized = new SerializedObject(feedback);

            FeedbackCopyHelper.Paste(serialized);
            serialized.ApplyModifiedProperties();
        }
Exemple #7
0
        public static void RemoveCopyReference(
            JuicyFeedbackBase feedback,
            List <JuicyFeedbackBase> feedbackList)
        {
            if (feedback.referenceCount > 0)
            {
                feedback.referenceCount--;
            }

            feedbackList.Remove(feedback);
        }
        private void PasteAsNew()
        {
            JuicyFeedbackBase newFeedback = AddFeedback(FeedbackCopyHelper.Type);

            SerializedObject obj = new SerializedObject(newFeedback);

            obj.Update();
            FeedbackCopyHelper.Paste(obj);
            obj.ApplyModifiedProperties();

            serializedObject.ApplyModifiedProperties();
        }
        private void HandleElementHiding()
        {
            for (int i = 0; i < feedbackListProp.arraySize; i++)
            {
                SerializedProperty property = feedbackListProp.GetArrayElementAtIndex(i);
                JuicyFeedbackBase  feedback = property.objectReferenceValue as JuicyFeedbackBase;

                if (feedback == null)
                {
                    continue;
                }

                feedback.hideFlags = debugView.boolValue ? HideFlags.None : HideFlags.HideInInspector;
            }
        }
        private void Toggle()
        {
            for (int i = 0; i < feedbackListProp.arraySize; i++)
            {
                JuicyFeedbackBase feedback = feedbackListProp.GetArrayElementAtIndex(i)
                                             .objectReferenceValue as JuicyFeedbackBase;

                if (feedback != null)
                {
                    feedback.isActive = toggleAll;
                }
            }

            serializedObject.ApplyModifiedProperties();
        }
Exemple #11
0
        public static void Copy(SerializedObject serializedObject)
        {
            copyReference = (JuicyFeedbackBase)serializedObject.targetObject;

            Type = serializedObject.targetObject.GetType();
            Properties.Clear();

            SerializedProperty property = serializedObject.GetIterator();

            property.Next(true);

            do
            {
                CacheCopy(property);
            } while (property.Next(false));
        }
        private void AddEditor(JuicyFeedbackBase feedback)
        {
            if (feedback == null)
            {
                return;
            }

            if (editors.ContainsKey(feedback))
            {
                return;
            }

            Editor editor = null;

            CreateCachedEditor(feedback, null, ref editor);

            editors.Add(feedback, editor);
        }
        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 Remove(SerializedProperty property,
                            JuicyFeedbackBase feedback, int index)
        {
            /*if (EditorUtility.DisplayDialog(
             *  $"Remove {label} Feedback",
             *  $"Do you really want to remove the {label} Feedback?",
             *  "Yes", "No")) {
             * }*/

            if (feedback.referenceCount == 0)
            {
                RemoveFeedback(property, feedback, index);
            }
            else
            {
                FeedbackCopyHelper.RemoveCopyReference(feedback,
                                                       juicyFeedbackList.feedbackList);
            }
        }
        private void RemoveFeedback(SerializedProperty property, JuicyFeedbackBase feedback, int index)
        {
            Undo.DestroyObjectImmediate(feedback);

            if (property.objectReferenceValue == null)
            {
                feedbackListProp.DeleteArrayElementAtIndex(index);
                juicyFeedbackList.Remove(feedback);
            }

            for (int i = feedbackListProp.arraySize - 1; i >= 0; i--)
            {
                if (feedbackListProp.GetArrayElementAtIndex(i).objectReferenceValue == null)
                {
                    feedbackListProp.DeleteArrayElementAtIndex(i);
                }
            }

            editors.Remove(feedback);
        }
        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();
                }
            }
        }
Exemple #17
0
 public static void CopyFeedback(SerializedProperty property,
                                 JuicyFeedbackBase feedback)
 {
     FeedbackCopyHelper.Copy(new SerializedObject(feedback));
 }
Exemple #18
0
        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);
        }
Exemple #19
0
 /// <summary>
 /// Removes a feedback from the list of feedbacks
 /// </summary>
 /// <param name="feedback"></param>
 public void Remove(JuicyFeedbackBase feedback)
 {
     feedbackList.Remove(feedback);
 }
Exemple #20
0
 public static void CopyReference(JuicyFeedbackBase feedback)
 {
     copyReference = feedback;
 }
        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;
                }
            }
        }