Spaces:
Sleeping
Sleeping
Update UnityProject/Assets/TestBuilder.cs
Browse files
UnityProject/Assets/TestBuilder.cs
CHANGED
|
@@ -10,14 +10,16 @@ public class TestBuilder
|
|
| 10 |
{
|
| 11 |
try
|
| 12 |
{
|
| 13 |
-
//
|
| 14 |
Unity.Jobs.LowLevel.Unsafe.JobsUtility.JobWorkerCount = 4;
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, ScriptingImplementation.Mono2x);
|
| 18 |
PlayerSettings.SetScriptingBackend(BuildTargetGroup.iOS, ScriptingImplementation.Mono2x);
|
| 19 |
|
| 20 |
-
// Perampingan Mesh
|
| 21 |
string inputPath = "Assets/InputRaw";
|
| 22 |
if (Directory.Exists(inputPath))
|
| 23 |
{
|
|
@@ -25,8 +27,10 @@ public class TestBuilder
|
|
| 25 |
foreach (string path in prefabs)
|
| 26 |
{
|
| 27 |
GameObject go = PrefabUtility.LoadPrefabContents(path);
|
| 28 |
-
if (go != null)
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
PrefabUtility.SaveAsPrefabAsset(go, path);
|
| 31 |
PrefabUtility.UnloadPrefabContents(go);
|
| 32 |
}
|
|
@@ -36,30 +40,36 @@ public class TestBuilder
|
|
| 36 |
AssetDatabase.SaveAssets();
|
| 37 |
AssetDatabase.Refresh();
|
| 38 |
|
| 39 |
-
//
|
|
|
|
| 40 |
ZepetoPackageCliBuilder.BuildWithArgs();
|
| 41 |
|
| 42 |
EditorApplication.Exit(0);
|
| 43 |
}
|
| 44 |
-
catch (Exception e)
|
| 45 |
-
|
|
|
|
| 46 |
EditorApplication.Exit(1);
|
| 47 |
}
|
| 48 |
}
|
| 49 |
|
| 50 |
-
static void
|
|
|
|
| 51 |
var renderers = go.GetComponentsInChildren<Renderer>();
|
| 52 |
-
foreach (var ren in renderers)
|
|
|
|
| 53 |
Mesh src = (ren is MeshRenderer mr) ? ren.GetComponent<MeshFilter>()?.sharedMesh :
|
| 54 |
(ren is SkinnedMeshRenderer smr) ? smr.sharedMesh : null;
|
| 55 |
|
| 56 |
-
if (src != null)
|
|
|
|
| 57 |
var simplifier = new MeshSimplifier();
|
| 58 |
simplifier.Initialize(src);
|
| 59 |
-
simplifier.SimplifyMesh(0.05f);
|
| 60 |
Mesh newMesh = simplifier.ToMesh();
|
| 61 |
newMesh.name = src.name + "_Internal";
|
| 62 |
AssetDatabase.AddObjectToAsset(newMesh, path);
|
|
|
|
| 63 |
if (ren is MeshRenderer) ren.GetComponent<MeshFilter>().sharedMesh = newMesh;
|
| 64 |
else if (ren is SkinnedMeshRenderer s) s.sharedMesh = newMesh;
|
| 65 |
}
|
|
|
|
| 10 |
{
|
| 11 |
try
|
| 12 |
{
|
| 13 |
+
// 1. Batasi 4 Worker (Job System)
|
| 14 |
Unity.Jobs.LowLevel.Unsafe.JobsUtility.JobWorkerCount = 4;
|
| 15 |
+
Debug.Log($"⚙️ [CLI] Job Worker Count dipaksa ke: {Unity.Jobs.LowLevel.Unsafe.JobsUtility.JobWorkerCount}");
|
| 16 |
+
|
| 17 |
+
// 2. Setup Backend Mono2x (Wajib untuk 2022.3)
|
| 18 |
+
PlayerSettings.SetScriptingBackend(BuildTargetGroup.Standalone, ScriptingImplementation.Mono2x);
|
| 19 |
PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, ScriptingImplementation.Mono2x);
|
| 20 |
PlayerSettings.SetScriptingBackend(BuildTargetGroup.iOS, ScriptingImplementation.Mono2x);
|
| 21 |
|
| 22 |
+
// 3. Proses Perampingan Mesh
|
| 23 |
string inputPath = "Assets/InputRaw";
|
| 24 |
if (Directory.Exists(inputPath))
|
| 25 |
{
|
|
|
|
| 27 |
foreach (string path in prefabs)
|
| 28 |
{
|
| 29 |
GameObject go = PrefabUtility.LoadPrefabContents(path);
|
| 30 |
+
if (go != null)
|
| 31 |
+
{
|
| 32 |
+
Debug.Log($"📦 Merampingkan Mesh: {path}");
|
| 33 |
+
SimplifyAsset(go, path);
|
| 34 |
PrefabUtility.SaveAsPrefabAsset(go, path);
|
| 35 |
PrefabUtility.UnloadPrefabContents(go);
|
| 36 |
}
|
|
|
|
| 40 |
AssetDatabase.SaveAssets();
|
| 41 |
AssetDatabase.Refresh();
|
| 42 |
|
| 43 |
+
// 4. Build ZEPETO
|
| 44 |
+
Debug.Log("🚀 [CLI] Menjalankan Pengepakan ZEPETO...");
|
| 45 |
ZepetoPackageCliBuilder.BuildWithArgs();
|
| 46 |
|
| 47 |
EditorApplication.Exit(0);
|
| 48 |
}
|
| 49 |
+
catch (Exception e)
|
| 50 |
+
{
|
| 51 |
+
Debug.LogError($"💀 [FATAL] {e.Message}");
|
| 52 |
EditorApplication.Exit(1);
|
| 53 |
}
|
| 54 |
}
|
| 55 |
|
| 56 |
+
static void SimplifyAsset(GameObject go, string path)
|
| 57 |
+
{
|
| 58 |
var renderers = go.GetComponentsInChildren<Renderer>();
|
| 59 |
+
foreach (var ren in renderers)
|
| 60 |
+
{
|
| 61 |
Mesh src = (ren is MeshRenderer mr) ? ren.GetComponent<MeshFilter>()?.sharedMesh :
|
| 62 |
(ren is SkinnedMeshRenderer smr) ? smr.sharedMesh : null;
|
| 63 |
|
| 64 |
+
if (src != null)
|
| 65 |
+
{
|
| 66 |
var simplifier = new MeshSimplifier();
|
| 67 |
simplifier.Initialize(src);
|
| 68 |
+
simplifier.SimplifyMesh(0.05f); // Sisa 5% poligon
|
| 69 |
Mesh newMesh = simplifier.ToMesh();
|
| 70 |
newMesh.name = src.name + "_Internal";
|
| 71 |
AssetDatabase.AddObjectToAsset(newMesh, path);
|
| 72 |
+
|
| 73 |
if (ren is MeshRenderer) ren.GetComponent<MeshFilter>().sharedMesh = newMesh;
|
| 74 |
else if (ren is SkinnedMeshRenderer s) s.sharedMesh = newMesh;
|
| 75 |
}
|