private void ShowGroup(ref bool isExpanded, string label, EditorDescriptor[] descriptors, Func <EditorDescriptor, string> getName) { EditorGUIUtility.labelWidth = 350; isExpanded = EditorGUILayout.Foldout(isExpanded, label); if (isExpanded) { EditorGUI.indentLevel++; EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginVertical(); for (int i = 0; i < descriptors.Length; ++i) { EditorDescriptor descriptor = descriptors[i]; descriptor.Enabled = EditorGUILayout.Toggle(getName(descriptor), descriptor.Enabled); } EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); for (int i = 0; i < descriptors.Length; ++i) { EditorDescriptor descriptor = descriptors[i]; descriptor.Editor = (GameObject)EditorGUILayout.ObjectField(descriptor.Editor, typeof(GameObject), false); } EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel--; } EditorGUIUtility.labelWidth = 0; }
private GameObject GetEditor(Type type, bool isPropertyEditor, bool strict = false) { EditorDescriptor descriptor = GetEditorDescriptor(type, isPropertyEditor, strict); if (descriptor != null) { return m_editors[descriptor.Index]; } return null; }
private bool IsEditorEnabled(Type type, bool isPropertyEditor, bool strict) { EditorDescriptor descriptor = GetEditorDescriptor(type, isPropertyEditor, strict); if (descriptor != null) { return descriptor.Enabled; } return false; }
private GameObject GetEditor(Type type, bool isPropertyEditor, bool strict = false) { EditorDescriptor descriptor = GetEditorDescriptor(type, isPropertyEditor, strict); if (descriptor != null && descriptor.Index < m_editors.Length) { return(m_editors[descriptor.Index]); } return(null); }
private static Dictionary <GameObject, int> CreateComponentEditorMap(EditorDescriptor[] descriptors) { Type type = typeof(EditorsMap); string fullPath = Path.GetFullPath(ScriptsPath); Directory.CreateDirectory(fullPath); StringBuilder builder = new StringBuilder(); builder.AppendLine("using Battlehub.RTCommon;"); builder.AppendLine("namespace " + type.Namespace); builder.AppendLine("{"); builder.AppendLine("\tpublic class EditorsMapCreator : IEditorsMapCreator"); builder.AppendLine("\t{"); builder.AppendLine("\t\t#if UNITY_EDITOR"); builder.AppendLine("\t\t[UnityEditor.InitializeOnLoadMethod]"); builder.AppendLine("\t\t#endif"); builder.AppendLine("\t\t[UnityEngine.RuntimeInitializeOnLoadMethod(UnityEngine.RuntimeInitializeLoadType.SubsystemRegistration)]"); builder.AppendLine("\t\tstatic void Register()"); builder.AppendLine("\t\t{"); builder.AppendLine("\t\t\tIOC.UnregisterFallback<IEditorsMapCreator>();"); builder.AppendLine("\t\t\tIOC.RegisterFallback<IEditorsMapCreator>(() => new EditorsMapCreator());"); builder.AppendLine("\t\t}"); builder.AppendLine("\t\t"); builder.AppendLine("\t\tvoid IEditorsMapCreator.Create(IEditorsMap map)"); builder.AppendLine("\t\t{"); Dictionary <GameObject, int> editors = new Dictionary <GameObject, int>(); int editorIndex = -1; for (int i = 0; i < descriptors.Length; ++i) { EditorDescriptor descriptor = descriptors[i]; if (descriptor.Editor == null) { continue; } string fullTypeName = descriptor.Type.FullName; fullTypeName = fullTypeName.Replace("Battlehub.RTEditor.", ""); fullTypeName = fullTypeName.Replace("Battlehub.", ""); if (editors.ContainsKey(descriptor.Editor)) { builder.AppendLine( string.Format( "\t\t\tmap.AddMapping(typeof({0}), {1}, {2}, {3});", fullTypeName.Replace("`1", "<>"), editors[descriptor.Editor], descriptor.Enabled ? "true" : "false", descriptor.IsPropertyEditor ? "true" : "false")); } else { editorIndex++; editors.Add(descriptor.Editor, editorIndex); builder.AppendLine( string.Format( "\t\t\tmap.AddMapping(typeof({0}), {1}, {2}, {3});", fullTypeName.Replace("`1", "<>"), editorIndex, descriptor.Enabled ? "true" : "false", descriptor.IsPropertyEditor ? "true" : "false")); } } builder.AppendLine("\t\t}"); builder.AppendLine("\t}"); builder.AppendLine("}"); //RTE 2.1 version files removal File.Delete(Path.Combine(fullPath, "EditorsMapAuto.cs")); File.Delete(Path.Combine(fullPath, "EditorsMapAuto.cs.meta")); string content = builder.ToString(); File.WriteAllText(Path.Combine(fullPath, ScriptName), content); return(editors); }
private static Dictionary <GameObject, int> CreateComponentEditorMap(EditorDescriptor[] descriptors) { Type type = typeof(EditorsMap); string fullPath = Application.dataPath + ScriptsPath; Directory.CreateDirectory(fullPath); StringBuilder builder = new StringBuilder(); builder.AppendLine(string.Format("using {0}; ", typeof(Type).Namespace)); builder.AppendLine(string.Format("using {0}; ", typeof(MonoBehaviour).Namespace)); builder.AppendLine(string.Format("using {0}; ", typeof(Dictionary <,>).Namespace)); builder.AppendLine("namespace " + type.Namespace); builder.AppendLine("{"); builder.AppendLine("\tpublic partial class " + type.Name); builder.AppendLine("\t{"); builder.AppendLine("\t\tprotected static void InitEditorsMap()"); builder.AppendLine("\t\t{"); builder.AppendLine("\t\t\tm_map = new Dictionary<Type, EditorDescriptor>"); builder.AppendLine("\t\t\t{"); Dictionary <GameObject, int> editors = new Dictionary <GameObject, int>(); int editorIndex = -1; for (int i = 0; i < descriptors.Length; ++i) { EditorDescriptor descriptor = descriptors[i]; if (descriptor.Editor == null) { continue; } if (editors.ContainsKey(descriptor.Editor)) { builder.AppendLine( string.Format( "\t\t\t\t{{ typeof({0}), new EditorDescriptor({1}, {2}, {3}) }},", descriptor.Type.FullName.Replace("`1", "<>"), editors[descriptor.Editor], descriptor.Enabled ? "true" : "false", descriptor.IsPropertyEditor ? "true" : "false")); } else { editorIndex++; editors.Add(descriptor.Editor, editorIndex); builder.AppendLine( string.Format( "\t\t\t\t{{ typeof({0}), new EditorDescriptor({1}, {2}, {3}) }},", descriptor.Type.FullName.Replace("`1", "<>"), editorIndex, descriptor.Enabled ? "true" : "false", descriptor.IsPropertyEditor ? "true" : "false")); } } builder.AppendLine("\t\t\t};"); builder.AppendLine("\t\t}"); builder.AppendLine("\t}"); builder.AppendLine("}"); string content = builder.ToString(); File.WriteAllText(Path.Combine(fullPath, ScriptName), content); return(editors); }