mirror of
https://github.com/maxartz15/VertexAnimation.git
synced 2024-12-05 01:30:44 +01:00
AnimationLibrary Editor
AnimationLibraryBook editor setup. AnimationLibrary texture2DArray generation and material setup.
This commit is contained in:
parent
52dd9d4b3c
commit
e4ca15301b
8
Editor/Scripts.meta
Normal file
8
Editor/Scripts.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a1800e0b8df6c3b4f8c7a3b063a355a7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Editor/Scripts/Editor.meta
Normal file
8
Editor/Scripts/Editor.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 736114389a5e3ad4f8a02fdb548d5431
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
222
Editor/Scripts/Editor/VA_AnimationBookEditor.cs
Normal file
222
Editor/Scripts/Editor/VA_AnimationBookEditor.cs
Normal file
@ -0,0 +1,222 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Runtime.CompilerServices;
|
||||
using UnityEngine.Rendering.VirtualTexturing;
|
||||
using System;
|
||||
|
||||
namespace TAO.VertexAnimation.Editor
|
||||
{
|
||||
[CustomEditor(typeof(VA_AnimationBook))]
|
||||
public class VA_AnimationBookEditor : UnityEditor.Editor
|
||||
{
|
||||
private VA_AnimationBook animationBook = null;
|
||||
private Vector2 textireGroupScollPos;
|
||||
private Vector2 animationPagesScollPos;
|
||||
|
||||
private UnityEditor.Editor previewEditor = null;
|
||||
private int previewIndex = 0;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
animationBook = target as VA_AnimationBook;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
|
||||
// Texture Groups.
|
||||
GeneralGUI();
|
||||
TextureGroupsGUI();
|
||||
SyncListSize();
|
||||
AnimationPagesGUI();
|
||||
MaterialGUI();
|
||||
Texture2DGUI();
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
private void SyncListSize()
|
||||
{
|
||||
foreach (var page in animationBook.animationPages)
|
||||
{
|
||||
if(page.textures.Count < animationBook.textureGroups.Count)
|
||||
{
|
||||
int diff = animationBook.textureGroups.Count - page.textures.Count;
|
||||
|
||||
for (int i = 0; i < diff; i++)
|
||||
{
|
||||
page.textures.Add(null);
|
||||
}
|
||||
}
|
||||
else if(page.textures.Count > animationBook.textureGroups.Count)
|
||||
{
|
||||
int diff = page.textures.Count - animationBook.textureGroups.Count;
|
||||
|
||||
for (int i = 0; i < diff; i++)
|
||||
{
|
||||
page.textures.RemoveRange(page.textures.Count - diff, diff);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void GeneralGUI()
|
||||
{
|
||||
using (new EditorGUILayout.VerticalScope())
|
||||
{
|
||||
EditorGUILayout.LabelField("General", EditorStyles.centeredGreyMiniLabel);
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("maxFrames"));
|
||||
}
|
||||
}
|
||||
|
||||
private void TextureGroupsGUI()
|
||||
{
|
||||
SerializedProperty textureGroups = serializedObject.FindProperty("textureGroups");
|
||||
int removeWidth = 16;
|
||||
int nameWidth = 152;
|
||||
int linearWidth = 50;
|
||||
|
||||
using (new EditorGUILayout.VerticalScope())
|
||||
{
|
||||
EditorGUILayout.LabelField("TextureGroups", EditorStyles.centeredGreyMiniLabel);
|
||||
|
||||
textireGroupScollPos = EditorGUILayout.BeginScrollView(textireGroupScollPos, false, false);
|
||||
using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar))
|
||||
{
|
||||
EditorGUILayout.LabelField("", GUILayout.Width(removeWidth));
|
||||
EditorGUILayout.LabelField("material parameter name", GUILayout.Width(nameWidth));
|
||||
EditorGUILayout.LabelField("is linear", GUILayout.MinWidth(linearWidth));
|
||||
}
|
||||
EditorGUILayout.EndScrollView();
|
||||
|
||||
for (int i = 0; i < textureGroups.arraySize; i++)
|
||||
{
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
if (GUILayout.Button("-", GUILayout.Width(removeWidth)))
|
||||
{
|
||||
textureGroups.DeleteArrayElementAtIndex(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
EditorGUILayout.PropertyField(textureGroups.GetArrayElementAtIndex(i).FindPropertyRelative("shaderParamName"), GUIContent.none, GUILayout.Width(nameWidth));
|
||||
EditorGUILayout.PropertyField(textureGroups.GetArrayElementAtIndex(i).FindPropertyRelative("isLinear"), GUIContent.none, GUILayout.MinWidth(linearWidth));
|
||||
}
|
||||
}
|
||||
|
||||
if (GUILayout.Button("+", EditorStyles.miniButton))
|
||||
{
|
||||
animationBook.textureGroups.Add(new TextureGroup
|
||||
{
|
||||
shaderParamName = "_ShaderPropertyName",
|
||||
isLinear = false
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void AnimationPagesGUI()
|
||||
{
|
||||
SerializedProperty animationPages = serializedObject.FindProperty("animationPages");
|
||||
int removeWidth = 16;
|
||||
int nameWidth = 100;
|
||||
int frameWidth = 50;
|
||||
int textureWidth = 150;
|
||||
|
||||
using (new EditorGUILayout.VerticalScope())
|
||||
{
|
||||
EditorGUILayout.LabelField("AnimationPages", EditorStyles.centeredGreyMiniLabel);
|
||||
|
||||
animationPagesScollPos = EditorGUILayout.BeginScrollView(animationPagesScollPos, false, false);
|
||||
using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar))
|
||||
{
|
||||
EditorGUILayout.LabelField("", GUILayout.Width(removeWidth));
|
||||
EditorGUILayout.LabelField("name", GUILayout.Width(nameWidth));
|
||||
EditorGUILayout.LabelField("frames", GUILayout.Width(frameWidth));
|
||||
foreach (var t in animationBook.textureGroups)
|
||||
{
|
||||
EditorGUILayout.LabelField(t.shaderParamName, GUILayout.MinWidth(textureWidth));
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndScrollView();
|
||||
|
||||
animationPagesScollPos = EditorGUILayout.BeginScrollView(animationPagesScollPos, false, false);
|
||||
for (int i = 0; i < animationPages.arraySize; i++)
|
||||
{
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
if (GUILayout.Button("-", GUILayout.Width(removeWidth)))
|
||||
{
|
||||
animationPages.DeleteArrayElementAtIndex(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
EditorGUILayout.PropertyField(animationPages.GetArrayElementAtIndex(i).FindPropertyRelative("name"), GUIContent.none, GUILayout.Width(nameWidth));
|
||||
|
||||
EditorGUILayout.PropertyField(animationPages.GetArrayElementAtIndex(i).FindPropertyRelative("frames"), GUIContent.none, GUILayout.Width(frameWidth));
|
||||
|
||||
SerializedProperty textures = animationPages.GetArrayElementAtIndex(i).FindPropertyRelative("textures");
|
||||
for (int t = 0; t < textures.arraySize; t++)
|
||||
{
|
||||
EditorGUILayout.PropertyField(textures.GetArrayElementAtIndex(t), GUIContent.none, GUILayout.MinWidth(textureWidth));
|
||||
}
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndScrollView();
|
||||
|
||||
if (GUILayout.Button("+", EditorStyles.miniButton))
|
||||
{
|
||||
animationPages.InsertArrayElementAtIndex(animationPages.arraySize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void MaterialGUI()
|
||||
{
|
||||
using (new EditorGUILayout.VerticalScope())
|
||||
{
|
||||
EditorGUILayout.LabelField("Materials", EditorStyles.centeredGreyMiniLabel);
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("materials"));
|
||||
}
|
||||
}
|
||||
|
||||
private void Texture2DGUI()
|
||||
{
|
||||
if (HasPreviewGUI())
|
||||
{
|
||||
using (new EditorGUILayout.VerticalScope())
|
||||
{
|
||||
SerializedProperty texture2DArray = serializedObject.FindProperty("texture2DArray");
|
||||
|
||||
EditorGUILayout.LabelField("Texture2DArray", EditorStyles.centeredGreyMiniLabel);
|
||||
previewIndex = EditorGUILayout.IntSlider(previewIndex, 0, texture2DArray.arraySize - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool HasPreviewGUI()
|
||||
{
|
||||
bool hasPreview = false;
|
||||
|
||||
if(animationBook.texture2DArray != null && animationBook.texture2DArray.Count > 0 && animationBook.texture2DArray[previewIndex] != null)
|
||||
{
|
||||
hasPreview = true;
|
||||
}
|
||||
|
||||
return hasPreview;
|
||||
}
|
||||
|
||||
public override void OnPreviewGUI(Rect r, GUIStyle background)
|
||||
{
|
||||
if (previewEditor == null)
|
||||
{
|
||||
previewEditor = UnityEditor.Editor.CreateEditor(animationBook.texture2DArray[previewIndex]);
|
||||
}
|
||||
|
||||
previewEditor.OnInteractivePreviewGUI(r, background);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d1625f26e651894b954faf1934378dc
|
||||
guid: 970e86c282fea004fb3b39c887587a36
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "TAO.VertexAnimation.Editor",
|
||||
"references": [
|
||||
"tech_art_outsource.vertex_animation"
|
||||
"TAO.VertexAnimation"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
|
86
Runtime/Scripts/VA_AnimationBook.cs
Normal file
86
Runtime/Scripts/VA_AnimationBook.cs
Normal file
@ -0,0 +1,86 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TAO.VertexAnimation
|
||||
{
|
||||
[CreateAssetMenu(fileName = "new AnimationBook", menuName = "AnimationBook", order = 0)]
|
||||
public class VA_AnimationBook : ScriptableObject
|
||||
{
|
||||
public int maxFrames;
|
||||
public List<TextureGroup> textureGroups = new List<TextureGroup>() { new TextureGroup { shaderParamName = "_PositionMap", isLinear = false } };
|
||||
public List<VA_AnimationPage> animationPages = new List<VA_AnimationPage>();
|
||||
|
||||
public Material[] materials;
|
||||
public List<Texture2DArray> texture2DArray = null;
|
||||
|
||||
public void Create()
|
||||
{
|
||||
// Create textures.
|
||||
texture2DArray.Clear();
|
||||
foreach (var item in GetTextures())
|
||||
{
|
||||
if(VA_Texture2DArrayUtils.IsValidForTextureArray(item.Value.ToArray()))
|
||||
{
|
||||
texture2DArray.Add(VA_Texture2DArrayUtils.CreateTextureArray(item.Value.ToArray(), false, textureGroups[item.Key].isLinear, TextureWrapMode.Repeat, FilterMode.Point, 1, name + "-" + item.Key.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
// Assign material parameters.
|
||||
if(materials != null)
|
||||
{
|
||||
foreach (Material mat in materials)
|
||||
{
|
||||
if(mat != null)
|
||||
{
|
||||
for (int i = 0; i < texture2DArray.Count; i++)
|
||||
{
|
||||
mat.SetTexture(textureGroups[i].shaderParamName, texture2DArray[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
foreach (var item in GetTextures())
|
||||
{
|
||||
VA_Texture2DArrayUtils.IsValidForTextureArray(item.Value.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<int, List<Texture2D>> GetTextures()
|
||||
{
|
||||
Dictionary<int, List<Texture2D>> dict = new Dictionary<int, List<Texture2D>>();
|
||||
|
||||
// Group and collect the textures.
|
||||
for (int i = 0; i < textureGroups.Count; i++)
|
||||
{
|
||||
dict.Add(i, new List<Texture2D>());
|
||||
|
||||
for (int j = 0; j < animationPages.Count; j++)
|
||||
{
|
||||
dict[i].Add(animationPages[j].textures[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public struct VA_AnimationPage
|
||||
{
|
||||
public string name;
|
||||
public int frames;
|
||||
public List<Texture2D> textures;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public struct TextureGroup
|
||||
{
|
||||
public string shaderParamName;
|
||||
public bool isLinear;
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TAO.VertexAnimation
|
||||
{
|
||||
[CreateAssetMenu(fileName = "new AnimationBook", menuName = "AnimationBook", order = 0)]
|
||||
public class VA_AnimationBookSO : ScriptableObject
|
||||
{
|
||||
public int maxFrames;
|
||||
public Material[] materials;
|
||||
public VA_AnimationPage[] animationPages;
|
||||
|
||||
private void Setup()
|
||||
{
|
||||
// TODO: ...
|
||||
// GenerateTextures.
|
||||
// SetupMaterials.
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public struct VA_AnimationPage
|
||||
{
|
||||
public string name;
|
||||
public int frames;
|
||||
public Texture2D texture2D;
|
||||
}
|
||||
|
||||
}
|
@ -1,38 +1,56 @@
|
||||
using Unity.Entities;
|
||||
using Unity.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TAO.VertexAnimation
|
||||
{
|
||||
[System.Serializable]
|
||||
public struct VA_AnimationData
|
||||
[CreateAssetMenu(fileName = "new AnimationLibrary", menuName = "AnimationLibrary", order = 0)]
|
||||
public class VA_AnimationLibrary : ScriptableObject
|
||||
{
|
||||
public FixedString32 name;
|
||||
public int frames;
|
||||
public int maxFrames;
|
||||
// 1.0f / maxFrames.
|
||||
public float frameTime;
|
||||
// frameTime * frames.
|
||||
public float duration;
|
||||
}
|
||||
[SerializeField]
|
||||
private VA_AnimationBook[] animationBooks;
|
||||
|
||||
public struct VA_AnimationLibrary
|
||||
{
|
||||
public BlobArray<VA_AnimationData> animations;
|
||||
}
|
||||
[HideInInspector]
|
||||
public List<VA_AnimationData> animations = null;
|
||||
|
||||
public static class VA_AnimationLibraryUtils
|
||||
{
|
||||
public static int GetAnimation(ref VA_AnimationLibrary animationsRef, FixedString32 animationName)
|
||||
public void Create()
|
||||
{
|
||||
for (int i = 0; i < animationsRef.animations.Length; i++)
|
||||
{
|
||||
if (animationsRef.animations[i].name == animationName)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
foreach (VA_AnimationBook book in animationBooks)
|
||||
{
|
||||
book.Create();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
ConvertAnimations();
|
||||
}
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
// TODO: Check for naming conflicts in AnimationBooks.
|
||||
}
|
||||
|
||||
private void ConvertAnimations()
|
||||
{
|
||||
animations = new List<VA_AnimationData>();
|
||||
|
||||
if (animationBooks != null)
|
||||
{
|
||||
for (int b = 0; b < animationBooks.Length; b++)
|
||||
{
|
||||
if(animationBooks[b].animationPages != null)
|
||||
{
|
||||
for (int p = 0; p < animationBooks[b].animationPages.Count; p++)
|
||||
{
|
||||
animations.Add(new VA_AnimationData
|
||||
{
|
||||
name = new Unity.Collections.FixedString32(animationBooks[b].animationPages[p].name),
|
||||
maxFrames = animationBooks[b].maxFrames,
|
||||
frames = animationBooks[b].animationPages[p].frames,
|
||||
frameTime = 1.0f / animationBooks[b].maxFrames,
|
||||
duration = 1.0f / animationBooks[b].maxFrames * animationBooks[b].animationPages[p].frames
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 79884e6263d984c44af76267d129d76b
|
||||
guid: 0d1625f26e651894b954faf1934378dc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
@ -7,7 +7,7 @@ namespace TAO.VertexAnimation
|
||||
[UnityEngine.DisallowMultipleComponent]
|
||||
public class VA_AnimationLibraryComponentAuthoring : UnityEngine.MonoBehaviour
|
||||
{
|
||||
public VA_AnimationLibrarySO animationLibrary;
|
||||
public VA_AnimationLibrary animationLibrary;
|
||||
}
|
||||
|
||||
public class VA_AnimationLibraryConversionSystem : GameObjectConversionSystem
|
||||
@ -16,11 +16,14 @@ namespace TAO.VertexAnimation
|
||||
{
|
||||
Entities.ForEach((VA_AnimationLibraryComponentAuthoring animationLib) =>
|
||||
{
|
||||
animationLib.animationLibrary.Create();
|
||||
|
||||
|
||||
// Blob builder to build.
|
||||
using (BlobBuilder blobBuilder = new BlobBuilder(Allocator.Temp))
|
||||
{
|
||||
// Construct the root.
|
||||
ref VA_AnimationLibrary animationDataBlobAsset = ref blobBuilder.ConstructRoot<VA_AnimationLibrary>();
|
||||
ref VA_AnimationLibraryData animationDataBlobAsset = ref blobBuilder.ConstructRoot<VA_AnimationLibraryData>();
|
||||
|
||||
// Set all the data.
|
||||
BlobBuilderArray<VA_AnimationData> animationDataArray = blobBuilder.Allocate(ref animationDataBlobAsset.animations, animationLib.animationLibrary.animations.Count);
|
||||
@ -32,7 +35,7 @@ namespace TAO.VertexAnimation
|
||||
}
|
||||
|
||||
// Construct blob asset reference.
|
||||
BlobAssetReference<VA_AnimationLibrary> animLibAssetRef = blobBuilder.CreateBlobAssetReference<VA_AnimationLibrary>(Allocator.Persistent);
|
||||
BlobAssetReference<VA_AnimationLibraryData> animLibAssetRef = blobBuilder.CreateBlobAssetReference<VA_AnimationLibraryData>(Allocator.Persistent);
|
||||
|
||||
// Add it to the asset store.
|
||||
// TODO: Generate Hash based on Guid.
|
||||
|
38
Runtime/Scripts/VA_AnimationLibraryData.cs
Normal file
38
Runtime/Scripts/VA_AnimationLibraryData.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using Unity.Entities;
|
||||
using Unity.Collections;
|
||||
|
||||
namespace TAO.VertexAnimation
|
||||
{
|
||||
[System.Serializable]
|
||||
public struct VA_AnimationData
|
||||
{
|
||||
public FixedString32 name;
|
||||
public int frames;
|
||||
public int maxFrames;
|
||||
// 1.0f / maxFrames.
|
||||
public float frameTime;
|
||||
// frameTime * frames.
|
||||
public float duration;
|
||||
}
|
||||
|
||||
public struct VA_AnimationLibraryData
|
||||
{
|
||||
public BlobArray<VA_AnimationData> animations;
|
||||
}
|
||||
|
||||
public static class VA_AnimationLibraryUtils
|
||||
{
|
||||
public static int GetAnimation(ref VA_AnimationLibraryData animationsRef, FixedString32 animationName)
|
||||
{
|
||||
for (int i = 0; i < animationsRef.animations.Length; i++)
|
||||
{
|
||||
if (animationsRef.animations[i].name == animationName)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
11
Runtime/Scripts/VA_AnimationLibraryData.cs.meta
Normal file
11
Runtime/Scripts/VA_AnimationLibraryData.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 79884e6263d984c44af76267d129d76b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,46 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TAO.VertexAnimation
|
||||
{
|
||||
[CreateAssetMenu(fileName = "new AnimationLibrary", menuName = "AnimationLibrary", order = 0)]
|
||||
public class VA_AnimationLibrarySO : ScriptableObject
|
||||
{
|
||||
[SerializeField]
|
||||
private VA_AnimationBookSO[] animationBooks;
|
||||
|
||||
[HideInInspector]
|
||||
public List<VA_AnimationData> animations = null;
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
SetupAnimations();
|
||||
}
|
||||
|
||||
private void SetupAnimations()
|
||||
{
|
||||
animations = new List<VA_AnimationData>();
|
||||
|
||||
if (animationBooks != null)
|
||||
{
|
||||
for (int b = 0; b < animationBooks.Length; b++)
|
||||
{
|
||||
if(animationBooks[b].animationPages != null)
|
||||
{
|
||||
for (int p = 0; p < animationBooks[b].animationPages.Length; p++)
|
||||
{
|
||||
animations.Add(new VA_AnimationData
|
||||
{
|
||||
name = new Unity.Collections.FixedString32(animationBooks[b].animationPages[p].name),
|
||||
maxFrames = animationBooks[b].maxFrames,
|
||||
frames = animationBooks[b].animationPages[p].frames,
|
||||
frameTime = 1.0f / animationBooks[b].maxFrames,
|
||||
duration = 1.0f / animationBooks[b].maxFrames * animationBooks[b].animationPages[p].frames
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@ namespace TAO.VertexAnimation
|
||||
public int animationIndex;
|
||||
public int animationIndexSchedule;
|
||||
public float animationTime;
|
||||
public BlobAssetReference<VA_AnimationLibrary> animationLibrary;
|
||||
public BlobAssetReference<VA_AnimationLibraryData> animationLibrary;
|
||||
}
|
||||
|
||||
[UpdateAfter(typeof(VA_AnimationLibraryConversionSystem))]
|
||||
@ -25,7 +25,7 @@ namespace TAO.VertexAnimation
|
||||
{
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
BlobAssetStore.TryGet(new Unity.Entities.Hash128("AnimationLib"), out BlobAssetReference<VA_AnimationLibrary> animLib);
|
||||
BlobAssetStore.TryGet(new Unity.Entities.Hash128("AnimationLib"), out BlobAssetReference<VA_AnimationLibraryData> animLib);
|
||||
|
||||
Entities.ForEach((VA_AnimatorComponentAuthoring animator) =>
|
||||
{
|
||||
|
@ -53,7 +53,7 @@ namespace TAO.VertexAnimation
|
||||
Entities.ForEach((ref VA_AnimatorComponent ac) =>
|
||||
{
|
||||
// Get the animation lib data.
|
||||
ref VA_AnimationLibrary animationsRef = ref ac.animationLibrary.Value;
|
||||
ref VA_AnimationLibraryData animationsRef = ref ac.animationLibrary.Value;
|
||||
|
||||
ac.animationTime += deltaTime;
|
||||
|
||||
@ -74,7 +74,7 @@ namespace TAO.VertexAnimation
|
||||
Entities.ForEach((Entity entity, ref VA_AnimatorComponent ac) =>
|
||||
{
|
||||
// Get the animation lib data.
|
||||
ref VA_AnimationLibrary animationLib = ref ac.animationLibrary.Value;
|
||||
ref VA_AnimationLibraryData animationLib = ref ac.animationLibrary.Value;
|
||||
|
||||
int animationIndex = VA_AnimationLibraryUtils.GetAnimation(ref animationLib, "Shoot");
|
||||
|
||||
|
64
Runtime/Scripts/VA_Texture2DArrayUtils.cs
Normal file
64
Runtime/Scripts/VA_Texture2DArrayUtils.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace TAO.VertexAnimation
|
||||
{
|
||||
public static class VA_Texture2DArrayUtils
|
||||
{
|
||||
public static Texture2DArray CreateTextureArray(Texture2D[] a_textures, bool a_useMipChain, bool a_isLinear,
|
||||
TextureWrapMode a_wrapMode = TextureWrapMode.Repeat, FilterMode a_filterMode = FilterMode.Bilinear, int a_anisoLevel = 1, string a_name = "")
|
||||
{
|
||||
if(!IsValidForTextureArray(a_textures))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Texture2DArray textureArray = new Texture2DArray(a_textures[0].width, a_textures[0].height, a_textures.Length, a_textures[0].format, a_useMipChain, a_isLinear);
|
||||
|
||||
for (int i = 0; i < a_textures.Length; i++)
|
||||
{
|
||||
Graphics.CopyTexture(a_textures[i], 0, 0, textureArray, i, 0);
|
||||
}
|
||||
|
||||
textureArray.wrapMode = a_wrapMode;
|
||||
textureArray.filterMode = a_filterMode;
|
||||
textureArray.anisoLevel = a_anisoLevel;
|
||||
textureArray.name = a_name;
|
||||
|
||||
textureArray.Apply(false, false);
|
||||
|
||||
return textureArray;
|
||||
}
|
||||
|
||||
public static bool IsValidForTextureArray(Texture2D[] a_textures)
|
||||
{
|
||||
if (a_textures == null || a_textures.Length <= 0)
|
||||
{
|
||||
Debug.LogError("No textures assigned!");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < a_textures.Length; i++)
|
||||
{
|
||||
if (a_textures[i] == null)
|
||||
{
|
||||
Debug.LogError("Texture " + i.ToString() + " not assigned!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (a_textures[0].width != a_textures[i].width || a_textures[0].height != a_textures[i].height)
|
||||
{
|
||||
Debug.LogError("Texture " + a_textures[i].name + " has a different size!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (a_textures[0].format != a_textures[i].format || a_textures[0].graphicsFormat != a_textures[i].graphicsFormat)
|
||||
{
|
||||
Debug.LogError("Texture " + a_textures[i].name + " has a different format/graphics format!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
11
Runtime/Scripts/VA_Texture2DArrayUtils.cs.meta
Normal file
11
Runtime/Scripts/VA_Texture2DArrayUtils.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 85b760f664e13f84a940f7859bc9a684
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue
Block a user