public Reference(UTinyType type, int value) { Assert.IsNotNull(type); Assert.IsTrue(type.IsEnum); var defaultValue = type.DefaultValue as UTinyObject; UTinyField field; if (null != defaultValue) { var name = string.Empty; var container = (IPropertyContainer)defaultValue.Properties; foreach (var property in defaultValue.Properties.PropertyBag.Properties) { var propertyValue = property.GetObjectValue(container); if (!value.Equals(propertyValue)) { continue; } name = property.Name; break; } field = type.FindFieldByName(name); } else { field = type.Fields.FirstOrDefault(); } m_Type = (UTinyType.Reference)type; m_Id = field?.Id ?? UTinyId.Empty; m_Name = field?.Name ?? string.Empty; m_Value = null != field ? (int?)defaultValue?[m_Name] ?? 0 : 0; }
public override void VisitType(UTinyType type) { if (type.IsRuntimeIncluded) { // @HACK if (type.Name == "Camera2D") { GenerateLayerComponents(); } return; } if (type.IsEnum) { // @TODO Handle underlying type - for now we assume C#-friendly types using (Writer.Scope($"public enum {type.Name}")) { var defaultValue = type.DefaultValue as UTinyObject; var first = true; foreach (var field in type.Fields) { var value = defaultValue[field.Name]; Writer.Line($"{(first ? "" : ", ")}{field.Name} = {value}"); first = false; } } } else { WriteType(type); } }
public void Reset(UTinyType type, UTinyObject defaultValue) { if (null == type) { return; } // The default value for this type var typeDefaultValue = !m_Object.IsDefaultValue ? defaultValue ?? type.DefaultValue as UTinyObject : null; var fields = type.Fields; for (var i = 0; i < fields.Count; i++) { var field = fields[i]; var fieldType = field.FieldType.Dereference(m_Object.Registry); var fieldValue = m_FieldValues[i]; fieldValue.Overridden = false; // The default value for this field var fieldDefaultValue = typeDefaultValue?[field.Name]; if (fieldType.IsPrimitive || fieldType.IsEnum) { fieldValue.Value = fieldDefaultValue; } else { (fieldValue.Value as UTinyObject)?.Reset(fieldDefaultValue as UTinyObject); } } }
protected override bool ValidateObject(UTinyObject tiny, UTinyType type) { if (type.TypeCode == UTinyTypeCode.Component) { return(Targets.Cast <UTinyEntity>().All(e => e.Components.Any(c => c.Type.Id == tiny.Type.Id))); } return(base.ValidateObject(tiny, type)); }
private static string GetDefaultJsValue(UTinyType type) { if (type.TypeCode == UTinyTypeCode.UnityObject || type.TypeCode == UTinyTypeCode.EntityReference) { return("ut.Entity.NONE"); } // @TODO Handle primitives return("null"); }
private static IList MigrateListValue(IRegistry registry, IVersionStorage version, IList value, UTinyType type) { var result = UTinyType.CreateListInstance(type); for (var i = 0; i < value?.Count; i++) { result.Add(UTinyObject.PropertiesContainer.MigrateFieldValue(registry, version, value[i], type, false)); } return(result); }
private bool DoRootObject(UTinyObject tiny, UTinyType type) { var foldout = GetFoldoutFromCache(tiny); EditorGUILayout.BeginHorizontal(); foldout = UpdateFoldout(tiny, Foldout(foldout, type.Name, tiny.Properties.PropertyBag.PropertyCount > 0, tiny)); ShowRemoveComponent((UTinyType.Reference)type); EditorGUILayout.EndHorizontal(); GUILayout.Space(5.0f); return(foldout); }
public Reference(UTinyType type, UTinyId fieldId) { Assert.IsNotNull(type); Assert.IsTrue(type.IsEnum); var defaultValue = type.DefaultValue as UTinyObject; var field = type.FindFieldById(fieldId); m_Type = (UTinyType.Reference)type; m_Id = field?.Id ?? UTinyId.Empty; m_Name = field?.Name ?? string.Empty; m_Value = null != field ? (int?)defaultValue?[m_Name] ?? 0 : 0; }
/// <summary> /// Creates a runtime instance of the given type /// /// NOTE: For primitives this returns the default .NET value /// </summary> /// <param name="type"></param> /// <returns></returns> public static object CreateInstance(UTinyType type) { var typeCode = type.TypeCode; switch (typeCode) { case UTinyTypeCode.Int8: return(default(sbyte)); case UTinyTypeCode.Int16: return(default(short)); case UTinyTypeCode.Int32: return(default(int)); case UTinyTypeCode.Int64: return(default(long)); case UTinyTypeCode.UInt8: return(default(byte)); case UTinyTypeCode.UInt16: return(default(ushort)); case UTinyTypeCode.UInt32: return(default(uint)); case UTinyTypeCode.UInt64: return(default(ulong)); case UTinyTypeCode.Float32: return(default(float)); case UTinyTypeCode.Float64: return(default(double)); case UTinyTypeCode.Boolean: return(default(bool)); case UTinyTypeCode.Char: return(default(char)); case UTinyTypeCode.String: return(string.Empty); default: return(null); } }
public UTinyType CreateType(UTinyId id, string name, UTinyTypeCode typeCode) { var type = new UTinyType(this, m_VersionStorage) { Id = id, Name = name, TypeCode = typeCode }; m_VersionStorage.MarkAsChanged(type); Register(type); return(type); }
private bool VisitComponent(UTinyObject tiny, UTinyType type) { ++EditorGUI.indentLevel; try { var editor = Mode == InspectMode.Normal && type.HasAttribute <EditorInspectorAttributes.CustomComponentEditor>() ? type.GetAttribute <EditorInspectorAttributes.CustomComponentEditor>().Visitor : s_DefaultComponentVisitor; TransferState(editor); return(editor.VisitComponent(tiny)); } finally { --EditorGUI.indentLevel; } }
private void WriteType(UTinyType type) { var typePost = ""; if (type.TypeCode == UTinyTypeCode.Component) { typePost = " : IComponentData"; } using (Writer.Scope($"public struct {type.Name}{typePost}")) { foreach (var field in type.Fields) { Writer.LineFormat(field.Array ? "public DynamicArray<{0}> {1};" : "public {0} {1};", FieldTypeToIDL(type.Registry, field), field.Name); } } }
public static void SetType(UTinyType type, bool additive = false) { var instance = GetInstance(); instance.Registry = type.Registry; instance.TypeRef = UTinyType.Reference.None; instance.TypeRef = (UTinyType.Reference)type; if (!additive) { Selection.activeInstanceID = instance.GetInstanceID(); } else { if (!Selection.instanceIDs.Contains(instance.GetInstanceID())) { var selection = Selection.instanceIDs.ToList(); selection.Add(instance.GetInstanceID()); Selection.instanceIDs = selection.ToArray(); } } }
private static IEnumerable <Reference> EnumerateFieldTypes(UTinyType type, ISet <Reference> visited) { foreach (var field in type.Fields) { if (!visited.Add(field.FieldType)) { continue; } var fieldType = field.FieldType.Dereference(type.Registry); if (null == fieldType) { continue; } yield return((Reference)fieldType); foreach (var fieldTypeReference in EnumerateFieldTypes(fieldType)) { yield return(fieldTypeReference); } } }
static UTinyType() { NewComponentType = new UTinyType(null, PassthroughVersionStorage.Instance) { Id = new UTinyId("696b7de3df0f4887abca1fb6aa7f2615"), Name = "NewComponentType", TypeCode = UTinyTypeCode.Component }; // @NOTE: Primitives do not belong to a single registry and are shared across all registries Int8 = new UTinyType(null, PassthroughVersionStorage.Instance) { Id = new UTinyId("27c155635ccb4ab2bcb79ef5aaf129ec"), Name = "Int8", TypeCode = UTinyTypeCode.Int8 }; Int16 = new UTinyType(null, PassthroughVersionStorage.Instance) { Id = new UTinyId("2aa56ce081e14e8a93d276da72d813bc"), Name = "Int16", TypeCode = UTinyTypeCode.Int16 }; Int32 = new UTinyType(null, PassthroughVersionStorage.Instance) { Id = new UTinyId("9633c95a0a68473682f09ed6a01194b4"), Name = "Int32", TypeCode = UTinyTypeCode.Int32 }; Int64 = new UTinyType(null, PassthroughVersionStorage.Instance) { Id = new UTinyId("37695933217a49f68ce15db33f63cdf9"), Name = "Int64", TypeCode = UTinyTypeCode.Int64 }; UInt8 = new UTinyType(null, PassthroughVersionStorage.Instance) { Id = new UTinyId("7112767112f747e2a340404a5ceb31b5"), Name = "UInt8", TypeCode = UTinyTypeCode.UInt8 }; UInt16 = new UTinyType(null, PassthroughVersionStorage.Instance) { Id = new UTinyId("86fa32ad22614762afdacbf4dba8180f"), Name = "UInt16", TypeCode = UTinyTypeCode.UInt16 }; UInt32 = new UTinyType(null, PassthroughVersionStorage.Instance) { Id = new UTinyId("1da58c8ba95a4c85a2b5920bd0663f70"), Name = "UInt32", TypeCode = UTinyTypeCode.UInt32 }; UInt64 = new UTinyType(null, PassthroughVersionStorage.Instance) { Id = new UTinyId("574059163cda44b3ade6ea7b2daf67f2"), Name = "UInt64", TypeCode = UTinyTypeCode.UInt64 }; Float32 = new UTinyType(null, PassthroughVersionStorage.Instance) { Id = new UTinyId("67325dccf2f047c19c7ef4a045354e67"), Name = "Float32", TypeCode = UTinyTypeCode.Float32 }; Float64 = new UTinyType(null, PassthroughVersionStorage.Instance) { Id = new UTinyId("74cf32c2744342b7903871f8feb2fdd7"), Name = "Float64", TypeCode = UTinyTypeCode.Float64 }; Boolean = new UTinyType(null, PassthroughVersionStorage.Instance) { Id = new UTinyId("2b477f505af74487b7092b5617d88d3f"), Name = "Boolean", TypeCode = UTinyTypeCode.Boolean }; Char = new UTinyType(null, PassthroughVersionStorage.Instance) { Id = new UTinyId("e9c46111504a470885988383d2091dc2"), Name = "Char", TypeCode = UTinyTypeCode.Char }; String = new UTinyType(null, PassthroughVersionStorage.Instance) { Id = new UTinyId("1bff5adddd7c41de98d3329c7c641208"), Name = "String", TypeCode = UTinyTypeCode.String }; EntityReference = new UTinyType(null, PassthroughVersionStorage.Instance) { Id = new UTinyId("5a182d9d039d4dfd8fa96132d05f9ee7"), Name = "EntityReference", TypeCode = UTinyTypeCode.EntityReference }; // Asset entity reference types Texture2DEntity = new UTinyType(null, PassthroughVersionStorage.Instance) { Id = new UTinyId("373ed9034ede4f84829bf01ed265f6ee"), Name = "Texture2DEntity", TypeCode = UTinyTypeCode.UnityObject }; SpriteEntity = new UTinyType(null, PassthroughVersionStorage.Instance) { Id = new UTinyId("cf54a635a25248ab87f2563bb840ed5b"), Name = "SpriteEntity", TypeCode = UTinyTypeCode.UnityObject }; AudioClipEntity = new UTinyType(null, PassthroughVersionStorage.Instance) { Id = new UTinyId("1ae8c073dc444f4fb2d3120e5e618326"), Name = "AudioClipEntity", TypeCode = UTinyTypeCode.UnityObject }; FontEntity = new UTinyType(null, PassthroughVersionStorage.Instance) { Id = new UTinyId("4b1f918c1c564e42a04a0cb8f4ee0665"), Name = "FontEntity", TypeCode = UTinyTypeCode.UnityObject }; BuiltInTypes = new List <UTinyType> { Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64, Float32, Float64, Boolean, Char, String, EntityReference, Texture2DEntity, SpriteEntity, AudioClipEntity, FontEntity }; }
public static IList CreateListInstance(UTinyType type) { var typeCode = type.TypeCode; switch (typeCode) { case UTinyTypeCode.Int8: return(new List <sbyte>()); case UTinyTypeCode.Int16: return(new List <short>()); case UTinyTypeCode.Int32: return(new List <int>()); case UTinyTypeCode.Int64: return(new List <long>()); case UTinyTypeCode.UInt8: return(new List <byte>()); case UTinyTypeCode.UInt16: return(new List <ushort>()); case UTinyTypeCode.UInt32: return(new List <uint>()); case UTinyTypeCode.UInt64: return(new List <ulong>()); case UTinyTypeCode.Float32: return(new List <float>()); case UTinyTypeCode.Float64: return(new List <double>()); case UTinyTypeCode.Boolean: return(new List <bool>()); case UTinyTypeCode.Char: return(new List <char>()); case UTinyTypeCode.String: return(new List <string>()); case UTinyTypeCode.Configuration: case UTinyTypeCode.Component: case UTinyTypeCode.Struct: return(new List <UTinyObject>()); case UTinyTypeCode.Enum: return(new List <UTinyEnum.Reference>()); case UTinyTypeCode.EntityReference: return(new List <UTinyEntity.Reference>()); case UTinyTypeCode.UnityObject: if (type.Id == Texture2DEntity.Id) { return(new List <UnityEngine.Texture2D>()); } else if (type.Id == SpriteEntity.Id) { return(new List <UnityEngine.Sprite>()); } else if (type.Id == AudioClipEntity.Id) { return(new List <UnityEngine.AudioClip>()); } else if (type.Id == FontEntity.Id) { return(new List <UnityEngine.Font>()); } else { return(new List <UnityEngine.Object>()); } default: throw new ArgumentOutOfRangeException(nameof(type.TypeCode), type.TypeCode, null); } }
public override void VisitType(UTinyType type) { m_Type?.Invoke(type); }
/// <summary> /// Determines if the provided System.Type maps to a built-in UTinyType. /// </summary> public static bool TryGetType(Type type, out UTinyType uTinyType) { uTinyType = GetType(type); return(null != uTinyType); }
public void Refresh(UTinyType type, UTinyObject defaultValue, bool skipTypeCheck = false) { Assert.IsNotNull(type); var fields = type.Fields; Assert.IsTrue(type.TypeCode == UTinyTypeCode.Struct || type.TypeCode == UTinyTypeCode.Component || type.TypeCode == UTinyTypeCode.Enum || type.TypeCode == UTinyTypeCode.Configuration); // Rebuild all fields and re-map the indicies correctly MigrateFields(fields, m_FieldValues); // Dynamically rebuild the property bag m_PropertyBag.Clear(); // Migrate dynamic values if (null != m_DynamicValues) { for (var i = 0; i < fields.Count; i++) { object dynamicValue; if (!m_DynamicValues.TryGetValue(fields[i].Name, out dynamicValue)) { continue; } m_FieldValues[i].Value = dynamicValue; m_FieldValues[i].Overridden = true; } m_DynamicValues = null; } for (var i = 0; i < fields.Count; i++) { var field = fields[i]; var fieldName = field.Name; var fieldType = field.FieldType.Dereference(type.Registry); var fieldValue = m_FieldValues[i]; if (null == fieldType) { continue; } // Force the field type to be refreshed if needed if (!skipTypeCheck) { fieldType.Refresh(); } // The default value for this field var fieldDefaultValue = defaultValue?[fieldName]; if (!fieldValue.Overridden && fieldType.IsPrimitive && !field.Array) { fieldValue.Value = fieldDefaultValue; } else { fieldValue.Value = MigrateFieldValue(m_Object.Registry, this, fieldValue.Value, fieldType, field.Array, fieldDefaultValue); } // @HACK if (fieldValue.Value is UTinyObject) { (fieldValue.Value as UTinyObject).Name = fieldName; } else if (fieldValue.Value is UTinyList) { (fieldValue.Value as UTinyList).Name = fieldName; } m_PropertyBag.AddProperty(CreateFieldProperty(field.Id, i, fieldName, fieldType, field.Array)); IncrementVersion(null, this); } }
public virtual void VisitType(UTinyType type) { }
private static IProperty CreateFieldProperty(UTinyId fieldId, int index, string name, UTinyType type, bool array) { IProperty property; s_FieldPropertyCache.TryGetValue(fieldId, out property); if (array) { property = property is ListFieldProperty && property.Name.Equals(name) ? property : new ListFieldProperty(index, name); } else { switch (type.TypeCode) { case UTinyTypeCode.Unknown: break; case UTinyTypeCode.Int8: property = property is FieldProperty <sbyte> && property.Name.Equals(name) ? property : new FieldProperty <sbyte>(index, name); break; case UTinyTypeCode.Int16: property = property is FieldProperty <short> && property.Name.Equals(name) ? property : new FieldProperty <short>(index, name); break; case UTinyTypeCode.Int32: property = property is FieldProperty <int> && property.Name.Equals(name) ? property : new FieldProperty <int>(index, name); break; case UTinyTypeCode.Int64: property = property is FieldProperty <long> && property.Name.Equals(name) ? property : new FieldProperty <long>(index, name); break; case UTinyTypeCode.UInt8: property = property is FieldProperty <byte> && property.Name.Equals(name) ? property : new FieldProperty <byte>(index, name); break; case UTinyTypeCode.UInt16: property = property is FieldProperty <ushort> && property.Name.Equals(name) ? property : new FieldProperty <ushort>(index, name); break; case UTinyTypeCode.UInt32: property = property is FieldProperty <uint> && property.Name.Equals(name) ? property : new FieldProperty <uint>(index, name); break; case UTinyTypeCode.UInt64: property = property is FieldProperty <ulong> && property.Name.Equals(name) ? property : new FieldProperty <ulong>(index, name); break; case UTinyTypeCode.Float32: property = property is FieldProperty <float> && property.Name.Equals(name) ? property : new FieldProperty <float>(index, name); break; case UTinyTypeCode.Float64: property = property is FieldProperty <double> && property.Name.Equals(name) ? property : new FieldProperty <double>(index, name); break; case UTinyTypeCode.Boolean: property = property is FieldProperty <bool> && property.Name.Equals(name) ? property : new FieldProperty <bool>(index, name); break; case UTinyTypeCode.Char: property = property is FieldProperty <char> && property.Name.Equals(name) ? property : new FieldProperty <char>(index, name); break; case UTinyTypeCode.String: property = property is FieldProperty <string> && property.Name.Equals(name) ? property : new FieldProperty <string>(index, name); break; case UTinyTypeCode.Configuration: case UTinyTypeCode.Component: throw new NotSupportedException(); case UTinyTypeCode.Struct: property = property is ObjectFieldProperty && property.Name.Equals(name) ? property : new ObjectFieldProperty(index, name); break; case UTinyTypeCode.Enum: property = property is MutableContainerFieldProperty <UTinyEnum.Reference> && property.Name.Equals(name) ? property : new MutableContainerFieldProperty <UTinyEnum.Reference>(index, name); break; case UTinyTypeCode.EntityReference: property = property is MutableContainerFieldProperty <UTinyEntity.Reference> && property.Name.Equals(name) ? property : new MutableContainerFieldProperty <UTinyEntity.Reference>(index, name); break; case UTinyTypeCode.UnityObject: if (type.Id == UTinyType.Texture2DEntity.Id) { property = property is FieldProperty <Texture2D> && property.Name.Equals(name) ? property : new FieldProperty <Texture2D>(index, name); } else if (type.Id == UTinyType.SpriteEntity.Id) { property = property is FieldProperty <Sprite> && property.Name.Equals(name) ? property : new FieldProperty <Sprite>(index, name); } else if (type.Id == UTinyType.AudioClipEntity.Id) { property = property is FieldProperty <AudioClip> && property.Name.Equals(name) ? property : new FieldProperty <AudioClip>(index, name); } else if (type.Id == UTinyType.FontEntity.Id) { property = property is FieldProperty <Font> && property.Name.Equals(name) ? property : new FieldProperty <Font>(index, name); } else { property = property is FieldProperty <Object> && property.Name.Equals(name) ? property : new FieldProperty <Object>(index, name); } break; default: throw new ArgumentOutOfRangeException(); } } var fieldProperty = property as IFieldProperty; if (null != fieldProperty) { fieldProperty.Index = index; } s_FieldPropertyCache[fieldId] = property; return(property); }
public static object MigrateFieldValue(IRegistry registry, IVersionStorage versionStorage, object value, UTinyType type, bool array, object defaultValue = null, bool skipTypeCheck = false) { if (array) { var list = value as UTinyList; if (null == list) { list = new UTinyList(registry, versionStorage) { Type = (UTinyType.Reference)type }; list.Refresh(defaultValue as UTinyList, skipTypeCheck); } else { list.Type = (UTinyType.Reference)type; list.Refresh(defaultValue as UTinyList, skipTypeCheck); } return(list); } switch (type.TypeCode) { case UTinyTypeCode.Unknown: break; case UTinyTypeCode.Int8: return(TryChangeType <sbyte>(value)); case UTinyTypeCode.Int16: return(TryChangeType <short>(value)); case UTinyTypeCode.Int32: return(TryChangeType <int>(value)); case UTinyTypeCode.Int64: return(TryChangeType <long>(value)); case UTinyTypeCode.UInt8: return(TryChangeType <byte>(value)); case UTinyTypeCode.UInt16: return(TryChangeType <ushort>(value)); case UTinyTypeCode.UInt32: return(TryChangeType <uint>(value)); case UTinyTypeCode.UInt64: return(TryChangeType <ulong>(value)); case UTinyTypeCode.Float32: return(TryChangeType <float>(value)); case UTinyTypeCode.Float64: return(TryChangeType <double>(value)); case UTinyTypeCode.Boolean: return(TryChangeType <bool>(value)); case UTinyTypeCode.Char: return(TryChangeType <char>(value)); case UTinyTypeCode.String: return(TryChangeType <string>(value) ?? string.Empty); case UTinyTypeCode.Configuration: case UTinyTypeCode.Component: // Components can not be fields, they can only exist at the entity level throw new NotSupportedException(); case UTinyTypeCode.Struct: { var obj = value as UTinyObject; if (null == obj) { obj = new UTinyObject(registry, (UTinyType.Reference)type, versionStorage, false); obj.Refresh(defaultValue as UTinyObject, skipTypeCheck); } else { obj.Type = (UTinyType.Reference)type; obj.Refresh(defaultValue as UTinyObject, skipTypeCheck); } return(obj); } case UTinyTypeCode.Enum: { if (value is UTinyEnum.Reference) { return(new UTinyEnum.Reference(type, ((UTinyEnum.Reference)value).Id)); } return(defaultValue is UTinyEnum.Reference ? new UTinyEnum.Reference(type, ((UTinyEnum.Reference)defaultValue).Id) : new UTinyEnum.Reference(type, type.Fields.First().Id)); } case UTinyTypeCode.EntityReference: { if (value is UTinyEntity.Reference) { return(value); } return(defaultValue is UTinyEntity.Reference ? defaultValue : UTinyEntity.Reference.None); } case UTinyTypeCode.UnityObject: { if (value is Object) { return(value); } return(defaultValue is Object ? defaultValue : null); } default: throw new ArgumentOutOfRangeException(); } return(null); }
protected virtual bool ValidateObject(UTinyObject tiny, UTinyType type) { return(true); }
private static IEnumerable <Reference> EnumerateFieldTypes(UTinyType type) { return(EnumerateFieldTypes(type, new HashSet <Reference>())); }
private bool VisitStructOrEnum <TContainer>(ref TContainer container, UTinyObject tiny, UTinyType type, int index) where TContainer : IPropertyContainer { var drawer = Mode == InspectMode.Normal && type.HasAttribute <EditorInspectorAttributes.CustomDrawerAttribute>() ? type.GetAttribute <EditorInspectorAttributes.CustomDrawerAttribute>().Visitor : s_DefaultStructVisitor; TransferState(drawer); var label = ConstructLabel(index >= 0 ? index.ToString() : tiny.Name); // We are in a list if (index >= 0) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginVertical(); } try { return(drawer.VisitStruct(tiny, label)); } finally { if (index >= 0) { EditorGUILayout.EndVertical(); if (GUILayout.Button("x", GUILayout.Width(16.0f), GUILayout.Height(16.0f))) { RemoveAtIndex = index; } EditorGUILayout.EndHorizontal(); } } }
private IListProperty CreateItemsProperty(UTinyType type) { switch (type.TypeCode) { case UTinyTypeCode.Unknown: break; case UTinyTypeCode.Int8: return(CreateSimpleListProperty <sbyte>()); case UTinyTypeCode.Int16: return(CreateSimpleListProperty <short>()); case UTinyTypeCode.Int32: return(CreateSimpleListProperty <int>()); case UTinyTypeCode.Int64: return(CreateSimpleListProperty <long>()); case UTinyTypeCode.UInt8: return(CreateSimpleListProperty <byte>()); case UTinyTypeCode.UInt16: return(CreateSimpleListProperty <ushort>()); case UTinyTypeCode.UInt32: return(CreateSimpleListProperty <uint>()); case UTinyTypeCode.UInt64: return(CreateSimpleListProperty <ulong>()); case UTinyTypeCode.Float32: return(CreateSimpleListProperty <float>()); case UTinyTypeCode.Float64: return(CreateSimpleListProperty <double>()); case UTinyTypeCode.Boolean: return(CreateSimpleListProperty <bool>()); case UTinyTypeCode.Char: return(CreateSimpleListProperty <char>()); case UTinyTypeCode.String: return(CreateSimpleListProperty <string>()); case UTinyTypeCode.Configuration: case UTinyTypeCode.Component: case UTinyTypeCode.Struct: { return(CreateContainerListProperty <UTinyObject>()); } case UTinyTypeCode.Enum: return(CreateMutableContainerListProperty <UTinyEnum.Reference>()); case UTinyTypeCode.EntityReference: return(CreateSimpleListProperty <UTinyEntity.Reference>()); case UTinyTypeCode.UnityObject: if (type.Id == UTinyType.Texture2DEntity.Id) { return(CreateSimpleListProperty <Texture2D>()); } else if (type.Id == UTinyType.SpriteEntity.Id) { return(CreateSimpleListProperty <Sprite>()); } else if (type.Id == UTinyType.AudioClipEntity.Id) { return(CreateSimpleListProperty <AudioClip>()); } else if (type.Id == UTinyType.FontEntity.Id) { return(CreateSimpleListProperty <Font>()); } else { return(CreateSimpleListProperty <Object>()); } default: throw new ArgumentOutOfRangeException(nameof(type.TypeCode), type.TypeCode, null); } return(null); }
public bool VisitTinyObject <TContainer>(ref TContainer container, UTinyObject tiny, UTinyType type, int index) where TContainer : IPropertyContainer { bool showProperties = true; // Root is [component|struct|enum], and recursive calls are [struct|enum] if (IsRoot) { GUILayout.Space(5); // Header showProperties = DoRootObject(tiny, type); } try { if (EditorGUILayout.BeginFadeGroup(showProperties ? 1.0f : 0.0f)) { GUI.enabled &= !type.HasAttribute <ReadonlyAttribute>(); var indent = EditorGUI.indentLevel; EditorGUI.indentLevel = s_Depth - 1; try { switch (type.TypeCode) { case UTinyTypeCode.Configuration: case UTinyTypeCode.Component: return(VisitComponent(tiny, type)); case UTinyTypeCode.Struct: case UTinyTypeCode.Enum: return(VisitStructOrEnum(ref container, tiny, type, index)); default: return(false); } } finally { EditorGUI.indentLevel = indent; if (IsRoot && tiny.Properties.PropertyBag.PropertyCount > 0) { GUILayout.Space(5); } EditorGUILayout.EndFadeGroup(); } } } finally { if (IsRoot) { UTinyGUILayout.Separator(UTinyColors.Inspector.Separator, UTinyGUIUtility.ComponentSeperatorHeight); } } return(true); }