Changed AssetsHelpers from editor window to context menu workflow.
This commit is contained in:
8
Editor/AssetsHelpers/Implementation/Material.meta
Normal file
8
Editor/AssetsHelpers/Implementation/Material.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d38cb46c0b7e6504c84d6caff2e89903
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
47
Editor/AssetsHelpers/Implementation/Material/CreateDecal.cs
Normal file
47
Editor/AssetsHelpers/Implementation/Material/CreateDecal.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering.HighDefinition;
|
||||
|
||||
namespace Misaki.ArtToolEditor
|
||||
{
|
||||
public class CreateDecal
|
||||
{
|
||||
[MenuItem("Assets/Art Tools/Material Helpers/Create Decal", true)]
|
||||
public static bool CreateDecalMenuValidator()
|
||||
{
|
||||
foreach (var selectedObject in Selection.objects)
|
||||
{
|
||||
if (selectedObject is not Material)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[MenuItem("Assets/Art Tools/Material Helpers/Create Decal")]
|
||||
public static void CreateDecalMenu()
|
||||
{
|
||||
OutputOptionsWindow.ShowWindow("Decal Output Options", Selection.objects, CreateDecalInternal);
|
||||
}
|
||||
|
||||
private static string CreateDecalInternal(Object inputObject, string outputDirectory)
|
||||
{
|
||||
if (inputObject is not Material mat)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var outputPath = Path.Combine(outputDirectory, mat.name + ".prefab");
|
||||
var decal = AssetCreationHelpers.CreateDecal(outputPath);
|
||||
|
||||
mat.shader = Shader.Find(Constants.Shader.DECAL_SHADER_PATH);
|
||||
decal.transform.rotation = Quaternion.Euler(90, 0, 0);
|
||||
decal.GetComponent<DecalProjector>().material = mat;
|
||||
|
||||
return outputPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a4585b41cdb0577478ac9c4e563dc639
|
||||
@@ -0,0 +1,52 @@
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Misaki.ArtToolEditor
|
||||
{
|
||||
public class CreateTerrainLayer
|
||||
{
|
||||
private const string Terrain_Layer_Extension = ".terrainlayer";
|
||||
|
||||
[MenuItem("Assets/Art Tools/Material Helpers/Create Terrain Layer", true)]
|
||||
public static bool CreateDecalMenuValidator()
|
||||
{
|
||||
foreach (var selectedObject in Selection.objects)
|
||||
{
|
||||
if (selectedObject is not Material)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[MenuItem("Assets/Art Tools/Material Helpers/Create Terrain Layer")]
|
||||
public static void CreateDecalMenu()
|
||||
{
|
||||
OutputOptionsWindow.ShowWindow("Terrain Layer Output Options", Selection.objects, CreateTerrainLayerInternal);
|
||||
}
|
||||
|
||||
private static string CreateTerrainLayerInternal(Object inputObject, string outputDirectory)
|
||||
{
|
||||
if (inputObject is not Material mat)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var terrainLayer = new TerrainLayer()
|
||||
{
|
||||
diffuseTexture = mat.GetTexture("_BaseColorMap") as Texture2D,
|
||||
normalMapTexture = mat.GetTexture("_NormalMap") as Texture2D,
|
||||
maskMapTexture = mat.GetTexture("_MaskMap") as Texture2D,
|
||||
};
|
||||
|
||||
var outputPath = Path.Combine(outputDirectory, mat.name + Terrain_Layer_Extension);
|
||||
AssetDatabase.CreateAsset(terrainLayer, outputPath);
|
||||
|
||||
return outputPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ba5b5a3211673749a18dae69e07a0f3
|
||||
8
Editor/AssetsHelpers/Implementation/Meshes.meta
Normal file
8
Editor/AssetsHelpers/Implementation/Meshes.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 223cd2d5e7a5b9b4cba370fb38777463
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
123
Editor/AssetsHelpers/Implementation/Meshes/RemapMaterials.cs
Normal file
123
Editor/AssetsHelpers/Implementation/Meshes/RemapMaterials.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace Misaki.ArtToolEditor
|
||||
{
|
||||
public class RemapMaterials
|
||||
{
|
||||
private const string Material_Extension = ".mat";
|
||||
|
||||
private static bool _useMaterialRemap = false;
|
||||
private static ModelImporterMaterialLocation _materialLocation = ModelImporterMaterialLocation.InPrefab;
|
||||
private static ModelImporterMaterialName _materialRemapNamingOption = ModelImporterMaterialName.BasedOnMaterialName;
|
||||
private static ModelImporterMaterialSearch _materialRemapSearchOption = ModelImporterMaterialSearch.RecursiveUp;
|
||||
|
||||
[MenuItem("Assets/Art Tools/Mesh Helpers/Extract Materials", true)]
|
||||
public static bool CreateDecalMenuValidator()
|
||||
{
|
||||
foreach (var selectedObject in Selection.objects)
|
||||
{
|
||||
var assetImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(selectedObject));
|
||||
if (assetImporter is not ModelImporter)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[MenuItem("Assets/Art Tools/Mesh Helpers/Extract Materials")]
|
||||
public static void CreateDecalMenu()
|
||||
{
|
||||
var window = EditorWindow.GetWindow<OutputOptionsWindow>(true, "Extract Materials Output Options");
|
||||
window.WithSource(Selection.objects);
|
||||
window.WithContentBeforeButton(() =>
|
||||
{
|
||||
var root = new VisualElement();
|
||||
var materialRemapOptionContainer = new VisualElement()
|
||||
{
|
||||
style =
|
||||
{
|
||||
display = DisplayStyle.None,
|
||||
}
|
||||
};
|
||||
|
||||
var useMaterialRemap = new DropdownField("Use Material Remap", new List<string> { "False", "True" }, "False");
|
||||
useMaterialRemap.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
_useMaterialRemap = evt.newValue == "True";
|
||||
materialRemapOptionContainer.style.display = _useMaterialRemap ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
});
|
||||
|
||||
var materialLocation = new EnumField("Material Location", _materialLocation);
|
||||
materialLocation.RegisterValueChangedCallback(evt => _materialLocation = (ModelImporterMaterialLocation)evt.newValue);
|
||||
|
||||
var materialRemapNamingOption = new EnumField("Material Naming Option", _materialRemapNamingOption);
|
||||
materialRemapNamingOption.RegisterValueChangedCallback(evt => _materialRemapNamingOption = (ModelImporterMaterialName)evt.newValue);
|
||||
|
||||
var materialRemapSearchOption = new EnumField("Material Search Option", _materialRemapSearchOption);
|
||||
materialRemapSearchOption.RegisterValueChangedCallback(evt => _materialRemapSearchOption = (ModelImporterMaterialSearch)evt.newValue);
|
||||
|
||||
materialRemapOptionContainer.Add(materialLocation);
|
||||
materialRemapOptionContainer.Add(materialRemapNamingOption);
|
||||
materialRemapOptionContainer.Add(materialRemapSearchOption);
|
||||
|
||||
root.Add(useMaterialRemap);
|
||||
root.Add(materialRemapOptionContainer);
|
||||
return root;
|
||||
});
|
||||
window.WithOutput(ExtractMaterialsInternal);
|
||||
window.WithPostOutput(ExtractMaterialsPostInternal);
|
||||
|
||||
window.ShowUtility();
|
||||
}
|
||||
|
||||
private static string ExtractMaterialsInternal(Object inputObject, string outputDirectory)
|
||||
{
|
||||
var assetImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(inputObject));
|
||||
if (assetImporter is not ModelImporter modelImporter)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (_useMaterialRemap)
|
||||
{
|
||||
modelImporter.materialLocation = _materialLocation;
|
||||
modelImporter.SearchAndRemapMaterials(_materialRemapNamingOption, _materialRemapSearchOption);
|
||||
modelImporter.SaveAndReimport();
|
||||
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
var materials = AssetDatabase.LoadAllAssetsAtPath(modelImporter.assetPath).Where(x => x.GetType() == typeof(Material));
|
||||
|
||||
foreach (var material in materials)
|
||||
{
|
||||
var newAssetPath = Path.Combine(outputDirectory, material.name) + Material_Extension;
|
||||
newAssetPath = AssetDatabase.GenerateUniqueAssetPath(newAssetPath);
|
||||
|
||||
AssetDatabase.ExtractAsset(material, newAssetPath);
|
||||
}
|
||||
|
||||
return modelImporter.assetPath;
|
||||
}
|
||||
}
|
||||
|
||||
private static void ExtractMaterialsPostInternal(string assetPath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(assetPath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AssetDatabase.WriteImportSettingsIfDirty(assetPath);
|
||||
AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cc9f1a0be83aa444884c32f825c5303
|
||||
Reference in New Issue
Block a user