mirror of
https://github.com/maxartz15/VertexAnimation.git
synced 2024-11-12 15:35:30 +01:00
Fix prefab overwrite.
This commit is contained in:
parent
f9a50c8c3a
commit
94f97c218a
@ -43,5 +43,10 @@ namespace TAO.VertexAnimation.Editor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool HasAsset(string path, System.Type type)
|
||||
{
|
||||
return (AssetDatabase.LoadAssetAtPath(path, type) ? true : false);
|
||||
}
|
||||
}
|
||||
}
|
@ -7,22 +7,65 @@ namespace TAO.VertexAnimation.Editor
|
||||
{
|
||||
public static GameObject Create(string path, string name, Mesh[] meshes, Material material, float[] lodTransitions)
|
||||
{
|
||||
// Create parent.
|
||||
GameObject parent = new GameObject(name, typeof(LODGroup), typeof(VA_AnimatorComponentAuthoring), typeof(Unity.Entities.ConvertToEntity));
|
||||
GameObject parent = null;
|
||||
if (AssetDatabaseUtils.HasAsset(path, typeof(GameObject)))
|
||||
{
|
||||
// Load existing parent.
|
||||
parent = PrefabUtility.LoadPrefabContents(path);
|
||||
|
||||
// Check setup.
|
||||
if (!parent.TryGetComponent(out LODGroup _))
|
||||
{
|
||||
parent.AddComponent<LODGroup>();
|
||||
}
|
||||
|
||||
if (!parent.TryGetComponent(out VA_AnimatorComponentAuthoring _))
|
||||
{
|
||||
parent.AddComponent<VA_AnimatorComponentAuthoring>();
|
||||
}
|
||||
|
||||
if (!parent.TryGetComponent(out Unity.Entities.ConvertToEntity _))
|
||||
{
|
||||
parent.AddComponent<Unity.Entities.ConvertToEntity>();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create parent.
|
||||
parent = new GameObject(name, typeof(LODGroup), typeof(VA_AnimatorComponentAuthoring), typeof(Unity.Entities.ConvertToEntity));
|
||||
}
|
||||
|
||||
// Create all LODs.
|
||||
LOD[] lods = new LOD[meshes.Length];
|
||||
|
||||
for (int i = 0; i < meshes.Length; i++)
|
||||
{
|
||||
GameObject lod = new GameObject(string.Format("{0}_LOD{1}", name, i), typeof(MeshFilter), typeof(MeshRenderer));
|
||||
|
||||
var mf = lod.GetComponent<MeshFilter>();
|
||||
mf.sharedMesh = meshes[i];
|
||||
var mr = lod.GetComponent<MeshRenderer>();
|
||||
mr.sharedMaterial = material;
|
||||
string childName = string.Format("{0}_LOD{1}", name, i);
|
||||
|
||||
lod.transform.SetParent(parent.transform);
|
||||
GameObject child;
|
||||
{
|
||||
Transform t = parent.transform.Find(childName);
|
||||
if (t)
|
||||
{
|
||||
child = t.gameObject;
|
||||
}
|
||||
else
|
||||
{
|
||||
child = new GameObject(childName, typeof(MeshFilter), typeof(MeshRenderer));
|
||||
}
|
||||
}
|
||||
|
||||
if (child.TryGetComponent(out MeshFilter mf))
|
||||
{
|
||||
mf.sharedMesh = meshes[i];
|
||||
}
|
||||
|
||||
if (child.TryGetComponent(out MeshRenderer mr))
|
||||
{
|
||||
mr.sharedMaterial = material;
|
||||
}
|
||||
|
||||
child.transform.SetParent(parent.transform);
|
||||
lods[i] = new LOD(lodTransitions[i], new Renderer[1] { mr });
|
||||
}
|
||||
|
||||
|
@ -39,31 +39,19 @@ namespace TAO.VertexAnimation.Editor
|
||||
|
||||
private void BakeGUI()
|
||||
{
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("saveBakedDataToAsset"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("lodSettings").FindPropertyRelative("lodSettings"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("generateAnimationBook"));
|
||||
|
||||
int il = EditorGUI.indentLevel;
|
||||
if (modelBaker.saveBakedDataToAsset)
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("generateAnimationBook"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("lodSettings"));
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("generatePrefab"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("materialShader"), new GUIContent(""));
|
||||
}
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("generatePrefab"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("materialShader"), new GUIContent(""));
|
||||
}
|
||||
EditorGUI.indentLevel = il;
|
||||
|
||||
if (GUILayout.Button("Bake", GUILayout.Height(32)))
|
||||
{
|
||||
modelBaker.Bake();
|
||||
|
||||
if (modelBaker.saveBakedDataToAsset)
|
||||
{
|
||||
modelBaker.SaveAssets();
|
||||
}
|
||||
modelBaker.SaveAssets();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Delete", EditorStyles.miniButtonRight))
|
||||
|
@ -16,7 +16,6 @@ namespace TAO.VertexAnimation.Editor
|
||||
public int textureWidth = 512;
|
||||
|
||||
public LODSettings lodSettings = new LODSettings();
|
||||
public bool saveBakedDataToAsset = true;
|
||||
public bool generateAnimationBook = true;
|
||||
public bool generatePrefab = true;
|
||||
public Shader materialShader = null;
|
||||
@ -34,7 +33,6 @@ namespace TAO.VertexAnimation.Editor
|
||||
[System.Serializable]
|
||||
public class LODSettings
|
||||
{
|
||||
public bool generate = true;
|
||||
public LODSetting[] lodSettings = new LODSetting[3] { new LODSetting(1, .4f), new LODSetting(.6f, .15f), new LODSetting(.3f, .01f) };
|
||||
|
||||
public float[] GetQualitySettings()
|
||||
@ -91,15 +89,7 @@ namespace TAO.VertexAnimation.Editor
|
||||
bakedData = target.Bake(animationClips, fps, textureWidth);
|
||||
|
||||
positionMap = VA_Texture2DArrayUtils.CreateTextureArray(bakedData.positionMaps.ToArray(), false, true, TextureWrapMode.Repeat, FilterMode.Point, 1, string.Format("{0}_PositionMap", name), true);
|
||||
|
||||
if (lodSettings.generate)
|
||||
{
|
||||
meshes = bakedData.mesh.GenerateLOD(lodSettings.LODCount(), lodSettings.GetQualitySettings());
|
||||
}
|
||||
else
|
||||
{
|
||||
meshes = new Mesh[1] { bakedData.mesh };
|
||||
}
|
||||
meshes = bakedData.mesh.GenerateLOD(lodSettings.LODCount(), lodSettings.GetQualitySettings());
|
||||
|
||||
DestroyImmediate(target);
|
||||
}
|
||||
@ -114,10 +104,6 @@ namespace TAO.VertexAnimation.Editor
|
||||
}
|
||||
|
||||
AssetDatabase.AddObjectToAsset(positionMap, this);
|
||||
//foreach (var pm in bakedData.positionMaps)
|
||||
//{
|
||||
// AssetDatabase.AddObjectToAsset(pm, this);
|
||||
//}
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
|
||||
@ -161,7 +147,7 @@ namespace TAO.VertexAnimation.Editor
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
public void GeneratePrefab()
|
||||
private void GeneratePrefab()
|
||||
{
|
||||
string path = AssetDatabase.GetAssetPath(this);
|
||||
int start = path.LastIndexOf('/');
|
||||
@ -186,7 +172,7 @@ namespace TAO.VertexAnimation.Editor
|
||||
prefab = AnimationPrefab.Create(path, name, meshes, material, lodSettings.GetTransitionSettings());
|
||||
}
|
||||
|
||||
public void GenerateBook()
|
||||
private void GenerateBook()
|
||||
{
|
||||
if (!book)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user