MapperContextActions.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using TriLibCore.Mappers;
  2. using TriLibCore.Utils;
  3. using UnityEditor;
  4. using UnityEngine;
  5. namespace TriLibCore.Editor
  6. {
  7. public class MapperContextActions : MonoBehaviour
  8. {
  9. [MenuItem("Assets/Create Mapper Instance")]
  10. private static void CreateInstance()
  11. {
  12. var monoScript = Selection.activeObject as MonoScript;
  13. if (monoScript != null)
  14. {
  15. var scriptableObject = ScriptableObject.CreateInstance(monoScript.GetClass());
  16. var assetPath = AssetDatabase.GetAssetPath(monoScript);
  17. var directory = FileUtils.GetFileDirectory(assetPath);
  18. var name = FileUtils.GetFilenameWithoutExtension(assetPath);
  19. AssetDatabase.CreateAsset(scriptableObject, $"{directory}/{name}.asset");
  20. AssetDatabase.SaveAssets();
  21. }
  22. }
  23. [MenuItem("Assets/Create Mapper Instance", true)]
  24. private static bool Validate()
  25. {
  26. if (Selection.activeObject is MonoScript monoScript)
  27. {
  28. var @class = monoScript.GetClass();
  29. return
  30. typeof(AnimationClipMapper).IsAssignableFrom(@class) ||
  31. typeof(MaterialMapper).IsAssignableFrom(@class) ||
  32. typeof(TextureMapper).IsAssignableFrom(@class) ||
  33. typeof(HumanoidAvatarMapper).IsAssignableFrom(@class) ||
  34. typeof(RootBoneMapper).IsAssignableFrom(@class) ||
  35. typeof(LipSyncMapper).IsAssignableFrom(@class) ||
  36. typeof(UserPropertiesMapper).IsAssignableFrom(@class) ||
  37. typeof(ExternalDataMapper).IsAssignableFrom(@class);
  38. }
  39. return false;
  40. }
  41. }
  42. }