Add automatic Rive asset refresh workflow
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
#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
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 69d5148788a7cf54495d98a1a6e11d59
|
||||
@@ -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
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 867b04f7b3f14254598149f4cb04a1c8
|
||||
@@ -45,6 +45,7 @@ namespace ProceduralEditor
|
||||
SetupPanel(faceMaterial);
|
||||
SetupFog();
|
||||
SetupPostProcessVolume();
|
||||
RemoveLegacyLogo();
|
||||
SetupFadeCanvas();
|
||||
|
||||
EditorSceneManager.MarkSceneDirty(scene);
|
||||
@@ -178,12 +179,46 @@ namespace ProceduralEditor
|
||||
RenderSettings.fog = false;
|
||||
}
|
||||
|
||||
static void RemoveLegacyLogo()
|
||||
{
|
||||
var legacyLogo = GameObject.Find("NetCode Logo");
|
||||
if (legacyLogo != null)
|
||||
Object.DestroyImmediate(legacyLogo);
|
||||
}
|
||||
|
||||
static void SetupFadeCanvas()
|
||||
{
|
||||
var existing = GameObject.Find("Fade Canvas");
|
||||
if (existing != null) Object.DestroyImmediate(existing);
|
||||
if (existing != null)
|
||||
{
|
||||
existing.SetActive(true);
|
||||
existing.transform.localScale = Vector3.one;
|
||||
var existingImage = existing.transform.Find("Fade Image");
|
||||
if (existingImage != null)
|
||||
{
|
||||
existingImage.gameObject.SetActive(true);
|
||||
var existingFadeIn = existingImage.GetComponent<MenuFadeIn>();
|
||||
if (existingFadeIn == null)
|
||||
existingFadeIn = existingImage.gameObject.AddComponent<MenuFadeIn>();
|
||||
|
||||
existingFadeIn.delay = 2.5f;
|
||||
existingFadeIn.duration = 3.5f;
|
||||
existingFadeIn.enabled = true;
|
||||
|
||||
var existingGroup = existingImage.GetComponent<CanvasGroup>();
|
||||
if (existingGroup != null)
|
||||
{
|
||||
existingGroup.alpha = 1f;
|
||||
existingGroup.blocksRaycasts = true;
|
||||
existingGroup.interactable = true;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var canvasGo = new GameObject("Fade Canvas", typeof(Canvas), typeof(CanvasScaler), typeof(GraphicRaycaster));
|
||||
canvasGo.transform.localScale = Vector3.one;
|
||||
var canvas = canvasGo.GetComponent<Canvas>();
|
||||
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
// Ensure fade canvas draws on top of other UI canvases
|
||||
@@ -204,11 +239,8 @@ namespace ProceduralEditor
|
||||
rect.offsetMax = Vector2.zero;
|
||||
|
||||
var fadeIn = imageGo.AddComponent<MenuFadeIn>();
|
||||
fadeIn.delay = 0.3f;
|
||||
fadeIn.delay = 2.5f;
|
||||
fadeIn.duration = 3.5f;
|
||||
// Disable automatic fade-on-start so the debug toggle controls opacity predictably.
|
||||
// If you prefer the automatic fade, remove this line.
|
||||
fadeIn.enabled = false;
|
||||
|
||||
// Make sure the image initially is fully opaque so the menu starts covered by the backdrop
|
||||
var initColor = image.color;
|
||||
|
||||
@@ -9,6 +9,20 @@ public class MenuFadeIn : MonoBehaviour
|
||||
|
||||
CanvasGroup _group;
|
||||
Coroutine _fadeRoutine;
|
||||
bool _started;
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
|
||||
static void ReactivateFadeImages()
|
||||
{
|
||||
var fadeComponents = Resources.FindObjectsOfTypeAll<MenuFadeIn>();
|
||||
foreach (var fadeComponent in fadeComponents)
|
||||
{
|
||||
if (!fadeComponent.gameObject.scene.IsValid())
|
||||
continue;
|
||||
|
||||
fadeComponent.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
@@ -16,6 +30,10 @@ public class MenuFadeIn : MonoBehaviour
|
||||
_group = GetComponent<CanvasGroup>();
|
||||
if (_group == null) _group = gameObject.AddComponent<CanvasGroup>();
|
||||
|
||||
var canvas = GetComponentInParent<Canvas>();
|
||||
if (canvas != null)
|
||||
canvas.transform.localScale = Vector3.one;
|
||||
|
||||
_group.alpha = 1f;
|
||||
_group.blocksRaycasts = true;
|
||||
Debug.Log("[MenuFadeIn] Awake - CanvasGroup ensured, alpha=1");
|
||||
@@ -23,14 +41,26 @@ public class MenuFadeIn : MonoBehaviour
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
// Reset state whenever enabled and start the fade
|
||||
if (_group == null) _group = GetComponent<CanvasGroup>() ?? gameObject.AddComponent<CanvasGroup>();
|
||||
|
||||
if (_started)
|
||||
BeginFade();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
_started = true;
|
||||
BeginFade();
|
||||
}
|
||||
|
||||
void BeginFade()
|
||||
{
|
||||
_group.alpha = 1f;
|
||||
_group.blocksRaycasts = true;
|
||||
|
||||
if (_fadeRoutine != null) StopCoroutine(_fadeRoutine);
|
||||
_fadeRoutine = StartCoroutine(Fade());
|
||||
Debug.Log("[MenuFadeIn] OnEnable - starting fade (delay=" + delay + ", duration=" + duration + ")");
|
||||
Debug.Log("[MenuFadeIn] Starting fade (delay=" + delay + ", duration=" + duration + ")");
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
@@ -57,7 +87,6 @@ public class MenuFadeIn : MonoBehaviour
|
||||
|
||||
_group.alpha = 0f;
|
||||
_group.blocksRaycasts = false;
|
||||
Debug.Log("[MenuFadeIn] Fade finished - disabling GameObject");
|
||||
gameObject.SetActive(false);
|
||||
Debug.Log("[MenuFadeIn] Fade finished");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user