Example #1
0
    public static void CreatUIManager(Vector2 referenceResolution, CanvasScaler.ScreenMatchMode MatchMode, bool isOnlyUICamera, bool isVertical)
    {
        //新增五个层级
        EditorExpand.AddSortLayerIfNotExist("GameUI");
        EditorExpand.AddSortLayerIfNotExist("Fixed");
        EditorExpand.AddSortLayerIfNotExist("Normal");
        EditorExpand.AddSortLayerIfNotExist("TopBar");
        EditorExpand.AddSortLayerIfNotExist("PopUp");

        //UIManager
        GameObject UIManagerGo = new GameObject("UIManager");

        UIManagerGo.layer = LayerMask.NameToLayer("UI");
        UIManager UIManager = UIManagerGo.AddComponent <UIManager>();

        CreateUICamera(UIManager, "DefaultUI", 1, referenceResolution, MatchMode, isOnlyUICamera, isVertical);

        ProjectWindowUtil.ShowCreatedAsset(UIManagerGo);

        //保存UIManager
        ReSaveUIManager(UIManagerGo);
    }
    public static void InitGuideSystem()
    {
        if (!GetGuideIsInit())
        {
            //创建数据表
            SaveDataTable();

            //创建脚本
            CreateGuideWindowScript();

            //增加Guide引导层

            EditorExpand.AddSortLayerIfNotExist("Guide");

            //添加引导开关
            RecordManager.SaveRecord(GuideSystemBase.c_guideRecordName, GuideSystemBase.c_guideSwitchName, true);
        }
        else
        {
            Debug.Log("新手引导已经初始化");
        }
    }
 public static void ShowAllMethod()
 {
     //增加Guide引导层
     EditorExpand.AddSortLayerIfNotExist("Guide");
 }
