124 lines
3.7 KiB (Stored with Git LFS)
C#
124 lines
3.7 KiB (Stored with Git LFS)
C#
using System.Diagnostics;
|
|
using UnityEditor;
|
|
|
|
public class SLAssetPostprocessor : AssetPostprocessor
|
|
{
|
|
private void OnPreprocessModel()
|
|
{
|
|
var importer = assetImporter as ModelImporter;
|
|
var upperPath = importer.assetPath.ToUpper();
|
|
|
|
if (upperPath.Contains("ASSETS/RAW/"))
|
|
{
|
|
}
|
|
|
|
if (upperPath.Contains("ASSETS/RAW/UNITS/") && upperPath.Contains("_") == false && upperPath.Contains(".FBX"))
|
|
{
|
|
var fileName = SLFileUtility.FileName(upperPath);
|
|
var folderName = SLFileUtility.FolderName(upperPath);
|
|
if (fileName == folderName)
|
|
{
|
|
SLAssetPostprocessorModel.OnPreprocessModel(importer);
|
|
}
|
|
}
|
|
else if (upperPath.Contains("ASSETS/RAW/UNITS/") && upperPath.Contains("_") && upperPath.Contains(".FBX"))
|
|
{
|
|
SLAssetPostprocessorAnim.OnPreprocessModel(importer);
|
|
}
|
|
else if (upperPath.Contains("ASSETS/RAW/UNITS/") && upperPath.Contains("_PREFAB.PREFAB"))
|
|
{
|
|
SLAssetPostprocessorModel.OnPreprocessModel(importer);
|
|
}
|
|
else if (upperPath.Contains("ASSETS/RAW/EFFECTS/"))
|
|
{
|
|
SLAssetPostprocessorEffect.OnPreprocessModel(importer);
|
|
}
|
|
}
|
|
|
|
private void OnPreprocessAnimation()
|
|
{
|
|
var importer = assetImporter as ModelImporter;
|
|
var upperPath = importer.assetPath.ToUpper();
|
|
if (upperPath.Contains("ASSETS/RAW/UNITS/") && upperPath.Contains("_") && upperPath.Contains(".FBX"))
|
|
{
|
|
SLAssetPostprocessorAnim.OnPreprocessAnim(importer);
|
|
}
|
|
}
|
|
|
|
private void OnPreprocessTexture()
|
|
{
|
|
var importer = assetImporter as TextureImporter;
|
|
|
|
var upperPath = importer.assetPath.ToUpper();
|
|
|
|
if (upperPath.Contains("ASSETS/RAW/Units/"))
|
|
{
|
|
SLAssetPostprocessorModel.OnPreprocessTexture(importer);
|
|
}
|
|
|
|
if (upperPath.Contains("ASSETS/RAW/SPRITES/"))
|
|
{
|
|
SLAssetPostprocessorSprite.OnPreprocessTexture(importer);
|
|
}
|
|
}
|
|
|
|
public static void OnPostprocessAllAssets(string[] importedAssets, string[] deleteAssets, string[] movedAssets, string[] movedFromAssetPaths)
|
|
{
|
|
foreach (var path in deleteAssets)
|
|
{
|
|
PostRem(path);
|
|
}
|
|
|
|
var index = 0;
|
|
foreach (var path in movedFromAssetPaths)
|
|
{
|
|
PostRem(path, movedAssets[index]);
|
|
++index;
|
|
}
|
|
|
|
foreach (var path in movedAssets)
|
|
{
|
|
PostAdd(path);
|
|
}
|
|
|
|
foreach (var path in importedAssets)
|
|
{
|
|
PostAdd(path);
|
|
}
|
|
|
|
SLAssetPostprocessorModel.BuildTarget();
|
|
SLAssetPostprocessorSprite.BuildTarget();
|
|
}
|
|
|
|
private static void PostRem(string path, string movePath = "")
|
|
{
|
|
try
|
|
{
|
|
SLAssetPostprocessorModel.OnRemove(path);
|
|
SLAssetPostprocessorAnim.OnRemove(path);
|
|
SLAssetPostprocessorEffect.OnRemove(path);
|
|
SLAssetPostprocessorSprite.OnRemove(path, movePath);
|
|
SLAssetPostprocessorScene.OnRemove(path);
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
UnityEngine.Debug.LogError("Can't remove " + path + "\n" + e);
|
|
}
|
|
}
|
|
|
|
private static void PostAdd(string path)
|
|
{
|
|
try
|
|
{
|
|
SLAssetPostprocessorModel.OnAdd(path);
|
|
SLAssetPostprocessorAnim.OnAdd(path);
|
|
SLAssetPostprocessorEffect.OnAdd(path);
|
|
SLAssetPostprocessorSprite.OnAdd(path);
|
|
SLAssetPostprocessorScene.OnAdd(path);
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
UnityEngine.Debug.LogError("Can't import " + path + "\n" + e);
|
|
}
|
|
}
|
|
} |