コード例 #1
0
        public ParameterValue CreateDefaultParameterValue(int i, IAction act)
        {
            ParameterValue p;

            if (i == 0)
            {
                p             = new ParameterValue(act);
                p.Name        = ConstObjectPointer.VALUE_Value;
                p.ParameterID = _property.MemberId;
                p.SetDataType(_property.PropertyType);
                p.ValueType = EnumValueType.Property;
            }
            else if (i == 1)
            {
                PropertyOverride po             = _property as PropertyOverride;
                bool             hasBaseVersion = (po != null && po.HasBaseImplementation);
                if (hasBaseVersion)
                {
                    CustomPropertyOverridePointer cpop = new CustomPropertyOverridePointer(po, (ClassPointer)(_property.Owner));
                    p             = new ParameterValue(act);
                    p.Name        = "BaseValue";
                    p.ParameterID = po.BasePropertyId;
                    p.SetDataType(_property.PropertyType);
                    p.ValueType = EnumValueType.Property;
                    p.Property  = cpop;
                }
            }
            else
            {
                p = null;
            }
            return(null);
        }
コード例 #2
0
        public override void OnWriteToXmlNode(IXmlCodeWriter writer, XmlNode node)
        {
            base.OnWriteToXmlNode(writer, node);
            XmlUtil.SetAttribute(node, XMLATT_FromBase, UseBaseValue);
            PropertyOverride po = (PropertyOverride)Property;

            XmlUtil.SetAttribute(node, XMLATT_BaseClassId, po.BaseClassId);
            XmlUtil.SetAttribute(node, XMLATT_BasePropId, po.BasePropertyId);
        }
コード例 #3
0
        /// <summary>
        /// Constructor for Path
        /// </summary>
        public ColumnContext(AssetListConfiguration configuration, AssetListWindow window)
        {
            configColumnIndex = -1;
            propertyPath      = null;
            propertyOverride  = PropertyOverride.Path;
            Texture persistent = EditorGUIUtility.IconContent("Project").image;
            Texture inScene    = EditorGUIUtility.ObjectContent(null, typeof(SceneAsset)).image;

            Texture GetIcon(Object o) => EditorUtility.IsPersistent(o) ? persistent : inScene;

            onGUI = (rect, sO, property) => PathLabelWithIcon(rect, sO, window, GetIcon);
        }
コード例 #4
0
        public void PropertyOverrideWithBuildUp()
        {
            MySimpleTypeForPropertyOverride instance = new MySimpleTypeForPropertyOverride();

            instance.X = 111;

            PropertyOverride overrideParam = new PropertyOverride("X", 222);

            IUnityContainer container = new UnityContainer();

            var result = container.BuildUp <MySimpleTypeForPropertyOverride>(instance, overrideParam);

            Assert.AreEqual <int>(222, result.X);
        }
コード例 #5
0
        public ColumnContext(AssetListConfiguration c, NamePropertyDisplay nameDisplay, AssetListWindow window)
        {
            configColumnIndex = -1;
            propertyPath      = null;
            propertyOverride  = PropertyOverride.Name;
            Func <SerializedObject, SerializedProperty> getIconProperty = null;

            if (!string.IsNullOrEmpty(c.IconPropertyPath))
            {
                if (c.IconIsArray)
                {
                    AssetListConfiguration.ArrayData propInfo = c.IconArrayPropertyInformation;
                    Func <SerializedProperty, SerializedProperty> arrayLookup = GetArrayPropertyLookup(propInfo);
                    if (arrayLookup != null)
                    {
                        getIconProperty = context =>
                        {
                            SerializedProperty iconPath = context.FindProperty(c.IconPropertyPath);
                            return(arrayLookup?.Invoke(iconPath));
                        };
                    }
                }
                else
                {
                    getIconProperty = context => context.FindProperty(c.IconPropertyPath);
                }
            }

            switch (nameDisplay)
            {
            case NamePropertyDisplay.Label:
                onGUI = (rect, sO, property) => LargeObjectLabelWithPing(rect, sO, getIconProperty, window, GUI.Label);
                break;

            case NamePropertyDisplay.NicifiedLabel:
                onGUI = (rect, sO, property) => LargeObjectLabelWithPing(rect, sO, getIconProperty, window, ReadonlyNicifiedLabelProperty);
                break;

            case NamePropertyDisplay.CenteredLabel:
                onGUI = (rect, sO, property) => LargeObjectLabelWithPing(rect, sO, getIconProperty, window, ReadonlyCenteredLabelProperty);
                break;

            case NamePropertyDisplay.NicifiedCenteredLabel:
                onGUI = (rect, sO, property) => LargeObjectLabelWithPing(rect, sO, getIconProperty, window, ReadonlyNicifiedCenteredLabelProperty);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(nameDisplay), nameDisplay, null);
            }
        }
