Comments (12)
SHAPEORIENTATION_UPY 是注释错误被隐藏了,已修复a458b25
其它的下划线变量我们是故意不让外部访问 这是ts的一种严谨模式功能"stripInternal": true。如果你想访问任何内部变量,但我们没有提供,可以告知我们,经过权衡会正式公开
from layaair.
Vector3的UP ZERO等常量希望开放,不然要在项目内定义
from layaair.
AnimatorControllerLayer希望开放currentPlayState,在一些逻辑下需要取动作原件,比如判断当前动作是否是循环动作,比如切换模型时需要处理动作同步
类似如下:
if (oldAnimator && this._animator) { let state: Laya.AnimatorState = oldAnimator.getControllerLayer(). **_currentPlayState**; let playState: Laya.AnimatorPlayState = oldAnimator.getCurrentAnimatorPlayState(); if (state && playState) { this._animator.play(state.name, 0, playState.normalizedTime); } }
from layaair.
在 8061ace 提交中公开了当前播放状态机,具体使用方式为 animator.getControllerLayer().getCurrentPlayState().animatorState,统一归类到动画播放状态信息中
from layaair.
Vector3的UP ZERO屏蔽的原因是因为在JS中无struct概念,vector3为class,公开Vector3.UP是一种极其危险的做法,开发者会经常无意中修改Vector3.UP,导致Vector3.UP值并非(0,1,0),连锁导致所有引用此变量的计算全都崩溃,我们曾收到大量疑似BUG的反馈均由此导致。通常像C#这种有struct概念的语言 我们会将vector3设计为struct,而非class,公开Vector3的UP和ZERO非常安全易用,但在LayaAir中由于我们采用TS(JS)语言,很遗憾,我们不能这么做。
from layaair.
Vector3的UP ZERO屏蔽的原因是因为在JS中无struct概念,vector3为class,公开Vector3.UP是一种极其危险的做法,开发者会经常无意中修改Vector3.UP,导致Vector3.UP值并非(0,1,0),连锁导致所有引用此变量的计算全都崩溃,我们曾收到大量疑似BUG的反馈均由此导致。通常像C#这种有struct概念的语言 我们会将vector3设计为struct,而非class,公开Vector3的UP和ZERO非常安全易用,但在LayaAir中由于我们采用TS(JS)语言,很遗憾,我们不能这么做。
了解了,这种我项目内自己定义。
from layaair.
@GuoLei1990
ts
是可以用 Readonly标记,
也可以利用Object.freeze
Vector3.UP = Object.freeze(new Vector3(0,1,0));
把属性锁定,防止修改
我也觉得你们写法并不是最舒服的
from layaair.
@eos3tion Readonly标记可以防止 Vector3.UP =new Vector3(100,100,100);但无法防止Vector3.UP.x=100,依然会造成Vector3.UP的实际值变化
from layaair.
@GuoLei1990 Readonly<T> 这个是可以的,你看下我上面那个对应的链接
https://www.typescriptlang.org/docs/handbook/release-notes/overview.html#improvements-for-readonlyarray-and-readonly-tuples
from layaair.
@eos3tion 很棒 试了一下 使用 readonly UP: Readonly<Vector3>
确实可以防止Vector3.UP.x=100。但另一个可能更常见的风险还是无法规避。
例如:
var out=Vector3.ZERO;
Vector3.add(a,b,out);
Vector3.add方法内部会对out做修改
不过 Readonly可能会对其它API的设计有帮助
from layaair.
@GuoLei1990 这种,tsservice目前没法直接报错,不过用Object.freeze是能强制锁死属性的。这种倒是不怕被误用,修改 Vector3.ZERO的属性
from layaair.
@eos3tion 目前看功能是可行的,我们需要对Object.freeze的性能进行一下测试,如果没有发现问题,后续可能会应用此方法
from layaair.
Related Issues (20)
- SpineTemplet内存泄漏
- 销毁节点后存在资源内存泄露
- Can't manage folder structure after finished project HOT 1
- 2.13.3 drawPath的arcTo方法计算错误 HOT 1
- 源码编译异常 HOT 1
- 支持微信小游戏AR吗?
- How can I convert canvas which playing live video into Laya.Sprite?
- “mediaDevices”返回 null
- shader中无效的#define来回切换shader导致性能下降
- When running the game on iPhone, the loading animation will reload the website HOT 1
- box2d物理碰撞onTriggerEnter获取碰撞位置百分百异常
- animation layer blend with mask not work when use Laya.Sprite3D.instantiate() to clone a sprite.
- 支持自定义shader类型,或者支持扩展渲染节点类型?
- PBR材质法线在移动端 webgl1中显示错误 HOT 1
- 请问如何设置加速度或者改变重力方向或者设置某个方向的力 HOT 1
- map sprite y calculation might be wrong HOT 1
- 安卓崩溃率非常的高,定位到liblayaair.so
- 能否增加类似CSS box-sizing: border-box 的属性?
- 3.0 透明相机报错 HOT 1
- Android Laya无法运行第二次 必崩
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from layaair.