Beispiel #1
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;
        }
Beispiel #2
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();
        }