快速开始

本页面将完成UNIHper的工程创建并输出第一个Hellow,World消息

1. 安装UNIHper

  • 打开工程Packages/manifest.json,添加如下配置到dependencies

    "com.parful.unihper": "https://github.com/mrbaoquan/unihper.git"

2. 快速上手

  1. 点击编辑器菜单栏[UNIHper/Initialize]进行工程初始化操作

// 上述操作会在Assets目录下初始化工作目录,结构如下
Assets
├─AddressableAssetsData                (Addressable资源配置,默认使用)
├─ArtAssets
│  └─UI Prefabs                        (用于存放UI预制体资源)
├─Develop
│  └─Scripts                           ( 用于存放工程脚本 )
│      │  GameMain.asmdef              ( 默认模块程序集文件 )
│      │  SceneEntryScript.cs          ( 场景脚本 )
│      ├─Configs                       ( 配置文件类脚本 )
│      ├─Game                          ( 用于存放游戏逻辑类脚本 )
│      └─UIs                           ( 用于存放UI类脚本 )
├─Resources                            
│  │  UNIHperSettings.asset            ( UNIHper 设置项 )
│  │
│  └─UNIHper
│      │  assemblies.json              ( 项目程序集配置项 )
│      │  resources.json               ( 资源配置项 )
│      │  uis.json                     ( UI配置项 )
│      │
│      └─Prefabs
│              UNIHper.prefab          ( UNIHper 入口预制体 )

├─Scenes
│      SceneEntry.unity                ( 入口场景 )

└─StreamingAssets

   └─Configs                           ( 配置类脚本默认序列化位置 )
  1. 新建UI脚本

在Assets/Develop/Scripts/UIs 目录下右键执行Create/UNIHper Framework/UIScript 菜单

// 生成的NewUI.cs脚本文件
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UniRx;
using UNIHper;
using UNIHper.UI;
using DNHper;

// Asset 为需要关联的UI预制体名称
[UIPage(, Order = -1, Type = UIType.Normal)]
public class NewUI : UIBase
{
    // Start is called before the first frame update
    private void Start() { }

    // Update is called once per frame
    private void Update() { }

    // Called when this ui is loaded
    protected override void OnLoaded() { }

    // Called when this ui is shown
    protected override void OnShown() { }

    // Called when this ui is hidden
    protected override void OnHidden() { }
}
  1. 在UI预制体所在文件夹右键执行,Add To Addressable System

  1. 编辑Assets/Develop/Scripts/SceneEntryScript.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UNIHper;
using UniRx;

public class SceneEntryScript : SceneScriptBase
{
    // Called once after scene is loaded
    private void Start()
    {
        Managements.UI.Show<NewUI>();
    }

    // Called per frame after Start
    private void Update() { }

    // Called when scene is unloaded
    private void OnDestroy() { }

    // Called when application is quit
    private void OnApplicationQuit() { }
}
  1. 启动编辑器预览,Game视图将会显示NewUI预制体

Last updated