private static void LabkitNewScriptableObject() { string path = EditorUtility.SaveFilePanelInProject( "New Scriptable Object", "NewScriptableObject.cs", "cs", "Create a source file for the ScriptableObject" ); if (string.IsNullOrEmpty(path)) { return; } string newAssetName = System.IO.Path.GetFileNameWithoutExtension(path); LabkitEditorUtility.WriteFileUsingTemplate( "ScriptableObject_So", path, "%NEWASSETNAME% " + newAssetName ); string editorPath = Path.Combine(Path.GetDirectoryName(path), "Editor"); Directory.CreateDirectory(editorPath); LabkitEditorUtility.WriteFileUsingTemplate( "ScriptableObject_SoEditor", Path.Combine(editorPath, newAssetName + "Editor.cs"), "%NEWASSETNAME% " + newAssetName ); }
private static void LabkitNewControllerClass() { string path = EditorUtility.SaveFilePanelInProject( "New MonoBehaviour with Settings", "NewMonoBehaviour.cs", "cs", "Create a source file for the MonoBehaviour" ); if (string.IsNullOrEmpty(path)) { return; } string newAssetName = System.IO.Path.GetFileNameWithoutExtension(path); LabkitEditorUtility.WriteFileUsingTemplate( "MonoBehaviourWithSettings_Mb", path, "%NEWASSETNAME% " + newAssetName ); LabkitEditorUtility.WriteFileUsingTemplate( "MonoBehaviourWithSettings_MbSo", Path.Combine(Path.GetDirectoryName(path), newAssetName + "Settings.cs"), "%NEWASSETNAME% " + newAssetName ); string editorPath = Path.Combine(Path.GetDirectoryName(path), "Editor"); Directory.CreateDirectory(editorPath); LabkitEditorUtility.WriteFileUsingTemplate( "MonoBehaviourWithSettings_MbEditor", Path.Combine(editorPath, newAssetName + "Editor.cs"), "%NEWASSETNAME% " + newAssetName ); LabkitEditorUtility.WriteFileUsingTemplate( "MonoBehaviourWithSettings_MbSoEditor", Path.Combine(editorPath, newAssetName + "SettingsEditor.cs"), "%NEWASSETNAME% " + newAssetName ); }
public override void OnInspectorGUI() { LabkitProjectSettings t = this.target as LabkitProjectSettings; if (t == null) { return; } t.name = "Labkit Settings"; var serializedObject = new SerializedObject(t); GUI.changed = false; bool anythingChanged = false; //----------------------------------------------------------------------------------- GUILayout.Label("Asset Processing", EditorStyles.boldLabel); //----------------------------------------------------------------------------------- t.TextureDefaults = (LabkitProjectSettings_TextureDefaults)EditorGUILayout.EnumPopup("Texture Defaults", t.TextureDefaults); bool inPixelPerfect2DMode = t.TextureDefaults == LabkitProjectSettings_TextureDefaults.PixelPerfect2D; //----------------------------------------------------------------------------------- GUILayout.Label("2D", EditorStyles.boldLabel, GUILayout.MinWidth(100f)); //----------------------------------------------------------------------------------- GUILayout.BeginHorizontal(); GUILayout.Label("Pixels Per Unit", GUILayout.ExpandWidth(true)); float powerOfTwo = GUILayout.HorizontalSlider(Mathf.Log(t.PixelsPerUnit) / Mathf.Log(2), 0, 8, GUILayout.ExpandWidth(true), GUILayout.MinWidth(50f)); int pixelsPerUnit = Mathf.NextPowerOfTwo(Mathf.RoundToInt(Mathf.Pow(2, powerOfTwo))); pixelsPerUnit = EditorGUILayout.IntField(pixelsPerUnit, GUILayout.Width(50f), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); t.PixelsPerUnit = pixelsPerUnit; //----------------------------------------------------------------------------------- GUILayout.Label("Rendering", EditorStyles.boldLabel); //----------------------------------------------------------------------------------- UnityEditor.PlayerSettings.colorSpace = (ColorSpace)EditorGUILayout.EnumPopup("Color Space", UnityEditor.PlayerSettings.colorSpace); if (UnityEditor.PlayerSettings.colorSpace == ColorSpace.Linear) { GUILayout.Label("Careful! Linear is better but breaks older mobile devices.", EditorStyles.miniLabel); EditorGUILayout.Space(); } //----------------------------------------------------------------------------------- GUILayout.Label("Development", EditorStyles.boldLabel); //----------------------------------------------------------------------------------- EditorGUILayout.PropertyField(serializedObject.FindProperty("BreakNonPowerOfTwoTextures")); if (inPixelPerfect2DMode && !t.BreakNonPowerOfTwoTextures) { GUILayout.Label("Turn this on to easily spot NPOT textures", EditorStyles.miniLabel); EditorGUILayout.Space(); } EditorGUILayout.PropertyField(serializedObject.FindProperty("PurpleEditorInPlayMode")); t.MetaFilesInVersionControl = EditorGUILayout.Toggle("Meta Files in Version Control", t.MetaFilesInVersionControl); //----------------------------------------------------------------------------------- GUILayout.Label("Optimization", EditorStyles.boldLabel); //----------------------------------------------------------------------------------- anythingChanged = anythingChanged || GUI.changed; GUI.changed = false; t.DisableAccelerometer = EditorGUILayout.Toggle("Disable Accelerometer", t.DisableAccelerometer); if (GUI.changed && !t.DisableAccelerometer) { UnityEditor.PlayerSettings.accelerometerFrequency = 60; } anythingChanged = anythingChanged || GUI.changed; GUI.changed = false; t.DontAutoSimulate2DPhysics = EditorGUILayout.Toggle("Disable 2D Physics", t.DontAutoSimulate2DPhysics); t.DontAutoSimulate3DPhysics = EditorGUILayout.Toggle("Disable 3D Physics", t.DontAutoSimulate3DPhysics); t.UseVisualStudioCode = EditorGUILayout.Toggle("Use Visual Studio Code", t.UseVisualStudioCode); if (!LabkitProjectSettings.CanFindVisualStudioCode()) { GUILayout.Label("Can't find VS Code; is it installed?", EditorStyles.miniLabel); } EditorGUILayout.Space(); //----------------------------------------------------------------------------------- GUILayout.Label("Fixes", EditorStyles.boldLabel); //----------------------------------------------------------------------------------- anythingChanged = anythingChanged || GUI.changed; EditorGUILayout.BeginHorizontal(); string gitignorePath = Path.Combine(Directory.GetParent(Application.dataPath).FullName, ".gitignore"); bool gitignoreExists = File.Exists(gitignorePath); GUILayout.Label(".gitignore" + (gitignoreExists ? " (exists)" : "")); GUILayout.FlexibleSpace(); if (GUILayout.Button("Write")) { bool shouldWriteFile = true; if (gitignoreExists) { shouldWriteFile = EditorUtility.DisplayDialog( "Overwrite?", "Overwrite project .gitignore file?", "Overwrite", "Keep Existing" ); } if (shouldWriteFile) { LabkitEditorUtility.WriteFileUsingTemplate( "gitignore", gitignorePath ); } } EditorGUI.BeginDisabledGroup(!gitignoreExists); if (GUILayout.Button("Open")) { UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal( gitignorePath, 1 ); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); anythingChanged = anythingChanged || GUI.changed; GUI.changed = false; if (GUI.changed || anythingChanged) { t.ApplySettingsToProject(); serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(this.target); } }