public override void RenderAdditionalGui(Component affectedComponent, ExposedPropertyConfiguration propertyConfiguration) { if (!(propertyConfiguration.AdditionalData is TagData)) { propertyConfiguration.AdditionalData = new TagData(); } TagData tagData = (TagData)propertyConfiguration.AdditionalData; tagData.Tag = UnityEditor.EditorGUILayout.TagField("Tag", tagData.Tag); UnityEditor.EditorGUILayout.EndHorizontal(); tagData.FilterByGameObjectName = UnityEditor.EditorGUILayout.ToggleLeft("Filter by gameObject's name", tagData.FilterByGameObjectName, GUILayout.Width(200)); UnityEditor.EditorGUILayout.BeginHorizontal(); //on config asset, there's no affected component -> no control label will be shown if (affectedComponent != null) { string usedFilter = !tagData.FilterByGameObjectName ? "" : affectedComponent.name; UnityEditor.EditorGUILayout.EndHorizontal(); UnityEditor.EditorGUILayout.LabelField("Used filter: " + usedFilter); UnityEditor.EditorGUILayout.BeginHorizontal(); } }
public void RenderAdditionalProcessorGui(ExposedPropertyConfiguration propertyConfiguration, Component affectedComponent) { if (_processors.ContainsKey(propertyConfiguration.OperationType)) { _processors[propertyConfiguration.OperationType].RenderAdditionalGui(affectedComponent, propertyConfiguration); } }
public override void RenderAdditionalGui(Component affectedComponent, ExposedPropertyConfiguration propertyConfiguration) { if (!(propertyConfiguration.AdditionalData is ObjectOfTypeData)) { propertyConfiguration.AdditionalData = new ObjectOfTypeData(); } ObjectOfTypeData objectOfTypeData = (ObjectOfTypeData)propertyConfiguration.AdditionalData; //beginHorizontal is in code before objectOfTypeData.FilterByName = UnityEditor.EditorGUILayout.ToggleLeft("Filter by name", objectOfTypeData.FilterByName, GUILayout.Width(100)); UnityEditor.EditorGUI.BeginDisabledGroup(!objectOfTypeData.FilterByName); objectOfTypeData.NameFilter = UnityEditor.EditorGUILayout.TextField(objectOfTypeData.NameFilter); UnityEditor.EditorGUILayout.EndHorizontal(); UnityEditor.EditorGUILayout.BeginHorizontal(); objectOfTypeData.AddCurrentNamePrefix = UnityEditor.EditorGUILayout.ToggleLeft("Add gameObject name as prefix", objectOfTypeData.AddCurrentNamePrefix, GUILayout.Width(200)); if (affectedComponent != null) { string usedFilter = !objectOfTypeData.FilterByName ? "" : GetCurrentNameFilter(affectedComponent.name, objectOfTypeData); UnityEditor.EditorGUILayout.EndHorizontal(); UnityEditor.EditorGUILayout.BeginHorizontal(); UnityEditor.EditorGUILayout.LabelField("Used filter: " + usedFilter); } //endHorizontal is in code after UnityEditor.EditorGUI.EndDisabledGroup(); }
private void RenderFieldForType(FieldInfo field, Component affectedComponent, ExposedConfiguration configuration) { string fieldId = field.Name; ExposedPropertyConfiguration propertyConfiguration = configuration.ScriptConfigurationManager.GetPropertyConfiguration(fieldId); EditorGUILayout.BeginHorizontal(); RenderFieldReferencesInformation(field, affectedComponent); string typeName = _arrayTypeUtils.GetFormatedType(field.FieldType); _configFieldRenderer.RenderConfigField(affectedComponent, propertyConfiguration, fieldId, typeName); }
public void RenderConfigField(Component affectedComponent, ExposedPropertyConfiguration propertyConfiguration, string fieldId, string typeName) { string toggleLabel = typeName != null?string.Format("{0} ({1})", fieldId, typeName) : fieldId; propertyConfiguration.Enabled = EditorGUILayout.ToggleLeft(toggleLabel, propertyConfiguration.Enabled, EditorStyles.boldLabel); EditorGUILayout.EndHorizontal(); #if UNITY_4_5 || UNITY_4_6 || UNITY_4_7 EditorGUILayout.BeginVertical(); #else EditorGUILayout.BeginVertical(EditorStyles.helpBox); #endif EditorGUI.BeginDisabledGroup(!propertyConfiguration.Enabled); EditorGUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); propertyConfiguration.SearchType = (ExposedSearchType)EditorGUILayout.EnumPopup(propertyConfiguration.SearchType, GUILayout.Width(57)); if (EditorGUI.EndChangeCheck()) { //reset operation type in case of changing type of search propertyConfiguration.OperationType = ""; } switch (propertyConfiguration.SearchType) { case ExposedSearchType.Custom: RenderPropertyPopup(propertyConfiguration, _customOperationTypes, _customOperationIds, _customOperationLabels); break; case ExposedSearchType.Query: propertyConfiguration.OperationType = "exposed-query"; EditorGUI.BeginDisabledGroup(true); //propertyConfiguration.Query = EditorGUILayout.TextField(propertyConfiguration.Query); EditorGUILayout.TextField("coming soon..."); EditorGUI.EndDisabledGroup(); break; //ExposedSearchType.Core default: RenderPropertyPopup(propertyConfiguration, _operationTypes, _operationIds, _operationLabels); break; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); _propertyProcessorManager.RenderAdditionalProcessorGui(propertyConfiguration, affectedComponent); EditorGUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); EditorGUILayout.EndVertical(); }
public void ProcessArrayFieldWithProcessor(ExposedPropertyConfiguration propertyConfiguration, Component affectedComponent, FieldInfo field, Type fieldType) { string operationType = propertyConfiguration.OperationType; if (_processors.ContainsKey(operationType)) { IPropertyProcessor propertyProcessor = _processors[operationType]; Object[] values = {}; if (fieldType == typeof(GameObject)) { values = propertyProcessor.ProcessArrayGameObjectField( affectedComponent, fieldType, propertyConfiguration); } else if (fieldType.IsSubclassOf(typeof(Component))) { values = propertyProcessor.ProcessArrayComponentField( affectedComponent, fieldType, propertyConfiguration); } if (values != null) { if (_arrayTypeUtils.IsArray(field.FieldType)) { Array referencedObjectsArray = Array.CreateInstance(fieldType, values.Length); for (int i = 0; i < referencedObjectsArray.Length; i++) { referencedObjectsArray.SetValue(values[i], i); } field.SetValue(affectedComponent, referencedObjectsArray); } //else it should be list else { var list = (IList)Activator.CreateInstance(field.FieldType); foreach (var value in values) { list.Add(value); } field.SetValue(affectedComponent, list); } } else { field.SetValue(affectedComponent, null); } } }
private void RenderPropertyPopup(ExposedPropertyConfiguration propertyConfiguration, int[] operationTypes, string[] operationIds, string[] operationLabels) { int selectedItem = 0; if (_operationNamesMapping.ContainsKey(propertyConfiguration.OperationType)) { selectedItem = _operationNamesMapping[propertyConfiguration.OperationType]; } selectedItem = EditorGUILayout.IntPopup("", selectedItem, operationLabels, operationTypes); if (operationTypes.Length > 0) { propertyConfiguration.OperationType = operationIds[selectedItem]; } }
public override void RenderAdditionalGui(Component affectedComponent, ExposedPropertyConfiguration propertyConfiguration) { UnityEditor.EditorGUILayout.BeginHorizontal(); //inicialization of new data if (!(propertyConfiguration.AdditionalData is HierarchyData)) { propertyConfiguration.AdditionalData = new HierarchyData(); } HierarchyData hierarchyData = (HierarchyData)propertyConfiguration.AdditionalData; hierarchyData.IncludeInactive = UnityEditor.EditorGUILayout.ToggleLeft("Nonactive included", hierarchyData.IncludeInactive, GUILayout.Width(130)); hierarchyData.IncludeSelf = UnityEditor.EditorGUILayout.ToggleLeft("Self included", hierarchyData.IncludeSelf); UnityEditor.EditorGUILayout.EndHorizontal(); }
public void ProcessSingleFieldWithProcessor(ExposedPropertyConfiguration propertyConfiguration, Component affectedComponent, FieldInfo field, Type fieldType) { string operationType = propertyConfiguration.OperationType; if (_processors.ContainsKey(operationType)) { IPropertyProcessor propertyProcessor = _processors[operationType]; Object value = null; if (fieldType == typeof(GameObject)) { value = propertyProcessor.ProcessSingleGameObjectField(affectedComponent, fieldType, propertyConfiguration); } else if (fieldType.IsSubclassOf(typeof(Component))) { value = propertyProcessor.ProcessSingleComponentField(affectedComponent, fieldType, propertyConfiguration); } field.SetValue(affectedComponent, value); } }
private void ProcessField(FieldInfo field, Component affectedComponent, ExposedConfiguration configuration) { ExposedPropertyConfiguration propertyConfiguration = configuration.ScriptConfigurationManager.GetPropertyConfiguration(field.Name); if (propertyConfiguration.Enabled) { //singlefield if (!_arrayTypeUtils.IsSupportedArrayType(field.FieldType)) { _propertyProcessorManager.ProcessSingleFieldWithProcessor(propertyConfiguration, affectedComponent, field, field.FieldType); } //arrayfield else { _propertyProcessorManager.ProcessArrayFieldWithProcessor(propertyConfiguration, affectedComponent, field, _arrayTypeUtils.GetElementTypeFromArray(field.FieldType)); } } }
private T FindObjectOfType <T>(Component affectedComponent, Type fieldType, ExposedPropertyConfiguration propertyConfiguration) where T : Object { ObjectOfTypeData objectOfTypeData = (ObjectOfTypeData)propertyConfiguration.AdditionalData; //without filtering by name if (!objectOfTypeData.FilterByName) { return(Object.FindObjectOfType(fieldType) as T); } string currentNameFilter = GetCurrentNameFilter(affectedComponent.name, objectOfTypeData); Object[] objects = Object.FindObjectsOfType(fieldType); foreach (var unityObject in objects) { if (unityObject.name == currentNameFilter) { return(unityObject as T); } } return(null); }
public virtual void RenderAdditionalGui(Component affectedComponent, ExposedPropertyConfiguration propertyConfiguration) { }
public override Component[] ProcessArrayComponentField(Component affectedComponent, Type fieldType, ExposedPropertyConfiguration propertyConfiguration) { return(affectedComponent.gameObject.GetComponents(fieldType)); }
public abstract Component ProcessSingleComponentField(Component affectedComponent, Type fieldType, ExposedPropertyConfiguration propertyConfiguration);
public abstract GameObject[] ProcessArrayGameObjectField(Component affectedComponent, Type fieldType, ExposedPropertyConfiguration propertyConfiguration);
public override GameObject[] ProcessArrayGameObjectField(Component affectedComponent, Type fieldType, ExposedPropertyConfiguration propertyConfiguration) { TagData tagData = (TagData)propertyConfiguration.AdditionalData; string tag = tagData.Tag; if (string.IsNullOrEmpty(tag)) { return(null); } GameObject[] gameObjects = GameObject.FindGameObjectsWithTag(tag); if (!tagData.FilterByGameObjectName) { return(gameObjects); } List <GameObject> resultGameObjects = new List <GameObject>(); //filtering by gameObject's name foreach (var gameObject in gameObjects) { if (gameObject.name == affectedComponent.name) { resultGameObjects.Add(gameObject); } } return(resultGameObjects.ToArray()); }
public override Component ProcessSingleComponentField(Component affectedComponent, Type fieldType, ExposedPropertyConfiguration propertyConfiguration) { TagData tagData = (TagData)propertyConfiguration.AdditionalData; string tag = tagData.Tag; if (string.IsNullOrEmpty(tag)) { return(null); } //filtering by gameObject's name GameObject[] findGameObjectsWithTag = GameObject.FindGameObjectsWithTag(tag); foreach (var gameObject in findGameObjectsWithTag) { Component component = gameObject.GetComponent(fieldType); if (component != null) { if (!tagData.FilterByGameObjectName) { return(component); } if (gameObject.name == affectedComponent.name) { return(component); } } } return(null); }
private T[] FindObjectsOfType <T>(Component affectedComponent, Type fieldType, ExposedPropertyConfiguration propertyConfiguration) where T : Object { ObjectOfTypeData objectOfTypeData = (ObjectOfTypeData)propertyConfiguration.AdditionalData; T[] objects = Object.FindObjectsOfType(fieldType) as T[]; //without filtering by name if (!objectOfTypeData.FilterByName) { return(objects); } if (objects == null) { return(null); } string currentNameFilter = GetCurrentNameFilter(affectedComponent.name, objectOfTypeData); List <T> filteredObjects = new List <T>(); foreach (var unityObject in objects) { if (unityObject.name == currentNameFilter) { filteredObjects.Add(unityObject); } } return(filteredObjects.ToArray()); }
public override GameObject ProcessSingleGameObjectField(Component affectedComponent, Type fieldType, ExposedPropertyConfiguration propertyConfiguration) { return(affectedComponent.gameObject); }
public override Component[] ProcessArrayComponentField(Component affectedComponent, Type fieldType, ExposedPropertyConfiguration propertyConfiguration) { return(FindObjectsOfType <Component>(affectedComponent, fieldType, propertyConfiguration)); }
public override Component[] ProcessArrayComponentField(Component affectedComponent, Type fieldType, ExposedPropertyConfiguration propertyConfiguration) { GameObject[] objects = ProcessArrayGameObjectField(affectedComponent, fieldType, propertyConfiguration); if (objects == null) { return(null); } List <Component> components = new List <Component>(); foreach (var gameObject in objects) { components.AddRange(gameObject.GetComponents(fieldType)); } return(components.ToArray()); }
public override GameObject[] ProcessArrayGameObjectField(Component affectedComponent, Type fieldType, ExposedPropertyConfiguration propertyConfiguration) { HierarchyData hierarchyData = (HierarchyData)propertyConfiguration.AdditionalData; Transform[] transforms = affectedComponent.gameObject.GetComponentsInChildren <Transform>(hierarchyData.IncludeInactive); List <GameObject> gameObjects = new List <GameObject>(); foreach (var transform in transforms) { if (HierarchyData.PassedThroughConditions(transform, affectedComponent, hierarchyData)) { gameObjects.Add(transform.gameObject); } } return(gameObjects.ToArray()); }
public override GameObject ProcessSingleGameObjectField(Component affectedComponent, Type fieldType, ExposedPropertyConfiguration propertyConfiguration) { HierarchyData hierarchyData = (HierarchyData)propertyConfiguration.AdditionalData; //active - fastest, self included variant if (!hierarchyData.IncludeInactive && hierarchyData.IncludeSelf) { Transform transform = affectedComponent.GetComponentInChildren <Transform>(); return(transform != null ? transform.gameObject : null); } //nonactive included Transform[] transforms = affectedComponent.gameObject.GetComponentsInChildren <Transform>(true); foreach (var component in transforms) { if (HierarchyData.PassedThroughConditions(component, affectedComponent, hierarchyData)) { return(component.gameObject); } } return(null); }
public override GameObject[] ProcessArrayGameObjectField(Component affectedComponent, Type fieldType, ExposedPropertyConfiguration propertyConfiguration) { return(new[] { affectedComponent.gameObject }); }
public override Component ProcessSingleComponentField(Component affectedComponent, Type fieldType, ExposedPropertyConfiguration propertyConfiguration) { HierarchyData hierarchyData = (HierarchyData)propertyConfiguration.AdditionalData; //active - fastest, self included variant if (!hierarchyData.IncludeInactive && hierarchyData.IncludeSelf) { return(affectedComponent.gameObject.GetComponentInChildren(fieldType)); } //nonactive included Component[] components = affectedComponent.gameObject.GetComponentsInChildren(fieldType, true); foreach (var component in components) { if (HierarchyData.PassedThroughConditions(component, affectedComponent, hierarchyData)) { return(component); } } return(null); }
public override GameObject ProcessSingleGameObjectField(Component affectedComponent, Type fieldType, ExposedPropertyConfiguration propertyConfiguration) { return(FindObjectOfType <GameObject>(affectedComponent, fieldType, propertyConfiguration)); }
public override Component[] ProcessArrayComponentField(Component affectedComponent, Type fieldType, ExposedPropertyConfiguration propertyConfiguration) { HierarchyData hierarchyData = (HierarchyData)propertyConfiguration.AdditionalData; Component[] components = affectedComponent.gameObject.GetComponentsInChildren(fieldType, hierarchyData.IncludeInactive); if (hierarchyData.IncludeSelf) { return(components); } List <Component> nonSelfComponents = new List <Component>(); foreach (var component in components) { if (HierarchyData.PassedThroughConditions(component, affectedComponent, hierarchyData)) { nonSelfComponents.Add(component); } } return(nonSelfComponents.ToArray()); }
public override Component ProcessSingleComponentField(Component affectedComponent, Type fieldType, ExposedPropertyConfiguration propertyConfiguration) { string query = propertyConfiguration.Query; return(affectedComponent.gameObject.GetComponent(query)); }