protected override void PopulateContextMenu(GenericMenu menu, OverrideState overrideState, IExposedPropertyTable exposedPropertyTable, SerializedProperty exposedName, SerializedProperty defaultValue)
    {
        var           propertyName = new PropertyName(exposedName.stringValue);
        OverrideState currentOverrideState;

        UnityEngine.Object currentValue = Resolve(new PropertyName(exposedName.stringValue), exposedPropertyTable, defaultValue.objectReferenceValue, out currentOverrideState);

        if (overrideState == OverrideState.DefaultValue)
        {
            menu.AddItem(new GUIContent(ExposePropertyContent.text), false, (userData) =>
            {
                var guid = UnityEditor.GUID.Generate();
                exposedName.stringValue = guid.ToString();
                exposedName.serializedObject.ApplyModifiedProperties();
                var newPropertyName = new PropertyName(exposedName.stringValue);

                Undo.RecordObject(exposedPropertyTable as Object, "Set Exposed Property");
                exposedPropertyTable.SetReferenceValue(newPropertyName, currentValue);
            }, null);
        }
        else
        {
            menu.AddItem(UnexposePropertyContent, false, (userData) =>
            {
                exposedName.stringValue = "";
                exposedName.serializedObject.ApplyModifiedProperties();

                Undo.RecordObject(exposedPropertyTable as Object, "Clear Exposed Property");
                exposedPropertyTable.ClearReferenceValue(propertyName);
            }, null);
        }
    }
    protected override void PopulateContextMenu(GenericMenu menu, BaseExposedPropertyDrawer.OverrideState overrideState, IExposedPropertyTable exposedPropertyTable, SerializedProperty exposedName, SerializedProperty defaultValue)
    {
        PropertyName propertyName = new PropertyName(exposedName.stringValue);

        BaseExposedPropertyDrawer.OverrideState overrideState2;
        UnityEngine.Object currentValue = base.Resolve(new PropertyName(exposedName.stringValue), exposedPropertyTable, defaultValue.objectReferenceValue, out overrideState2);
        if (overrideState == BaseExposedPropertyDrawer.OverrideState.DefaultValue)
        {
            menu.AddItem(new GUIContent(this.ExposePropertyContent.text), false, delegate(object userData)
            {
                GUID gUID = GUID.Generate();
                exposedName.stringValue = gUID.ToString();
                exposedName.serializedObject.ApplyModifiedProperties();
                PropertyName id = new PropertyName(exposedName.stringValue);
                Undo.RecordObject(exposedPropertyTable as UnityEngine.Object, "Set Exposed Property");
                exposedPropertyTable.SetReferenceValue(id, currentValue);
            }, null);
        }
        else
        {
            menu.AddItem(this.UnexposePropertyContent, false, delegate(object userData)
            {
                exposedName.stringValue = "";
                exposedName.serializedObject.ApplyModifiedProperties();
                Undo.RecordObject(exposedPropertyTable as UnityEngine.Object, "Clear Exposed Property");
                exposedPropertyTable.ClearReferenceValue(propertyName);
            }, null);
        }
    }
    public static int ClearReferenceValue(IntPtr l)
    {
        int result;

        try
        {
            IExposedPropertyTable exposedPropertyTable = (IExposedPropertyTable)LuaObject.checkSelf(l);
            PropertyName          id;
            LuaObject.checkValueType <PropertyName>(l, 2, out id);
            exposedPropertyTable.ClearReferenceValue(id);
            LuaObject.pushValue(l, true);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
Exemplo n.º 4
0
        static bool ExposedReferenceProperty(FieldInfo p_fieldInfo, Object p_object, GUIContent p_name, IReferencable p_reference)
        {
            if (!IsExposedReferenceProperty(p_fieldInfo))
            {
                return(false);
            }

            IExposedPropertyTable propertyTable = DashEditorCore.EditorConfig.editingController;
            var exposedReference = p_fieldInfo.GetValue(p_object);

            PropertyName exposedName = (PropertyName)exposedReference.GetType().GetField("exposedName").GetValue(exposedReference);
            bool         isDefault   = PropertyName.IsNullOrEmpty(exposedName);

            GUILayout.BeginHorizontal();
            GUILayout.Label(p_name, GUILayout.Width(160));
            HandleReferencing(p_reference, p_fieldInfo);
            EditorGUI.BeginChangeCheck();

            UnityEngine.Object exposedValue = (UnityEngine.Object)exposedReference.GetType().GetMethod("Resolve")
                                              .Invoke(exposedReference, new object[] { propertyTable });
            var newValue = EditorGUILayout.ObjectField(exposedValue, p_fieldInfo.FieldType.GetGenericArguments()[0], true);

            GUILayout.EndHorizontal();

            if (EditorGUI.EndChangeCheck())
            {
                if (propertyTable != null)
                {
                    Undo.RegisterCompleteObjectUndo(propertyTable as UnityEngine.Object, "Set Exposed Property");
                }

                if (!isDefault)
                {
                    if (newValue == null)
                    {
                        propertyTable.ClearReferenceValue(exposedName);
                        exposedReference.GetType().GetField("exposedName").SetValue(exposedReference, null);
                        p_fieldInfo.SetValue(p_object, exposedReference);
                    }
                    else
                    {
                        propertyTable.SetReferenceValue(exposedName, newValue);
                    }
                }
                else
                {
                    if (newValue != null)
                    {
                        PropertyName newExposedName = new PropertyName(GUID.Generate().ToString());
                        exposedReference.GetType().GetField("exposedName")
                        .SetValue(exposedReference, newExposedName);
                        propertyTable.SetReferenceValue(newExposedName, newValue);
                        p_fieldInfo.SetValue(p_object, exposedReference);
                    }
                }

                return(true);
            }

            return(false);
        }