Spaces:
Running
Running
Update UnityProject/Assets/Editor/TestBuilder.cs
Browse files
UnityProject/Assets/Editor/TestBuilder.cs
CHANGED
|
@@ -1,102 +1,111 @@
|
|
| 1 |
-
using UnityEngine;
|
| 2 |
-
using UnityEditor;
|
| 3 |
-
using System.IO;
|
| 4 |
-
using System.Collections.Generic;
|
| 5 |
-
|
| 6 |
-
public class TestBuilder
|
| 7 |
-
{
|
| 8 |
-
public static void ManualConvert()
|
| 9 |
-
{
|
| 10 |
-
// 1. BACA INPUT DARI HUGGING FACE
|
| 11 |
-
string inputFileName = GetArg("-inputFile");
|
| 12 |
-
if (string.IsNullOrEmpty(inputFileName))
|
| 13 |
-
{
|
| 14 |
-
Debug.LogError("❌ Tidak ada file input!");
|
| 15 |
-
return;
|
| 16 |
-
}
|
| 17 |
-
|
| 18 |
-
string rootPath = Directory.GetCurrentDirectory();
|
| 19 |
-
string
|
| 20 |
-
string outputDir = Path.Combine(rootPath, "output");
|
| 21 |
-
string outputFileName = Path.GetFileNameWithoutExtension(inputFileName) + ".zepeto";
|
| 22 |
-
string finalOutputPath = Path.Combine(outputDir, outputFileName);
|
| 23 |
-
|
| 24 |
-
// 2.
|
| 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 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
}
|
|
|
|
| 1 |
+
using UnityEngine;
|
| 2 |
+
using UnityEditor;
|
| 3 |
+
using System.IO;
|
| 4 |
+
using System.Collections.Generic;
|
| 5 |
+
|
| 6 |
+
public class TestBuilder
|
| 7 |
+
{
|
| 8 |
+
public static void ManualConvert()
|
| 9 |
+
{
|
| 10 |
+
// 1. BACA INPUT DARI HUGGING FACE
|
| 11 |
+
string inputFileName = GetArg("-inputFile");
|
| 12 |
+
if (string.IsNullOrEmpty(inputFileName))
|
| 13 |
+
{
|
| 14 |
+
Debug.LogError("❌ Tidak ada file input!");
|
| 15 |
+
return;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
string rootPath = Directory.GetCurrentDirectory();
|
| 19 |
+
string assetPath = $"Assets/{inputFileName}";
|
| 20 |
+
string outputDir = Path.Combine(rootPath, "output");
|
| 21 |
+
string outputFileName = Path.GetFileNameWithoutExtension(inputFileName) + ".zepeto";
|
| 22 |
+
string finalOutputPath = Path.Combine(outputDir, outputFileName);
|
| 23 |
+
|
| 24 |
+
// 2. RAHASIA RAMPING 1: OPTIMASI MESH (POLIGON & VERTEX)
|
| 25 |
+
// Sebelum load model, kita set dulu aturan import-nya
|
| 26 |
+
ModelImporter mi = AssetImporter.GetAtPath(assetPath) as ModelImporter;
|
| 27 |
+
if (mi != null)
|
| 28 |
+
{
|
| 29 |
+
mi.meshCompression = ModelImporterMeshCompression.High; // Kompresi poligon tinggi
|
| 30 |
+
mi.optimizeMeshPolygons = true;
|
| 31 |
+
mi.optimizeMeshVertices = true;
|
| 32 |
+
mi.weldVertices = true; // Menggabungkan vertex yang berdekatan (mengurangi berat)
|
| 33 |
+
mi.importBlendShapes = false; // Matikan jika tidak butuh (hemat size besar)
|
| 34 |
+
mi.addSecondaryUV = false;
|
| 35 |
+
AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
// Load Model setelah dioptimasi
|
| 39 |
+
GameObject fbx = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
|
| 40 |
+
if (fbx == null) return;
|
| 41 |
+
|
| 42 |
+
// 3. RAHASIA RAMPING 2: TEXTURE COMPRESSION (ASTC)
|
| 43 |
+
Renderer[] renderers = fbx.GetComponentsInChildren<Renderer>();
|
| 44 |
+
foreach (Renderer r in renderers)
|
| 45 |
+
{
|
| 46 |
+
foreach (Material m in r.sharedMaterials)
|
| 47 |
+
{
|
| 48 |
+
if (m != null && m.mainTexture != null)
|
| 49 |
+
{
|
| 50 |
+
string texPath = AssetDatabase.GetAssetPath(m.mainTexture);
|
| 51 |
+
TextureImporter ti = AssetImporter.GetAtPath(texPath) as TextureImporter;
|
| 52 |
+
if (ti != null)
|
| 53 |
+
{
|
| 54 |
+
TextureImporterPlatformSettings settings = new TextureImporterPlatformSettings();
|
| 55 |
+
settings.name = "Android";
|
| 56 |
+
settings.overridden = true;
|
| 57 |
+
settings.maxTextureSize = 1024; // Zepeto menyarankan 1024 untuk item kecil
|
| 58 |
+
settings.format = TextureImporterFormat.ASTC_6x6;
|
| 59 |
+
settings.compressionQuality = 100;
|
| 60 |
+
ti.SetPlatformTextureSettings(settings);
|
| 61 |
+
ti.SaveAndReimport();
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
// 4. BUAT PREFAB
|
| 68 |
+
GameObject instance = (GameObject)PrefabUtility.InstantiatePrefab(fbx);
|
| 69 |
+
string prefabPath = "Assets/TempZepetoItem.prefab";
|
| 70 |
+
PrefabUtility.SaveAsPrefabAsset(instance, prefabPath);
|
| 71 |
+
GameObject.DestroyImmediate(instance);
|
| 72 |
+
|
| 73 |
+
// 5. BUILD ASSET BUNDLE (.ZEPETO)
|
| 74 |
+
if (!Directory.Exists("TempBuild")) Directory.CreateDirectory("TempBuild");
|
| 75 |
+
|
| 76 |
+
AssetBundleBuild[] buildMap = new AssetBundleBuild[1];
|
| 77 |
+
buildMap[0].assetBundleName = "zepeto_bundle";
|
| 78 |
+
buildMap[0].assetNames = new string[] { prefabPath };
|
| 79 |
+
|
| 80 |
+
BuildPipeline.BuildAssetBundles(
|
| 81 |
+
"TempBuild",
|
| 82 |
+
buildMap,
|
| 83 |
+
BuildAssetBundleOptions.ChunkBasedCompression | BuildAssetBundleOptions.StrictMode,
|
| 84 |
+
BuildTarget.Android
|
| 85 |
+
);
|
| 86 |
+
|
| 87 |
+
// 6. FINISHING & MOVE TO OUTPUT
|
| 88 |
+
string generatedFile = Path.Combine(rootPath, "TempBuild", "zepeto_bundle");
|
| 89 |
+
if (File.Exists(generatedFile))
|
| 90 |
+
{
|
| 91 |
+
if (!Directory.Exists(outputDir)) Directory.CreateDirectory(outputDir);
|
| 92 |
+
if (File.Exists(finalOutputPath)) File.Delete(finalOutputPath);
|
| 93 |
+
File.Move(generatedFile, finalOutputPath);
|
| 94 |
+
Debug.Log($"✅ [ALL OPTIMIZED] Poligon & Tekstur Ramping: {finalOutputPath}");
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
// Bersihkan sampah
|
| 98 |
+
AssetDatabase.DeleteAsset(assetPath);
|
| 99 |
+
AssetDatabase.DeleteAsset(prefabPath);
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
private static string GetArg(string name)
|
| 103 |
+
{
|
| 104 |
+
var args = System.Environment.GetCommandLineArgs();
|
| 105 |
+
for (int i = 0; i < args.Length; i++)
|
| 106 |
+
{
|
| 107 |
+
if (args[i] == name && args.Length > i + 1) return args[i + 1];
|
| 108 |
+
}
|
| 109 |
+
return null;
|
| 110 |
+
}
|
| 111 |
}
|