MeshSequenceInspector.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. using UnityEditorInternal;
  10. namespace VertexAnimationTools_30{
  11. [InitializeOnLoad]
  12. [CustomEditor(typeof(MeshSequence))]
  13. public class MeshSequenceInspector : Editor {
  14. static bool ShowDetailedFramesInfo;
  15. AnimBool detailedFramesInfoAB;
  16. static MeshSequence dragged;
  17. void OnEnable(){
  18. detailedFramesInfoAB = new AnimBool( ShowDetailedFramesInfo, Repaint);
  19. }
  20. public override void OnInspectorGUI(){
  21. GUIContent polyVertHeader = new GUIContent("poly | vert", "polygons and vertcses count of obj file");
  22. GUIContent trisVertsHeader = new GUIContent("tris | vert", "triangles and vertcses count of Unity Mesh");
  23. GUIContent submeshHeader = new GUIContent("submeshes", "Submeshes (Material IDs) count");
  24. MeshSequence t = target as MeshSequence;
  25. GUILayout.Label("Mesh Sequence Asset", EditorStyles.boldLabel);
  26. if (t.FramesCount <= 0) {
  27. EditorGUILayout.HelpBox(" 1) Create player \n 2) Set sources in Import Tab \n 3) Press Import button", MessageType.Info);
  28. } else {
  29. EditorGUI.indentLevel++;
  30. EditorGUILayout.LabelField(string.Format("Imported {0} frames", t.FramesCount) );
  31. EditorGUILayout.LabelField(string.Format("{0}-{1} vertices", t.SequenceVerticesCount.Min, t.SequenceVerticesCount.Max));
  32. EditorGUILayout.LabelField(string.Format("{0}-{1} triangles", t.SequenceTrianglesCount.Min, t.SequenceTrianglesCount.Max));
  33. EditorGUILayout.LabelField(string.Format("{0}-{1} obj vertices", t.SequenceObjVerticesCount.Min, t.SequenceObjVerticesCount.Max));
  34. EditorGUILayout.LabelField(string.Format("{0}-{1} obj polygons", t.SequenceObjPolygonsCount.Min, t.SequenceObjPolygonsCount.Max));
  35. EditorGUILayout.LabelField(string.Format("{0}-{1} submeshes", t.SequenceSubmeshesCount.Min, t.SequenceSubmeshesCount.Max));
  36. GUILayout.Space(4);
  37. EditorGUILayout.LabelField(string.Format("Directory: {0}", t.PostImport.MSI.DirectoryPath));
  38. EditorGUILayout.LabelField(string.Format("Sequence: {0} , {1} files", t.PostImport.MSI.SequenceName, t.PostImport.MSI.Count) );
  39. EditorGUILayout.LabelField(string.Format("Imported at: {0}", t.PostImport.ImportDate));
  40. EditorGUILayout.LabelField(string.Format("Asset file size: {0} MB", t.AssetFileSize.ToString("F4")));
  41. GUILayout.Space(4);
  42. ShowDetailedFramesInfo = EditorGUILayout.Foldout(ShowDetailedFramesInfo, "Show detailed frames info");
  43. detailedFramesInfoAB.target = ShowDetailedFramesInfo;
  44. if (EditorGUILayout.BeginFadeGroup(detailedFramesInfoAB.faded)) {
  45. float nameWidth = 50;
  46. for (int f = 0; f < t.FramesCount; f++) {
  47. nameWidth = Mathf.Max(nameWidth, EditorStyles.label.CalcSize(new GUIContent(t[f].Name)).x);
  48. }
  49. nameWidth += 4;
  50. GUILayout.BeginHorizontal();
  51. EditorGUILayout.LabelField("Idx", GUILayout.Width(40));
  52. EditorGUILayout.LabelField("obj name", GUILayout.Width(164));
  53. EditorGUILayout.LabelField(polyVertHeader, GUILayout.Width(120));
  54. EditorGUILayout.LabelField(trisVertsHeader, GUILayout.Width(120));
  55. EditorGUILayout.LabelField(submeshHeader, GUILayout.Width(90));
  56. GUILayout.EndHorizontal();
  57. GUILayout.Space(4);
  58. for (int f = 0; f < t.FramesCount; f++) {
  59. GUILayout.BeginHorizontal();
  60. EditorGUILayout.LabelField(string.Format("#{0}", f.ToString()), GUILayout.Width(50));
  61. EditorGUILayout.LabelField(t[f].Name, GUILayout.Width(150));
  62. EditorGUILayout.LabelField(string.Format("{0} | {1}", t[f].ObjPolygonsCount, t[f].ObjVerticesCount), GUILayout.Width(120));
  63. EditorGUILayout.LabelField(string.Format("{0} | {1}", t[f].MeshTrisCount, t[f].MeshVertsCount), GUILayout.Width(120));
  64. EditorGUILayout.LabelField(string.Format(" {0} ", t[f].Materials==null? 0 : t[f].Materials.Length ), GUILayout.Width(100));
  65. GUILayout.EndHorizontal();
  66. }
  67. }
  68. EditorGUILayout.EndFadeGroup();
  69. EditorGUI.indentLevel--;
  70. }
  71. GUILayout.Space(4);
  72. if (GUILayout.Button("Create Mesh Sequence Player")) {
  73. t.SpawnMeshSequencePlayer();
  74. }
  75. // DrawDefaultInspector();
  76. }
  77. }
  78. public class ObjSequenceFactory{
  79. [MenuItem("Assets/Create/Vertex Animation Tools/Mesh Sequence", priority = 202)]
  80. static void MenuCreateMeshSequenceAsset(){
  81. var icon = InspectorsBase.ResourceHolder.MeshSequenceIcon;
  82. ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<DoCreateMeshSequence>(), "MeshSequence.asset", icon, null);
  83. }
  84. internal static MeshSequence CreateMeshSequenceAtPath(string path){
  85. var data = ScriptableObject.CreateInstance<MeshSequence>();
  86. data.name = Path.GetFileName(path);
  87. AssetDatabase.CreateAsset(data, path);
  88. AssetDatabase.SaveAssets();
  89. AssetDatabase.Refresh();
  90. return data;
  91. }
  92. }
  93. class DoCreateMeshSequence : EndNameEditAction {
  94. public override void Action(int instanceId, string pathName, string resourceFile){
  95. MeshSequence data = ObjSequenceFactory.CreateMeshSequenceAtPath(pathName);
  96. ProjectWindowUtil.ShowCreatedAsset(data);
  97. }
  98. }
  99. }