Esempio n. 1
0
 public void DrawInspector(SerializedProperty currentProperty, MMF_Feedback feedback)
 {
     Initialization(currentProperty, feedback, _expandGroupInspectors);
     if (!DrawBase(currentProperty, feedback))
     {
         DrawContainer(feedback);
         DrawContents(feedback);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Adds the specified MMF_Feedback to the player
 /// </summary>
 /// <param name="newFeedback"></param>
 public virtual void AddFeedback(MMF_Feedback newFeedback)
 {
     InitializeList();
     newFeedback.Owner    = this;
     newFeedback.UniqueID = Guid.NewGuid().GetHashCode();
     FeedbacksList.Add(newFeedback);
     newFeedback.CacheRequiresSetup();
     newFeedback.InitializeCustomAttributes();
 }
Esempio n. 3
0
        static public void Copy(MMF_Feedback feedback)
        {
            Type         feedbackType = feedback.GetType();
            MMF_Feedback newFeedback  = (MMF_Feedback)Activator.CreateInstance(feedbackType);

            EditorUtility.CopySerializedManagedFieldsOnly(feedback, newFeedback);
            CopiedFeedbacks.Clear();
            CopiedFeedbacks.Add(newFeedback);
        }
Esempio n. 4
0
 static public void CopyAll(MMF_Player sourceFeedbacks)
 {
     CopiedFeedbacks.Clear();
     foreach (MMF_Feedback feedback in sourceFeedbacks.FeedbacksList)
     {
         Type         feedbackType = feedback.GetType();
         MMF_Feedback newFeedback  = (MMF_Feedback)Activator.CreateInstance(feedbackType);
         EditorUtility.CopySerializedManagedFieldsOnly(feedback, newFeedback);
         CopiedFeedbacks.Add(newFeedback);
     }
 }
Esempio n. 5
0
 protected virtual bool DrawBase(SerializedProperty currentProperty, MMF_Feedback feedback)
 {
     if (_shouldDrawBase || !feedback.DrawGroupInspectors)
     {
         DrawNoGroupInspector(currentProperty, feedback);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Adds a feedback of the specified type to the player
        /// </summary>
        /// <param name="feedbackType"></param>
        /// <returns></returns>
        public new MMF_Feedback AddFeedback(System.Type feedbackType)
        {
            InitializeList();
            MMF_Feedback newFeedback = (MMF_Feedback)Activator.CreateInstance(feedbackType);

            newFeedback.Label    = FeedbackPathAttribute.GetFeedbackDefaultName(feedbackType);
            newFeedback.Owner    = this;
            newFeedback.UniqueID = Guid.NewGuid().GetHashCode();
            FeedbacksList.Add(newFeedback);
            newFeedback.InitializeCustomAttributes();
            newFeedback.CacheRequiresSetup();
            return(newFeedback);
        }
Esempio n. 7
0
        protected virtual void DrawContainer(MMF_Feedback feedback)
        {
            if (PropertiesList.Count == 0)
            {
                return;
            }

            foreach (KeyValuePair <string, MMFInspectorGroupData> pair in GroupData)
            {
                DrawVerticalLayout(() => DrawGroup(pair.Value, feedback), MMF_FeedbackInspectorStyle.ContainerStyle);
                EditorGUI.indentLevel = 0;
            }
        }
Esempio n. 8
0
 /// <summary>
 /// This will return true if the conditions defined in the specified feedback's Timing section allow it to play in the current play direction of this MMFeedbacks
 /// </summary>
 /// <param name="feedback"></param>
 /// <returns></returns>
 protected bool FeedbackCanPlay(MMF_Feedback feedback)
 {
     if (feedback.Timing.MMFeedbacksDirectionCondition == MMFeedbackTiming.MMFeedbacksDirectionConditions.Always)
     {
         return(true);
     }
     else if (((Direction == Directions.TopToBottom) && (feedback.Timing.MMFeedbacksDirectionCondition == MMFeedbackTiming.MMFeedbacksDirectionConditions.OnlyWhenForwards)) ||
              ((Direction == Directions.BottomToTop) && (feedback.Timing.MMFeedbacksDirectionCondition == MMFeedbackTiming.MMFeedbacksDirectionConditions.OnlyWhenBackwards)))
     {
         return(true);
     }
     return(false);
 }
Esempio n. 9
0
        public void DrawNoGroupInspector(SerializedProperty currentProperty, MMF_Feedback feedback)
        {
            SerializedProperty endProp = currentProperty.GetEndProperty();

            while (currentProperty.NextVisible(true) && !EqualContents(endProp, currentProperty))
            {
                if (currentProperty.depth <= 2)
                {
                    if (!DrawCustomInspectors(currentProperty, feedback))
                    {
                        EditorGUILayout.PropertyField(currentProperty, true);
                    }
                }
            }
        }
        public static int GetFieldInfo(MMF_Feedback target, out List <FieldInfo> fieldInfoList)
        {
            Type targetType         = target.GetType();
            int  targetTypeHashCode = targetType.GetHashCode();

            if (!FieldInfoList.TryGetValue(targetTypeHashCode, out fieldInfoList))
            {
                IList <Type> typeTree = targetType.GetBaseTypes();
                fieldInfoList = target.GetType().GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.NonPublic)
                                .OrderByDescending(x => typeTree.IndexOf(x.DeclaringType))
                                .ToList();
                FieldInfoList.Add(targetTypeHashCode, fieldInfoList);
            }

            return(fieldInfoList.Count);
        }
Esempio n. 11
0
        private bool DrawCustomInspectors(SerializedProperty currentProperty, MMF_Feedback feedback)
        {
            if (feedback.HasCustomInspectors)
            {
                switch (currentProperty.type)
                {
                case "MMF_Button":
                    MMF_Button myButton = (MMF_Button)(currentProperty.MMFGetObjectValue());
                    if (GUILayout.Button(myButton.ButtonText))
                    {
                        myButton.TargetMethod();
                    }
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 12
0
        protected virtual void DrawContents(MMF_Feedback feedback)
        {
            if (PropertiesList.Count == 0)
            {
                return;
            }

            EditorGUILayout.Space();
            for (int i = 1; i < PropertiesList.Count; i++)
            {
                if (_hasMMHiddenProperties && (!_mmHiddenPropertiesToHide.Contains(PropertiesList[i].name)))
                {
                    if (!DrawCustomInspectors(PropertiesList[i], feedback))
                    {
                        EditorGUILayout.PropertyField(PropertiesList[i], true);
                    }
                }
            }
        }
Esempio n. 13
0
        public virtual void Initialization(SerializedProperty currentProperty, MMF_Feedback feedback, bool expandGroupInspectors)
        {
            if (DrawerInitialized)
            {
                return;
            }

            _expandGroupInspectors = expandGroupInspectors;
            _currentProperty       = currentProperty;
            _feedback = feedback;

            List <FieldInfo>           fieldInfoList;
            MMFInspectorGroupAttribute previousGroupAttribute = default;
            int fieldInfoLength = MMF_FieldInfo.GetFieldInfo(feedback, out fieldInfoList);

            for (int i = 0; i < fieldInfoLength; i++)
            {
                MMFInspectorGroupAttribute group = Attribute.GetCustomAttribute(fieldInfoList[i], typeof(MMFInspectorGroupAttribute)) as MMFInspectorGroupAttribute;

                MMFInspectorGroupData groupData;
                if (group == null)
                {
                    if (previousGroupAttribute != null && previousGroupAttribute.GroupAllFieldsUntilNextGroupAttribute)
                    {
                        _shouldDrawBase = false;
                        if (!GroupData.TryGetValue(previousGroupAttribute.GroupName, out groupData))
                        {
                            GroupData.Add(previousGroupAttribute.GroupName, new MMFInspectorGroupData
                            {
                                GroupAttribute = previousGroupAttribute,
                                GroupHashSet   = new HashSet <string> {
                                    fieldInfoList[i].Name
                                },
                                GroupColor = MMFeedbacksColors.GetColorAt(previousGroupAttribute.GroupColorIndex)
                            });
                        }
                        else
                        {
                            groupData.GroupColor = MMFeedbacksColors.GetColorAt(previousGroupAttribute.GroupColorIndex);
                            groupData.GroupHashSet.Add(fieldInfoList[i].Name);
                        }
                    }

                    continue;
                }

                previousGroupAttribute = group;

                if (!GroupData.TryGetValue(group.GroupName, out groupData))
                {
                    bool fallbackOpenState = _expandGroupInspectors;
                    if (group.ClosedByDefault)
                    {
                        fallbackOpenState = false;
                    }
                    bool groupIsOpen = EditorPrefs.GetBool(string.Format($"{group.GroupName}{fieldInfoList[i].Name}{feedback.UniqueID}"), fallbackOpenState);
                    GroupData.Add(group.GroupName, new MMFInspectorGroupData
                    {
                        GroupAttribute = group,
                        GroupColor     = MMFeedbacksColors.GetColorAt(previousGroupAttribute.GroupColorIndex),
                        GroupHashSet   = new HashSet <string> {
                            fieldInfoList[i].Name
                        }, GroupIsOpen = groupIsOpen
                    });
                }
                else
                {
                    groupData.GroupHashSet.Add(fieldInfoList[i].Name);
                    groupData.GroupColor = MMFeedbacksColors.GetColorAt(previousGroupAttribute.GroupColorIndex);
                }
            }


            if (currentProperty.NextVisible(true))
            {
                do
                {
                    FillPropertiesList(currentProperty);
                } while (currentProperty.NextVisible(false));
            }

            DrawerInitialized = true;
        }
Esempio n. 14
0
        protected virtual void DrawGroup(MMFInspectorGroupData groupData, MMF_Feedback feedback)
        {
            _verticalGroup = EditorGUILayout.BeginVertical();

            // we draw a colored line on the left
            _leftBorderRect.x      = _verticalGroup.xMin + 5;
            _leftBorderRect.y      = _verticalGroup.yMin - 0;
            _leftBorderRect.width  = 3f;
            _leftBorderRect.height = _verticalGroup.height + 0;
            _leftBorderRect.xMin   = 15f;
            _leftBorderRect.xMax   = 18f;
            EditorGUI.DrawRect(_leftBorderRect, groupData.GroupColor);

            if (groupData.GroupAttribute.RequiresSetup && feedback.RequiresSetup)
            {
                // we draw a warning sign if needed
                _widthRect = EditorGUILayout.GetControlRect(false, 0);
                float setupRectWidth = 20f;
                _setupRect.x      = _widthRect.xMax - setupRectWidth;
                _setupRect.y      = _verticalGroup.yMin;
                _setupRect.width  = setupRectWidth;
                _setupRect.height = 17f;

                EditorGUI.LabelField(_setupRect, MMF_PlayerStyling._setupRequiredIcon);
            }

            groupData.GroupIsOpen = EditorGUILayout.Foldout(groupData.GroupIsOpen, groupData.GroupAttribute.GroupName, true, MMF_FeedbackInspectorStyle.GroupStyle);

            if (groupData.GroupIsOpen)
            {
                EditorGUI.indentLevel = 0;

                for (int i = 0; i < groupData.PropertiesList.Count; i++)
                {
                    DrawVerticalLayout(() => DrawChild(i), MMF_FeedbackInspectorStyle.BoxChildStyle);
                }
            }

            EditorGUILayout.EndVertical();

            void DrawChild(int i)
            {
                if (i > groupData.PropertiesList.Count - 1)
                {
                    return;
                }

                if ((_hasMMHiddenProperties) && (_mmHiddenPropertiesToHide.Contains(groupData.PropertiesList[i].name)))
                {
                    return;
                }

                if (!feedback.HasChannel && groupData.PropertiesList[i].name == _channelFieldName)
                {
                    return;
                }

                _groupTitle.text    = ObjectNames.NicifyVariableName(groupData.PropertiesList[i].name);
                _groupTitle.tooltip = groupData.PropertiesList[i].tooltip;

                if (!DrawCustomInspectors(groupData.PropertiesList[i], feedback))
                {
                    EditorGUILayout.PropertyField(groupData.PropertiesList[i], _groupTitle, true);
                }
            }
        }
Esempio n. 15
0
        protected virtual void CopyFromMMFeedbacksToMMF_Player(MMF_Player newPlayer)
        {
            // we copy all its settings
            newPlayer.InitializationMode         = _targetMMFeedbacks.InitializationMode;
            newPlayer.SafeMode                   = _targetMMFeedbacks.SafeMode;
            newPlayer.Direction                  = _targetMMFeedbacks.Direction;
            newPlayer.AutoChangeDirectionOnEnd   = _targetMMFeedbacks.AutoChangeDirectionOnEnd;
            newPlayer.AutoPlayOnStart            = _targetMMFeedbacks.AutoPlayOnStart;
            newPlayer.AutoPlayOnEnable           = _targetMMFeedbacks.AutoPlayOnEnable;
            newPlayer.DurationMultiplier         = _targetMMFeedbacks.DurationMultiplier;
            newPlayer.DisplayFullDurationDetails = _targetMMFeedbacks.DisplayFullDurationDetails;
            newPlayer.CooldownDuration           = _targetMMFeedbacks.CooldownDuration;
            newPlayer.InitialDelay               = _targetMMFeedbacks.InitialDelay;
            newPlayer.CanPlayWhileAlreadyPlaying = _targetMMFeedbacks.CanPlayWhileAlreadyPlaying;
            newPlayer.FeedbacksIntensity         = _targetMMFeedbacks.FeedbacksIntensity;
            newPlayer.Events = _targetMMFeedbacks.Events;

            // we copy all its feedbacks
            SerializedProperty feedbacks = serializedObject.FindProperty("Feedbacks");

            for (int i = 0; i < feedbacks.arraySize; i++)
            {
                MMFeedback oldFeedback = (feedbacks.GetArrayElementAtIndex(i).objectReferenceValue as MMFeedback);

                // we look for a match in the new classes
                Type   oldType     = oldFeedback.GetType();
                string oldTypeName = oldType.Name.ToString();
                string newTypeName = oldTypeName.Replace("MMFeedback", "MMF_");
                Type   newType     = MMFeedbackStaticMethods.MMFGetTypeByName(newTypeName);

                if (newType == null)
                {
                    Debug.Log("<color=red>Couldn't find any MMF_Feedback matching " + oldTypeName + "</color>");
                }
                else
                {
                    MMF_Feedback newFeedback = newPlayer.AddFeedback(newType);

                    List <FieldInfo> oldFieldsList;
                    int oldFieldsListLength = MMF_FieldInfo.GetFieldInfo(oldFeedback, out oldFieldsList);

                    for (int j = 0; j < oldFieldsListLength; j++)
                    {
                        string searchedField = oldFieldsList[j].Name;

                        if (!FeedbackCopy.IgnoreList.Contains(searchedField))
                        {
                            FieldInfo newField = newType.GetField(searchedField);
                            FieldInfo oldField = oldType.GetField(searchedField);

                            if (newField != null)
                            {
                                if (newField.FieldType == oldField.FieldType)
                                {
                                    newField.SetValue(newFeedback, oldField.GetValue(oldFeedback));
                                }
                                else
                                {
                                    if (oldField.FieldType.IsEnum)
                                    {
                                        newField.SetValue(newFeedback, (int)oldField.GetValue(oldFeedback));
                                    }
                                }
                            }
                        }
                    }
                    Debug.Log("Added new feedback of type " + newTypeName);
                }
            }
            newPlayer.RefreshCache();
        }
Esempio n. 16
0
        protected virtual void DrawFeedbackHeader(int i)
        {
            MMF_PlayerStyling.DrawSplitter();
            _feedbackListProperty = _mmfeedbacksList.GetArrayElementAtIndex(i);

            // Retrieve feedback
            _feedbackListFeedback = TargetMmfPlayer.FeedbacksList[i];

            if (_feedbackListFeedback == null)
            {
                return;
            }

            // Draw header
            _feedbackListIsExpanded = _feedbackListProperty.isExpanded;
            _feedbackListLabel      = _feedbackListFeedback.Label;
            _feedbackListPause      = false;

            if (_feedbackListFeedback.Pause != null)
            {
                _feedbackListPause = true;
            }
            if ((_feedbackListFeedback.LooperPause == true) && (Application.isPlaying))
            {
                if ((_feedbackListFeedback as MMF_Looper).InfiniteLoop)
                {
                    _feedbackListLabel = _feedbackListLabel + _infiniteLoopText;
                }
                else
                {
                    _feedbackListLabel = _feedbackListLabel + "[ " + (_feedbackListFeedback as MMF_Looper).NumberOfLoopsLeft + " loops left ] ";
                }
            }

            Rect headerRect = MMF_PlayerStyling.DrawHeader(
                ref _feedbackListIsExpanded,
                ref _feedbackListFeedback.Active,
                _feedbackListLabel,
                _feedbackListFeedback.FeedbackColor,
                (GenericMenu menu) =>
            {
                if (Application.isPlaying)
                {
                    menu.AddItem(_feedbackPlayGUIContent, false, () => PlayFeedback(i));
                }
                else
                {
                    menu.AddDisabledItem(_feedbackPlayGUIContent);
                }
                menu.AddSeparator(null);
                menu.AddItem(_feedbackRemoveGUIContent, false, () => RemoveFeedback(i));
                menu.AddSeparator(null);
                menu.AddItem(_feedbackCopyGUIContent, false, () => CopyFeedback(i));
                if (MMF_PlayerCopy.HasCopy())
                {
                    menu.AddItem(_feedbackPasteGUIContent, false, PasteAsNew);
                }
                else
                {
                    menu.AddDisabledItem(_feedbackPasteGUIContent);
                }
            },
                _feedbackListFeedback.FeedbackStartedAt,
                _feedbackListFeedback.FeedbackDuration,
                _feedbackListFeedback.TotalDuration,
                _feedbackListFeedback.Timing,
                _feedbackListPause,
                _feedbackListFeedback.RequiresSetup,
                _feedbackListFeedback.RequiredTarget,
                _feedbackListFeedback.DisplayColor,
                TargetMmfPlayer
                );

            // Check if we start dragging this feedback

            switch (_currentEvent.type)
            {
            case EventType.MouseDown:
                if (headerRect.Contains(_currentEvent.mousePosition))
                {
                    _draggedStartID = i;
                    _currentEvent.Use();
                }
                break;
            }

            // Draw blue rect if feedback is being dragged

            if (_draggedStartID == i && headerRect != Rect.zero)
            {
                EditorGUI.DrawRect(headerRect, _draggedColor);
            }

            // If hovering at the top of the feedback while dragging one, check where the feedback should be dropped : top or bottom

            if (headerRect.Contains(_currentEvent.mousePosition))
            {
                if (_draggedStartID >= 0)
                {
                    _draggedEndID = i;
                    Rect headerSplit = headerRect;
                    headerSplit.height *= 0.5f;
                    headerSplit.y      += headerSplit.height;
                    if (headerSplit.Contains(_currentEvent.mousePosition))
                    {
                        _draggedEndID = i + 1;
                    }
                }
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Play the selected feedback
        /// </summary>
        protected virtual void InitializeFeedback(int id)
        {
            MMF_Feedback feedback = TargetMmfPlayer.FeedbacksList[id];

            feedback.Initialization(TargetMmfPlayer);
        }
Esempio n. 18
0
        /// <summary>
        /// Play the selected feedback
        /// </summary>
        protected virtual void PlayFeedback(int id)
        {
            MMF_Feedback feedback = TargetMmfPlayer.FeedbacksList[id];

            feedback.Play(TargetMmfPlayer.transform.position, TargetMmfPlayer.FeedbacksIntensity);
        }
Esempio n. 19
0
        /// <summary>
        /// Copy the selected feedback
        /// </summary>
        protected virtual void CopyFeedback(int id)
        {
            MMF_Feedback feedback = TargetMmfPlayer.FeedbacksList[id];

            MMF_PlayerCopy.Copy(feedback);
        }
Esempio n. 20
0
        /// <summary>
        /// Resets the selected feedback
        /// </summary>
        /// <param name="id"></param>
        protected virtual void ResetFeedback(int id)
        {
            MMF_Feedback feedback = TargetMmfPlayer.FeedbacksList[id];

            feedback.ResetFeedback();
        }
Esempio n. 21
0
        /// <summary>
        /// Play the selected feedback
        /// </summary>
        protected virtual void StopFeedback(int id)
        {
            MMF_Feedback feedback = TargetMmfPlayer.FeedbacksList[id];

            feedback.Stop(TargetMmfPlayer.transform.position);
        }