【Unity 框架】QFramework v1.0 使用指南 工具篇:08. FluentAPI 链式 API | Unity 游戏框架 | Unity 游戏开发 | Unity 独立游戏

FluentAPI 简介

FluentAPI 是 笔者积累的 Unity API 的一些链式封装。

基本使用非常简单,如下:

// traditional style
var playerPrefab = Resources.Load<GameObject>("no prefab don't run");
var playerObj = Instantiate(playerPrefab);

playerObj.transform.SetParent(null);
playerObj.transform.localRotation = Quaternion.identity;
playerObj.transform.localPosition = Vector3.left;
playerObj.transform.localScale = Vector3.one;
playerObj.layer = 1;
playerObj.layer = LayerMask.GetMask("Default");

Debug.Log("playerPrefab instantiated");

// Extension's Style,same as above 
Resources.Load<GameObject>("playerPrefab")
    .Instantiate()
    .transform
    .Parent(null)
    .LocalRotationIdentity()
    .LocalPosition(Vector3.left)
    .LocalScaleIdentity()
    .Layer(1)
    .Layer("Default")
    .ApplySelfTo(_ => { Debug.Log("playerPrefab instantiated"); });

代码很简单。

FluentAPI 包含 100 多个常用 API 的链式封装,具体可以参考编辑器内文档。

image.png

另外 链式 API 可以与 QFramework 的其他模块配合使用事半功倍,比如 ResKit 与 FluentAPI 结合,参考代码如下:

mResLoader.LoadSync<GameObject>("mygameobj")
  .InstantiateWithParent(parent)
  .transform
  .LocalIdentity()
  .Name("MyGameObj")
  .Show();

链式 API 就介绍到这里。

地址

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

凉鞋的笔记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值