/// <inheritdoc />
        protected override void RenderMemberControl(Rect position)
        {
            var options = GetNameOptions();

            DropdownOption <AnimatorParameter> selectedOption = null;
            DropdownOption <AnimatorParameter> noneOption     = new DropdownOption <AnimatorParameter>(null, "No Parameter");

            AnimatorParameter value = GetValue();

            if (value != null)
            {
                string label = value.name;

                AnimatorParameter valueInOptions = options.Select(option => option.value).FirstOrDefault(ap => ap.Corresponds(value));

                if (valueInOptions != null)
                {
                    selectedOption = new DropdownOption <AnimatorParameter>(valueInOptions, label);
                }
                else
                {
                    selectedOption = new DropdownOption <AnimatorParameter>(value, label);
                }
            }

            // Make sure the callback uses the property of this drawer, not at its later value.
            var propertyNow = property;

            bool enabled = targets.Any(target => target != null);

            if (!enabled)
            {
                EditorGUI.BeginDisabledGroup(true);
            }

            DropdownGUI <AnimatorParameter> .PopupSingle
            (
                position,
                newValue =>
            {
                Update(propertyNow);
                SetValue(newValue);
                propertyNow.serializedObject.ApplyModifiedProperties();
            },
                options,
                selectedOption,
                noneOption,
                nameProperty.hasMultipleDifferentValues
            );

            if (!enabled)
            {
                EditorGUI.EndDisabledGroup();
            }
        }
        /// <inheritdoc />
        protected override void RenderMemberControl(Rect position)
        {
            bool enabled = targets.Any(target => target != null);

            if (!enabled)
            {
                EditorGUI.BeginDisabledGroup(true);
            }

            EditorGUI.BeginChangeCheck();

            EditorGUI.showMixedValue = nameProperty.hasMultipleDifferentValues;

            var value = GetValue();

            var selectedOption = value != null ? new DropdownOption <AnimatorParameter>(value, value.name) : null;

            value = DropdownGUI <AnimatorParameter> .PopupSingle
                    (
                position,
                GetNameOptions,
                selectedOption,
                new DropdownOption <AnimatorParameter>(null, "No Parameter")
                    );

            EditorGUI.showMixedValue = false;

            if (EditorGUI.EndChangeCheck())
            {
                SetValue(value);
            }

            if (!enabled)
            {
                EditorGUI.EndDisabledGroup();
            }
        }
Пример #3
0
        /// <inheritdoc />
        protected override void RenderMemberControl(Rect position)
        {
            // Other Targets
            // Some Unity Objects, like Assets, are not supported by the drawer.
            // Just display an error message to let the user change their target.

            if (targetType == UnityObjectType.Other)
            {
                EditorGUI.HelpBox(position, "Unsupported Unity Object type.", MessageType.None);
                return;
            }

            // Display a list of all available reflected members in a popup.

            UnityMember value = GetValue();

            DropdownOption <UnityMember> selectedOption = null;

            if (value != null)
            {
                if (targetType == UnityObjectType.GameObject)
                {
                    string label;

                    if (value.component == null)
                    {
                        label = string.Format("GameObject.{0}", value.name);
                    }
                    else
                    {
                        label = string.Format("{0}.{1}", value.component, value.name);
                    }

                    // There seems to be no way of differentiating between null parameter types
                    // (fields, properties and implicitly typed methods) and zero parameter types
                    // because Unity's serialized property array cannot be assigned to null, only
                    // given an array size of zero.

                    // TODO: The solution would be to use a single comma-separated
                    // string instead of an array of strings, which we could differentiate manually.
                    if (value.parameterTypes != null && value.parameterTypes.Length > 0)
                    {
                        string parameterString = string.Join(", ", value.parameterTypes.Select(t => t.PrettyName()).ToArray());

                        label += string.Format(" ({0})", parameterString);
                    }

                    selectedOption = new DropdownOption <UnityMember>(value, label);
                }
                else if (targetType == UnityObjectType.ScriptableObject)
                {
                    selectedOption = new DropdownOption <UnityMember>(value, value.name);
                }
            }

            bool enabled = targetType != UnityObjectType.None;

            if (!enabled)
            {
                EditorGUI.BeginDisabledGroup(true);
            }

            EditorGUI.BeginChangeCheck();

            EditorGUI.showMixedValue = nameProperty.hasMultipleDifferentValues;

            value = DropdownGUI <UnityMember> .PopupSingle
                    (
                position,
                GetAllMemberOptions,
                selectedOption,
                new DropdownOption <UnityMember>(null, string.Format("Nothing"))
                    );

            EditorGUI.showMixedValue = false;

            if (EditorGUI.EndChangeCheck())
            {
                SetValue(value);
            }

            if (!enabled)
            {
                EditorGUI.EndDisabledGroup();
            }
        }
