/// <summary>
        /// Creates all the relevant style information for a SerializableField.
        /// </summary>
        /// <param name="field">Field to create the style info structure for.</param>
        /// <returns>Style information retrieved from the field.</returns>
        public static InspectableFieldStyleInfo Create(SerializableField field)
        {
            SerializableFieldStyle style = field.Style;

            var styleInfo = new InspectableFieldStyleInfo();

            styleInfo.RangeStyle  = style.HasRange ? new InspectableFieldRangeStyle(style.RangeMin, style.RangeMax, style.DisplayAsSlider) : null;
            styleInfo.StepStyle   = style.HasStep ? new InspectableFieldStepStyle(style.StepIncrement) : null;
            styleInfo.StyleFlags |= style.DisplayAsSlider ? InspectableFieldStyleFlags.UseSlider : 0;
            styleInfo.StyleFlags |= style.DisplayAsLayerMask ? InspectableFieldStyleFlags.UseLayerMask : 0;
            styleInfo.StyleFlags |= field.Flags.HasFlag(SerializableFieldAttributes.PassByCopy)
                ? InspectableFieldStyleFlags.CopiedAsValue
                : 0;

            styleInfo.StyleFlags |= field.Flags.HasFlag(SerializableFieldAttributes.NotNull)
                ? InspectableFieldStyleFlags.NotNull
                : 0;

            styleInfo.StyleFlags |= field.Flags.HasFlag(SerializableFieldAttributes.NativeWrapper)
                ? InspectableFieldStyleFlags.NativeWrapper
                : 0;

            styleInfo.StyleFlags |= field.Flags.HasFlag(SerializableFieldAttributes.ApplyOnDirty)
                ? InspectableFieldStyleFlags.ApplyOnDirty
                : 0;

            styleInfo.StyleFlags |= field.Flags.HasFlag(SerializableFieldAttributes.DisplayAsQuaternion)
                ? InspectableFieldStyleFlags.AsQuaternion
                : 0;

            return(styleInfo);
        }
Exemple #2
0
 private static object ConvertComplexType(SerializableField fieldVal, Type type, bool isArray)
 {
     try
     {
         if (isArray)
         {
             var elmType = type.GetGenericArguments()[0];
             var arrType = typeof(List <>).MakeGenericType(elmType);
             var ret     = Activator.CreateInstance(arrType) as IList ?? throw new ArgumentException();
             foreach (SerializableStructure record in (IAsset[])fieldVal.CValue)
             {
                 var item = MapProperties(record, elmType);
                 ret.Add(item);
             }
             return(ret);
         }
         else
         {
             return(MapProperties((SerializableStructure)fieldVal.CValue, type));
         }
     }
     catch (InvalidCastException)
     {
         throw new NotSupportedException();
     }
 }
Exemple #3
0
            public override bool Equals(object o)
            {
                if (!(o is SerializableField))
                {
                    return(false);
                }
                SerializableField other = (SerializableField)o;

                if (!m_name.Equals(other.Name))
                {
                    return(false);
                }
                string value = StringValue;

                if (value != null)
                {
                    if (value.Equals(other.StringValue))
                    {
                        return(true);
                    }
                    return(false);
                }
                byte[] binValue = BinaryValue;
                if (binValue != null)
                {
                    return(Arrays.Equals(binValue, other.BinaryValue));
                }
                return(false);
            }
        /// <summary>
        /// Creates all the relevant style information for a SerializableField.
        /// </summary>
        /// <param name="field">Field to create the style info structure for.</param>
        /// <returns>Style information retrieved from the field.</returns>
        public static InspectableFieldStyleInfo Create(SerializableField field)
        {
            SerializableFieldStyle style = field.Style;

            var styleInfo = new InspectableFieldStyleInfo();

            styleInfo.RangeStyle = style.HasRange ? new InspectableFieldRangeStyle(style.RangeMin, style.RangeMax, style.DisplayAsSlider) : null;
            styleInfo.StepStyle  = style.HasStep ? new InspectableFieldStepStyle(style.StepIncrement) : null;

            return(styleInfo);
        }
