using System; using System.Reflection; using System.Threading; using UnityEngine; namespace ET { public interface IEntry { void Start(); void Update(); void LateUpdate(); void OnApplicationQuit(); } public class Init: MonoBehaviour { private IEntry entry; private void Awake() { SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance); DontDestroyOnLoad(gameObject); Assembly modelAssembly = null; if (Define.IsEditor) { UnityEngine.Debug.Log("unity editor mode!"); foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { string assemblyName = $"{assembly.GetName().Name}.dll"; if (assemblyName != "Unity.ModelView.dll") { continue; } modelAssembly = assembly; break; } } else { UnityEngine.Debug.Log("unity standalone mode!"); foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { string assemblyName = $"{assembly.GetName().Name}.dll"; if (assemblyName != "Unity.ModelView.dll") { continue; } modelAssembly = assembly; break; } } if (!Define.UseLua) { Type initType = modelAssembly.GetType("ET.MonoEntry"); this.entry = Activator.CreateInstance(initType) as IEntry; } else { Type initType = this.GetType().Assembly.GetType("ET.LuaEntry"); this.entry = Activator.CreateInstance(initType) as IEntry; } } private void Start() { this.entry.Start(); } private void Update() { this.entry.Update(); } private void LateUpdate() { this.entry.LateUpdate(); } private void OnApplicationQuit() { this.entry.OnApplicationQuit(); } } }