コード例 #6
0
        public void TypeBasedOverrideWithBuildUp()
        {
            MySimpleType instance = new MySimpleType();

            instance.X = 111;

            PropertyOverride  overrideParam     = new PropertyOverride("X", 222);
            TypeBasedOverride overrideDecorator = new TypeBasedOverride(typeof(MySimpleType), overrideParam);

            UnityContainer container = new UnityContainer();

            var result = container.BuildUp <MySimpleType>(instance, overrideDecorator);

            Assert.AreEqual <int>(222, result.X);
        }
コード例 #7
0
        public void TypeBasedOverrideInjectsDependentTypeProperty()
        {
            ParameterOverride overrideParam           = new ParameterOverride("value", 222);
            PropertyOverride  overrideProp            = new PropertyOverride("PropertyToInject", "TestOverrideProp");
            TypeBasedOverride typeOverrideConstructor = new TypeBasedOverride(typeof(TypeToInject3ForTypeOverride), overrideParam);
            TypeBasedOverride typeOverrideProp        = new TypeBasedOverride(typeof(TypeToInject3ForTypeOverride), overrideProp);

            IUnityContainer container = new UnityContainer();

            container.RegisterType <TypeToUndergoeTypeBasedInject1>().RegisterType <IForTypeToInject, TypeToInject3ForTypeOverride>(new InjectionConstructor(111), new InjectionProperty("PropertyToInject", "DefaultValue"));
            var result = container.Resolve <TypeToUndergoeTypeBasedInject1>(typeOverrideConstructor, typeOverrideProp);
            TypeToInject3ForTypeOverride overriddenProperty = (TypeToInject3ForTypeOverride)result.IForTypeToInject;

            Assert.AreEqual <int>(222, overriddenProperty.Value);
            Assert.AreEqual <string>("TestOverrideProp", overriddenProperty.PropertyToInject);
        }
コード例 #8
0
        public GetterClass(PropertyClass property)
            : base((ClassPointer)(property.Owner))
        {
            _property = property;
            ReturnValue.SetDataType(_property.PropertyType);
            PropertyOverride po             = property as PropertyOverride;
            bool             hasBaseVersion = (po != null && po.HasBaseImplementation);

            if (hasBaseVersion)
            {
                List <ParameterClass>      pl = new List <ParameterClass>();
                ParameterClassBaseProperty pc = new ParameterClassBaseProperty(this);
                pl.Add(pc);

                this.Parameters = pl;
            }
        }
