webzepetoku commited on
Commit
8054c2a
·
verified ·
1 Parent(s): 1728b4a

Update UnityProject/Assets/Editor/TestBuilder.cs

Browse files
UnityProject/Assets/Editor/TestBuilder.cs CHANGED
@@ -1,13 +1,16 @@
1
  using UnityEngine;
2
  using UnityEditor;
 
3
  using System.IO;
4
  using System.Linq;
 
5
  using UnityMeshSimplifier;
6
 
7
  public class TestBuilder
8
  {
9
  static readonly string RAW_PATH = "Assets/InputRaw";
10
  static readonly string ASSETBUNDLE_DIR = "Assets/InputRaw/assetbundles";
 
11
 
12
  public static void ManualConvert()
13
  {
@@ -24,11 +27,16 @@ public class TestBuilder
24
  {
25
  AssetDatabase.Refresh();
26
 
27
- // 1. Ambil semua aset asli di folder InputRaw
28
  string[] allAssets = Directory.GetFiles(RAW_PATH, "*.*", SearchOption.AllDirectories)
29
- .Where(s => !s.EndsWith(".meta") && !s.Contains("assetbundles")).ToArray();
30
 
31
- if (!Directory.Exists(ASSETBUNDLE_DIR)) Directory.CreateDirectory(ASSETBUNDLE_DIR);
 
 
 
 
 
32
 
33
  // 2. PROSES PERAMPINGAN (SIMPLIFY) & LABELING
34
  foreach (BuildTarget t in targets)
@@ -71,7 +79,40 @@ public class TestBuilder
71
  Debug.LogWarning($"⚠️ [UNITY] Gagal build untuk {platformName}. Error: {ex.Message}");
72
  }
73
  }
74
- Debug.Log("✅ [UNITY] Build binary selesai.");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  EditorApplication.Exit(0);
76
  }
