protected abstract void OnRenderProperty(Rect position,
                                          PropertyName exposedPropertyNameString,
                                          Object currentReferenceValue,
                                          UnityEditor.SerializedProperty exposedPropertyDefault,
                                          UnityEditor.SerializedProperty exposedPropertyName,
                                          ExposedPropertyMode mode,
                                          IExposedPropertyTable exposedProperties);
Esempio n. 2
0
        public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
        {
            SerializedProperty  serializedProperty  = prop.FindPropertyRelative("defaultValue");
            SerializedProperty  serializedProperty2 = prop.FindPropertyRelative("exposedName");
            string              stringValue         = serializedProperty2.stringValue;
            ExposedPropertyMode exposedPropertyMode = GetExposedPropertyMode(stringValue);
            Rect rect = position;

            rect.xMax -= kDriveWidgetWidth;
            Rect position2 = position;

            position2.x     = rect.xMax;
            position2.width = kDriveWidgetWidth;
            IExposedPropertyTable exposedPropertyTable = GetExposedPropertyTable(prop);
            bool          flag                  = exposedPropertyTable != null;
            PropertyName  propertyName          = new PropertyName(stringValue);
            OverrideState currentOverrideState  = OverrideState.DefaultValue;
            Object        currentReferenceValue = Resolve(propertyName, exposedPropertyTable,
                                                          serializedProperty.objectReferenceValue, out currentOverrideState);
            Color color = GUI.color;
            //bool boldDefaultFont = false;//EditorGUIUtility.GetBoldDefaultFont();
            Rect position3 = DrawLabel(flag, currentOverrideState, label, position, exposedPropertyTable, stringValue,
                                       serializedProperty2, serializedProperty);

            if (exposedPropertyMode == ExposedPropertyMode.DefaultValue ||
                exposedPropertyMode == ExposedPropertyMode.NamedGUID)
            {
                OnRenderProperty(position3, propertyName, currentReferenceValue, serializedProperty,
                                 serializedProperty2, exposedPropertyMode, exposedPropertyTable);
            }
            else
            {
                position3.width /= 2f;
                EditorGUI.BeginChangeCheck();
                stringValue = EditorGUI.TextField(position3, stringValue);
                if (EditorGUI.EndChangeCheck())
                {
                    serializedProperty2.stringValue = stringValue;
                }

                position3.x += position3.width;
                OnRenderProperty(position3, new PropertyName(stringValue), currentReferenceValue, serializedProperty,
                                 serializedProperty2, exposedPropertyMode, exposedPropertyTable);
            }

            GUI.color = color;
            //EditorGUIUtility.SetBoldDefaultFont(boldDefaultFont);
            if (flag && GUI.Button(position2, GUIContent.none, kDropDownStyle))
            {
                GenericMenu genericMenu = new GenericMenu();
                PopulateContextMenu(genericMenu, currentOverrideState, exposedPropertyTable, serializedProperty2,
                                    serializedProperty);
                genericMenu.ShowAsContext();
                Event.current.Use();
            }
        }
    protected override void OnRenderProperty(Rect position,
                                             PropertyName exposedPropertyNameString,
                                             Object currentReferenceValue,
                                             UnityEditor.SerializedProperty exposedPropertyDefault,
                                             UnityEditor.SerializedProperty exposedPropertyName,
                                             ExposedPropertyMode mode,
                                             IExposedPropertyTable exposedPropertyTable)
    {
        var propertyType = fieldInfo.FieldType;

        if (propertyType.IsArrayOrList())
        {
            propertyType = propertyType.GetArrayOrListElementType();
        }

        var typeOfExposedReference = propertyType.GetGenericArguments()[0];

        EditorGUI.BeginChangeCheck();
        var newValue = EditorGUI.ObjectField(position, currentReferenceValue, typeOfExposedReference, exposedPropertyTable != null);

        if (EditorGUI.EndChangeCheck())
        {
            if (mode == ExposedPropertyMode.DefaultValue)
            {
                // We can directly assign to the exposed property default value if
                // * asset we are modifying is in the scene
                // * object we are assigning to the property is also an asset
                if (!EditorUtility.IsPersistent(exposedPropertyDefault.serializedObject.targetObject) || newValue == null || EditorUtility.IsPersistent(newValue))
                {
                    if (!EditorGUI.CheckForCrossSceneReferencing(exposedPropertyDefault.serializedObject.targetObject, newValue))
                    {
                        exposedPropertyDefault.objectReferenceValue = newValue;
                    }
                }
                else
                {
                    var guid = UnityEditor.GUID.Generate();
                    var str  = guid.ToString();
                    exposedPropertyNameString       = new PropertyName(str);
                    exposedPropertyName.stringValue = str;

                    Undo.RecordObject(exposedPropertyTable as UnityEngine.Object, "Set Exposed Property");
                    exposedPropertyTable.SetReferenceValue(exposedPropertyNameString, newValue);
                }
            }
            else
            {
                Undo.RecordObject(exposedPropertyTable as UnityEngine.Object, "Set Exposed Property");
                exposedPropertyTable.SetReferenceValue(exposedPropertyNameString, newValue);
            }
        }
    }
Esempio n. 4
0
        protected override void OnRenderProperty(Rect position, PropertyName exposedPropertyNameString,
                                                 UnityEngine.Object currentReferenceValue, SerializedProperty exposedPropertyDefault,
                                                 SerializedProperty exposedPropertyName, ExposedPropertyMode mode,
                                                 IExposedPropertyTable exposedPropertyTable)
        {
            Type objType = Restriction;

            EditorGUI.BeginChangeCheck();
            UnityEngine.Object @object =
                EditorGUI.ObjectField(position, currentReferenceValue, objType, exposedPropertyTable != null);
            if (!EditorGUI.EndChangeCheck())
            {
                return;
            }

            if (mode == ExposedPropertyMode.DefaultValue)
            {
                if (!EditorUtility.IsPersistent(exposedPropertyDefault.serializedObject.targetObject) ||
                    @object == null || EditorUtility.IsPersistent(@object))
                {
                    if (!CheckForCrossSceneReferencing(exposedPropertyDefault.serializedObject.targetObject,
                                                       @object))
                    {
                        exposedPropertyDefault.objectReferenceValue = @object;
                    }
                }
                else
                {
                    string text = GUID.Generate().ToString();
                    exposedPropertyNameString       = new PropertyName(text);
                    exposedPropertyName.stringValue = text;
                    Undo.RecordObject(exposedPropertyTable as UnityEngine.Object, "Set Exposed Property");
                    exposedPropertyTable.SetReferenceValue(exposedPropertyNameString, @object);
                }
            }
            else
            {
                Undo.RecordObject(exposedPropertyTable as UnityEngine.Object, "Set Exposed Property");
                exposedPropertyTable.SetReferenceValue(exposedPropertyNameString, @object);
            }
        }