using System; using System.IO; using Ashfall.Core; using UnityEditor; using UnityEditor.Build.Reporting; using UnityEditor.SceneManagement; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.Rendering.Universal; namespace Ashfall.Editor { public static class ProjectSetup { private const string ScenePath = "Assets/Ashfall/Scenes/Frontier.unity"; [InitializeOnLoadMethod] private static void OnLoaded() { EditorApplication.delayCall += () => { if (EditorApplication.isPlayingOrWillChangePlaymode || EditorApplication.isCompiling) return; if (!File.Exists(ScenePath)) Configure(); }; } [MenuItem("Ashfall/Configure project")] public static void Configure() { Directory.CreateDirectory("Assets/Ashfall/Settings"); Directory.CreateDirectory("Assets/Ashfall/Scenes"); AssetDatabase.Refresh(); var renderer = AssetDatabase.LoadAssetAtPath("Assets/Ashfall/Settings/FrontierRenderer.asset"); if (renderer == null) { renderer = ScriptableObject.CreateInstance(); AssetDatabase.CreateAsset(renderer, "Assets/Ashfall/Settings/FrontierRenderer.asset"); } var pipeline = AssetDatabase.LoadAssetAtPath("Assets/Ashfall/Settings/FrontierPipeline.asset"); if (pipeline == null) { pipeline = UniversalRenderPipelineAsset.Create(renderer); AssetDatabase.CreateAsset(pipeline, "Assets/Ashfall/Settings/FrontierPipeline.asset"); } GraphicsSettings.defaultRenderPipeline = pipeline; QualitySettings.renderPipeline = pipeline; pipeline.msaaSampleCount = 1; pipeline.renderScale = 1; PlayerSettings.companyName = "XFEstudio"; PlayerSettings.productName = "Ashfall Frontier"; PlayerSettings.bundleVersion = "0.1.0"; PlayerSettings.runInBackground = true; PlayerSettings.defaultScreenWidth = 1440; PlayerSettings.defaultScreenHeight = 900; PlayerSettings.fullScreenMode = FullScreenMode.Windowed; PlayerSettings.colorSpace = ColorSpace.Linear; var settings = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/ProjectSettings.asset")[0]); var input = settings.FindProperty("activeInputHandler"); if (input != null) input.intValue = 1; settings.ApplyModifiedPropertiesWithoutUndo(); foreach (string path in new[] { "Assets/Ashfall/Resources/Art/ExpeditionAtlas.png", "Assets/Ashfall/Resources/Art/LifeformsAtlas.png" }) if (AssetImporter.GetAtPath(path) is TextureImporter importer) { importer.textureType = TextureImporterType.Default; importer.alphaIsTransparency = true; importer.mipmapEnabled = false; importer.maxTextureSize = 2048; importer.filterMode = FilterMode.Bilinear; importer.textureCompression = TextureImporterCompression.Uncompressed; importer.SaveAndReimport(); } if (!File.Exists(ScenePath)) { var scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); var camera = new GameObject("Main Camera"); camera.tag = "MainCamera"; camera.AddComponent().orthographic = true; camera.AddComponent(); camera.transform.position = new Vector3(0, 0, -20); EditorSceneManager.SaveScene(scene, ScenePath); } EditorBuildSettings.scenes = new[] { new EditorBuildSettingsScene(ScenePath, true) }; AssetDatabase.SaveAssets(); var catalog = ContentCatalog.CreateDefault(); catalog.Validate(); var content = AssetDatabase.LoadAssetAtPath("Assets/Ashfall/Resources/ContentCatalog.asset"); if (content == null) { content = ScriptableObject.CreateInstance(); content.catalog = catalog; AssetDatabase.CreateAsset(content, "Assets/Ashfall/Resources/ContentCatalog.asset"); } AssetDatabase.SaveAssets(); Directory.CreateDirectory("Docs"); File.WriteAllText("Docs/content-catalog.json", JsonUtility.ToJson(catalog, true)); Debug.Log("ASHFALL_SETUP_OK: URP 2D, scene, sprites and catalog configured."); } [MenuItem("Ashfall/Build Windows prototype")] public static void BuildWindows() { Configure(); Directory.CreateDirectory("Builds/Windows"); var report = BuildPipeline.BuildPlayer(new BuildPlayerOptions { scenes = new[] { ScenePath }, locationPathName = "Builds/Windows/AshfallFrontier.exe", target = BuildTarget.StandaloneWindows64, options = BuildOptions.Development }); if (report.summary.result != BuildResult.Succeeded) throw new InvalidOperationException("Windows build failed: " + report.summary.result); Debug.Log("ASHFALL_BUILD_OK: " + report.summary.totalSize + " bytes"); } } }