Coder Social home page Coder Social logo

Comments (12)

GuoLei1990 avatar GuoLei1990 commented on May 22, 2024

SHAPEORIENTATION_UPY 是注释错误被隐藏了,已修复a458b25
其它的下划线变量我们是故意不让外部访问 这是ts的一种严谨模式功能"stripInternal": true。如果你想访问任何内部变量,但我们没有提供,可以告知我们,经过权衡会正式公开

from layaair.

HiKit avatar HiKit commented on May 22, 2024

Vector3的UP ZERO等常量希望开放,不然要在项目内定义

from layaair.

HiKit avatar HiKit commented on May 22, 2024

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.

GuoLei1990 avatar GuoLei1990 commented on May 22, 2024

8061ace 提交中公开了当前播放状态机,具体使用方式为 animator.getControllerLayer().getCurrentPlayState().animatorState,统一归类到动画播放状态信息中

from layaair.

GuoLei1990 avatar GuoLei1990 commented on May 22, 2024

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.

HiKit avatar HiKit commented on May 22, 2024

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.

eos3tion avatar eos3tion commented on May 22, 2024

@GuoLei1990
ts是可以用 Readonly标记,
也可以利用Object.freeze

Vector3.UP = Object.freeze(new Vector3(0,1,0));

把属性锁定,防止修改
我也觉得你们写法并不是最舒服的

from layaair.

GuoLei1990 avatar GuoLei1990 commented on May 22, 2024

@eos3tion Readonly标记可以防止 Vector3.UP =new Vector3(100,100,100);但无法防止Vector3.UP.x=100,依然会造成Vector3.UP的实际值变化

from layaair.

eos3tion avatar eos3tion commented on May 22, 2024

@GuoLei1990 Readonly<T> 这个是可以的,你看下我上面那个对应的链接
https://www.typescriptlang.org/docs/handbook/release-notes/overview.html#improvements-for-readonlyarray-and-readonly-tuples

from layaair.

GuoLei1990 avatar GuoLei1990 commented on May 22, 2024

@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.

eos3tion avatar eos3tion commented on May 22, 2024

@GuoLei1990 这种,tsservice目前没法直接报错,不过用Object.freeze是能强制锁死属性的。这种倒是不怕被误用,修改 Vector3.ZERO的属性

from layaair.

GuoLei1990 avatar GuoLei1990 commented on May 22, 2024

@eos3tion 目前看功能是可行的,我们需要对Object.freeze的性能进行一下测试,如果没有发现问题,后续可能会应用此方法

from layaair.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.