protected override void OnRenderProperty(Rect position, PropertyName exposedPropertyNameString, UnityEngine.Object currentReferenceValue, SerializedProperty exposedPropertyDefault, SerializedProperty exposedPropertyName, BaseExposedPropertyDrawer.ExposedPropertyMode mode, IExposedPropertyTable exposedPropertyTable)
    {
        Type objType = base.fieldInfo.FieldType.GetGenericArguments()[0];

        EditorGUI.BeginChangeCheck();
        UnityEngine.Object @object = EditorGUI.ObjectField(position, currentReferenceValue, objType, exposedPropertyTable != null);
        if (EditorGUI.EndChangeCheck())
        {
            if (mode == BaseExposedPropertyDrawer.ExposedPropertyMode.DefaultValue)
            {
                if (!EditorUtility.IsPersistent(exposedPropertyDefault.serializedObject.targetObject) || @object == null || EditorUtility.IsPersistent(@object))
                {
                    if (!EditorGUI.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);
            }
        }
    }
    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);
            }
        }
    }
    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);
        }
    }
예제 #4
0
        public NodeModelBase Clone()
        {
            // Doing a shallow copy
            var clone = (NodeModelBase)SerializationUtility.CreateCopy(this);

            // Exposed references are not copied in serialization as they are external Unity references so they will refer to the same exposed reference instance not just the unity object reference, we need to copy them additionally
            FieldInfo[] fields = clone.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public);
            fields.ToList().FindAll(f => f.FieldType.IsGenericType && f.FieldType.GetGenericTypeDefinition() == typeof(ExposedReference <>)).ForEach(f =>
            {
                Type exposedRefType = typeof(ExposedReference <>).MakeGenericType(f.FieldType.GenericTypeArguments[0]);

                if (DashEditorCore.EditorConfig.editingController != null)
                {
                    IExposedPropertyTable propertyTable = DashEditorCore.EditorConfig.editingController;
                    var curExposedRef = f.GetValue(clone);
                    UnityEngine.Object exposedValue = (UnityEngine.Object)curExposedRef.GetType().GetMethod("Resolve")
                                                      .Invoke(curExposedRef, new object[] { propertyTable });

                    var clonedExposedRef        = Activator.CreateInstance(exposedRefType);
                    PropertyName newExposedName = new PropertyName(UnityEditor.GUID.Generate().ToString());
                    propertyTable.SetReferenceValue(newExposedName, exposedValue);
                    clonedExposedRef.GetType().GetField("exposedName")
                    .SetValue(clonedExposedRef, newExposedName);
                    f.SetValue(clone, clonedExposedRef);
                }
            });

            return(clone);
        }
    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);
        }
    }
