ProjectDDD/Assets/_Datas/SLShared/SLUnity/Editor/SLAssetPostprocessorEffect.cs
2025-06-17 20:47:57 +09:00

79 lines
2.3 KiB (Stored with Git LFS)
C#

using Superlazy;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.U2D;
using UnityEngine;
using Object = UnityEngine.Object;
public interface IPostProcessorEffect
{
void OnCreateEffectPrefab(GameObject root);
}
public static class SLAssetPostprocessorEffect
{
public static void OnPreprocessModel(ModelImporter importer)
{
importer.materialImportMode = ModelImporterMaterialImportMode.None;
}
public static void CreateEffect(string path, string destPath)
{
var effectCreateComponents = new List<IPostProcessorEffect>();
effectCreateComponents.CreateInstanceList();
var originalPrefab = AssetDatabase.LoadMainAssetAtPath(path) as GameObject;
var obj = Object.Instantiate(originalPrefab);
if (obj == null) return;
var root = new GameObject();
root.SetActive(false);
obj.transform.localPosition = Vector3.zero;
obj.transform.localRotation = Quaternion.identity;
obj.transform.SetParent(root.transform);
obj.name = originalPrefab.name;
var res = root.AddComponent<SLResourceObject>();
foreach (var comp in effectCreateComponents)
{
comp.OnCreateEffectPrefab(root);
}
res.Init();
SLFileUtility.MakeFolderFromFilePath(destPath);
var prefab = PrefabUtility.SaveAsPrefabAsset(root, destPath);
prefab.SetActive(true);
Object.DestroyImmediate(root);
Debug.Log("Build : " + destPath, prefab);
}
public static void OnRemove(string path)
{
var upperPath = path.ToUpper();
if (upperPath.IsLeft("ASSETS/RAW/EFFECTS") && upperPath.Contains(".PREFAB"))
{
var newPath = GetDestPath(path);
AssetDatabase.DeleteAsset(newPath);
}
}
private static string GetDestPath(string path)
{
var name = SLFileUtility.FileName(path);
return SLFileUtility.FolderPath(path).Replace("/Raw/", "/Addressables/") + "/" + name + ".prefab";
}
public static void OnAdd(string path)
{
var upperPath = path.ToUpper();
if (SLFileUtility.FolderPath(path).IsLeft("Assets/Raw/Effects") && upperPath.Contains(".PREFAB"))
{
var newPath = GetDestPath(path);
CreateEffect(path, newPath);
}
}
}