PointCacheInspector.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. using VertexAnimationTools_30;
  6. using UnityEditor.AnimatedValues;
  7. using UnityEditor.ProjectWindowCallback;
  8. using System.IO;
  9. namespace VertexAnimationTools_30{
  10. [CustomEditor(typeof(PointCache))]
  11. public class PointCacheInspector : Editor {
  12. public override void OnInspectorGUI(){
  13. PointCache t = target as PointCache;
  14. GUILayout.Label("Point Cache Asset", EditorStyles.boldLabel);
  15. EditorGUI.indentLevel++;
  16. if (t.Meshes[0].mesh == null) {
  17. EditorGUILayout.HelpBox(" 1) Create player \n 2) Set sources in Import Tab \n 3) Press Import button", MessageType.Info);
  18. } else {
  19. for (int i = 0; i < t.PostImport.UsedMeshesCount; i++) {
  20. EditorGUILayout.LabelField(string.Format("Mesh #{0} name:{1}", i, t.Meshes[i].Name));
  21. EditorGUI.indentLevel++;
  22. EditorGUILayout.LabelField(string.Format("Path {0}", t.Meshes[i].Path));
  23. EditorGUILayout.LabelField(string.Format("Mesh: {0} vertices, {1} triangles", t.Meshes[i].mesh.vertexCount, t.Meshes[i].mesh.triangles.Length / 3));
  24. EditorGUILayout.LabelField(string.Format("Source: {0}", t.Meshes[i].Info));
  25. EditorGUI.indentLevel--;
  26. GUILayout.Space(4);
  27. }
  28. GUILayout.Space(4);
  29. for (int i = 0; i < t.PostImport.UsedClipsCount; i++) {
  30. EditorGUILayout.LabelField(string.Format("Clip #{0} name:{1}", i, t.Clips[i].PostImport.Name));
  31. EditorGUI.indentLevel++;
  32. EditorGUILayout.LabelField(string.Format("{0} frames {1} ", t.Clips[i].PostImport.ImportRangeLength, t.Clips[i].PostImport.IsLoop ? ", loop" : ""));
  33. EditorGUILayout.LabelField(string.Format("Path: {0}", t.Clips[i].PostImport.FilePath));
  34. string type = t.Clips[i].PostImport.FilePath.EndsWith("obj") ? "obj sequence" : ".pc2";
  35. EditorGUILayout.LabelField(string.Format("Source type: {0}", type));
  36. EditorGUILayout.LabelField(string.Format("Source frames count:{0}", t.Clips[i].PostImport.FileFramesCount));
  37. EditorGUILayout.LabelField(string.Format("Motion path count:{0}", t.Clips[i].MotionPathsCount));
  38. EditorGUI.indentLevel--;
  39. GUILayout.Space(4);
  40. }
  41. EditorGUILayout.LabelField(string.Format("{0} constraints", t.PostConstraints.Length));
  42. EditorGUILayout.LabelField(string.Format("Imported at: {0}", t.ImportingDate));
  43. EditorGUILayout.LabelField(string.Format("Asset file size: {0} MB", t.AssetFileSize.ToString("F4")));
  44. }
  45. if (GUILayout.Button("Create Point Cache Player")) {
  46. Selection.activeGameObject = t.CreatePlayer();
  47. }
  48. //DrawDefaultInspector();
  49. }
  50. }
  51. public class PointCacheFactory{
  52. [MenuItem("Assets/Create/Vertex Animation Tools/Point Cache", priority = 203)]
  53. static void MenuCreatePointCache(){
  54. var icon = InspectorsBase.ResourceHolder.PointCacheIcon;
  55. ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<DoCreatePointCacheAsset>(), "PointCache.asset", icon, null);
  56. }
  57. public static PointCache CreatePointCacheAssetAtPath(string path){
  58. var data = ScriptableObject.CreateInstance<PointCache>();
  59. data.name = Path.GetFileName(path);
  60. AssetDatabase.CreateAsset(data, path);
  61. AssetDatabase.SaveAssets();
  62. AssetDatabase.Refresh();
  63. return data;
  64. }
  65. }
  66. class DoCreatePointCacheAsset : EndNameEditAction {
  67. public override void Action(int instanceId, string pathName, string resourceFile){
  68. PointCache data = PointCacheFactory.CreatePointCacheAssetAtPath(pathName);
  69. ProjectWindowUtil.ShowCreatedAsset(data);
  70. }
  71. }
  72. }