HKUnityTools 是我们团队在 Unity 项目中开发的工具集,涵盖编辑器和运行时功能,旨在优化工作流程并降低开发负担。若有任何疑问,欢迎联系 QQ : 511919078
微信 : JingChanChangFan
本项目部分模块基于:
HKUnityTools更新日志:https://kdocs.cn/l/caGHelWvXD0f
团队案例:https://kdocs.cn/l/csfyzM0GfoI9
(号外!我们团队位于青岛,专注于XR、虚拟仿真及数字化展项等项目开发,现诚邀开发者加入。感兴趣请私信或联系QQ和微信!)
HKUnityTools Gitee地址:传送门
QFramework Github地址:传送门
In-game Debug Console Github地址:传送门
HKUnityTools 的扩展功能基于 QFramework 实现。在进行开发及测试时,默认采用 HK_DefaultArchitecture 框架。当在其他项目中引入 HKUnityTools 时,务必替换为对应项目的框架(Architecture),同时注册 HKUnityTools 的系统层、模型层和工具层,否则相关功能将无法正常使用
对于新建的 Unity 工程,可借助“自动化生成项目脚本模板”工具,依据 QFramework 的规则生成初始化模板,生成后在全局设置里更改当前框架(Architecture)。
提供专门的全局设置窗口,便捷管理和切换 HKUnityTools 所应用的框架(Architecture),并配置各类工具的启用状态。
使用方式:
/// <summary>
/// HKTools 框架提供工具
/// </summary>
public static class HK_ArchitectureProvider
{
static IArchitecture architecture;
/// <summary>
/// 获取当前项目的架构实例,确保在第一次访问时进行初始化。
/// </summary>
public static IArchitecture Architecture
{
get
{
// 懒加载架构实例
if (architecture == null)
{
SetArchitecture();
}
return architecture;
}
}
/// <summary>
/// 设置当前项目的架构实例。
/// </summary>
static void SetArchitecture()
{
// 修改此处,设定为当前项目 Architecture 框架
architecture = HKTools.HK_DefaultArchitecture.Interface;
}
}
本工具是一款用于 Unity 编辑器的扩展工具,旨在根据QFramework框架规则,自动生成Unity项目的脚本模板和基础文件夹结构。可以帮助开发者快速搭建项目架构,提高效率,主要功能如下:
功能描述:
HK_FreeCam 是一款轻量级的运行时摄像机控制系统,为开发调试阶段设计的场景漫游预览工具。主要功能包括:
使用方式:
参数名 | 类型 | 默认值 | 说明 |
---|---|---|---|
Move Speed | float | 10 | 移动速度 |
Rotate Speed | float | 300 | 视角旋转灵敏度 |
X Axis Range | Vector2 | (-45,45) | 俯仰角度限制 |
外部依赖:
功能描述:
HK_TargetCam 是一款多功能的Unity摄像机多目标管理系统,能够在项目中实现 Camera 在多个 Target 之间的平滑切换与精确控制。主要功能如下:
多目标切换,各目标类型及切换效果如下:
运行时控制功能:
使用方式:
public class XXX_Architecture : Architecture<XXX_Architecture>
{
protected override void Init()
{
this.RegisterSystem<IHK_TargetCamSystem>(new HK_TargetCamSystem());
}
}
// 设置相机的移动速度和缩放速度
this.SendCommand(new CMD_SetMoveAndZoomSpeed(1.5f, 3));
// 设置相机的俯仰角范围
this.SendCommand(new CMD_SetPitchAngle(5, 85));
// 设置相机切换目标的运动市场为2秒
this.SendCommand(new CMD_SetTargetChangeTime(2f));
// 冻结相机
this.SendCommand(new CMD_SetFreezeMode(true));
// 解冻相机
this.SendCommand(new CMD_SetFreezeMode(false));
// 相机切换至 RotTarget_01
this.SendCommand(new CMD_ChangeCamTarget(HK_TargetEnum.RotTarget_01));
// 相机切换至 RotTarget_01,使用闪现的方式
this.SendCommand(new CMD_ChangeCamTarget(HK_TargetEnum.RotTarget_01).SetUsingFlash());
// 获取当前相机的目标类型
HK_TargetEnum targetType = this.SendQuery(new Query_GetCurrentTarget());
using UnityEngine;
using QFramework;
using DG.Tweening;
using HKTools;
using UnityEngine.UI;
/// <summary>
/// Camera多目标切换管理工具,测试脚本
/// </summary>
public class Test_UseTargetCam : HKTargetCam_BaseController
{
// 相机状态及设置
[SerializeField] Text tips_Txt;
[SerializeField] Toggle toggle_FreezeCam;
[SerializeField] Button btn_QueryTarget;
[SerializeField] Slider slider_TargetChangeTime;
[SerializeField] Text txt_TargetChangeTime;
[SerializeField] Button btn_Ensure;
// 正常切换方式的按钮
[SerializeField] Button btn_RotTarget01;
[SerializeField] Button btn_RotTarget02;
[SerializeField] Button btn_RotTarget03;
[SerializeField] Button btn_RotTarget04;
[SerializeField] Button btn_AreaTarget01;
[SerializeField] Button btn_AreaTarget02;
[SerializeField] Button btn_BirdViewTarget01;
[SerializeField] Button btn_FollowTarget01;
// 闪现切换方式的按钮
[SerializeField] Button btn_RotTarget01_Flash;
[SerializeField] Button btn_RotTarget02_Flash;
[SerializeField] Button btn_RotTarget03_Flash;
[SerializeField] Button btn_RotTarget04_Flash;
[SerializeField] Button btn_AreaTarget01_Flash;
[SerializeField] Button btn_AreaTarget02_Flash;
[SerializeField] Button btn_BirdViewTarget01_Flash;
[SerializeField] Button btn_FollowTarget01_Flash;
// 测试用的移动目标
[SerializeField] Transform testMoveNPC;
void Start()
{
// 设置相机的移动速度和缩放速度
this.SendCommand(new CMD_SetMoveAndZoomSpeed(1.5f, 3));
// 设置相机的俯仰角度范围,从5度到85度
this.SendCommand(new CMD_SetPitchAngle(5, 85));
toggle_FreezeCam.onValueChanged.AddListener(isOn =>
{
if (isOn)
{
// 冻结相机
this.SendCommand(new CMD_SetFreezeMode(true));
}
else
{
// 解冻相机
this.SendCommand(new CMD_SetFreezeMode(false));
}
});
btn_QueryTarget.onClick.AddListener(() =>
{
// 获取当前相机的目标类型
HK_TargetEnum targetType = this.SendQuery(new Query_GetCurrentTarget());
HKDebug.Log("当前目标为:" + targetType.ToString());
});
txt_TargetChangeTime.text = slider_TargetChangeTime.value.ToString("0.00" + " 秒");
slider_TargetChangeTime.onValueChanged.AddListener(value =>
{
txt_TargetChangeTime.text = value.ToString("0.00" + " 秒");
});
// 点击按钮,设置目标切换时间
btn_Ensure.onClick.AddListener(() =>
{
var targetChangeTime = slider_TargetChangeTime.value;
this.SendCommand(new CMD_SetTargetChangeTime(targetChangeTime));
});
btn_RotTarget01.onClick.AddListener(() => this.SendCommand(new CMD_ChangeCamTarget(HK_TargetEnum.RotTarget_01)));
btn_RotTarget02.onClick.AddListener(() => this.SendCommand(new CMD_ChangeCamTarget(HK_TargetEnum.RotTarget_02)));
btn_RotTarget03.onClick.AddListener(() => this.SendCommand(new CMD_ChangeCamTarget(HK_TargetEnum.RotTarget_03)));
btn_RotTarget04.onClick.AddListener(() => this.SendCommand(new CMD_ChangeCamTarget(HK_TargetEnum.RotTarget_04)));
btn_AreaTarget01.onClick.AddListener(() => this.SendCommand(new CMD_ChangeCamTarget(HK_TargetEnum.AreaTarget_01)));
btn_AreaTarget02.onClick.AddListener(() => this.SendCommand(new CMD_ChangeCamTarget(HK_TargetEnum.AreaTarget_02)));
btn_BirdViewTarget01.onClick.AddListener(() => this.SendCommand(new CMD_ChangeCamTarget(HK_TargetEnum.BirdViewTarget_01)));
btn_FollowTarget01.onClick.AddListener(() =>
{
this.SendCommand(new CMD_ChangeCamTarget(HK_TargetEnum.FollowTarget_01));
/*---------------------测试-----------------*/
testMoveNPC.position = new Vector3(-15f, 1, 4.5f);
testMoveNPC.DOMoveX(13f, 6f).SetEase(Ease.Linear).SetDelay(1f);
/*------------------------------------------*/
});
btn_RotTarget01_Flash.onClick.AddListener(() => this.SendCommand(new CMD_ChangeCamTarget(HK_TargetEnum.RotTarget_01).SetUsingFlash()));
btn_RotTarget02_Flash.onClick.AddListener(() => this.SendCommand(new CMD_ChangeCamTarget(HK_TargetEnum.RotTarget_02).SetUsingFlash()));
btn_RotTarget03_Flash.onClick.AddListener(() => this.SendCommand(new CMD_ChangeCamTarget(HK_TargetEnum.RotTarget_03).SetUsingFlash()));
btn_RotTarget04_Flash.onClick.AddListener(() => this.SendCommand(new CMD_ChangeCamTarget(HK_TargetEnum.RotTarget_04).SetUsingFlash()));
btn_AreaTarget01_Flash.onClick.AddListener(() => this.SendCommand(new CMD_ChangeCamTarget(HK_TargetEnum.AreaTarget_01).SetUsingFlash()));
btn_AreaTarget02_Flash.onClick.AddListener(() => this.SendCommand(new CMD_ChangeCamTarget(HK_TargetEnum.AreaTarget_02).SetUsingFlash()));
btn_BirdViewTarget01_Flash.onClick.AddListener(() => this.SendCommand(new CMD_ChangeCamTarget(HK_TargetEnum.BirdViewTarget_01).SetUsingFlash()));
btn_FollowTarget01_Flash.onClick.AddListener(() =>
{
this.SendCommand(new CMD_ChangeCamTarget(HK_TargetEnum.FollowTarget_01).SetUsingFlash());
/*---------------------测试-----------------*/
testMoveNPC.position = new Vector3(-15f, 1, 4.5f);
testMoveNPC.DOMoveX(13f, 6f).SetEase(Ease.Linear).SetDelay(1f);
/*------------------------------------------*/
});
// 注册 开始切换 Target 事件
this.RegisterEvent<Event_SwitchTargetBegin>(args =>
{
HKDebug.Log($"开始 切换 Target:{args._targetEnum}");
}).UnRegisterWhenGameObjectDestroyed(gameObject);
// 注册 完成切换 Target 事件
this.RegisterEvent<Event_SwitchTargetEnd>(args =>
{
HKDebug.Log($"完成 切换 Target:{args._targetEnum}");
tips_Txt.text = $"当前 Target 为:{args._targetEnum}";
}).UnRegisterWhenGameObjectDestroyed(gameObject);
}
}
外部依赖:
功能描述:
使用方式:
外部依赖:
功能描述:
使用方式:
外部依赖:
功能描述:
HK_SimpleTaskSystem 是一个基于 QFramework 的简易任务管理系统,适用于 线性任务队列 的使用场景。使用枚举 (enum) 定义 任务队列(TaskQueue)和 任务(Task),可根据业务需求,自定义任务队列和任务步骤。主要功能特点如下:
使用方式:
public class XXX_Architecture : Architecture<XXX_Architecture>
{
protected override void Init()
{
RegisterSystem<IHK_SimpleTaskSystem>(new HK_SimpleTaskSystem());
}
}
/// <summary>
/// 简易任务队列类型,只可对内部的枚举值进行新增或修改
/// </summary>
public enum STS_TaskQueueType
{
Queue1,
Queue2,
}
/// <summary>
/// 任务队列1 相关任务,基于泛型使用,可新增或删除
/// </summary>
public enum TaskQueue01
{
Step01_放置干扰天线支架,
Step02_安装干扰天线,
Step03_连接干扰天线与干扰源,
Step04_放置抗干扰天线支架,
Step05_安装抗干扰天线,
Step06_连接抗干扰天线与电脑,
Step07_将干扰天线对准抗干扰天线,
Step08_放置标定天线,
}
/// <summary>
/// 任务队列2 相关任务,基于泛型使用,可新增或删除
/// </summary>
public enum TaskQueue02
{
Step01_开启设备电源,
Step02_初始化设备参数,
Step03_运行设备自检,
Step04_开始数据采集,
Step05_保存采集结果,
}
Queue<TaskQueue01> taskQueue = new Queue<TaskQueue01>(new TaskQueue01[]
{
TaskQueue01.Step01_放置干扰天线支架,
TaskQueue01.Step02_安装干扰天线,
TaskQueue01.Step03_连接干扰天线与干扰源,
TaskQueue01.Step04_放置抗干扰天线支架,
TaskQueue01.Step05_安装抗干扰天线,
TaskQueue01.Step06_连接抗干扰天线与电脑,
TaskQueue01.Step07_将干扰天线对准抗干扰天线,
TaskQueue01.Step08_放置标定天线,
});
// 初始化并开始 任务队列1
this.SendCommand(new CMD_STS_InitTaskQueue<TaskQueue01>(STS_TaskQueueType.Queue1, taskQueue));
// 按顺序完成 任务队列1 当前任务
this.SendCommand(new CMD_STS_CompleteCurrentTask(STS_TaskQueueType.Queue1));
// 按顺序完成 任务队列1 当前任务,延时1.5秒后,开始下个任务
this.SendCommand(new CMD_STS_CompleteCurrentTask(STS_TaskQueueType.Queue1, 1.5f));
// 完成步骤1
this.SendCommand(new CMD_STS_CompleteAppointTask(STS_TaskQueueType.Queue1, TaskQueue01.Step01_放置干扰天线支架));
// 完成步骤1,延时1.5秒后,开始下个任务
this.SendCommand(new CMD_STS_CompleteAppointTask(STS_TaskQueueType.Queue1, TaskQueue01.Step01_放置干扰天线支架, 1.5f));
// 查询 任务队列1的所有任务名
List<string> allTaskNames = this.SendQuery(new Query_STS_AllTaskNames(STS_TaskQueueType.任务队列1));
allTaskNames.ForEach(taskName => HKDebug.Log(taskName));
// 查询 任务队列1的进度
float progress = this.SendQuery(new Query_STS_TaskQueue(STS_TaskQueueType.任务队列1));
HKDebug.Log($"任务队列1的进度为:{progress}");
// 中断 任务队列1
this.SendCommand(new CMD_STS_BreakUpTaskQueue(STS_TaskQueueType.任务队列1));
// 注册 任务队列开始 事件
this.RegisterEvent<Event_STS_TaskQueueStart>(args =>
{
HKDebug.Log($"任务队列 开始:{args._taskQueueType}", LogColor.Blue);
});
// 注册 任务队列结束 事件
this.RegisterEvent<Event_STS_TaskQueueFinish>(args =>
{
HKDebug.Log($"任务队列 结束:{args._taskQueueType}", LogColor.Blue);
});
// 注册 任务队列中断 事件
this.RegisterEvent<Event_STS_TaskQueueBreakUp>(args =>
{
HKDebug.Log($"任务队列 中断:{args._taskQueueType}", LogColor.Yellow);
});
// 注册 任务开始 事件
this.RegisterEvent<Event_STS_TaskStart>(args =>
{
HKDebug.Log($"任务 开始:{args._taskQueueType} : {args._taskName}", LogColor.Green);
});
// 注册 任务完成 事件
this.RegisterEvent<Event_STS_TaskFinish>(args =>
{
HKDebug.Log($"任务 结束:{args._taskQueueType} : {args._taskName}", LogColor.Green);
});
示例代码:
/// <summary>
/// 简单版任务系统 演示测试脚本
/// </summary>
public class Test_UseSimpleTask : MonoBehaviour, IController
{
public IArchitecture GetArchitecture()
{
return HK_ArchitectureProvider.Architecture;
}
void Start()
{
// 注册 任务队列开始 事件
this.RegisterEvent<Event_STS_TaskQueueStart>(args =>
{
HKDebug.Log($"任务队列 开始:{args._taskQueueType}", LogColor.Blue);
});
// 注册 任务队列结束 事件
this.RegisterEvent<Event_STS_TaskQueueFinish>(args =>
{
HKDebug.Log($"任务队列 结束:{args._taskQueueType}", LogColor.Blue);
});
// 注册 任务队列中断 事件
this.RegisterEvent<Event_STS_TaskQueueBreakUp>(args =>
{
HKDebug.Log($"任务队列 中断:{args._taskQueueType}", LogColor.Yellow);
});
// 注册 任务开始 事件
this.RegisterEvent<Event_STS_TaskStart>(args =>
{
HKDebug.Log($"任务 开始:{args._taskQueueType} : {args._taskName}", LogColor.Green);
});
// 注册 任务完成 事件
this.RegisterEvent<Event_STS_TaskFinish>(args =>
{
HKDebug.Log($"任务 结束:{args._taskQueueType} : {args._taskName}", LogColor.Green);
});
}
void Update()
{
if (Input.GetKeyDown(KeyCode.F1))
{
Queue<TaskQueue01> taskQueue = new Queue<TaskQueue01>(new TaskQueue01[]
{
TaskQueue01.Step01_放置干扰天线支架,
TaskQueue01.Step02_安装干扰天线,
TaskQueue01.Step03_连接干扰天线与干扰源,
TaskQueue01.Step04_放置抗干扰天线支架,
TaskQueue01.Step05_安装抗干扰天线,
TaskQueue01.Step06_连接抗干扰天线与电脑,
TaskQueue01.Step07_将干扰天线对准抗干扰天线,
TaskQueue01.Step08_放置标定天线,
});
// 初始化并开始 任务队列1
this.SendCommand(new CMD_STS_InitTaskQueue<TaskQueue01>(STS_TaskQueueType.Queue1, taskQueue));
}
if (Input.GetKeyDown(KeyCode.F2))
{
Queue<TaskQueue02> taskQueue = new Queue<TaskQueue02>(new TaskQueue02[]
{
TaskQueue02.Step01_开启设备电源,
TaskQueue02.Step02_初始化设备参数,
TaskQueue02.Step03_运行设备自检,
TaskQueue02.Step04_开始数据采集,
TaskQueue02.Step05_保存采集结果,
});
// 初始化并开始 任务队列2
this.SendCommand(new CMD_STS_InitTaskQueue<TaskQueue02>(STS_TaskQueueType.Queue2, taskQueue));
}
if (Input.GetKeyDown(KeyCode.Escape))
{
// 中断 任务队列1
this.SendCommand(new CMD_STS_BreakUpTaskQueue(STS_TaskQueueType.Queue1));
}
if (Input.GetKeyDown(KeyCode.Q))
{
// 查询 任务队列1的所有任务名
List<string> allTaskNames = this.SendQuery(new Query_STS_AllTaskNames(STS_TaskQueueType.Queue1));
allTaskNames.ForEach(taskName => HKDebug.Log(taskName));
}
if (Input.GetKeyDown(KeyCode.W))
{
// 查询 任务队列1的进度
float progress = this.SendQuery(new Query_STS_TaskQueueProgress(STS_TaskQueueType.Queue1));
HKDebug.Log($"任务队列1的进度为:{progress}");
}
if (Input.GetKeyDown(KeyCode.Space))
{
// 按顺序完成 任务队列1 当前任务,延时1秒开始下个任务
this.SendCommand(new CMD_STS_CompleteCurrentTask(STS_TaskQueueType.Queue1, 1f));
}
if (Input.GetKeyDown(KeyCode.Alpha1))
{
// 完成步骤1,延时1.5秒开始下个任务
this.SendCommand(new CMD_STS_CompleteAppointTask(STS_TaskQueueType.Queue1, TaskQueue01.Step01_放置干扰天线支架, 1.5f));
}
if (Input.GetKeyDown(KeyCode.Alpha2))
{
// 完成步骤2,延时0.5秒开始下个任务
this.SendCommand(new CMD_STS_CompleteAppointTask(STS_TaskQueueType.Queue1, TaskQueue01.Step02_安装干扰天线, 0.5f));
}
if (Input.GetKeyDown(KeyCode.Alpha3))
{
// 完成步骤3,延时0.5秒开始下个任务
this.SendCommand(new CMD_STS_CompleteAppointTask(STS_TaskQueueType.Queue1, TaskQueue01.Step03_连接干扰天线与干扰源, 0.5f));
}
if (Input.GetKeyDown(KeyCode.Alpha4))
{
// 完成步骤4,延时0.5秒开始下个任务
this.SendCommand(new CMD_STS_CompleteAppointTask(STS_TaskQueueType.Queue1, TaskQueue01.Step04_放置抗干扰天线支架, 0.5f));
}
if (Input.GetKeyDown(KeyCode.Alpha5))
{
// 完成步骤5,延时0.5秒开始下个任务
this.SendCommand(new CMD_STS_CompleteAppointTask(STS_TaskQueueType.Queue1, TaskQueue01.Step05_安装抗干扰天线, 0.5f));
}
if (Input.GetKeyDown(KeyCode.Alpha6))
{
// 完成步骤6,延时0.5秒开始下个任务
this.SendCommand(new CMD_STS_CompleteAppointTask(STS_TaskQueueType.Queue1, TaskQueue01.Step06_连接抗干扰天线与电脑, 0.5f));
}
if (Input.GetKeyDown(KeyCode.Alpha7))
{
// 完成步骤7,延时0.5秒开始下个任务
this.SendCommand(new CMD_STS_CompleteAppointTask(STS_TaskQueueType.Queue1, TaskQueue01.Step07_将干扰天线对准抗干扰天线, 0.5f));
}
if (Input.GetKeyDown(KeyCode.Alpha8))
{
// 完成步骤8,延时0.5秒开始下个任务
this.SendCommand(new CMD_STS_CompleteAppointTask(STS_TaskQueueType.Queue1, TaskQueue01.Step08_放置标定天线, 0.5f));
}
}
}
外部依赖:
功能描述:
使用方式:
外部依赖:
示例代码:
public class Test_TaskUse : HK_TaskSystemController
{
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
this.SendCommand<CMD_BreakOffTaskList>();
}
if (Input.GetKeyDown(KeyCode.P))
{
this.SendCommand<CMD_StopTaskAudio>();
}
if (Input.GetKeyDown(KeyCode.F1))
{
this.SendCommand(new CMD_StartNewTaskList("到应聘公司"));
}
if (Input.GetKeyDown(KeyCode.Alpha1))
{
this.SendCommand(new CMD_AchieveCondition(HK_ConditionType.C1_1到电梯门口));
}
if (Input.GetKeyDown(KeyCode.Alpha2))
{
// 延时 1s 达成条件
this.SendCommand(new CMD_AchieveCondition(HK_ConditionType.C1_2跟门卫打招呼, 1));
}
if (Input.GetKeyDown(KeyCode.Alpha3))
{
this.SendCommand(new CMD_AchieveCondition(HK_ConditionType.C2_1按电梯按键));
}
if (Input.GetKeyDown(KeyCode.Alpha4))
{
this.SendCommand(new CMD_AchieveCondition(HK_ConditionType.C2_2走到光圈位置));
}
if (Input.GetKeyDown(KeyCode.Alpha5))
{
this.SendCommand(new CMD_AchieveCondition(HK_ConditionType.C3_1选择指示标));
}
if (Input.GetKeyDown(KeyCode.F2))
{
this.SendCommand(new CMD_StartNewTaskList("参与面试"));
}
if (Input.GetKeyDown(KeyCode.Q))
{
this.SendCommand(new CMD_AchieveCondition(HK_ConditionType.C4_1回答问题1));
}
if (Input.GetKeyDown(KeyCode.W))
{
this.SendCommand(new CMD_AchieveCondition(HK_ConditionType.C4_2回答问题2));
}
if (Input.GetKeyDown(KeyCode.E))
{
this.SendCommand(new CMD_AchieveCondition(HK_ConditionType.C5_1做笔试题1));
}
if (Input.GetKeyDown(KeyCode.R))
{
this.SendCommand(new CMD_AchieveCondition(HK_ConditionType.C5_2做笔试题2));
}
if (Input.GetKeyDown(KeyCode.Space))
{
bool isConditionFinish = this.SendQuery(new Query_ConditionState(HK_ConditionType.C1_1到电梯门口));
Debug.Log("Condition_C1_1到电梯门口 是否完成:" + isConditionFinish);
}
if(Input.GetKeyDown(KeyCode.Backspace))
{
this.SendCommand<CMD_ImmediateFinishTaskList>();
}
}
}
功能描述:
使用方式:
外部依赖:
功能描述:
使用方式:
public class XXX_Architecture : Architecture<XXX_Architecture>
{
protected override void Init()
{
this.RegisterSystem<IHK_TipSystem>(new HK_TipSystem());
}
}
// 显示所有的 HKTip
this.SendCommand<CMD_ShowAllHKTips>();
// 隐藏所有的 HKTip
this.SendCommand<CMD_HideAllHKTips>();
// 禁用所有的 HKTip
this.SendCommand(new CMD_SetAllHKTipActiveState(false));
// 激活所有的 HKTip
this.SendCommand(new CMD_SetAllHKTipActiveState(true));
this.RegisterEvent<Event_HKTipClick>(args =>
{
Debug.Log("点击的Tip名称为:" + args._tipName);
Debug.Log("点击的Tip类型为:" + args._tipType);
}).UnRegisterWhenGameObjectDestroyed(gameObject);
外部依赖:
功能描述:
HKDebug 工具通过对 Unity 内置 Debug 功能的扩展和封装,旨在提供更灵活、强大且高效的日志管理解决方案。通过使用 HKDebug,可以轻松控制和优化日志输出,提升调试效率和代码可维护性。以下是HKDebug的主要功能:
使用方式:
HKDebug.Log("这是默认白色普通日志");
HKDebug.Log("这是黄色普通日志", LogColor.Yellow);
HKDebug.Log("这是绿色粗斜体日志", LogColor.Green, LogStyle.BoldAndItalic);
HKDebug.Log("这是蓝色粗体日志", LogColor.Blue, LogStyle.Bold);
HKDebug.Log("这是青色普通日志", LogColor.Cyan);
HKDebug.Log("这是红色普通日志",LogColor.Red);
HKDebug.LogWarning("这是一个警告日志");
HKDebug.LogError("这是一个错误日志");
功能描述:
使用方式:
外部依赖:
功能描述:
使用方式:
{
"PortName": "COM3",
"BaudRate": 9600,
"Parity": "None",
"DataBits": 8,
"StopBits": "None"
}
public class XXX_Architecture : Architecture<XXX_Architecture>
{
protected override void Init()
{
this.RegisterSystem<IHK_SerialPortSystem>(new HK_SerialPortSystem());
}
}
this.GetSystem<IHK_SerialPortSystem>().InitSerialPort(6);
this.GetSystem<IHK_SerialPortSystem>().OpenSerialPort();
this.GetSystem<IHK_SerialPortSystem>().CloseSerialPort();
this.RegisterEvent<Event_ReceiveSerialPortData>(args =>
{
Debug.Log("接收到串口数据: " + args._serialPortData);
}).UnRegisterWhenGameObjectDestroyed(gameObject);
外部依赖:
功能描述:
本UI框架旨在管理各种UI面板的打开、关闭及其层级、排序关系,本框架提供了一套机制,使得开发者可以方便地操控UI元素,确保界面层级按照预期显示,并且不同面板类型(全局面板和层级面板)能够和谐共存。
全局面板(Global Panel):
层级面板(Hierarchy Panel):
使用方式:
public class XXX_Architecture : Architecture<XXX_Architecture>
{
protected override void Init()
{
this.RegisterSystem<IHK_UISystem>(new HK_UISystem());
}
}
功能描述: 本系统层是一个Unity的网络通信系统(不支持WebGL),包含了Server端和Client端两个部分,使用 TCP 协议实现客户端和服务器之间的消息传递。该系统通过 QFramework 框架进行管理,提供了服务器端和客户端的启动、关闭及消息发送等功能。以下是系统的主要功能: 主要特性如下:
使用方式:
在本项目的 Architecture 中注册 Server端或Client端的系统层;
public class XXX_Architecture : Architecture<XXX_Architecture>
{
protected override void Init()
{
// 注册 Client端系统层
this.RegisterSystem<IHK_TcpClientSystem>(new HK_TcpClientSystem());
// 注册 Server端系统层
this.RegisterSystem<IHK_TcpServerSystem>(new HK_TcpServerSystem());
}
}
通过指令开启 Server端;
// 作为 Server端,开启
this.SendCommand(new CMD_StartAsServer());
通过指令给Client端发送消息;
// 作为 Server端,给 所有的Client端 发送指令
this.SendCommand(new CMD_SendMsg_ServerToAllClients("Hello Client"));
Server端订阅事件;
// 当 Client端 连接时
this.RegisterEvent<Event_ClientConnect>(args =>
{
HKDebug.Log($"Event:Client端 {args._address}:{args._port} 加入", LogColor.Green);
}).UnRegisterWhenGameObjectDestroyed(gameObject);
// 当 Client端 断开连接时
this.RegisterEvent<Event_ClientDisConnect>(args =>
{
HKDebug.Log($"Event:Client端 {args._address}:{args._port} 退出", LogColor.Green);
}).UnRegisterWhenGameObjectDestroyed(gameObject);
// 作为 Server端,接收 Client端 发送的消息
this.RegisterEvent<Event_FromClientMsg>(args =>
{
HKDebug.Log($"Event:Client端 {args._address}:{args._port} 发送消息 {args._msg}", LogColor.Green);
}).UnRegisterWhenGameObjectDestroyed(gameObject);
通过指令关闭 Server端;
// 关闭 Server端
this.SendCommand(new CMD_CloseServer());
通过指令开启 Client端;
// 作为 Client端,开启,并传入 Server端的Ip及端口号
this.SendCommand(new CMD_StartAsClient("192.168.0.135", 8080));
通过指令给Server端发送消息;
// 作为 Client端,给 Server端发送指令
this.SendCommand(new CMD_SendMsg_ClientToServer("Hello Server"));
Client端订阅事件;
this.RegisterEvent<Event_ConnectToServer>(args =>
{
HKDebug.Log($"Event:连接入Server端", LogColor.Green);
}).UnRegisterWhenGameObjectDestroyed(gameObject);
this.RegisterEvent<Event_DisconnectToServer>(args =>
{
HKDebug.Log($"Event:与Server端断开连接", LogColor.Green);
}).UnRegisterWhenGameObjectDestroyed(gameObject);
this.RegisterEvent<Event_FromServerMsg>(args =>
{
HKDebug.Log($"Event:Server端 发送消息 {args._msg}", LogColor.Green);
}).UnRegisterWhenGameObjectDestroyed(gameObject);
通过指令关闭 Client端;
// 关闭 Client端
this.SendCommand(new CMD_CloseClient());
外部依赖:
功能描述:
本工具是一个为Unity设计的UDP通信工具。提供了通过指令和事件,来进行发送、接收和广播UDP消息。该工具适用于需要实时通信的应用程序,例如多人VR或展厅多端通信应用。
主要功能及特性如下:
使用方式:
在本项目的 Architecture 中注册 IHK_UdpSystem 系统层;
public class XXX_Architecture : Architecture<XXX_Architecture>
{
protected override void Init()
{
this.RegisterSystem<IHK_UdpSystem>(new HK_UdpSystem());
}
}
通过指令开启 UDP通信;
// 传入端口号,开启UDP通信
this.SendCommand(new CMD_UDP_Start(7878));
通过指令初始化,需订阅的Ack消息;
// 通过 List<string> 初始化本机订阅的Ack消息
this.SendCommand(new CMD_UDP_InitAckList(new List<string>() { "模式1","模式2"}));
通过指令广播消息;
// 给本网段下所有主机的8787端口广播消息
this.SendCommand(new CMD_UDP_BroadcastMsg("模式3", 8787));
通过指令广播Ack消息,并传入消息发送成功的回调事件;
// 给本网段下所有主机的8787端口广播消息
this.SendCommand(new CMD_UDP_BroadcastAckMsg("模式2", 8787, () => HKDebug.Log("确认发送成功!")));
订阅消息接收事件;
// 订阅 广播消息 事件
this.RegisterEvent<Event_UDP_ReceiveMsg>(args =>
{
HKDebug.Log("接收到UDP广播消息:" + args._msg);
}).UnRegisterWhenGameObjectDestroyed(gameObject);
// 订阅 Ack广播消息 事件
this.RegisterEvent<Event_UDP_ReceiveAckMsg>(args =>
{
if (args._ackMsg == "模式2")
{
HKDebug.Log("接收到 UDP 广播Ack消息:" + args._ackMsg);
}
}).UnRegisterWhenGameObjectDestroyed(gameObject);
通过指令关闭 UDP通信;
// 关闭 Client端
this.SendCommand(new CMD_UDP_Close());
外部依赖:
功能描述:
本工具是一个 FPS(每秒帧数)监控系统,可用于实时监测和优化 Unity 应用程序的性能。其主要功能包括:
通过上述功能,能够辅助在不同设备和场景下监控和优化应用性能,确保获得流畅的体验。
使用方式:
在本项目的 Architecture 中注册 HK_FPSSystem系统层;
public class XXX_Architecture : Architecture<XXX_Architecture>
{
protected override void Init()
{
// 注册 Client端系统层
this.RegisterSystem<IHK_FPSSystem>(new HK_FPSSystem());
}
}
通过 CMD_ShowFPSDisplay() 指令,在应用界面上激活显示 FPS;
this.SendCommand(new CMD_ShowFPSDisplay());
通过 CMD_HideFPSDisplay() 指令,在应用界面上隐藏 FPS;
this.SendCommand(new CMD_HideFPSDisplay());
通过 CMD_SetTargetFrameRate() 指令,设置目标刷新率;
// 关闭 垂直同步,将目标刷新率设置为 60
if (Input.GetKeyDown(KeyCode.F3))
{
this.SendCommand(new CMD_SetTargetFrameRate(60, false));
}
// 开启 垂直同步,不限制目标刷新率
if (Input.GetKeyDown(KeyCode.F4))
{
this.SendCommand(new CMD_SetTargetFrameRate(-1, true));
}
具体用法,可参考 Test_FPSSystem 脚本。
public class Test_FPSSystem : MonoBehaviour, IController
{
public IArchitecture GetArchitecture()
{
return HK_ArchitectureProvider.Architecture;
}
void Update()
{
// 显示 当前刷新率
if (Input.GetKeyDown(KeyCode.F1))
{
this.SendCommand(new CMD_ShowFPSDisplay());
}
// 隐藏 当前刷新率
if (Input.GetKeyDown(KeyCode.F2))
{
this.SendCommand(new CMD_HideFPSDisplay());
}
// 关闭 垂直同步,将目标刷新率设置为 60
if (Input.GetKeyDown(KeyCode.F3))
{
this.SendCommand(new CMD_SetTargetFrameRate(60, false));
}
// 开启 垂直同步,不限制目标刷新率
if (Input.GetKeyDown(KeyCode.F4))
{
this.SendCommand(new CMD_SetTargetFrameRate(-1, true));
}
}
}
外部依赖:
功能描述:
HK_StopwatchSystem 是一个多功能倒计时管理系统,为开发者提供精确的时序控制能力,主要功能如下:
使用方式:
在本项目的 Architecture 中注册 HK_FPSSystem系统层;
public class XXX_Architecture : Architecture<XXX_Architecture>
{
protected override void Init()
{
// 注册 Client端系统层
this.RegisterSystem<IHK_StopwatchSystem>(new HK_StopwatchSystem());
}
}
通过系统层实例化一个Stopwatch实例,传入时间、回调方法等参数,进行初始化;
// 创建30秒倒计时
stopwatch = this.GetSystem<IHK_StopwatchSystem>().CreateStopwatch(30, () =>
{
HKDebug.Log("倒计时结束");
});
可注册Stopwatch实例的 RemainingTime 响应式属性进行使用;
// 绑定剩余时间显示(带初始值注册)
stopwatch.RemainingTime.RegisterWithInitValue((value) =>
{
txt_RemainingTime.text = $"剩余时间:{value:F1}秒";
}).UnRegisterWhenGameObjectDestroyed(gameObject);
可通过Stopwatch实例的 Start、Pause、Resume、Restart、Stop 方法,进行倒计时的控制;
btn_Start.onClick.AddListener(() =>
{
stopwatch?.Start();
});
btn_Pause.onClick.AddListener(() =>
{
stopwatch?.Pause();
});
btn_Resume.onClick.AddListener(() =>
{
stopwatch?.Resume();
});
btn_Restart.onClick.AddListener(() =>
{
stopwatch?.Restart();
});
btn_Stop.onClick.AddListener(() =>
{
stopwatch?.Stop();
});
具体用法,可参考 Test_Stopwatch 脚本。
public class Test_Stopwatch : MonoBehaviour, IController
{
public IArchitecture GetArchitecture()
{
return HK_ArchitectureProvider.Architecture;
}
[Header("UI Controls")]
[SerializeField] Button btn_CreateStopwatch; // 创建新计时器
[SerializeField] Button btn_Start; // 开始计时
[SerializeField] Button btn_Pause; // 暂停计时
[SerializeField] Button btn_Resume; // 恢复计时
[SerializeField] Button btn_Stop; // 停止并重置
[SerializeField] Button btn_Restart; // 重新开始
[Header("Display")]
[SerializeField] Text txt_RemainingTime; // 剩余时间显示文本
// 当前活动的倒计时实例
HK_Stopwatch stopwatch;
void Awake()
{
// 初始化按钮交互逻辑
btn_CreateStopwatch.onClick.AddListener(() =>
{
// 创建新实例前清理旧计时器
stopwatch?.Stop();
stopwatch = null;
// 创建30秒倒计时(测试用例)
stopwatch = this.GetSystem<IHK_StopwatchSystem>().CreateStopwatch(30, () =>
{
HKDebug.Log("倒计时结束");
});
// 绑定剩余时间显示(带初始值注册)
stopwatch.RemainingTime.RegisterWithInitValue((value) =>
{
txt_RemainingTime.text = $"剩余时间:{value:F1}秒";
}).UnRegisterWhenGameObjectDestroyed(gameObject);
});
btn_Start.onClick.AddListener(() =>
{
stopwatch?.Start();
});
btn_Pause.onClick.AddListener(() =>
{
stopwatch?.Pause();
});
btn_Resume.onClick.AddListener(() =>
{
stopwatch?.Resume();
});
btn_Restart.onClick.AddListener(() =>
{
stopwatch?.Restart();
});
btn_Stop.onClick.AddListener(() =>
{
stopwatch?.Stop();
});
}
}
外部依赖:
void OnMouseDown()
{
// 判断是否点击到UI,如果点击的是UI则返回
if (HKUtility.Instance.IsClickUI())
return;
Debug.Log("点击到了GameObject");
}
HKMonoUtility.Instance.GetJsonFromStreamingAssets<JsonData>("JsonDatas/TestData", jsonData =>
{
Debug.Log(jsonData.Name);
});
HKMonoUtility.Instance.GetSpriteFromStreamingAssets("Image/Texture.png", sprite =>
{
GetComponent<Image>().sprite = sprite;
});
本工具模仿 Maya 中的智能复制功能,用于智能复制选中的游戏对象。通过新增位置、旋转和缩放的偏移量,允许用户快速创建连续的、增量复制的游戏对象。这一功能类似于Maya中的复制功能,使得一些排列和布局任务变得更加高效,使用方式如下:
本工具模仿 Maya 中的打组功能,用于将选中的多个 Unity 游戏对象(GameObjects)打组操作。生成一个新的父对象,将所有选中的对象作为该新父对象的子对象,并将新父对象在层次视图中位置与第一个选中物体保持一致。使用方式如下:
本工具提供了在Unity中进行代办事项清单管理的功能,使用方法如下:
本工具提供了两大主要功能:替换选中物体名称中的特定字符串 和 对选中物体进行重命名。
该工具使得开发者可以更高效地管理游戏对象的命名,提高项目的组织和维护便利性。
使用方式如下:
本工具用于自动处理FBX及OBJ模型文件的导入设置。自动化设置如下:
本工具用于在导入贴图时自动检测并设置法线贴图的 TextureType 为 Normal map。自动化设置如下:
本工具,可帮助用户在指定的路径上生成多个GameObject实例,并配置其位置偏移和旋转偏移。用户可以通过该工具快速在场景中布置物体,提高工作效率。使用方式如下:
本工具是一个 Unity 编辑器扩展工具,旨在解决在 Unity 中导入或新建脚本时,因编码问题导致的中文字符乱码现象。
当在 Unity 中新建或导入脚本(例如 .cs 或 .csv 文件)时,若脚本的编码不是 UTF-8,可能会在 Inspector 面板预览或编辑脚本时出现中文乱码。为了自动解决这个问题,本工具会在资产导入过程中自动检测并转换脚本文件的编码。主要功能如下:
HK_HierarchyPro 是一款用于增强Unity编辑器中Hierarchy(层级)面板显示功能的实用工具。通过该工具,开发者可以更直观地查看对象的状态、层级和组件信息,从而有效提高工作效率。该工具具备以下主要功能:
使用方式如下:
HK_ProjectPro 用于在 Project 面板中为特定的文件夹显示自定义图标。这些文件夹包括但不限于脚本文件夹(Scripts)、预设体文件夹(Prefabs)、资源文件夹(Resources)等。该工具可以帮助开发者更直观地识别和管理项目中的不同类型文件夹,默认支持以下对应文件夹名称的图标显示(不区分大小写):
使用方式如下:
HK_InspectorPro 是一款用于增强Unity编辑器中 Inspector(监视器)面板显示功能的实用工具。主要功能如下:
增强一 HK_CSharpInspector C#脚本预览增强:
HK_ScenePro是一个用于增强 Unity 编辑器中 Scene 视图功能的工具。主要提供了类似于 Photoshop 中的标尺和参考线功能,方便开发者在 Scene 视图中进行UI或场景的精确布局和排版工作。主要功能如下:
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。