Пример #4
0
        /// <inheritdoc />
        protected override void RenderMemberControl(Rect position)
        {
            // Other Targets
            // Some Unity Objects, like Assets, are not supported by the drawer.
            // Just display an error message to let the user change their target.

            if (targetType == UnityObjectType.Other)
            {
                EditorGUI.HelpBox(position, "Unsupported Unity Object type.", MessageType.None);
                return;
            }

            // Display a list of all available reflected members in a popup.

            var options = new List <DropdownOption <TMember> >();

            TMember value = GetValue();

            DropdownOption <TMember> selectedOption = null;
            DropdownOption <TMember> noneOption     = new DropdownOption <TMember>(null, string.Format("No {0}", memberLabel));

            if (targetType == UnityObjectType.GameObject)
            {
                // Check if all targets have a GameObject (none are empty).
                // If they do, display all members of the GameObject type.

                if (HasSharedGameObject())
                {
                    var gameObjectOptions = GetSortedMemberOptions(typeof(GameObject));

                    foreach (var gameObjectOption in gameObjectOptions)
                    {
                        // Prefix label by GameObject for popup clarity.

                        gameObjectOption.label = string.Format("GameObject/{0}", gameObjectOption.label);

                        options.Add(gameObjectOption);
                    }
                }

                // Find all shared component types across targets.
                // Display all members of each one found.

                foreach (Type componentType in GetSharedComponentTypes())
                {
                    var componentOptions = GetSortedMemberOptions(componentType, componentType.Name);

                    foreach (var componentOption in componentOptions)
                    {
                        // Prefix label and option by component type for clear distinction.

                        componentOption.label = string.Format("{0}/{1}", componentType.Name, componentOption.label);

                        options.Add(componentOption);
                    }
                }

                // Determine which option is currently selected.

                if (value != null)
                {
                    string label;

                    if (value.component == null)
                    {
                        label = string.Format("GameObject.{0}", value.name);
                    }
                    else
                    {
                        label = string.Format("{0}.{1}", value.component, value.name);
                    }

                    UnityMethod method = value as UnityMethod;

                    if (method != null)
                    {
                        string parameterString = string.Join(", ", method.parameterTypes.Select(t => t.PrettyName()).ToArray());

                        label += string.Format(" ({0})", parameterString);
                    }

                    TMember valueInOptions = options.Select(option => option.value).FirstOrDefault(member => member.Corresponds(value));

                    if (valueInOptions != null)
                    {
                        selectedOption = new DropdownOption <TMember>(valueInOptions, label);
                    }
                    else
                    {
                        selectedOption = new DropdownOption <TMember>(value, label);
                    }
                }
            }
            else if (targetType == UnityObjectType.ScriptableObject)
            {
                // ScriptableObject Target
                // Make sure all targets share the same ScriptableObject Type.
                // If they do, display all members of that type.

                Type scriptableObjectType = GetSharedScriptableObjectType();

                if (scriptableObjectType != null)
                {
                    options.AddRange(GetSortedMemberOptions(scriptableObjectType));

                    // Determine which option is currently selected.

                    if (value != null)
                    {
                        selectedOption = options.Find(o => o.value.Corresponds(value));

                        if (selectedOption == null)
                        {
                            selectedOption = new DropdownOption <TMember>(value, value.name);
                        }
                    }
                }
            }

            // Make sure the callback uses the property of this drawer, not at its later value.
            var propertyNow = property;

            bool enabled = targetType != UnityObjectType.None;

            if (!enabled)
            {
                EditorGUI.BeginDisabledGroup(true);
            }

            DropdownGUI <TMember> .PopupSingle
            (
                position,
                newValue =>
            {
                Update(propertyNow);
                SetValue(newValue);
                propertyNow.serializedObject.ApplyModifiedProperties();
            },
                options,
                selectedOption,
                noneOption,
                hasMultipleDifferentValues
            );

            if (!enabled)
            {
                EditorGUI.EndDisabledGroup();
            }
        }