예제 #6
0
        static void CreateAnimationNodesFromSelection(object p_nodeType)
        {
            Transform[] selectedTransforms = SelectionUtils.GetTransformsFromSelection();
            float       zoom       = DashEditorCore.EditorConfig.zoom;
            Vector2     viewOffset = DashEditorCore.EditorConfig.editingGraph.viewOffset;
            Vector2     position   = new Vector2(_lastMousePosition.x * zoom - viewOffset.x, _lastMousePosition.y * zoom - viewOffset.y);
            Vector2     offset     = Vector2.zero;

            foreach (Transform transform in selectedTransforms)
            {
                NodeBase node = NodeUtils.CreateNode(DashEditorCore.EditorConfig.editingGraph, (Type)p_nodeType, position + offset);

                if (node != null)
                {
                    RetargetNodeModelBase model = node.GetModel() as RetargetNodeModelBase;
                    model.retarget = true;
                    //model.target.SetValue(transform.name);

                    model.useReference = true;
                    IExposedPropertyTable propertyTable = DashEditorCore.EditorConfig.editingController;
                    bool isDefault = PropertyName.IsNullOrEmpty(model.targetReference.exposedName);

                    if (isDefault)
                    {
                        PropertyName newExposedName = new PropertyName(GUID.Generate().ToString());
                        model.targetReference.exposedName = newExposedName;

                        propertyTable.SetReferenceValue(newExposedName, transform);
                        //p_fieldInfo.SetValue(p_object, exposedReference);
                    }
                    else
                    {
                        propertyTable.SetReferenceValue(model.targetReference.exposedName, transform);
                    }

                    // If its bindable bind all values to current transform
                    if (node is IAnimationNodeBindable)
                    {
                        ((IAnimationNodeBindable)node).GetTargetFrom(transform);
                        ((IAnimationNodeBindable)node).GetTargetTo(transform);
                    }

                    offset.y += node.Size.y + 24;
                }
            }
        }
        //Can be used to unlink an exposedReference after duplicating it.
        internal static void RecreateReferenceInEditor <T>(ref ExposedReference <T> exposedRef,
                                                           IExposedPropertyTable table) where T : Object
        {
            T obj = exposedRef.Resolve(table);

            exposedRef.exposedName = GUID.Generate().ToString();
            table.SetReferenceValue(exposedRef.exposedName, obj);
        }
 internal static void SetReferenceValueInEditor <T>(ref ExposedReference <T> exposedRef,
                                                    IExposedPropertyTable propertyTable, T obj) where T : Object
 {
     //check if exposedName hasn't been initialized
     if (exposedRef.exposedName.ToString() == ":0")
     {
         exposedRef.exposedName = GUID.Generate().ToString();
     }
     propertyTable.SetReferenceValue(exposedRef.exposedName, obj);
 }
예제 #9
0
        public static void CloneExposedReferences(ScriptableObject clone, IExposedPropertyTable sourceTable, IExposedPropertyTable destTable)
        {
            var cloneObject         = new SerializedObject(clone);
            SerializedProperty prop = cloneObject.GetIterator();

            while (prop.Next(true))
            {
                if (prop.propertyType == SerializedPropertyType.ExposedReference)
                {
                    var exposedNameProp = prop.FindPropertyRelative("exposedName");
                    var sourceKey       = exposedNameProp.stringValue;
                    var destKey         = sourceKey;

                    if (!IsExposedReferenceExplicitlyNamed(sourceKey))
                    {
                        destKey = GenerateExposedReferenceName();
                    }

                    exposedNameProp.stringValue = destKey;

                    var requiresCopy = sourceTable != destTable || sourceKey != destKey;
                    if (requiresCopy && sourceTable != null && destTable != null)
                    {
                        var valid  = false;
                        var target = sourceTable.GetReferenceValue(sourceKey, out valid);
                        if (valid && target != null)
                        {
                            var existing = destTable.GetReferenceValue(destKey, out valid);
                            if (!valid || existing != target)
                            {
                                var destTableObj = destTable as UnityEngine.Object;
                                if (destTableObj != null)
                                {
                                    TimelineUndo.PushUndo(destTableObj, "Create Clip");
                                }
                                destTable.SetReferenceValue(destKey, target);
                            }
                        }
                    }
                }
            }
            cloneObject.ApplyModifiedPropertiesWithoutUndo();
        }
    public static int SetReferenceValue(IntPtr l)
    {
        int result;

        try
        {
            IExposedPropertyTable exposedPropertyTable = (IExposedPropertyTable)LuaObject.checkSelf(l);
            PropertyName          id;
            LuaObject.checkValueType <PropertyName>(l, 2, out id);
            UnityEngine.Object value;
            LuaObject.checkType <UnityEngine.Object>(l, 3, out value);
            exposedPropertyTable.SetReferenceValue(id, value);
            LuaObject.pushValue(l, true);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
예제 #11
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);
        }
예제 #12
0
 public void SetRoot(Transform root, IExposedPropertyTable resolver)
 {
     resolver.SetReferenceValue(m_Root.exposedName, root);
 }