74 lines
1.8 KiB
C#
74 lines
1.8 KiB
C#
#if UNITY_EDITOR
|
|
using System;
|
|
using UnityEditor;
|
|
using UnityEditor.SceneManagement;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
public class RiveAssetAutoRefresh: AssetPostprocessor
|
|
{
|
|
private static bool refreshQueued;
|
|
|
|
private static void OnPostprocessAllAssets(
|
|
string[] importedAssets,
|
|
string[] deletedAssets,
|
|
string[] movedAssets,
|
|
string[] movedFromAssetPaths)
|
|
{
|
|
foreach (string assetPath in importedAssets)
|
|
{
|
|
if (!assetPath.EndsWith(".riv", StringComparison.OrdinalIgnoreCase))
|
|
continue;
|
|
|
|
QueueSceneReload();
|
|
return;
|
|
}
|
|
}
|
|
|
|
private static void QueueSceneReload()
|
|
{
|
|
if (refreshQueued)
|
|
return;
|
|
|
|
refreshQueued = true;
|
|
|
|
EditorApplication.delayCall += ReloadSceneAfterImport;
|
|
}
|
|
|
|
private static void ReloadSceneAfterImport()
|
|
{
|
|
refreshQueued = false;
|
|
|
|
if (EditorApplication.isPlaying)
|
|
{
|
|
Debug.Log("A Rive asset changed. Scene reload skipped because Play Mode is active.");
|
|
|
|
return;
|
|
}
|
|
|
|
Scene activeScene = SceneManager.GetActiveScene();
|
|
|
|
if (!activeScene.IsValid() || string.IsNullOrEmpty(activeScene.path))
|
|
{
|
|
Debug.LogWarning("A Rive asset changed, but the active scene has not been saved yet.");
|
|
|
|
return;
|
|
}
|
|
|
|
bool saved = EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
|
|
|
|
if (!saved)
|
|
{
|
|
Debug.LogWarning("Rive scene refresh cancelled because the scene was not saved.");
|
|
|
|
return;
|
|
}
|
|
|
|
EditorSceneManager.OpenScene(
|
|
activeScene.path,
|
|
OpenSceneMode.Single);
|
|
|
|
Debug.Log("Rive asset changed. THe active scene was reloaded automatically.");
|
|
}
|
|
}
|
|
#endif |