FR2_CacheEditor.cs 904 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using UnityEditor;
  2. using UnityEngine;
  3. using vietlabs.fr2;
  4. [CustomEditor(typeof(FR2_Cache))]
  5. internal class FR2_CacheEditor : Editor
  6. {
  7. private static string inspectGUID;
  8. private static int index;
  9. public override void OnInspectorGUI()
  10. {
  11. var c = (FR2_Cache) target;
  12. GUILayout.Label("Total : " + c.AssetList.Count);
  13. FR2_Cache.DrawPriorityGUI();
  14. Object s = Selection.activeObject;
  15. if (s == null)
  16. {
  17. return;
  18. }
  19. string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(s));
  20. if (inspectGUID != guid)
  21. {
  22. inspectGUID = guid;
  23. index = c.AssetList.FindIndex(item => item.guid == guid);
  24. }
  25. if (index != -1)
  26. {
  27. if (index >= c.AssetList.Count)
  28. {
  29. index = 0;
  30. }
  31. serializedObject.Update();
  32. SerializedProperty prop = serializedObject.FindProperty("AssetList").GetArrayElementAtIndex(index);
  33. EditorGUILayout.PropertyField(prop, true);
  34. }
  35. }
  36. }