namespace Guru
{
using System;
using UnityEngine;
///
/// 屏幕方向
///
public enum ScreenOrientation
{
Portrait = 0,
Landscape,
}
public interface IDisposable
{
void Dispose();
}
public interface IContext
{
//--------- Components -----------------
bool RegisterResManager(T manager, string name = "") where T : IResManager, new();
T GetResManager(string name = "") where T : IResManager, new();
bool RegisterModel(T model, string name = "") where T : IModel, new();
T GetModel(string name = "") where T : IModel, new();
bool RegisterController(T controller, string name = "") where T : IController, new();
T GetController(string name = "") where T : IController, new();
bool RegisterHelper(T controller, string name = "") where T : IHelper, new();
T GetHelper(string name = "") where T : IHelper, new();
void RegisterUpdater(IUpdater updater);
void UnregisterUpdater(IUpdater updater);
}
///
/// 消息管线
///
public interface IEventPipeline
{
//--------- Event Bus ------------------
public void Subscribe(Action onReceiveMessage) where T : struct;
public void Unsubscribe(Action onReceiveMessage) where T : struct;
public void Send(T message) where T : struct;
}
///
/// 控制器接口
///
public interface IController
{
string Name { get;}
Context Context { get; set;}
void Init();
}
public interface IModel
{
string Name { get;}
void Update(); // 数据刷新
}
public interface IView
{
string Name { get;}
void Refresh(); // UI 刷新
}
public interface IHelper
{
string Name { get;}
Context Context { get; set;}
}
public interface IResManager
{
string Name { get;}
Context Context { get; set;}
void Init();
T Load(string resUri) where T : UnityEngine.Object;
void LoadAsync(string resUri, Action onLoaded);
}
///
/// 资源加载器
///
public interface IResLoader
{
void LoadAsync(string resUri, Action onLoaded);
}
///
/// 更新器
///
public interface IUpdater
{
void OnUpdate();
bool IsStopped { get; set; }
}
///
/// 资源加载信息
///
public class ResLoadInfo
{
public string uri = "";
public bool success = false; // 加载是否成功
public string bundleName = ""; // bundle包的名称
public object target = null;
public ResLoadInfo()
{
}
public ResLoadInfo(string uri)
{
this.uri = uri;
}
public GameObject AsGameObject() => target as GameObject;
public Texture AsTexture() => target as Texture;
public T AsObject() where T : UnityEngine.Object => (T)target;
public string AsString() => (target as TextAsset)?.text ?? "";
public byte[] AsBinary() => (byte[])target;
}
}