void OnEnable() { if (windows == null) { InitSubWindows(); } // Set the window name and icon. var icon = AssetDatabase.LoadAssetAtPath <Texture2D>(ES3Settings.PathToEasySaveFolder() + "Editor/es3Logo16x16.png"); titleContent = new GUIContent("Easy Save", icon); // Get the last opened window and open it. if (currentWindow == null) { var currentWindowName = EditorPrefs.GetString("ES3Editor.Window.currentWindow", windows[0].name); for (int i = 0; i < windows.Length; i++) { if (windows[i].name == currentWindowName) { currentWindow = windows[i]; break; } } } }
public EditorStyle() { // An area with padding. area = new GUIStyle(); area.padding = new RectOffset(10, 10, 10, 10); area.wordWrap = true; // An area with more padding. areaPadded = new GUIStyle(); areaPadded.padding = new RectOffset(20, 20, 20, 20); areaPadded.wordWrap = true; // Unselected menu button. menuButton = new GUIStyle(EditorStyles.toolbarButton); menuButton.fontStyle = FontStyle.Normal; menuButton.fontSize = 14; menuButton.fixedHeight = 24; // Selected menu button. menuButtonSelected = new GUIStyle(menuButton); menuButtonSelected.fontStyle = FontStyle.Bold; // Main Headings heading = new GUIStyle(EditorStyles.label); heading.fontStyle = FontStyle.Bold; heading.fontSize = 24; subheading = new GUIStyle(heading); subheading.fontSize = 18; subheading2 = new GUIStyle(heading); subheading2.fontSize = 14; boldLabelNoStretch = new GUIStyle(EditorStyles.label); boldLabelNoStretch.stretchWidth = false; boldLabelNoStretch.fontStyle = FontStyle.Bold; link = new GUIStyle(); link.fontSize = 16; if (EditorGUIUtility.isProSkin) { link.normal.textColor = new Color(0.262f, 0.670f, 0.788f); } else { link.normal.textColor = new Color(0.129f, 0.129f, 0.8f); } toggle = new GUIStyle(EditorStyles.toggle); toggle.stretchWidth = false; saveIconSelected = AssetDatabase.LoadAssetAtPath <Texture2D>(ES3Settings.PathToEasySaveFolder() + "Editor/es3Logo16x16.png"); saveIconUnselected = AssetDatabase.LoadAssetAtPath <Texture2D>(ES3Settings.PathToEasySaveFolder() + "Editor/es3Logo16x16-bw.png"); }
private static string PathToGlobalReferences() { return(ES3Settings.PathToEasySaveFolder() + "Resources/" + globalReferencesPath + ".asset"); }
private string GetOutputPath(Type type) { return(ES3Settings.PathToEasySaveFolder() + "Custom Types/ES3UserType_" + type.Name + ".cs"); }
private void Generate() { var type = types[selectedType].type; if (type == null) { EditorUtility.DisplayDialog("Type not selected", "Type not selected. Please ensure you select a type", "Ok"); return; } unsavedChanges = false; // Get the serializable fields of this class. //var fields = ES3Reflection.GetSerializableES3Fields(type); // The string that we suffix to the class name. i.e. UnityEngine_UnityEngine_Transform. string es3TypeSuffix = type.Name; // The string for the full C#-safe type name. This name must be suitable for going inside typeof(). string fullType = GetFullTypeName(type); // The list of WriteProperty calls to write the properties of this type. string writes = GenerateWrites(); // The list of case statements and Read calls to read the properties of this type. string reads = GenerateReads(); // A comma-seperated string of fields we've supported in this type. string propertyNames = ""; bool first = true; for (int i = 0; i < fields.Length; i++) { if (!fieldSelected[i]) { continue; } if (first) { first = false; } else { propertyNames += ", "; } propertyNames += "\"" + fields[i].Name + "\""; } var easySaveEditorPath = ES3Settings.PathToEasySaveFolder() + "Editor/"; // Insert the relevant strings into the template. string template; if (typeof(Component).IsAssignableFrom(type)) { template = File.ReadAllText(easySaveEditorPath + componentTemplateFile); } else if (ES3Reflection.IsValueType(type)) { template = File.ReadAllText(easySaveEditorPath + valueTemplateFile); } else if (typeof(ScriptableObject).IsAssignableFrom(type)) { template = File.ReadAllText(easySaveEditorPath + scriptableObjectTemplateFile); } else { template = File.ReadAllText(easySaveEditorPath + classTemplateFile); } template = template.Replace("[es3TypeSuffix]", es3TypeSuffix); template = template.Replace("[fullType]", fullType); template = template.Replace("[writes]", writes); template = template.Replace("[reads]", reads); template = template.Replace("[propertyNames]", propertyNames); // Create the output file. string outputFilePath = GetOutputPath(type); var fileInfo = new FileInfo(outputFilePath); fileInfo.Directory.Create(); File.WriteAllText(outputFilePath, template); AssetDatabase.Refresh(); }
private void Init() { componentTemplateFile = "ES3ComponentTypeTemplate.txt"; classTemplateFile = "ES3ClassTypeTemplate.txt"; valueTemplateFile = "ES3ValueTypeTemplate.txt"; scriptableObjectTemplateFile = "ES3ScriptableObjectTypeTemplate.txt"; // Init Type List var tempTypes = new List <TypeListItem> (); var assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(assembly => !assembly.FullName.Contains("Editor") && assembly.FullName != "ES3" && !assembly.FullName.Contains("ES3")).OrderBy(assembly => assembly.GetName().Name).ToArray(); foreach (var assembly in assemblies) { var assemblyTypes = assembly.GetTypes(); for (int i = 0; i < assemblyTypes.Length; i++) { var type = assemblyTypes [i]; if (type.IsGenericType || type.IsEnum || type.IsNotPublic || type.IsAbstract || type.IsInterface) { continue; } var typeName = type.Name; if (typeName [0] == '$' || typeName [0] == '_' || typeName [0] == '<') { continue; } var typeNamespace = type.Namespace; var namespaceName = typeNamespace == null ? "" : typeNamespace.ToString(); tempTypes.Add(new TypeListItem(type.Name, namespaceName, type, true, HasExplicitES3Type(type))); } } types = tempTypes.OrderBy(type => type.name).ToArray(); // Load types and recent types. if (Event.current.type == EventType.Layout) { recentTypes = new List <int>(); for (int i = 0; i < recentTypeCount; i++) { int typeIndex = LoadTypeIndex("TypesWindowRecentType" + i); if (typeIndex != -1) { recentTypes.Add(typeIndex); } } SelectType(LoadTypeIndex("TypesWindowSelectedType")); } PerformSearch(searchFieldValue); // Init Assets. string es3FolderPath = ES3Settings.PathToEasySaveFolder(); checkmark = AssetDatabase.LoadAssetAtPath <Texture2D>(es3FolderPath + "Editor/checkmark.png"); //checkmarkSmall = AssetDatabase.LoadAssetAtPath<Texture2D>(es3FolderPath + "Editor/checkmarkSmall.png"); // Init Styles. searchBarCancelButtonStyle = new GUIStyle(EditorStyles.miniButton); var cancelButtonSize = EditorStyles.miniTextField.CalcHeight(new GUIContent(""), 20); searchBarCancelButtonStyle.fixedWidth = cancelButtonSize; searchBarCancelButtonStyle.fixedHeight = cancelButtonSize; searchBarCancelButtonStyle.fontSize = 8; searchBarCancelButtonStyle.padding = new RectOffset(); searchBarStyle = new GUIStyle(EditorStyles.toolbarTextField); searchBarStyle.stretchWidth = true; typeButtonStyle = new GUIStyle(EditorStyles.largeLabel); typeButtonStyle.alignment = TextAnchor.MiddleLeft; typeButtonStyle.stretchWidth = false; selectedTypeButtonStyle = new GUIStyle(typeButtonStyle); selectedTypeButtonStyle.fontStyle = FontStyle.Bold; leftPaneStyle = new GUIStyle(); leftPaneStyle.fixedWidth = leftPaneWidth; leftPaneStyle.clipping = TextClipping.Clip; leftPaneStyle.padding = new RectOffset(10, 10, 10, 10); selectAllNoneButtonStyle = new GUIStyle(EditorStyles.miniButton); selectAllNoneButtonStyle.stretchWidth = false; selectAllNoneButtonStyle.margin = new RectOffset(0, 0, 0, 10); }