游戏基础框架搭建(二)

UI框架

Posted by MagicianJoker on November 7, 2020
  • MVC

    image-20230521140641436

    PureMVC框架

    image-20250219153400160

    image-20250219153424991

  • MVCS

    StrangeIOC

  • MVP

  • MVVM

    uFrame

  • MVE

  • UI管理系统

​ 加载、弹出、隐藏、显示、销毁

  • 遮罩系统

    堆叠遮罩

    单层遮罩

  • 堆栈系统

    回溯上个界面

  • 灵活的层级系统

  • 自动化系统

  • 高效率系统

UI异形屏幕适配

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using UnityEngine;
using UnityEngine.UI;

public class SafeArea : MonoBehaviour
{
    RectTransform Panel;
    Rect LastSafeArea = new Rect(0, 0, 0, 0);
    void Awake()
    {
        Panel = GetComponent<RectTransform>();
        Refresh();
    }

    void Update()
    {
        Refresh();
    }
	
    void Refresh()
    {
        Rect safeArea = GetSafeArea();
        if (safeArea != LastSafeArea)
            ApplySafeArea(safeArea);
    }

    Rect GetSafeArea()
    {
        //自行拓展区分
        return Screen.safeArea;
    }

    void ApplySafeArea(Rect r)
    {
        LastSafeArea = r;
        // Convert safe area rectangle from absolute pixels to normalised anchor coordinates
        Vector2 anchorMin = r.position;
        Vector2 anchorMax = r.position + r.size;
        anchorMin.x /= Screen.width;
        anchorMin.y /= Screen.height;
        anchorMax.x /= Screen.width;
        anchorMax.y /= Screen.height;
        Panel.anchorMin = anchorMin;
        Panel.anchorMax = anchorMax;

        Debug.LogFormat("New safe area applied to {0}: x={1}, y={2}, w={3}, h={4} on full extents w={5}, h={6}",name, r.x, r.y, r.width, r.height, Screen.width, Screen.height);
    }
}