Spaces:
Sleeping
Sleeping
Update UnityProject/Assets/TestBuilder.cs
Browse files
UnityProject/Assets/TestBuilder.cs
CHANGED
|
@@ -2,7 +2,7 @@ using UnityEngine;
|
|
| 2 |
using UnityEditor;
|
| 3 |
using System;
|
| 4 |
using System.IO;
|
| 5 |
-
using UnityMeshSimplifier;
|
| 6 |
|
| 7 |
public class TestBuilder
|
| 8 |
{
|
|
@@ -10,16 +10,14 @@ public class TestBuilder
|
|
| 10 |
{
|
| 11 |
try
|
| 12 |
{
|
| 13 |
-
//
|
| 14 |
Unity.Jobs.LowLevel.Unsafe.JobsUtility.JobWorkerCount = 4;
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
// 2. FIX BACKEND (Wajib Mono2x untuk Unity 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 |
-
//
|
| 23 |
string inputPath = "Assets/InputRaw";
|
| 24 |
if (Directory.Exists(inputPath))
|
| 25 |
{
|
|
@@ -27,10 +25,8 @@ public class TestBuilder
|
|
| 27 |
foreach (string path in prefabs)
|
| 28 |
{
|
| 29 |
GameObject go = PrefabUtility.LoadPrefabContents(path);
|
| 30 |
-
if (go != null)
|
| 31 |
-
|
| 32 |
-
Debug.Log($"📦 Merampingkan (Simplify) Mesh: {path}");
|
| 33 |
-
SimplifyAndEmbed(go, path);
|
| 34 |
PrefabUtility.SaveAsPrefabAsset(go, path);
|
| 35 |
PrefabUtility.UnloadPrefabContents(go);
|
| 36 |
}
|
|
@@ -40,37 +36,30 @@ public class TestBuilder
|
|
| 40 |
AssetDatabase.SaveAssets();
|
| 41 |
AssetDatabase.Refresh();
|
| 42 |
|
| 43 |
-
//
|
| 44 |
-
Debug.Log("🚀 [CLI] Menjalankan Pengepakan ZEPETO...");
|
| 45 |
ZepetoPackageCliBuilder.BuildWithArgs();
|
| 46 |
|
| 47 |
-
Debug.Log("✅ [CLI] Selesai.");
|
| 48 |
EditorApplication.Exit(0);
|
| 49 |
}
|
| 50 |
-
catch (Exception e)
|
| 51 |
-
|
| 52 |
-
Debug.LogError($"💀 [ERROR] {e.Message}");
|
| 53 |
EditorApplication.Exit(1);
|
| 54 |
}
|
| 55 |
}
|
| 56 |
|
| 57 |
-
static void
|
| 58 |
-
{
|
| 59 |
var renderers = go.GetComponentsInChildren<Renderer>();
|
| 60 |
-
foreach (var ren in renderers)
|
| 61 |
-
{
|
| 62 |
Mesh src = (ren is MeshRenderer mr) ? ren.GetComponent<MeshFilter>()?.sharedMesh :
|
| 63 |
(ren is SkinnedMeshRenderer smr) ? smr.sharedMesh : null;
|
| 64 |
|
| 65 |
-
if (src != null)
|
| 66 |
-
{
|
| 67 |
var simplifier = new MeshSimplifier();
|
| 68 |
simplifier.Initialize(src);
|
| 69 |
-
simplifier.SimplifyMesh(0.05f);
|
| 70 |
Mesh newMesh = simplifier.ToMesh();
|
| 71 |
-
newMesh.name = src.name + "
|
| 72 |
-
|
| 73 |
-
AssetDatabase.AddObjectToAsset(newMesh, assetPath);
|
| 74 |
if (ren is MeshRenderer) ren.GetComponent<MeshFilter>().sharedMesh = newMesh;
|
| 75 |
else if (ren is SkinnedMeshRenderer s) s.sharedMesh = newMesh;
|
| 76 |
}
|
|
|
|
| 2 |
using UnityEditor;
|
| 3 |
using System;
|
| 4 |
using System.IO;
|
| 5 |
+
using UnityMeshSimplifier;
|
| 6 |
|
| 7 |
public class TestBuilder
|
| 8 |
{
|
|
|
|
| 10 |
{
|
| 11 |
try
|
| 12 |
{
|
| 13 |
+
// Paksa 4 worker
|
| 14 |
Unity.Jobs.LowLevel.Unsafe.JobsUtility.JobWorkerCount = 4;
|
| 15 |
+
|
| 16 |
+
// Setting Backend Mono2x (Wajib untuk 2022.3)
|
|
|
|
|
|
|
| 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 |
foreach (string path in prefabs)
|
| 26 |
{
|
| 27 |
GameObject go = PrefabUtility.LoadPrefabContents(path);
|
| 28 |
+
if (go != null) {
|
| 29 |
+
SimplifyMesh(go, path);
|
|
|
|
|
|
|
| 30 |
PrefabUtility.SaveAsPrefabAsset(go, path);
|
| 31 |
PrefabUtility.UnloadPrefabContents(go);
|
| 32 |
}
|
|
|
|
| 36 |
AssetDatabase.SaveAssets();
|
| 37 |
AssetDatabase.Refresh();
|
| 38 |
|
| 39 |
+
// Pengepakan Zepeto
|
|
|
|
| 40 |
ZepetoPackageCliBuilder.BuildWithArgs();
|
| 41 |
|
|
|
|
| 42 |
EditorApplication.Exit(0);
|
| 43 |
}
|
| 44 |
+
catch (Exception e) {
|
| 45 |
+
Debug.LogError(e.Message);
|
|
|
|
| 46 |
EditorApplication.Exit(1);
|
| 47 |
}
|
| 48 |
}
|
| 49 |
|
| 50 |
+
static void SimplifyMesh(GameObject go, string path) {
|
|
|
|
| 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 |
}
|