Spaces:
Sleeping
Sleeping
Update UnityProject/Assets/TestBuilder.cs
Browse files1 unmodified line23456781 unmodified line1011121314151617181920212223242526273 unmodified lines31323334353637383 unmodified lines42434445464748495051523 unmodified lines56575859606162635 unmodified lines69707172737475767778798081821 unmodified lineusing UnityEditor;using System;using System.IO;using UnityMeshSimplifier; // Wajib ada plugin ini di folder projectpublic class TestBuilder{1 unmodified line{try{// --- PENGATURAN WORKER ---// Memaksa Job System Unity hanya pakai 4 worker (agar tidak jadi 16 lagi)Unity.Jobs.LowLevel.Unsafe.JobsUtility.JobWorkerCount = 4;Debug.Log($"โ๏ธ [CLI] Job Worker Count dipaksa ke: {Unity.Jobs.LowLevel.Unsafe.JobsUtility.JobWorkerCount}");// --- KONFIGURASI BACKEND ---Debug.Log("๐ ๏ธ [CLI] Konfigurasi Backend: Mono2x...");PlayerSettings.SetScriptingBackend(BuildTargetGroup.Standalone, ScriptingImplementation.Mono2x);PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, ScriptingImplementation.Mono2x);PlayerSettings.SetScriptingBackend(BuildTargetGroup.iOS, ScriptingImplementation.Mono2x);// --- PROSES PERAMPINGAN (OPTIMASI MESH) ---string inputPath = "Assets/InputRaw";if (Directory.Exists(inputPath)){3 unmodified linesGameObject go = PrefabUtility.LoadPrefabContents(path);if (go != null){Debug.Log($"๐ฆ Merampingkan Mesh: {path}");ProcessAndEmbed(go, path);PrefabUtility.SaveAsPrefabAsset(go, path);PrefabUtility.UnloadPrefabContents(go);}3 unmodified linesAssetDatabase.SaveAssets();AssetDatabase.Refresh();// --- PENGEPAKAN ZEPETO ---Debug.Log("๐ [CLI] Menjalankan Pengepakan ZEPETO...");ZepetoPackageCliBuilder.BuildWithArgs();Debug.Log("โ [CLI] Build Selesai.");EditorApplication.Exit(0);}catch (Exception e)3 unmodified lines}}// Fungsi Perampingan Meshstatic void ProcessAndEmbed(GameObject go, string assetPath){var renderers = go.GetComponentsInChildren<Renderer>();foreach (var ren in renderers)5 unmodified lines{var simplifier = new MeshSimplifier();simplifier.Initialize(src);// Menghapus 95% poligon yang tidak perlu (hanya sisa 5%)simplifier.SimplifyMesh(0.05f);Mesh newMesh = simplifier.ToMesh();newMesh.name = src.name + "_Internal";// Simpan mesh baru ke dalam file prefab (Embedding)AssetDatabase.AddObjectToAsset(newMesh, assetPath);if (ren is MeshRenderer) ren.GetComponent<MeshFilter>().sharedMesh = newMesh;else if (ren is SkinnedMeshRenderer s) s.sharedMesh = newMesh;}1 unmodified line23456781 unmodified line101112131415161718192021222324253 unmodified lines29303132333435363 unmodified lines40414243444546474849503 unmodified lines545556575859605 unmodified lines66676869707172737475761 unmodified lineusing UnityEditor;using System;using System.IO;using UnityMeshSimplifier; // Pastikan folder plugin ini ada di Assetspublic class TestBuilder{1 unmodified line{try{// 1. PAKSA 4 WORKER (Agar tidak menggunakan 16 thread CPU)Unity.Jobs.LowLevel.Unsafe.JobsUtility.JobWorkerCount = 4;Debug.Log($"โ๏ธ [CLI] Job Worker Count diset ke: {Unity.Jobs.LowLevel.Unsafe.JobsUtility.JobWorkerCount}");// 2. FIX BACKEND (Wajib Mono2x untuk Unity 2022.3)PlayerSettings.SetScriptingBackend(BuildTargetGroup.Standalone, ScriptingImplementation.Mono2x);PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, ScriptingImplementation.Mono2x);PlayerSettings.SetScriptingBackend(BuildTargetGroup.iOS, ScriptingImplementation.Mono2x);// 3. PROSES PERAMPINGAN MESH (Optimasi)string inputPath = "Assets/InputRaw";if (Directory.Exists(inputPath)){3 unmodified linesGameObject go = PrefabUtility.LoadPrefabContents(path);if (go != null){Debug.Log($"๐ฆ Merampingkan (Simplify) Mesh: {path}");SimplifyAndEmbed(go, path);PrefabUtility.SaveAsPrefabAsset(go, path);PrefabUtility.UnloadPrefabContents(go);}3 unmodified linesAssetDatabase.SaveAssets();AssetDatabase.Refresh();// 4. JALANKAN PENGEPAKAN ZEPETODebug.Log("๐ [CLI] Menjalankan Pengepakan ZEPETO...");ZepetoPackageCliBuilder.BuildWithArgs();Debug.Log("โ [CLI] Selesai.");EditorApplication.Exit(0);}catch (Exception e)3 unmodified lines}}static void SimplifyAndEmbed(GameObject go, string assetPath){var renderers = go.GetComponentsInChildren<Renderer>();foreach (var ren in renderers)5 unmodified lines{var simplifier = new MeshSimplifier();simplifier.Initialize(src);simplifier.SimplifyMesh(0.05f); // Sisakan 5% poligon (Perampingan agresif)Mesh newMesh = simplifier.ToMesh();newMesh.name = src.name + "_Optimized";AssetDatabase.AddObjectToAsset(newMesh, assetPath);if (ren is MeshRenderer) ren.GetComponent<MeshFilter>().sharedMesh = newMesh;else if (ren is SkinnedMeshRenderer s) s.sharedMesh = newMesh;}
UnityProject/Assets/TestBuilder.cs+12-18