Add automatic Rive asset refresh workflow
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public static class RiveAssetRefreshMenu
|
||||
{
|
||||
private const string LoginRiveAssetPath = "Assets/UI/Login UI.riv";
|
||||
|
||||
[MenuItem("Tools/Rive/Reimport Login UI")]
|
||||
private static void ReimportLoginUI()
|
||||
{
|
||||
if (EditorApplication.isPlaying)
|
||||
{
|
||||
Debug.LogWarning("Stop Play Mode before reimporting the Rive asset.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Scene activeScene = SceneManager.GetActiveScene();
|
||||
|
||||
if (!activeScene.IsValid() || string.IsNullOrEmpty(activeScene.path))
|
||||
{
|
||||
Debug.LogError("Rive refresh failed: the active scene has not been saved.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool saved = EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
|
||||
|
||||
if (!saved)
|
||||
{
|
||||
Debug.LogWarning("Rive refresh cancelled because the scene was not saved.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
AssetDatabase.ImportAsset(
|
||||
LoginRiveAssetPath,
|
||||
ImportAssetOptions.ForceUpdate |
|
||||
ImportAssetOptions.ForceSynchronousImport);
|
||||
|
||||
AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
|
||||
|
||||
string scenePath = activeScene.path;
|
||||
|
||||
EditorApplication.delayCall += () =>
|
||||
{
|
||||
if (EditorApplication.isPlaying)
|
||||
return;
|
||||
|
||||
EditorSceneManager.OpenScene(
|
||||
scenePath,
|
||||
OpenSceneMode.Single);
|
||||
|
||||
Debug.Log($"Reimported {LoginRiveAssetPath} and reloaded {scenePath}.");
|
||||
};
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Rive/Reimport Login UI", validate = true)]
|
||||
private static bool ValidateReimportLoginUI()
|
||||
{
|
||||
return AssetDatabase.AssetPathToGUID(LoginRiveAssetPath) != string.Empty;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user