Compare commits

...

2 Commits

Author SHA1 Message Date
NTG_Lenovo
e33bef85ec 에셋 추가 2025-08-01 17:30:50 +09:00
NTG_Lenovo
1157dc0931 prop material, prefab 자동 생성화 2025-08-01 17:30:36 +09:00
8 changed files with 235 additions and 4 deletions

View File

@ -117,6 +117,12 @@ MonoBehaviour:
m_SerializedLabels: m_SerializedLabels:
- Atlas - Atlas
FlaggedDuringContentUpdateRestriction: 0 FlaggedDuringContentUpdateRestriction: 0
- m_GUID: bdaaf61c74a901948adb2ec33a16f303
m_Address: TEst
m_ReadOnly: 0
m_SerializedLabels:
- Atlas
FlaggedDuringContentUpdateRestriction: 0
- m_GUID: c6d19267dabc844449cc778f2f03fb34 - m_GUID: c6d19267dabc844449cc778f2f03fb34
m_Address: SummerGrass01_SkeletonData m_Address: SummerGrass01_SkeletonData
m_ReadOnly: 0 m_ReadOnly: 0

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4e0dbc016d2c12f4c99558ee241527c2
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a091bea407408bf479358f16dd8f42bf
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 01ae87c507a6ccc4d8b56b35df17d10d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,7 +1,6 @@
#if UNITY_EDITOR #if UNITY_EDITOR
using UnityEngine; using UnityEngine;
using UnityEditor; using UnityEditor;
using UnityEngine.Networking;
namespace DDD namespace DDD
{ {
@ -12,8 +11,8 @@ private void OnPreprocessTexture()
var importer = assetImporter as TextureImporter; var importer = assetImporter as TextureImporter;
var upperPath = importer.assetPath.ToUpper(); var upperPath = importer.assetPath.ToUpper();
if (upperPath.Contains(PathConstants.RawUiPathUpper)) if (upperPath.Contains(PathConstants.RawSpritesPathUpper))
{ {
if (upperPath.Contains(PathConstants.RawOnlyAtlasPathUpper)) if (upperPath.Contains(PathConstants.RawOnlyAtlasPathUpper))
{ {
@ -28,6 +27,10 @@ private void OnPreprocessTexture()
AssetPostprocessorSprite.OnPreprocessTextureForUi(importer); AssetPostprocessorSprite.OnPreprocessTextureForUi(importer);
} }
} }
else if (upperPath.Contains(PathConstants.RawEnvironmentsPathUpper))
{
AssetPostprocessorEnvironment.OnPreprocessTexture(importer);
}
} }
public static void OnPostprocessAllAssets(string[] importedAssets, string[] deleteAssets, string[] movedAssets, public static void OnPostprocessAllAssets(string[] importedAssets, string[] deleteAssets, string[] movedAssets,
@ -75,7 +78,7 @@ public static void OnPostprocessAllAssets(string[] importedAssets, string[] dele
} }
AssetPostprocessorSprite.BuildTarget(); AssetPostprocessorSprite.BuildTarget();
AssetPostprocessorSprite.BuildTarget(); AssetPostprocessorEnvironment.BuildTarget();
} }
private static void PostRemove(string path, string movePath = "") private static void PostRemove(string path, string movePath = "")
@ -83,6 +86,7 @@ private static void PostRemove(string path, string movePath = "")
try try
{ {
AssetPostprocessorSprite.OnRemove(path, movePath); AssetPostprocessorSprite.OnRemove(path, movePath);
AssetPostprocessorEnvironment.OnRemove(path);
} }
catch (System.Exception e) catch (System.Exception e)
{ {
@ -95,6 +99,7 @@ private static void PostAdd(string path)
try try
{ {
AssetPostprocessorSprite.OnAdd(path); AssetPostprocessorSprite.OnAdd(path);
AssetPostprocessorEnvironment.OnAdd(path);
} }
catch (System.Exception e) catch (System.Exception e)
{ {

View File

@ -0,0 +1,188 @@
#if UNITY_EDITOR
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEditor.AddressableAssets;
using UnityEditor.AddressableAssets.Settings;
using UnityEngine;
namespace DDD
{
public static class AssetPostprocessorEnvironment
{
private static readonly HashSet<string> SpriteTargetPaths = new();
private static readonly HashSet<string> MeshTargetPaths = new();
private static readonly int BaseMap = Shader.PropertyToID("_BaseMap");
private static readonly int MetallicGlossMap = Shader.PropertyToID("_MetallicGlossMap");
private static readonly int BumpMap = Shader.PropertyToID("_BumpMap");
private static readonly int EmissionMap = Shader.PropertyToID("_EmissionMap");
private const string BaseMeshPrefabPath = "Assets/_DDD/_Raw/Environments/Env_Mesh_Prop.prefab";
private const string BaseSpritePrefabPath = "Assets/_DDD/_Raw/Environments/Env_Sprite_Background.prefab";
private const string ShaderName = "Universal Render Pipeline/LitEnvironment";
private const string Prop = "Prop_";
private const string BaseColorUpper = "_BASECOLOR";
private const string MohsUpper = "_MOHS";
private const string NormalUpper = "_NORMAL";
private const string EmissionUpper = "_EMISSION";
public static void OnPreprocessTexture(TextureImporter importer)
{
var path = importer.assetPath;
string fileNameUpper = Utils.FileName(path).ToUpper();
if (fileNameUpper.Contains(NormalUpper))
{
importer.textureType = TextureImporterType.NormalMap;
}
else
{
importer.textureType = TextureImporterType.Default;
importer.sRGBTexture = true;
}
importer.mipmapEnabled = true;
}
public static void OnAdd(string path)
{
string upperPath = path.ToUpper();
if (upperPath.Contains(PathConstants.RawEnvSpritesPathUpper) &&
upperPath.Contains(ExtenstionConstants.PngExtensionUpper))
{
if (!SpriteTargetPaths.Contains(path))
SpriteTargetPaths.Add(path);
}
else if (upperPath.Contains(PathConstants.RawEnvMeshesPathUpper) &&
upperPath.Contains(ExtenstionConstants.PngExtensionUpper))
{
if (!MeshTargetPaths.Contains(path))
MeshTargetPaths.Add(path);
}
}
public static void OnRemove(string path, string movePath = "")
{
string upperPath = path.ToUpper();
if (upperPath.Contains(PathConstants.RawEnvSpritesPathUpper) &&
upperPath.Contains(ExtenstionConstants.PngExtensionUpper))
{
if (!SpriteTargetPaths.Contains(path))
SpriteTargetPaths.Add(path);
}
else if (upperPath.Contains(PathConstants.RawEnvMeshesPathUpper) &&
upperPath.Contains(ExtenstionConstants.PngExtensionUpper))
{
if (!MeshTargetPaths.Contains(path))
MeshTargetPaths.Add(path);
}
}
public static void BuildMaterialAndPrefab(string path, bool isMesh)
{
var di = new DirectoryInfo(path);
if (!di.Exists) return;
string folderName = di.Name;
string rawRoot = PathConstants.RawFolderPath; // "/_Raw"
string addrRoot = PathConstants.AddressablesFolderPath; // "/_Addressables"
string destDir = path.Replace(rawRoot, addrRoot);
string materialPath = $"{destDir}/{folderName}{ExtenstionConstants.MaterialExtenstionLower}";
string prefabPath = $"{destDir}/{Prop}{folderName}{ExtenstionConstants.PrefabExtenstionLower}";
Utils.MakeFolderFromFilePath(materialPath);
// 머티리얼 생성 또는 로드
Material mat = AssetDatabase.LoadAssetAtPath<Material>(materialPath);
if (mat == null)
{
mat = new Material(Shader.Find(ShaderName));
AssetDatabase.CreateAsset(mat, materialPath);
}
// PNG 텍스처 매핑
var files = Directory.GetFiles(path, $"*{ExtenstionConstants.PngExtensionLower}", SearchOption.TopDirectoryOnly);
foreach (var file in files)
{
string texName = Path.GetFileNameWithoutExtension(file).ToUpper();
var tex = AssetDatabase.LoadAssetAtPath<Texture>(file);
if (tex == null) continue;
if (texName.Contains(BaseColorUpper))
{
mat.SetTexture(BaseMap, tex);
}
else if (texName.Contains(MohsUpper))
{
mat.SetTexture(MetallicGlossMap, tex);
}
else if (texName.Contains(NormalUpper))
{
mat.SetTexture(BumpMap, tex);
}
else if (texName.Contains(EmissionUpper))
{
mat.SetTexture(EmissionMap, tex);
}
}
AssetDatabase.ImportAsset(materialPath, ImportAssetOptions.ForceUpdate);
AssetDatabase.SaveAssets();
CreateOrUpdatePrefabVariant(folderName, mat, prefabPath, isMesh);
}
private static void CreateOrUpdatePrefabVariant(string folderName, Material mat, string prefabPath, bool isMesh)
{
if (AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath) != null) return;
string basePrefabPath = isMesh ? BaseMeshPrefabPath : BaseSpritePrefabPath;
var basePrefab = AssetDatabase.LoadAssetAtPath<GameObject>(basePrefabPath);
if (basePrefab == null)
{
Debug.LogWarning($"Base prefab not found: {basePrefabPath}");
return;
}
GameObject instancePrefab = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
if (instancePrefab == null)
{
instancePrefab = (GameObject)PrefabUtility.InstantiatePrefab(basePrefab);
instancePrefab.name = $"{Prop}{folderName}";
}
var renderer = instancePrefab.GetComponentInChildren<Renderer>();
if (renderer != null) renderer.sharedMaterial = mat;
Utils.MakeFolderFromFilePath(prefabPath);
PrefabUtility.SaveAsPrefabAssetAndConnect(instancePrefab, prefabPath, InteractionMode.AutomatedAction);
Object.DestroyImmediate(instancePrefab);
AssetDatabase.ImportAsset(prefabPath, ImportAssetOptions.ForceUpdate);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
public static void BuildTarget()
{
foreach (var path in SpriteTargetPaths)
{
BuildMaterialAndPrefab(Utils.FolderPath(path), isMesh: false);
}
foreach (var path in MeshTargetPaths)
{
BuildMaterialAndPrefab(Utils.FolderPath(path), isMesh: true);
}
SpriteTargetPaths.Clear();
MeshTargetPaths.Clear();
}
}
}
#endif

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 423ca2e84db846d08980f4821dd69f25
timeCreated: 1754028565

View File

@ -42,6 +42,9 @@ public static class PathConstants
public const string RawOnlyAtlasPathUpper = "ASSETS/_DDD/_RAW/SPRITES/ONLYATLAS/"; public const string RawOnlyAtlasPathUpper = "ASSETS/_DDD/_RAW/SPRITES/ONLYATLAS/";
public const string RawFolderPath = "/_Raw"; public const string RawFolderPath = "/_Raw";
public const string AddressablesFolderPath = "/_Addressables"; public const string AddressablesFolderPath = "/_Addressables";
public const string RawEnvironmentsPathUpper = "ASSETS/_DDD/_RAW/ENVIRONMENTS/";
public const string RawEnvSpritesPathUpper = "ASSETS/_DDD/_RAW/ENVIRONMENTS/SPRITES/";
public const string RawEnvMeshesPathUpper = "ASSETS/_DDD/_RAW/ENVIRONMENTS/MESHES/";
} }
public static class ExtenstionConstants public static class ExtenstionConstants
@ -49,6 +52,8 @@ public static class ExtenstionConstants
public const string PngExtensionUpper = ".PNG"; public const string PngExtensionUpper = ".PNG";
public const string PngExtensionLower = ".png"; public const string PngExtensionLower = ".png";
public const string SpriteAtlasExtenstionLower = ".spriteatlasv2"; public const string SpriteAtlasExtenstionLower = ".spriteatlasv2";
public const string MaterialExtenstionLower = ".mat";
public const string PrefabExtenstionLower = ".prefab";
} }
public static class SpriteConstants public static class SpriteConstants