Spaces:
Running
Running
File size: 3,448 Bytes
396e9bd 37fe00a 8fffbf7 396e9bd 40410bc 4b2b582 c3547e2 40410bc c3547e2 37fe00a 413bde2 37fe00a 413bde2 37fe00a 0eba640 571258a 2aa5bbb 8fffbf7 4b2b582 dc3f2dc 4b2b582 8fffbf7 2aa5bbb 37fe00a 2aa5bbb 8fffbf7 413bde2 2aa5bbb 413bde2 4b2b582 413bde2 2aa5bbb 413bde2 4b2b582 413bde2 37fe00a 2aa5bbb 413bde2 2aa5bbb 8fffbf7 4b2b582 8fffbf7 0eba640 37fe00a 2aa5bbb 37fe00a 0eba640 8fffbf7 413bde2 40410bc 396e9bd 8fffbf7 4b2b582 8fffbf7 61cfa5d | 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 80 81 82 83 84 85 86 87 88 89 90 91 | using UnityEngine;
using UnityEditor;
using System.IO;
using System.Linq;
using UnityMeshSimplifier;
public class TestBuilder
{
static readonly string RAW_PATH = "Assets/InputRaw";
static readonly string ASSETBUNDLE_DIR = "Assets/InputRaw/assetbundles";
public static void ManualConvert()
{
BuildTarget[] targets = {
BuildTarget.Android,
BuildTarget.iOS,
BuildTarget.StandaloneLinux64,
BuildTarget.StandaloneOSX,
BuildTarget.StandaloneWindows64,
BuildTarget.WebGL
};
try
{
AssetDatabase.Refresh();
// 1. Ambil semua aset asli di folder InputRaw
string[] allAssets = Directory.GetFiles(RAW_PATH, "*.*", SearchOption.AllDirectories)
.Where(s => !s.EndsWith(".meta") && !s.Contains("assetbundles")).ToArray();
if (!Directory.Exists(ASSETBUNDLE_DIR)) Directory.CreateDirectory(ASSETBUNDLE_DIR);
// 2. PROSES PERAMPINGAN (SIMPLIFY) & LABELING
foreach (BuildTarget t in targets)
{
string platformName = t.ToString();
foreach (string path in allAssets)
{
// Rampingkan poligon 50% untuk file 3D
if (path.EndsWith(".prefab") || path.EndsWith(".fbx")) {
GameObject go = AssetDatabase.LoadAssetAtPath<GameObject>(path);
if (go != null) SimplifyMeshInGameObject(go);
}
// Beri label bundle sesuai nama platform (agar binary tanpa ekstensi)
AssetImporter importer = AssetImporter.GetAtPath(path);
if (importer != null) importer.assetBundleName = platformName;
}
Debug.Log($"π [UNITY] Membangun binary platform: {platformName}");
// Build binary platform tanpa ekstensi ke dalam folder assetbundles/
BuildPipeline.BuildAssetBundles(
ASSETBUNDLE_DIR,
BuildAssetBundleOptions.ForceRebuildAssetBundle,
t
);
}
Debug.Log("β
[UNITY] Build binary selesai.");
EditorApplication.Exit(0);
}
catch (System.Exception e) {
Debug.LogError($"π Error: {e.Message}");
EditorApplication.Exit(1);
}
}
static void SimplifyMeshInGameObject(GameObject go)
{
var meshFilters = go.GetComponentsInChildren<MeshFilter>();
foreach (var mf in meshFilters) {
if (mf.sharedMesh != null) {
var meshSimplifier = new UnityMeshSimplifier.MeshSimplifier();
meshSimplifier.Initialize(mf.sharedMesh);
meshSimplifier.SimplifyMesh(0.5f);
mf.sharedMesh = meshSimplifier.ToMesh();
}
}
var skinnedMeshes = go.GetComponentsInChildren<SkinnedMeshRenderer>();
foreach (var smr in skinnedMeshes) {
if (smr.sharedMesh != null) {
var meshSimplifier = new UnityMeshSimplifier.MeshSimplifier();
meshSimplifier.Initialize(smr.sharedMesh);
meshSimplifier.SimplifyMesh(0.5f);
smr.sharedMesh = meshSimplifier.ToMesh();
}
}
}
} |