コード例 #1
0
        private void DrawParamField(ref Rect fieldRect, ref int index, SerializedProperty property, bool modified = false)
        {
            fieldRect.y += BoxBackgroundMargin;
            int result = EditorGUI.Popup
                         (
                fieldRect,
                GUIContent.none,
                index + 1,
                ParameterListContent.ToArray(),
                SpaceEditorStyles.ParametrizedField
                         );

            bool changed = (result - 1) != index || modified;

            if (changed && DataProvider.CanEditObject(Target))
            {
                if (result > 0 && result <= Parameters.Count)
                {
                    var parameter = Parameters[result - 1];

                    AsParametrized.SetParameter(property.name, parameter);
                }
                else
                {
                    AsParametrized.ClearParameter(property.name);
                }
            }
        }
コード例 #2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (!Initialize(ref position, property, label))
            {
                return;
            }

//            Parameters.FindIndex(p => p.Name.Equals(property.name)
//                                      && p.HoldType.Equals(value.Parameter.HoldType)
//                                      && p.HoldType.Type == type);

            DrawBackground(position, DarkRed); // ? Color.white : DarkRed

            label = EditorGUI.BeginProperty(position, label, property);
            {
                position.y += BoxBackgroundHeight * 0.5f;
                position    = EditorGUI.PrefixLabel(position, new GUIContent(property.displayName));

                EditorGUI.indentLevel = 0;
                EditorGUI.BeginChangeCheck();
                {
                    var objectFieldRect = position;
                    objectFieldRect.y += BoxBackgroundMargin;

                    int result = EditorGUI.Popup
                                 (
                        objectFieldRect,
                        GUIContent.none,
                        0,//index + 1,
                        ParameterListContent.ToArray(),
                        SpaceEditorStyles.ParametrizedField
                                 );

                    if (!DataProvider.CanEditObject(Target))
                    {
                        if (result > 0 && result <= Parameters.Count)
                        {
                            var parameter = Parameters[result - 1];

                            AsParametrized.SetParameter(property.name, parameter);
                        }
                        else
                        {
                            AsParametrized.ClearParameter(property.name);
                        }
                    }
                }
                if (EditorGUI.EndChangeCheck())
                {
                    EditorUtility.SetDirty(Target);
                }
            }
            EditorGUI.EndProperty();
        }
コード例 #3
0
        public void OnGUI(Rect position, SerializedProperty property, GUIContent label,
                          SerializedType fieldType, PropertyAttribute attribute, bool displayLock = true)
        {
            SetContentForParameters();

            int  index       = -1;
            bool wasConstant = false;
            var  setParam    = AsParametrized.GetParameter(property.name, fieldType);

            if (setParam != null)
            {
                index       = Parameters.FindIndex(p => p.Name.Equals(setParam.Name) && p.HoldType.Equals(setParam.HoldType));
                wasConstant = AsParametrized.IsParameterConstant(property.name);
            }

            DrawBackground(position, index != -1 || wasConstant);

            label = EditorGUI.BeginProperty(position, label, property);
            {
                position.y += BoxBackgroundHeight * 0.5f;
                position    = EditorGUI.PrefixLabel(position, new GUIContent(property.displayName));

                EditorGUI.indentLevel = 0;
                EditorGUI.BeginChangeCheck();
                {
                    var fieldRect = position;

                    if (displayLock)
                    {
                        var lockRect = new Rect(fieldRect.x + fieldRect.width - LockSize, fieldRect.y + 2, LockSize,
                                                fieldRect.height);

                        bool isConstant = EditorGUI.Toggle(lockRect, wasConstant, SpaceEditorStyles.LockButton);

                        fieldRect.width -= LockSize;

                        if (isConstant)
                        {
                            GenericParameter parameter = wasConstant
                                ? AsParametrized.GetParameter(property.name, fieldType)
                                : new GenericParameter(fieldType);

                            GenericParamUtils.DrawParameter(fieldRect, parameter, false);

                            AsParametrized.SetParameter(property.name, parameter, true);
                        }
                        else
                        {
                            DrawParamField(ref fieldRect, ref index, property, wasConstant != isConstant);
                        }
                    }
                    else
                    {
                        DrawParamField(ref fieldRect, ref index, property);
                    }
                }
                if (EditorGUI.EndChangeCheck())
                {
                    EditorUtility.SetDirty(Target);
                }
            }
            EditorGUI.EndProperty();
        }