/// <summary> /// Returns the module that this enum type belongs to /// </summary> private static UTinyModule GetEnumModule(IRegistry registry, UTinyType.Reference type) { // @TODO Optimization/direct lookup... this is really bad var modules = registry.FindAllByType <UTinyModule>(); return(modules.FirstOrDefault(module => module.Enums.Contains(type))); }
public void RemoveTypeReference(UTinyType.Reference type) { s_ConfigurationsProperty.Remove(this, type); s_ComponentsProperty.Remove(this, type); s_StructsProperty.Remove(this, type); s_EnumsProperty.Remove(this, type); }
public UTinyList(IRegistry registry, UTinyType.Reference type, IVersionStorage versionStorage = null) : this(registry, versionStorage) { m_Registry = registry; m_Type = type; m_SharedVersionStorage = versionStorage; Refresh(); }
public void Refresh(IRegistry registry) { var fieldtype = m_FieldType.Dereference(registry); if (fieldtype != null) { fieldtype.Refresh(); if (fieldtype.Version == m_FieldTypeVersion) { return; } // Fix up the reference m_FieldType = (UTinyType.Reference)fieldtype; VersionStorage.IncrementVersion(null, this); m_FieldTypeVersion = fieldtype.Version; } else { if (m_FieldTypeVersion == -1) { return; } VersionStorage.IncrementVersion(null, this); m_FieldTypeVersion = -1; } }
public static void RegisterTypeIdChange(string srcTypeFullName, string dstTypeFullName) { var name = dstTypeFullName.Substring(dstTypeFullName.LastIndexOf(".", StringComparison.Ordinal) + 1); var type = new UTinyType.Reference(UTinyId.Generate(dstTypeFullName), name); Register(UTinyId.Generate(srcTypeFullName), new TypeIdChange(type)); }
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 Reference(UTinyType.Reference type, UTinyId id, string name, int value) { m_Type = type; m_Id = id; m_Name = name; m_Value = value; }
public Sprite2DRendererHitBox2DBindings(UTinyType.Reference typeRef) : base(typeRef) { UnityEditor.EditorApplication.delayCall += () => { RegisterForEvent(UTinyEditorApplication.Registry.GetSprite2DRendererType()); }; }
public UTinyObject AddComponent(UTinyType.Reference type) { var component = NewComponent(type); s_ComponentsProperty.Add(this, component); OnComponentAdded?.Invoke(this, component); return(component); }
public LifetimeRotationBindings(UTinyType.Reference typeRef) : base(typeRef) { RequireComponentType <ParticleSystem>(); UnityEditor.EditorApplication.delayCall += () => { RegisterForEvent(UTinyEditorApplication.Registry.GetCurveType()); }; }
public Sprite2DRendererTilingBindings(UTinyType.Reference typeRef) : base(typeRef) { RequireComponentType <SpriteRenderer>(); UnityEditor.EditorApplication.delayCall += () => { RegisterForEvent(UTinyEditorApplication.Registry.GetSprite2DRendererType()); RegisterForEvent(UTinyEditorApplication.Registry.GetTransformType()); }; }
public ParticleEmitter(UTinyType.Reference typeRef) : base(typeRef) { UnityEditor.EditorApplication.delayCall += () => { RegisterForEvent(UTinyEditorApplication.Registry.GetSprite2DRendererType()); RegisterForEvent(UTinyEditorApplication.Registry.GetSprite2DType()); RegisterForEvent(UTinyEditorApplication.Registry.GetImage2DType()); RegisterForEvent(UTinyEditorApplication.Registry.GetTransformType()); }; }
public UTinyObject(IRegistry registry, UTinyType.Reference type, IVersionStorage versionStorage = null, bool refresh = true) { Registry = registry; m_SharedVersionStorage = versionStorage; m_Properties = new PropertiesContainer(this); m_Type = type; if (refresh) { Refresh(); } }
public UTinyObject GetComponent(UTinyType.Reference type) { for (int i = 0; i < Components.Count; ++i) { var component = Components[i]; if (component.Type.Equals(type)) { return(component); } } return(null); }
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; }
protected void RegisterForEvent(UTinyType.Reference typeref) { IList <ComponentBinding> bindings; if (!s_Listeners.TryGetValue(typeref, out bindings)) { bindings = s_Listeners[typeref] = new List <ComponentBinding>(); } if (!bindings.Contains(this)) { bindings.Add(this); } }
public UTinyObject RemoveComponent(UTinyType.Reference type) { var component = Components.FirstOrDefault(o => o.Type.Equals(type)); if (null != component) { var e = OnComponentRemoved; e?.Invoke(this, component); var self = this; s_ComponentsProperty.Remove(self, component); } return(component); }
private static void ProcessDependency(UTinyType.Reference typeRef, IEnumerable <UTinyEntity> entities) { IList <ComponentBinding> bindings; if (!s_Listeners.TryGetValue(typeRef, out bindings)) { return; } foreach (var binding in bindings) { Run(binding, BindingTiming.OnUpdateBindings, binding.TypeRef); } }
private static void Run(IComponentBinding binding, BindingTiming timing, UTinyType.Reference type) { var registry = UTinyEditorApplication.Registry; foreach (var entity in UTinyEditorApplication.EntityGroupManager.LoadedEntityGroups.Deref(registry).Entities()) { var component = entity.GetComponent(type); if (null == component) { continue; } binding.Run(timing, entity, component); } }
public static UTinyType.Reference UpdateReference(UTinyType.Reference reference) { UTinyId id; do { var updater = GetTypeUpdater(reference.Id); if (null == updater) { break; } id = reference.Id; reference = updater.UpdateReference(reference); } while (!id.Equals(reference.Id)); return(reference); }
/// <summary> /// Updates the value tree based on its internal type and migrates any values /// /// @TODO This method does WAY to much /// - We migrate data /// - Ensure types are up to date /// - Rebuild properties /// </summary> public void Refresh(UTinyObject defaultValue = null, bool skipTypeCheck = false) { var type = Type.Dereference(Registry); if (null == type) { // m_Properties.Clear(); return; } if (!IsDefaultValue) { // Force the type to be refreshed if (!skipTypeCheck) { type.Refresh(); } if (defaultValue == null) { defaultValue = type.GetDefaultValue() as UTinyObject; } } var defaultValueVersion = defaultValue?.Version ?? -1; if (m_CurrentTypeVersion == type.Version && m_DefaultValueVersion == defaultValueVersion) { return; } // Fix up the ref name m_Type = (UTinyType.Reference)type; m_Properties.Refresh(type, defaultValue, skipTypeCheck); m_CurrentTypeVersion = type.Version; m_DefaultValueVersion = defaultValueVersion; if (type.TypeCode == UTinyTypeCode.Component) { Name = type.Name; } }
private void ShowRemoveComponent(UTinyType.Reference typeRef) { var type = typeRef.Dereference(Registry); if ((null == type || type.TypeCode == UTinyTypeCode.Component) && TargetType == typeof(UTinyEntity)) { var rect = EditorGUILayout.GetControlRect(false, GUILayout.Width(16.0f)); if (GUI.Button(rect, UTinyIcons.X_Icon_8, UTinyStyles.MiddleCenteredLabel)) { var targets = Targets.Cast <UTinyEntity>().ToList(); EditorApplication.delayCall += () => { foreach (var entity in targets.Cast <UTinyEntity>()) { entity.RemoveComponent(typeRef); } // This is called manually because we want the scene graphs to be recreated. UTinyEventDispatcher <ChangeSource> .Dispatch(ChangeSource.DataModel); }; } GUILayout.Space(5.0f); } }
private void ShowRemoveComponent(UTinyType.Reference typeRef) { var type = typeRef.Dereference(Registry); if ((null == type || type.TypeCode == UTinyTypeCode.Component) && TargetType == typeof(UTinyEntity)) { var rect = EditorGUILayout.GetControlRect(false, GUILayout.Width(16.0f)); if (GUI.Button(rect, UTinyIcons.X_Icon_8, UTinyStyles.MiddleCenteredLabel)) { var targets = Targets.Cast <UTinyEntity>().ToList(); EditorApplication.delayCall += () => { foreach (var entity in targets.Cast <UTinyEntity>()) { entity.RemoveComponent(typeRef); } UTinyHierarchyWindow.InvalidateDataModel(); UTinyInspector.RepaintAll(); }; } GUILayout.Space(5.0f); } }
public UTinyType.Reference UpdateReference(UTinyType.Reference reference) { return(s_ColorType); }
public UTinyType.Reference UpdateReference(UTinyType.Reference reference) { return(m_Type); }
public TypeIdChange(UTinyType.Reference type) { m_Type = type; }
public EmitterInitialRotation(UTinyType.Reference typeRef) : base(typeRef) { RequireComponentType <ParticleSystem>(); }
private static void AddBindings <TBinding>(IRegistry registry, UTinyType.Reference type, Func <UTinyType.Reference, TBinding> del) where TBinding : IComponentBinding { type.Dereference(registry)?.AddAttribute(Bindings(del(type))); }
private static void AddDrawer <TDrawer>(IRegistry registry, UTinyType.Reference type) where TDrawer : StructDrawer, new() { type.Dereference(registry)?.AddAttribute(CustomDrawer(new TDrawer())); }
private static void AddEditor <TEditor>(IRegistry registry, UTinyType.Reference type) where TEditor : ComponentEditor, new() { type.Dereference(registry)?.AddAttribute(CustomEditor(new TEditor())); }