Spaces:
Sleeping
Sleeping
File size: 3,141 Bytes
fd1820b 0dc3e2e fd1820b 0dc3e2e eadb69c 0dc3e2e eadb69c 0dc3e2e c1b8c2f fd1820b 0dc3e2e fd1820b 0dc3e2e fd1820b 0dc3e2e eadb69c fd1820b 0dc3e2e fd1820b 0dc3e2e fd1820b 0dc3e2e fd1820b 0dc3e2e fd1820b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | using UnityEngine;
using UnityEditor;
using System;
using System.IO;
using UnityMeshSimplifier; // Pastikan folder plugin ini ada di Assets
public class TestBuilder
{
public static void ManualConvert()
{
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))
{
string[] prefabs = Directory.GetFiles(inputPath, "*.prefab", SearchOption.AllDirectories);
foreach (string path in prefabs)
{
GameObject go = PrefabUtility.LoadPrefabContents(path);
if (go != null)
{
Debug.Log($"📦 Merampingkan (Simplify) Mesh: {path}");
SimplifyAndEmbed(go, path);
PrefabUtility.SaveAsPrefabAsset(go, path);
PrefabUtility.UnloadPrefabContents(go);
}
}
}
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
// 4. JALANKAN PENGEPAKAN ZEPETO
Debug.Log("🚀 [CLI] Menjalankan Pengepakan ZEPETO...");
ZepetoPackageCliBuilder.BuildWithArgs();
Debug.Log("✅ [CLI] Selesai.");
EditorApplication.Exit(0);
}
catch (Exception e)
{
Debug.LogError($"💀 [ERROR] {e.Message}");
EditorApplication.Exit(1);
}
}
static void SimplifyAndEmbed(GameObject go, string assetPath)
{
var renderers = go.GetComponentsInChildren<Renderer>();
foreach (var ren in renderers)
{
Mesh src = (ren is MeshRenderer mr) ? ren.GetComponent<MeshFilter>()?.sharedMesh :
(ren is SkinnedMeshRenderer smr) ? smr.sharedMesh : null;
if (src != null)
{
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;
}
}
}
} |