Exemple #5
0
 private static bool HasSerializeFieldAttribute(FieldDefinition field)
 {
     foreach (CustomAttribute attribute in field.CustomAttributes)
     {
         TypeReference type = attribute.AttributeType;
         if (SerializableField.IsSerializeFieldAttrribute(type.Namespace, type.Name))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #6
0
 public static bool IsCompilerGenerated(FieldDefinition field)
 {
     foreach (CustomAttribute attribute in field.CustomAttributes)
     {
         TypeReference type = attribute.AttributeType;
         if (SerializableField.IsCompilerGeneratedAttrribute(type.Namespace, type.Name))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #7
0
        /// <summary>
        /// Creates all the relevant style information for a SerializableField.
        /// </summary>
        /// <param name="field">Field to create the style info structure for.</param>
        /// <returns>Style information retrieved from the field.</returns>
        public static InspectableFieldStyleInfo Create(SerializableField field)
        {
            SerializableFieldStyle      style = field.Style;
            SerializableFieldAttributes flags = field.Flags;

            var styleInfo = new InspectableFieldStyleInfo();

            styleInfo.RangeStyle = flags.HasFlag(SerializableFieldAttributes.Ranged)
                ? new InspectableFieldRangeStyle(style.RangeMin, style.RangeMax, style.DisplayAsSlider) : null;
            styleInfo.StepStyle = flags.HasFlag(SerializableFieldAttributes.Stepped)
                ? new InspectableFieldStepStyle(style.StepIncrement) : null;
            styleInfo.CategoryStyle = flags.HasFlag(SerializableFieldAttributes.Category)
                ? new InspectableFieldCategoryStyle(style.CategoryName) : null;
            styleInfo.OrderStyle = flags.HasFlag(SerializableFieldAttributes.Order)
                ? new InspectableFieldOrderStyle(style.Order) : null;
            styleInfo.StyleFlags |= flags.HasFlag(SerializableFieldAttributes.AsLayerMask)
                ? InspectableFieldStyleFlags.AsLayerMask : 0;
            styleInfo.StyleFlags |= style.DisplayAsSlider ? InspectableFieldStyleFlags.AsSlider : 0;
            styleInfo.StyleFlags |= flags.HasFlag(SerializableFieldAttributes.PassByCopy)
                ? InspectableFieldStyleFlags.CopiedAsValue
                : 0;

            styleInfo.StyleFlags |= flags.HasFlag(SerializableFieldAttributes.NotNull)
                ? InspectableFieldStyleFlags.NotNull
                : 0;

            styleInfo.StyleFlags |= flags.HasFlag(SerializableFieldAttributes.NativeWrapper)
                ? InspectableFieldStyleFlags.NativeWrapper
                : 0;

            styleInfo.StyleFlags |= flags.HasFlag(SerializableFieldAttributes.ApplyOnDirty)
                ? InspectableFieldStyleFlags.ApplyOnDirty
                : 0;

            styleInfo.StyleFlags |= flags.HasFlag(SerializableFieldAttributes.AsQuaternion)
                ? InspectableFieldStyleFlags.AsQuaternion
                : 0;

            styleInfo.StyleFlags |= flags.HasFlag(SerializableFieldAttributes.Inline)
                ? InspectableFieldStyleFlags.Inline
                : 0;

            styleInfo.StyleFlags |= flags.HasFlag(SerializableFieldAttributes.LoadOnAssign)
                ? InspectableFieldStyleFlags.LoadOnAssign
                : 0;

            styleInfo.StyleFlags |= flags.HasFlag(SerializableFieldAttributes.HDR)
                ? InspectableFieldStyleFlags.HDR
                : 0;

            return(styleInfo);
        }
Exemple #8
0
        /// <summary>
        /// Searches the object hierarchy using the provided path elements. <see cref="FindProperty(string)"/>
        /// </summary>
        /// <param name="pathElements">Path elements representing field names and keys to look for.</param>
        /// <param name="elementIdx">Index in the <paramref name="pathElements"/> array to start the search at.</param>
        /// <returns>Property representing the final path element, or null if not found.</returns>
        internal SerializableProperty FindProperty(PropertyPathElement[] pathElements, int elementIdx)
        {
            SerializableField field = FindField(pathElements[0].name);

            if (field != null)
            {
                SerializableProperty property = field.GetProperty();
                if (elementIdx == (pathElements.Length - 1))
                {
                    return(property);
                }

                return(property.FindProperty(pathElements, elementIdx + 1));
            }

            return(null);
        }
Exemple #9
0
        public List <SerializableType> CollectSerializableTypes(FieldInfo fieldInfo)
        {
            var field = new SerializableField(fieldInfo);

            var cache = ProjectUtility.GetOrCreateProjectAsset <SerializableMemberCache>();

            if (!cache.types.TryGetValue(field.FullName, out List <SerializableType> result))
            {
                result = new List <SerializableType>();
                foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
                {
                    var output = new List <SerializableType>();
                    foreach (var type in assembly.GetTypes())
                    {
                        if (type.GetCustomAttribute <HideInInspector>() == null && IsValid(type))
                        {
                            output.Add(type);
                        }
                    }
                    if (!output.IsEmpty())
                    {
                        if (!cache.assemblyData.TryGetValue(assembly.FullName, out var data))
                        {
                            data = new SerializableMemberCache.AssemblyData();
                            cache.assemblyData[assembly.FullName] = data;
                        }
                        data.types[field.FullName] = output;
                        result.AddRange(output);
                    }
                }
                if (!cache.typeFields.Contains(field))
                {
                    cache.typeFields.Add(field);
                }
                ProjectUtility.UpdateProjectAsset(cache);
                return(result);
            }
            else
            {
                return(result.Where(r => r.IsCreated && IsValid(r)).ToList());
            }
        }
Exemple #10
0
 private static object ConvertType(SerializableField fieldVal, in SerializableType.Field field)