140 lines
3.4 KiB
C#
140 lines
3.4 KiB
C#
|
|
namespace Guru
|
||
|
|
{
|
||
|
|
using System;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 屏幕方向
|
||
|
|
/// </summary>
|
||
|
|
public enum ScreenOrientation
|
||
|
|
{
|
||
|
|
Portrait = 0,
|
||
|
|
Landscape,
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
public interface IDisposable
|
||
|
|
{
|
||
|
|
void Dispose();
|
||
|
|
}
|
||
|
|
|
||
|
|
public interface IContext
|
||
|
|
{
|
||
|
|
//--------- Components -----------------
|
||
|
|
bool RegisterResManager<T>(T manager, string name = "") where T : IResManager, new();
|
||
|
|
T GetResManager<T>(string name = "") where T : IResManager, new();
|
||
|
|
|
||
|
|
bool RegisterModel<T>(T model, string name = "") where T : IModel, new();
|
||
|
|
T GetModel<T>(string name = "") where T : IModel, new();
|
||
|
|
|
||
|
|
bool RegisterController<T>(T controller, string name = "") where T : IController, new();
|
||
|
|
T GetController<T>(string name = "") where T : IController, new();
|
||
|
|
|
||
|
|
bool RegisterHelper<T>(T controller, string name = "") where T : IHelper, new();
|
||
|
|
T GetHelper<T>(string name = "") where T : IHelper, new();
|
||
|
|
|
||
|
|
|
||
|
|
void RegisterUpdater(IUpdater updater);
|
||
|
|
void UnregisterUpdater(IUpdater updater);
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 消息管线
|
||
|
|
/// </summary>
|
||
|
|
public interface IEventPipeline
|
||
|
|
{
|
||
|
|
//--------- Event Bus ------------------
|
||
|
|
public void Subscribe<T>(Action<T> onReceiveMessage) where T : struct;
|
||
|
|
public void Unsubscribe<T>(Action<T> onReceiveMessage) where T : struct;
|
||
|
|
public void Send<T>(T message) where T : struct;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 控制器接口
|
||
|
|
/// </summary>
|
||
|
|
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<T>(string resUri) where T : UnityEngine.Object;
|
||
|
|
void LoadAsync(string resUri, Action<ResLoadInfo> onLoaded);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 资源加载器
|
||
|
|
/// </summary>
|
||
|
|
public interface IResLoader
|
||
|
|
{
|
||
|
|
void LoadAsync(string resUri, Action<ResLoadInfo> onLoaded);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 更新器
|
||
|
|
/// </summary>
|
||
|
|
public interface IUpdater
|
||
|
|
{
|
||
|
|
void OnUpdate();
|
||
|
|
bool IsStopped { get; set; }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 资源加载信息
|
||
|
|
/// </summary>
|
||
|
|
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<T>() where T : UnityEngine.Object => (T)target;
|
||
|
|
public string AsString() => (target as TextAsset)?.text ?? "";
|
||
|
|
public byte[] AsBinary() => (byte[])target;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
}
|