/// <summary> /// Transform entity type properties. /// </summary> /// <param name="entityName">Entity type properties.</param> /// <param name="properties">Entity type properties.</param> /// <returns>Transformed entity type properties.</returns> public List <Dictionary <string, object> > TransformProperties(string entityName, List <Dictionary <string, object> > properties) { var transformedProperties = new List <Dictionary <string, object> >(); foreach (var property in properties) { var propTypeInfo = new EntityPropertyInfo( entityName, property["property-type"] as string, property["property-name"] as string, (property["property-isnullable"] as bool?) == true); var transformedProp = PropertyTransformer?.Invoke(propTypeInfo) ?? propTypeInfo; transformedProperties.Add(new Dictionary <string, object> { { "property-type", transformedProp.PropertyType }, { "property-name", transformedProp.PropertyName }, { "property-annotations", property["property-annotations"] }, { "property-comment", property["property-comment"] }, { "property-isnullable", transformedProp.PropertyIsNullable }, { "nullable-reference-types", property["nullable-reference-types"] } }); } return(transformedProperties); }
/// <summary> /// Transform single property name. /// </summary> /// <param name="propertyName">Property name.</param> /// <returns>Transformed property name.</returns> public string TransformPropertyName(string propertyName) { var propTypeInfo = new EntityPropertyInfo { PropertyName = propertyName }; return(PropertyTransformer?.Invoke(propTypeInfo)?.PropertyName ?? propertyName); }
/// <summary> /// Transform entity type properties. /// </summary> /// <param name="properties">Entity type properties.</param> /// <returns>Transformed entity type properties.</returns> public List <Dictionary <string, object> > TransformProperties(List <Dictionary <string, object> > properties) { var transformedProperties = new List <Dictionary <string, object> >(); foreach (var property in properties) { var propTypeInfo = new EntityPropertyInfo(property["property-type"] as string, property["property-name"] as string); var transformedProp = PropertyTransformer?.Invoke(propTypeInfo) ?? propTypeInfo; transformedProperties.Add(new Dictionary <string, object> { { "property-type", transformedProp.PropertyType }, { "property-name", transformedProp.PropertyName }, { "property-annotations", property["property-annotations"] } }); } return(transformedProperties); }
private void CreatePresetLayout() { EditorContent.Label("Create DynamicBone preset from existing GameObject tree."); EditorGUIUtility.labelWidth = 200; _gameObject = EditorContent.ObjectPicker<GameObject>("Root GameObject", _gameObject, true); if (ReferenceEquals(_gameObject, null)) return; var components = new List<Component>(); components.AddRange(_gameObject.GetComponentsInChildren(TypeFinder.GetType(DynamicBoneFullName))); components.AddRange(_gameObject.GetComponentsInChildren(TypeFinder.GetType(DynamicBoneColliderFullName))); components.AddRange(_gameObject.GetComponentsInChildren(TypeFinder.GetType(DynamicBonePlaneColliderFullName))); if (components.Count == 0) return; // differ { var added = components.Where(w => !_enabledComponents.ContainsKey(w.GetInstanceID())).ToList(); var removed = _enabledComponents.Where(w => ReferenceEquals(components.SingleOrDefault(v => v.GetInstanceID() == w.Key), null)).ToList(); foreach (var component in added) _enabledComponents.Add(component.GetInstanceID(), false); foreach (var instanceId in removed.Select(w => w.Key)) _enabledComponents.Remove(instanceId); } EditorContent.Space(); EditorContent.Label("Enabled Components:"); foreach (var component in components) { var instanceId = component.GetInstanceID(); _enabledComponents[instanceId] = EditorContent.Checkbox(component.ToString(), _enabledComponents[instanceId]); } if (_enabledComponents.Any(w => w.Value)) { EditorContent.Space(); EditorContent.Label("Naming Conventions:"); } foreach (var component in _enabledComponents.Where(w => w.Value).Select(w => components.Single(v => v.GetInstanceID() == w.Key))) { var convention = PropertyTransformer.TransformToStringPath(component); var instance = _configurations.SingleOrDefault(w => w.OriginalInstanceId == component.GetInstanceID()); if (ReferenceEquals(instance, null)) { instance = new DynamicBoneConfiguration(); instance.Name = instance.NamingConvention = convention; instance.Component = component; instance.OriginalInstanceId = component.GetInstanceID(); _configurations.Add(instance); } instance.NamingConvention = EditorContent.TextField(component.ToString(), instance.NamingConvention); } // cleanup instances foreach (var configuration in _enabledComponents.Where(w => !w.Value).Select(w => _configurations.SingleOrDefault(v => w.Key == v.OriginalInstanceId)).Where(w => !ReferenceEquals(w, null)).ToList()) _configurations.Remove(configuration); EditorContent.Space(); EditorContent.Label("DynamicBone Preset Manager convert hierarchy tree to the below name:"); EditorContent.Label("Avatar → Armature → Hips → ... to Avatar/Armature/Hips/..."); EditorContent.Label("If you want to preserve the tree structure, use `/` and `[^/]*?` in the naming convention."); using (EditorContent.DisabledGroup(_configurations.Count == 0)) _name = EditorContent.TextField("Preset Name", _name); using (EditorContent.DisabledGroup(string.IsNullOrEmpty(_name) || _configurations.Count == 0)) if (EditorContent.Button("Create DynamicBone Preset")) CreatePreset(); }
private List<GameObject> FindGameObjectByPath(string path) { var compiled = new Regex(string.Format("^{0}$", path)); var objects = _gameObject.GetComponentsInChildren<Transform>(); return objects.Select(w => w.gameObject).Where(w => compiled.IsMatch(PropertyTransformer.TransformToStringPath(w))).ToList(); }
public PropertyTransformerBuilder() { Base = new PropertyTransformer(); }