Example #4
0
    public static void CreatUIManager(Vector2 referenceResolution, CanvasScaler.ScreenMatchMode MatchMode, bool isOnlyUICamera, bool isVertical)
    {
        //新增五个层级
        EditorExpand.AddSortLayerIfNotExist("GameUI");
        EditorExpand.AddSortLayerIfNotExist("Fixed");
        EditorExpand.AddSortLayerIfNotExist("Normal");
        EditorExpand.AddSortLayerIfNotExist("TopBar");
        EditorExpand.AddSortLayerIfNotExist("PopUp");

        //UIManager
        GameObject UIManagerGo = new GameObject("UIManager");

        UIManagerGo.layer = LayerMask.NameToLayer("UI");
        //UIManager UIManager = UIManagerGo.AddComponent<UIManager>();
        UIManagerGo.AddComponent <UIManager>();

        //UIcamera
        GameObject cameraGo = new GameObject("UICamera");

        cameraGo.transform.SetParent(UIManagerGo.transform);
        cameraGo.transform.localPosition = new Vector3(0, 0, -1000);
        Camera camera = cameraGo.AddComponent <Camera>();

        camera.cullingMask  = LayerMask.GetMask("UI");
        camera.orthographic = true;
        if (!isOnlyUICamera)
        {
            camera.clearFlags = CameraClearFlags.Depth;
            camera.depth      = 1;
        }
        else
        {
            camera.clearFlags      = CameraClearFlags.SolidColor;
            camera.backgroundColor = Color.black;
        }

        //Canvas
        Canvas canvas = UIManagerGo.AddComponent <Canvas>();

        canvas.renderMode  = RenderMode.ScreenSpaceCamera;
        canvas.worldCamera = camera;

        //UI Raycaster
        //GraphicRaycaster Graphic = UIManagerGo.AddComponent<GraphicRaycaster>();
        UIManagerGo.AddComponent <GraphicRaycaster>();

        //CanvasScaler
        CanvasScaler scaler = UIManagerGo.AddComponent <CanvasScaler>();

        scaler.uiScaleMode         = CanvasScaler.ScaleMode.ScaleWithScreenSize;
        scaler.referenceResolution = referenceResolution;
        scaler.screenMatchMode     = MatchMode;

        if (isVertical)
        {
            scaler.matchWidthOrHeight = 1;
        }
        else
        {
            scaler.matchWidthOrHeight = 0;
        }

        //挂载点
        GameObject     goTmp    = null;
        RectTransform  rtTmp    = null;
        UILayerManager layerTmp = UIManagerGo.GetComponent <UILayerManager>();

        goTmp       = new GameObject("GameUI");
        goTmp.layer = LayerMask.NameToLayer("UI");
        goTmp.transform.SetParent(UIManagerGo.transform);
        goTmp.transform.localScale = Vector3.one;
        rtTmp                        = goTmp.AddComponent <RectTransform>();
        rtTmp.anchorMax              = new Vector2(1, 1);
        rtTmp.anchorMin              = new Vector2(0, 0);
        rtTmp.anchoredPosition3D     = Vector3.zero;
        rtTmp.sizeDelta              = Vector2.zero;
        layerTmp.m_GameUILayerParent = goTmp.transform;

        goTmp       = new GameObject("Fixed");
        goTmp.layer = LayerMask.NameToLayer("UI");
        goTmp.transform.SetParent(UIManagerGo.transform);
        goTmp.transform.localScale = Vector3.one;
        rtTmp                       = goTmp.AddComponent <RectTransform>();
        rtTmp.anchorMax             = new Vector2(1, 1);
        rtTmp.anchorMin             = new Vector2(0, 0);
        rtTmp.anchoredPosition3D    = Vector3.zero;
        rtTmp.sizeDelta             = Vector2.zero;
        layerTmp.m_FixedLayerParent = goTmp.transform;

        goTmp       = new GameObject("Normal");
        goTmp.layer = LayerMask.NameToLayer("UI");
        goTmp.transform.SetParent(UIManagerGo.transform);
        goTmp.transform.localScale = Vector3.one;
        rtTmp                        = goTmp.AddComponent <RectTransform>();
        rtTmp.anchorMax              = new Vector2(1, 1);
        rtTmp.anchorMin              = new Vector2(0, 0);
        rtTmp.anchoredPosition3D     = Vector3.zero;
        rtTmp.sizeDelta              = Vector2.zero;
        layerTmp.m_NormalLayerParent = goTmp.transform;

        goTmp       = new GameObject("TopBar");
        goTmp.layer = LayerMask.NameToLayer("UI");
        goTmp.transform.SetParent(UIManagerGo.transform);
        goTmp.transform.localScale = Vector3.one;
        rtTmp                        = goTmp.AddComponent <RectTransform>();
        rtTmp.anchorMax              = new Vector2(1, 1);
        rtTmp.anchorMin              = new Vector2(0, 0);
        rtTmp.anchoredPosition3D     = Vector3.zero;
        rtTmp.sizeDelta              = Vector2.zero;
        layerTmp.m_TopbarLayerParent = goTmp.transform;

        goTmp       = new GameObject("PopUp");
        goTmp.layer = LayerMask.NameToLayer("UI");
        goTmp.transform.SetParent(UIManagerGo.transform);
        goTmp.transform.localScale = Vector3.one;
        rtTmp                       = goTmp.AddComponent <RectTransform>();
        rtTmp.anchorMax             = new Vector2(1, 1);
        rtTmp.anchorMin             = new Vector2(0, 0);
        rtTmp.anchoredPosition3D    = Vector3.zero;
        rtTmp.sizeDelta             = Vector2.zero;
        layerTmp.m_PopUpLayerParent = goTmp.transform;
        //m_UILayerManager = layerTmp;

        ProjectWindowUtil.ShowCreatedAsset(UIManagerGo);

        string Path = "Resources/UI/UIManager.prefab";

        FileTool.CreatFilePath(Application.dataPath + "/" + Path);
        PrefabUtility.CreatePrefab("Assets/" + Path, UIManagerGo, ReplacePrefabOptions.ConnectToPrefab);
    }