コード例 #9
0
        void mnu_remove(object sender, EventArgs e)
        {
            EventPath ep = this.Parent as EventPath;

            if (ep != null)
            {
                ClassPointer     root = ep.Panes.Loader.GetRootId();
                PropertyOverride po   = Property as PropertyOverride;
                if (po == null)
                {
                    throw new DesignerException("Overriden property is not found. [{0}]", Property);
                }
                if (MessageBox.Show(ep.FindForm(), "Do you want to remove the override of this property?", "Property", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                {
                    root.DeleteProperty(po);
                }
            }
        }
コード例 #10
0
        public SetterClass(PropertyClass property)
            : base((ClassPointer)(property.Owner))
        {
            _property   = property;
            ReturnValue = new ParameterClass(new TypePointer(typeof(void)), this);
            PropertyOverride po             = property as PropertyOverride;
            bool             hasBaseVersion = (po != null && po.HasBaseImplementation);
            //
            List <ParameterClass> pl = new List <ParameterClass>();
            PropertyValueClass    p  = new PropertyValueClass(this);

            p.SetDataType(_property.PropertyType);
            pl.Add(p);
            //
            if (hasBaseVersion)
            {
                ParameterClassBaseProperty pc = new ParameterClassBaseProperty(this);
                pl.Add(pc);
            }
            this.Parameters = pl;
        }
コード例 #11
0
        public void EqualsNull()
        {
            // Field
            var field = new FieldOverride(string.Empty, OverrideValue);

            Assert.IsFalse(field.Equals((object)null));
            Assert.IsFalse(field.Equals((FieldInfo)null));

            // Property
            var property = new PropertyOverride(string.Empty, OverrideValue);

            Assert.IsFalse(property.Equals((object)null));
            Assert.IsFalse(property.Equals((PropertyInfo)null));

            // Parameter
            var parameter = new ParameterOverride(string.Empty, OverrideValue);

            Assert.IsFalse(parameter.Equals((object)null));
            Assert.IsFalse(parameter.Equals((ParameterInfo)null));

            // Dependency
            Assert.IsFalse(new DependencyOverride(typeof(object), OverrideValue).Equals(null));
        }
コード例 #12
0
        public bool SetData(Transform root, Transform root_prefab, System.Action <IEnumerable <ViewElementPropertyOverrideData> > OnImport, ViewSystemNode node)
        {
            this.root        = root;
            this.root_prefab = root_prefab;
            this.node        = node;
            this.OnImport    = OnImport;
            titleContent     = new GUIContent("ViewElement Overrides Importer");

            propertyModification = PrefabUtility.GetPropertyModifications(root.gameObject)
                                   .ToArray();

            var group = propertyModification.GroupBy(x => x.target);

            var groupedByTarget = group.Where(m => m.Key != null).ToDictionary(o => o.Key, o => o.ToList());

            foreach (var target in groupedByTarget.Keys)
            {
                var groupedByProperty = groupedByTarget[target].GroupBy(x => x.propertyPath.Split('.')[0]).ToDictionary(o => o.Key, o => o.ToList());
                foreach (var property in groupedByProperty.Keys)
                {
                    // This find the orignal SerializedObject
                    var so = new SerializedObject(target);
                    // This find the orignal SerializedProperty
                    var sp = so.FindProperty(property);
                    if (VS_EditorUtility.IsPropertyNeedIgnore(sp))
                    {
                        continue;
                    }
                    var temp = new OverridesPropertiesCheckerData();
                    temp.serializedPropertyType          = sp.propertyType;
                    temp.overrideData.targetPropertyName = property;
                    //temp.overrideData.targetPropertyType = sp.propertyType.ToString();
                    //temp.overrideData.targetPropertyPath = VS_EditorUtility.ParseUnityEngineProperty(property);

                    Transform t;
                    if (sp.serializedObject.targetObject as Component == null)
                    {
                        t = ((GameObject)sp.serializedObject.targetObject).transform;
                    }
                    else
                    {
                        t = ((Component)sp.serializedObject.targetObject).transform;
                    }

                    var path     = AnimationUtility.CalculateTransformPath(t, root);
                    var selfName = root_prefab.name.Length + 1;
                    if (path.Length > selfName - 1)
                    {
                        path = path.Substring(selfName, path.Length - selfName);
                    }
                    else if (path.Length == selfName - 1)
                    {
                        path = "";
                    }
                    temp.overrideData.targetTransformPath = path;
                    temp.overrideData.targetComponentType = target.GetType().ToString();
                    temp.displayName = $"{sp.displayName}  ({property})";

                    //Find the prefab instance SerializedObject

                    var overrideGameObject = root.Find(path);
                    if (overrideGameObject == null)
                    {
                        ViewSystemLog.LogError("Target GameObject is not found, this feature only works on a root prefab instance, make sure which is not a child of other prefab instance.");
                        return(false);
                    }

                    UnityEngine.Object obj;
                    if (target is GameObject)
                    {
                        obj = overrideGameObject.gameObject;
                    }
                    else
                    {
                        obj = overrideGameObject.GetComponent(target.GetType());
                    }
                    var so_instance = new SerializedObject(obj);
                    //Find the prefab instance SerializedProperty
                    var sp_instance = so_instance.FindProperty(property);

                    // Add PropertyOverride to OverridesPropertiesCheckerData
                    PropertyOverride overProperty = new PropertyOverride();
                    overProperty.SetValue(sp_instance);
                    temp.overrideData.Value = overProperty;

                    // Add OverridesPropertiesCheckerData to list wait for user check
                    overridesPropertiesCheckerDatas.Add(temp);
                }
            }
            maxSize = new Vector2(800, 800);
            return(true);
        }
コード例 #13
0
 public CustomPropertyOverridePointer(PropertyOverride p, IClass holder)
     : base(p, holder)
 {
 }
コード例 #14
0
        public ColumnContext(AssetListConfiguration.ColumnConfiguration c, int configColumnIndex)
        {
            this.configColumnIndex = configColumnIndex;
            propertyPath           = c.PropertyPath;
            propertyOverride       = PropertyOverride.None;
            if (!c.IsArray)
            {
                ConfigureGUI(c.PropertyType);
                return;
            }

            void ConfigureGUI(SerializedPropertyType propertyType)
            {
                switch (propertyType)
                {
                case SerializedPropertyType.Float:
                case SerializedPropertyType.Integer:
                    switch (c.NumericalDisplay)
                    {
                    case NumericalPropertyDisplay.Property:
                        onGUI = Property;
                        break;

                    case NumericalPropertyDisplay.ReadonlyProperty:
                        onGUI = ReadonlyProperty;
                        break;

                    case NumericalPropertyDisplay.ReadonlyLabel:
                        onGUI = NumericalProperty;
                        break;

                    case NumericalPropertyDisplay.ReadonlyPercentageLabel:
                        onGUI = NumericalPropertyPercentage;
                        break;

                    case NumericalPropertyDisplay.ReadonlyPercentageLabelNormalised:
                        onGUI = NumericalPropertyPercentageNormalised;
                        break;

                    case NumericalPropertyDisplay.ReadonlyProgressBar:
                        onGUI = NumericalPropertyProgressBar;
                        break;

                    case NumericalPropertyDisplay.ReadonlyProgressBarNormalised:
                        onGUI = NumericalPropertyProgressBarNormalised;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(c.NumericalDisplay), c.NumericalDisplay, null);
                    }

                    break;

                case SerializedPropertyType.Enum:
                    switch (c.EnumDisplay)
                    {
                    case EnumPropertyDisplay.Property:
                        onGUI = Property;
                        break;

                    case EnumPropertyDisplay.ReadonlyProperty:
                        onGUI = ReadonlyProperty;
                        break;

                    case EnumPropertyDisplay.ReadonlyLabel:
                        onGUI = ReadonlyEnumProperty;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(c.EnumDisplay), c.EnumDisplay, null);
                    }

                    break;

                case SerializedPropertyType.String:
                    switch (c.StringDisplay)
                    {
                    case StringPropertyDisplay.Property:
                        onGUI = Property;
                        break;

                    case StringPropertyDisplay.ReadonlyProperty:
                        onGUI = ReadonlyProperty;
                        break;

                    case StringPropertyDisplay.ReadonlyLabel:
                        onGUI = (rect, sO, property) => GUI.Label(rect, property.stringValue);
                        break;

                    case StringPropertyDisplay.ReadonlyNicifiedLabel:
                        onGUI = (rect, sO, property) => ReadonlyNicifiedLabelProperty(rect, property.stringValue);
                        break;

                    case StringPropertyDisplay.ReadonlyCenteredLabel:
                        onGUI = (rect, sO, property) => ReadonlyCenteredLabelProperty(rect, property.stringValue);
                        break;

                    case StringPropertyDisplay.ReadonlyNicifiedCenteredLabel:
                        onGUI = (rect, sO, property) => ReadonlyNicifiedCenteredLabelProperty(rect, property.stringValue);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(c.StringDisplay), c.StringDisplay, null);
                    }

                    break;

                case SerializedPropertyType.Color:
                    switch (c.ColorDisplay)
                    {
                    case ColorPropertyDisplay.Property:
                        onGUI = Property;
                        break;

                    case ColorPropertyDisplay.ReadonlyProperty:
                        onGUI = ReadonlyProperty;
                        break;

                    case ColorPropertyDisplay.ReadonlySimplified:
                        onGUI = (rect, sO, property) => ReadonlyColorSimplified(rect, property, false);
                        break;

                    case ColorPropertyDisplay.ReadonlySimplifiedHDR:
                        onGUI = (rect, sO, property) => ReadonlyColorSimplified(rect, property, true);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(c.ColorDisplay), c.ColorDisplay, null);
                    }

                    break;

                case SerializedPropertyType.ObjectReference:
                    switch (c.ObjectDisplay)
                    {
                    case ObjectPropertyDisplay.Property:
                        onGUI = Property;
                        break;

                    case ObjectPropertyDisplay.ReadonlyProperty:
                        onGUI = ReadonlyProperty;
                        break;

                    case ObjectPropertyDisplay.ReadonlyLabelWithIcon:
                        onGUI = (rect, sO, property) =>
                        {
                            if (property.objectReferenceValue == null)
                            {
                                GUI.Label(rect, "Null");
                            }
                            else
                            {
                                GUI.Label(rect, EditorGUIUtility.ObjectContent(property.objectReferenceValue, null));
                            }
                        };
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(c.ObjectDisplay), c.ObjectDisplay, null);
                    }

                    break;

                case SerializedPropertyType.Generic:
                    throw new NotImplementedException($"{SerializedPropertyType.Generic} is not supported without being an array.");

                case SerializedPropertyType.Boolean:
                case SerializedPropertyType.LayerMask:
                case SerializedPropertyType.Vector2:
                case SerializedPropertyType.Vector3:
                case SerializedPropertyType.Vector4:
                case SerializedPropertyType.Rect:
                case SerializedPropertyType.ArraySize:
                case SerializedPropertyType.Character:
                case SerializedPropertyType.AnimationCurve:
                case SerializedPropertyType.Bounds:
                case SerializedPropertyType.Gradient:
                case SerializedPropertyType.Quaternion:
                case SerializedPropertyType.ExposedReference:
                case SerializedPropertyType.FixedBufferSize:
                case SerializedPropertyType.Vector2Int:
                case SerializedPropertyType.Vector3Int:
                case SerializedPropertyType.RectInt:
                case SerializedPropertyType.BoundsInt:
                                        #if UNITY_2019_3_OR_NEWER
                case SerializedPropertyType.ManagedReference:
                                        #endif
                default:
                    switch (c.DefaultDisplay)
                    {
                    case GUIType.Property:
                        onGUI = Property;
                        break;

                    case GUIType.ReadonlyProperty:
                        onGUI = ReadonlyProperty;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    break;
                }
            }

            // Configuration for an array property -------------------------------

            AssetListConfiguration.ArrayData propInfo = c.ArrayPropertyInformation;
            Func <SerializedProperty, SerializedProperty> getProperty = GetArrayPropertyLookup(propInfo);

            getPropertyOverride = context =>
            {
                SerializedProperty property = context.FindProperty(propertyPath);
                return(getProperty.Invoke(property));
            };

            ConfigureGUI(propInfo.ArrayPropertyType);
        }