77
  catch (System.Exception e) {
@@ -82,8 +123,7 @@ public class TestBuilder
82
 
83
  static void SimplifyMeshInGameObject(GameObject go)
84
  {
85
- string meshDir = "Assets/InputRaw/SimplifiedMeshes";
86
- if (!Directory.Exists(meshDir)) Directory.CreateDirectory(meshDir);
87
 
88
  var meshFilters = go.GetComponentsInChildren<MeshFilter>();
89
  foreach (var mf in meshFilters) {
@@ -93,7 +133,7 @@ public class TestBuilder
93
  meshSimplifier.SimplifyMesh(0.5f);
94
  Mesh newMesh = meshSimplifier.ToMesh();
95
 
96
- string newPath = $"{meshDir}/{go.name}_{mf.name}_{newMesh.GetInstanceID()}.asset";
97
  AssetDatabase.CreateAsset(newMesh, newPath);
98
 
99
  mf.sharedMesh = newMesh;
@@ -108,7 +148,7 @@ public class TestBuilder
108
  meshSimplifier.SimplifyMesh(0.5f);
109
  Mesh newMesh = meshSimplifier.ToMesh();
110
 
111
- string newPath = $"{meshDir}/{go.name}_{smr.name}_{newMesh.GetInstanceID()}_skinned.asset";
112
  AssetDatabase.CreateAsset(newMesh, newPath);
113
 
114
  smr.sharedMesh = newMesh;
 
1
  using UnityEngine;
2
  using UnityEditor;
3
+ using System;
4
  using System.IO;
5
  using System.Linq;
6
+ using System.IO.Compression;
7
  using UnityMeshSimplifier;
8
 
9
  public class TestBuilder
10
  {
11
  static readonly string RAW_PATH = "Assets/InputRaw";
12
  static readonly string ASSETBUNDLE_DIR = "Assets/InputRaw/assetbundles";
13
+ static readonly string SIMPLIFIED_MESH_DIR = "Assets/InputRaw/SimplifiedMeshes";
14
 
15
  public static void ManualConvert()
16
  {
 
27
  {
28
  AssetDatabase.Refresh();
29
 
30
+ // 1. Ambil semua aset asli di folder InputRaw (kecuali meta, folder assetbundles, hasil zip, dan zepeto)
31
  string[] allAssets = Directory.GetFiles(RAW_PATH, "*.*", SearchOption.AllDirectories)
32
+ .Where(s => !s.EndsWith(".meta") && !s.Contains("assetbundles") && !s.EndsWith(".zip") && !s.EndsWith(".zepeto")).ToArray();
33
 
34
+ // Bersihkan area kerja sebelum mulai
35
+ if (Directory.Exists(ASSETBUNDLE_DIR))
36
+ {
37
+ Directory.Delete(ASSETBUNDLE_DIR, true);
38
+ }
39
+ Directory.CreateDirectory(ASSETBUNDLE_DIR);
40
 
41
  // 2. PROSES PERAMPINGAN (SIMPLIFY) & LABELING
42
  foreach (BuildTarget t in targets)
 
79
  Debug.LogWarning($"⚠️ [UNITY] Gagal build untuk {platformName}. Error: {ex.Message}");
80
  }
81
  }
82
+
83
+ // 3. PROSES REPACKING FOLDER ASSETBUNDLES MENJADI .ZEPETO DENGAN TIMESTAMP
84
+ Debug.Log("📦 [UNITY] Memulai proses repacking folder assetbundles...");
85
+
86
+ string timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
87
+ string repackFile = $"Assets/InputRaw/Repacked_AssetBundles_{timestamp}.zepeto";
88
+
89
+ if (File.Exists(repackFile))
90
+ {
91
+ File.Delete(repackFile);
92
+ }
93
+
94
+ // Membuat arsip ZIP standar tetapi dengan ekstensi .zepeto agar dikenali WinRAR/7Zip
95
+ ZipFile.CreateFromDirectory(ASSETBUNDLE_DIR, repackFile);
96
+ Debug.Log($"✅ [UNITY] Repacking selesai: {repackFile}");
97
+
98
+ // 4. FASE PEMBERSIHAN (CLEANUP) - Hapus sisa file sementara
99
+ Debug.Log("🧹 [UNITY] Membersihkan sisa folder sementara (assetbundles & meshes)...");
100
+
101
+ if (Directory.Exists(ASSETBUNDLE_DIR))
102
+ {
103
+ Directory.Delete(ASSETBUNDLE_DIR, true);
104
+ if (File.Exists(ASSETBUNDLE_DIR + ".meta")) File.Delete(ASSETBUNDLE_DIR + ".meta");
105
+ }
106
+
107
+ if (Directory.Exists(SIMPLIFIED_MESH_DIR))
108
+ {
109
+ Directory.Delete(SIMPLIFIED_MESH_DIR, true);
110
+ if (File.Exists(SIMPLIFIED_MESH_DIR + ".meta")) File.Delete(SIMPLIFIED_MESH_DIR + ".meta");
111
+ }
112
+
113
+ AssetDatabase.Refresh(); // Segarkan database agar Unity tahu file sisa sudah dihapus
114
+
115
+ Debug.Log("✅ [UNITY] Seluruh proses build dan cleanup selesai dengan bersih.");
116
  EditorApplication.Exit(0);
117
  }
118
  catch (System.Exception e) {
 
123
 
124
  static void SimplifyMeshInGameObject(GameObject go)
125
  {
126
+ if (!Directory.Exists(SIMPLIFIED_MESH_DIR)) Directory.CreateDirectory(SIMPLIFIED_MESH_DIR);
 
127
 
128
  var meshFilters = go.GetComponentsInChildren<MeshFilter>();
129
  foreach (var mf in meshFilters) {
 
133
  meshSimplifier.SimplifyMesh(0.5f);
134
  Mesh newMesh = meshSimplifier.ToMesh();
135
 
136
+ string newPath = $"{SIMPLIFIED_MESH_DIR}/{go.name}_{mf.name}_{newMesh.GetInstanceID()}.asset";
137
  AssetDatabase.CreateAsset(newMesh, newPath);
138
 
139
  mf.sharedMesh = newMesh;
 
148
  meshSimplifier.SimplifyMesh(0.5f);
149
  Mesh newMesh = meshSimplifier.ToMesh();
150
 
151
+ string newPath = $"{SIMPLIFIED_MESH_DIR}/{go.name}_{smr.name}_{newMesh.GetInstanceID()}_skinned.asset";
152
  AssetDatabase.CreateAsset(newMesh, newPath);
153
 
154
  smr.sharedMesh = newMesh;