69 lines
1.7 KiB
C#
69 lines
1.7 KiB
C#
|
|
using Guru.UI;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
namespace Guru
|
||
|
|
{
|
||
|
|
public class GuruUIController: IController
|
||
|
|
{
|
||
|
|
public string Name => "guru_ui";
|
||
|
|
public Context Context { get; set; }
|
||
|
|
|
||
|
|
//----------- 设置分辨率 --------------
|
||
|
|
public static readonly int DefaultDesignSize_1080 = 1080;
|
||
|
|
public static readonly int DefaultDesignSize_2340 = 2340;
|
||
|
|
|
||
|
|
public int designWidth;
|
||
|
|
public int designHeight;
|
||
|
|
private UIRoot _root;
|
||
|
|
|
||
|
|
public static GuruUIController Create(Context context)
|
||
|
|
{
|
||
|
|
var root = new GuruUIController { Context = context };
|
||
|
|
root.Init();
|
||
|
|
return root;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
private GuruResManager _resMgr;
|
||
|
|
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 初始化
|
||
|
|
/// </summary>
|
||
|
|
public void Init()
|
||
|
|
{
|
||
|
|
_resMgr = Context.GetResManager<GuruResManager>();
|
||
|
|
CreateRoot();
|
||
|
|
SetOrientation();
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
public void SetOrientation(ScreenOrientation orientation = ScreenOrientation.Portrait)
|
||
|
|
{
|
||
|
|
if (orientation == ScreenOrientation.Portrait)
|
||
|
|
{
|
||
|
|
designWidth = DefaultDesignSize_1080;
|
||
|
|
designHeight = DefaultDesignSize_2340;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
designWidth = DefaultDesignSize_2340;
|
||
|
|
designHeight = DefaultDesignSize_1080;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
private void CreateRoot()
|
||
|
|
{
|
||
|
|
_root = UIRoot.Instance;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
public RectTransform AddNode(string nodePath = "", Transform parent = null)
|
||
|
|
{
|
||
|
|
return _root.CreateNodeFromPath(nodePath, parent);
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|