using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using UnityEngine;
using UnityEngine.Rendering;
using UnityObject = UnityEngine.Object;
namespace Gallop.Live
{
public interface ILiveFlashController
{
bool IsInitialized { get; }
void SetParent(Transform parent, bool worldPositionStays);
void Destroy();
void AlterUpdate();
void PlayLabel(string label, float currentTime, object curData = null);
void UpdateOrientationLandscape();
void UpdateOrientationPortrait();
void Reset();
}
///
/// Official-like LiveFlashController bridge for UmaViewer-style projects.
///
/// It does not require compile-time references to AnimateToUnity/FlashPlayer.
/// If the real Flash runtime exists on the instantiated prefab, calls are forwarded by reflection.
/// If it does not exist, it falls back to direct Unity hierarchy edits by object name.
///
public class LiveFlashController : MonoBehaviour, ILiveFlashController
{
protected const string LABEL_IN00 = "in00";
protected const string LABEL_IN = "in";
protected const string LABEL_OUT = "out";
protected const string LABEL_END = "end";
private const int FLASH_POSITION_OFFSET_Z = 100;
private const int FLASH_CAMERA_CLIP_NEAR = -20;
private const int FLASH_CAMERA_CLIP_FAR = 70;
private const string PARTICLE_ROOT_NAME = "root";
private const float PARTICLE_ASPECT_RATIO_SCALE_MAX = 1f;
private const float OVERRIDE_GRADATION_ALPHA_VALUE = 1f;
[SerializeField] private Canvas _flashCanvas;
[SerializeField] private Camera _flashCamera;
[SerializeField] private Transform _cachedTransform;
[SerializeField] private GameObject _flashRoot;
// Official fields are FlashActionPlayer / FlashPlayer. Keep them as object so the project compiles
// without AnimateToUnity assemblies.
private object _flashActionPlayer;
private object _flashPlayer;
[SerializeField] private bool _isVertical;
private object _currentTimelineKeyFlashPlayerData;
[SerializeField] private bool _isFlashInitialized;
[SerializeField] private bool _isInitialized;
protected object FlashActionPlayer { get { return _flashActionPlayer; } }
protected object FlashPlayer { get { return _flashPlayer; } }
protected GameObject FlashRoot { get { return _flashRoot; } }
protected Font CurrentFlashFont { get; private set; }
public bool IsInitialized { get { return _isInitialized; } }
private void OnDestroy()
{
Destroy();
}
public virtual void Initialize(string flashResourcePath)
{
if (_isInitialized)
Destroy();
_cachedTransform = transform;
CreateFlashCamera(_cachedTransform);
CreateFlashCanvas(_cachedTransform, _flashCamera);
InitializeFlash(flashResourcePath, _flashCanvas != null ? _flashCanvas.transform : _cachedTransform);
SetupFlashCameraCallback();
_isFlashInitialized = _flashRoot != null;
_isInitialized = _isFlashInitialized;
}
private void CreateFlashCamera(Transform parent)
{
if (_flashCamera != null)
return;
GameObject cameraObject = new GameObject("FlashCamera");
cameraObject.transform.SetParent(parent, false);
cameraObject.transform.localPosition = new Vector3(0f, 0f, -FLASH_POSITION_OFFSET_Z);
cameraObject.transform.localRotation = Quaternion.identity;
cameraObject.transform.localScale = Vector3.one;
_flashCamera = cameraObject.AddComponent();
_flashCamera.clearFlags = CameraClearFlags.Depth;
_flashCamera.orthographic = true;
_flashCamera.orthographicSize = 1f;
_flashCamera.nearClipPlane = FLASH_CAMERA_CLIP_NEAR;
_flashCamera.farClipPlane = FLASH_CAMERA_CLIP_FAR;
_flashCamera.allowHDR = false;
_flashCamera.allowMSAA = false;
_flashCamera.depth = 100f;
}
private void SetupFlashCameraCallback()
{
// Official registers camera callbacks for Flash rendering.
// In this bridge we keep the camera alive and let Unity/Flash runtime render normally.
}
private void CreateFlashCanvas(Transform parent, Camera flashCamera)
{
if (_flashCanvas != null)
return;
GameObject canvasObject = new GameObject("FlashCanvas");
canvasObject.transform.SetParent(parent, false);
canvasObject.transform.localPosition = Vector3.zero;
canvasObject.transform.localRotation = Quaternion.identity;
canvasObject.transform.localScale = Vector3.one;
_flashCanvas = canvasObject.AddComponent