private void Init() { m_map = Resources.Load <EditorsMapStorage>(EditorsMapStorage.EditorsMapPrefabName); if (m_map == null) { m_map = Resources.Load <EditorsMapStorage>(EditorsMapStorage.EditorsMapTemplateName); } EditorsMap editorsMap = new EditorsMap(); Assembly[] allAssemblies; Type[] types; GetUOAssembliesAndTypes(out allAssemblies, out types); Assembly[] unityAssemblies = allAssemblies.Where(a => a != null && a.FullName != null && a.FullName.Contains("UnityEngine")).ToArray(); Assembly[] otherAssemblies = allAssemblies.Where(a => a != null && a.FullName != null && !a.FullName.Contains("UnityEngine")).ToArray(); m_objectEditorDescriptors = new[] { typeof(GameObject) } .Where(t => t.IsPublic && !t.IsGenericType) .Select(t => new EditorDescriptor(t, m_map != null && editorsMap.IsObjectEditorEnabled(t), m_map != null ? editorsMap.GetObjectEditor(t, true) : null, false)).ToArray(); m_propertyEditorDescriptors = new[] { typeof(object), typeof(UnityEngine.Object), typeof(bool), typeof(Enum), typeof(List <>), typeof(Array), typeof(string), typeof(int), typeof(float), typeof(Range), typeof(Vector2), typeof(Vector3), typeof(Vector4), typeof(Quaternion), typeof(Color), typeof(Bounds) } .Where(t => t.IsPublic) .Select(t => new EditorDescriptor(t, m_map != null && editorsMap.IsPropertyEditorEnabled(t), m_map != null ? editorsMap.GetPropertyEditor(t, true) : null, true)).ToArray(); m_stdComponentEditorDescriptors = unityAssemblies.SelectMany(a => a.GetTypes()) .Where(t => typeof(Component).IsAssignableFrom(t) && t.IsPublic && !t.IsGenericType) .OrderBy(t => (t == typeof(Component)) ? string.Empty : t.Name) .Select(t => new EditorDescriptor(t, m_map != null && editorsMap.IsObjectEditorEnabled(t), m_map != null ? editorsMap.GetObjectEditor(t, true) : null, false)).ToArray(); m_scriptEditorDescriptors = otherAssemblies.SelectMany(a => a.GetTypes()) .Where(t => typeof(MonoBehaviour).IsAssignableFrom(t) && t.IsPublic && !t.IsGenericType) .OrderBy(t => t.FullName) .Select(t => new EditorDescriptor(t, m_map != null && editorsMap.IsObjectEditorEnabled(t), m_map != null ? editorsMap.GetObjectEditor(t, true) : null, false)).ToArray(); List <Material> materials = new List <Material>(); string[] assets = AssetDatabase.GetAllAssetPaths(); foreach (string asset in assets) { if (!asset.EndsWith(".mat")) { continue; } Material material = AssetDatabase.LoadAssetAtPath <Material>(asset); if (material == null || (material.hideFlags & HideFlags.DontSaveInBuild) != 0 || material.shader == null || (material.shader.hideFlags & HideFlags.DontSaveInBuild) != 0) { continue; } materials.Add(material); } MaterialEditorDescriptor[] defaultDescriptors = new[] { new MaterialEditorDescriptor(null, m_map != null && m_map.IsDefaultMaterialEditorEnabled, m_map != null ? m_map.DefaultMaterialEditor : null) }; MaterialEditorDescriptor[] materialDescriptors = materials.Where(m => m.shader != null && !m.shader.name.StartsWith("Hidden/")) .Select(m => m.shader).Distinct() .OrderBy(s => s.name.StartsWith("Standard") ? string.Empty : s.name) .Select(s => new MaterialEditorDescriptor(s, m_map != null && editorsMap.IsMaterialEditorEnabled(s), m_map != null ? editorsMap.GetMaterialEditor(s, true) : null)).ToArray(); m_materialDescriptors = defaultDescriptors.Union(materialDescriptors).ToArray(); }
protected override void InitOverride(object target, MemberInfo memberInfo, string label = null) { Type elementType = null; if (memberInfo is PropertyInfo) { elementType = ((PropertyInfo)memberInfo).PropertyType.GetElementType(); if (elementType == null) { if (((PropertyInfo)memberInfo).PropertyType.IsGenericType) { elementType = ((PropertyInfo)memberInfo).PropertyType.GetGenericArguments()[0]; } } } else if (memberInfo is FieldInfo) { elementType = ((FieldInfo)memberInfo).FieldType.GetElementType(); if (elementType == null) { if (((FieldInfo)memberInfo).FieldType.IsGenericType) { elementType = ((FieldInfo)memberInfo).FieldType.GetGenericArguments()[0]; } } } if (elementType != null) { GameObject editor = EditorsMap.GetPropertyEditor(elementType); if (EditorsMap.IsPropertyEditorEnabled(elementType)) { m_editorPrefab = editor.GetComponent <PropertyEditor>(); } if (m_editorPrefab == null) { Debug.LogWarning("Editor for " + memberInfo.Name + " not found"); Destroy(gameObject); } base.InitOverride(target, memberInfo, label); } else { if (elementType == null) { Debug.LogWarning("Editor for " + memberInfo.Name + " not found"); Destroy(gameObject); } } if (StartExpanded) { Expander.isOn = GetValue().Count < 8; } }
private PropertyEditor InstantiateEditor(PropertyInfo propertyInfo) { PropertyEditor editor = null; if (EditorsMap.IsPropertyEditorEnabled(propertyInfo.PropertyType)) { GameObject prefab = EditorsMap.GetPropertyEditor(propertyInfo.PropertyType); if (prefab != null) { editor = Instantiate(prefab).GetComponent <PropertyEditor>(); editor.transform.SetParent(EditorsPanel, false); } } return(editor); }
private void CreateElementEditor(MemberInfo memberInfo, Type type) { if (!EditorsMap.IsPropertyEditorEnabled(type)) { return; } GameObject editorPrefab = EditorsMap.GetPropertyEditor(type); if (editorPrefab == null) { return; } PropertyEditor editor = Instantiate(editorPrefab).GetComponent <PropertyEditor>(); if (editor == null) { return; } CustomTypeFieldAccessor accessor = null; if (ChildDescriptors == null) { accessor = new CustomTypeFieldAccessor(this, memberInfo, memberInfo.Name); } else { PropertyDescriptor childPropertyDescriptor; if (ChildDescriptors.TryGetValue(memberInfo, out childPropertyDescriptor)) { accessor = new CustomTypeFieldAccessor( this, childPropertyDescriptor.MemberInfo, childPropertyDescriptor.Label); } } if (accessor != null) { editor.transform.SetParent(Panel, false); editor.Init(accessor, accessor.GetType().GetProperty("Value"), accessor.Name, OnValueChanging, OnValueChanged, null, false); } }
private EditorDescriptor GetScriptEditorDescriptor(Type t, EditorsMap editorsMap) { bool isPropertyEditorType = typeof(PropertyEditor).IsAssignableFrom(t); bool isEditorEnabled = false; GameObject editor = null; if (m_map != null) { if (isPropertyEditorType) { isEditorEnabled = editorsMap.IsPropertyEditorEnabled(t, true); editor = editorsMap.GetPropertyEditor(t, true); } else { isEditorEnabled = editorsMap.IsObjectEditorEnabled(t); editor = editorsMap.GetObjectEditor(t, true); } } return(new EditorDescriptor(t, isEditorEnabled, editor, isPropertyEditorType)); }
private PropertyEditor InstantiatePropertyEditor(PropertyDescriptor descriptor) { if (descriptor.MemberInfo == null) { Debug.LogError("desciptor.MemberInfo is null"); return(null); } if (descriptor.MemberType == null) { Debug.LogError("descriptor.MemberType is null"); return(null); } GameObject editorGo = EditorsMap.GetPropertyEditor(descriptor.MemberType); if (editorGo == null) { return(null); } if (!EditorsMap.IsPropertyEditorEnabled(descriptor.MemberType)) { return(null); } PropertyEditor editor = editorGo.GetComponent <PropertyEditor>(); if (editor == null) { Debug.LogErrorFormat("editor {0} is not PropertyEditor", editorGo); return(null); } PropertyEditor instance = Instantiate(editor); instance.transform.SetParent(EditorsPanel, false); return(instance); }
public void BuildEditor() { foreach (Transform t in EditorsPanel) { Destroy(t.gameObject); } IMaterialDescriptor selector; if (!m_propertySelectors.TryGetValue(Material.shader.name, out selector)) { selector = new MaterialDescriptor(); } object converter = selector.CreateConverter(this); MaterialPropertyDescriptor[] descriptors = selector.GetProperties(this, converter); if (descriptors == null) { Destroy(gameObject); return; } for (int i = 0; i < descriptors.Length; ++i) { MaterialPropertyDescriptor descriptor = descriptors[i]; PropertyEditor editor = null; object target = descriptor.Target; PropertyInfo propertyInfo = descriptor.PropertyInfo; #if !UNITY_WEBGL && PROC_MATERIAL if (descriptor.ProceduralDescription == null) #endif { RTShaderPropertyType propertyType = descriptor.Type; switch (propertyType) { case RTShaderPropertyType.Range: if (RangeEditor != null) { RangeEditor range = Instantiate(RangeEditor); range.transform.SetParent(EditorsPanel, false); var rangeLimits = descriptor.Limits; range.Min = rangeLimits.Min; range.Max = rangeLimits.Max; editor = range; } break; default: if (EditorsMap.IsPropertyEditorEnabled(propertyInfo.PropertyType)) { GameObject editorPrefab = EditorsMap.GetPropertyEditor(propertyInfo.PropertyType); GameObject instance = Instantiate(editorPrefab); instance.transform.SetParent(EditorsPanel, false); if (instance != null) { editor = instance.GetComponent <PropertyEditor>(); } } break; } } #if !UNITY_WEBGL && PROC_MATERIAL else { ProcPropertyDescription input = descriptor.ProceduralDescription; if (input.hasRange) { if (input.type == ProcPropertyType.Float) { if (RangeEditor != null) { RangeEditor range = Instantiate(RangeEditor); range.transform.SetParent(EditorsPanel, false); range.Min = input.minimum; range.Max = input.maximum; //TODO implement step on range editor // = input.step editor = range; } } else { //TODO: Implement range on vector editors if (EditorsMap.IsPropertyEditorEnabled(propertyInfo.PropertyType)) { GameObject editorPrefab = EditorsMap.GetPropertyEditor(propertyInfo.PropertyType); GameObject instance = Instantiate(editorPrefab); instance.transform.SetParent(EditorsPanel, false); if (instance != null) { editor = instance.GetComponent <PropertyEditor>(); } } } } else { //if(input.type == ProceduralPropertyType.Enum) //TODO: Implement enum from string array editor. //input.enumOptions if (EditorsMap.IsPropertyEditorEnabled(propertyInfo.PropertyType)) { GameObject editorPrefab = EditorsMap.GetPropertyEditor(propertyInfo.PropertyType); GameObject instance = Instantiate(editorPrefab); instance.transform.SetParent(EditorsPanel, false); if (instance != null) { editor = instance.GetComponent <PropertyEditor>(); } } } } #endif if (editor == null) { continue; } editor.Init(target, propertyInfo, descriptor.Label, null, descriptor.ValueChangedCallback, () => { RuntimeEditorApplication.SaveSelectedObjects(); }); } }