throw-out/puerts-unity-kit

General Support Questions

Closed this issue · 4 comments

  • Is it possible to GetComponent for components defined in Ts by extending Xor.TsComponent? ditto for AddComponent
  • Does serialization work for Custom data types? or does that need to be customized? Would it be possible to ask for a feature to add byte[] serialization which would allow us to serialize any TS types? And maybe use SerializeReference for default editor support?
  • I was reading in the docs that a TsComponent needs to be marked with Xor.Guid is this a manual process?
  • How does the TsComponent find scripts/modules? is the search path configurable? For example if my tsconfig lives under Assets/
  • Can modules be loaded Over the air? For example if I load a unity asset bundle with compiled scripts or have a zip file in s3 with compiled scripts?

Thank you!

Please forgive my lack of English, the following content is from the robot.

  • In fact, the GetComponent(TS Type) method is implemented, and AddComponent is not necessary. xor.TsComponent is implemented to collaborate with Unity Serialization, and AddComponent cannot be added with any Serialization information. You can use xor.TsBehaviour to call Unity lifecycle functions.
  • You can add any of the serialized data types supported by Unity without modifying the framework code. The sample code can be viewed here. Serializing ts type references can be costly, cause unexpected problems, and the framework can't handle their instantiation order when they loop references.
  • xor.guid is automatically assigned by TsComponents Services without manual processing.
  • TsComponent will first try to get the ts constructor using xor.guid('guid value') and will try to load the cached script path if guid does not exist. The script path depends on the configuration of tsconfig.json and is usually a relative path to the files in the src/ directory. If you are using a builder such as webpack, you will be responsible for loading the entry script yourself, and the guid of all the constructors will be registered.

    The default path is project/TsProject tsconfig.json, you can through the menu Tools/XOR/Settings - Project Path to modify.
  • XOR.Application.Loader is XOR.MixerLoader, which allows multiple Puerts.ILoader instances to be added, and it calls them serially when in use. Each Puerts.ILoader instance can have its own implementation method, such as XOR.CacheLoader in the framework, you can download the script resource pack from the local cache, the network and extract the script content and then give it to him. You only need to prepare the corresponding ILoader before the Load script.

  • 事实上这里尝试实现了GetComponent(TS Type)方法, 而AddComponent是不必要的. xor.TsComponent是为了协作Unity Serialization实现的, 而AddComponent并不能携带任何Serialization信息. 你可以使用xor.TsBehaviour来调用Unity 生命周期函数.
  • 在不修改框架代码的前提下, 可以添加任意Unity支持的序列化数据类型, 示例代码可以查看这里.
    序列化ts类型引用的代价可能是可怕的, 会带来意料之外的问题 , 并且当它们循环引用时框架无法处理它们的实例化顺序.
  • xor.guid由TsComponents Services自动分配, 无需手动处理.
  • TsComponent首先会尝试使用xor.guid( 'guid value' )来获取ts构造函数, 当guid不存在时将尝试加载缓存的脚本路径. 脚本路径取决于tsconfig.json的配置, 通常是src/目录下的文件的相对路径. 如果你使用了webpack这类构建器, 此时你需要自行负责加载入口脚本, 然后所有构造函数的guid将被注册.

    框架默认的路径为project/TsProject/tsconfig.json, 你可以通过菜单Tools/XOR/Settings - Project Path来修改.
  • XOR.Application.Loader是XOR.MixerLoader, 它允许添加多个Puerts.ILoader实例, 在使用时它将串行调用它们. 每个Puerts.ILoader实例可以有各自不同的实现方法,例如框架中的XOR.CacheLoader, 你可以从本地缓存丶网络上下载脚本资源包并解压获取脚本内容然后交给他它. 你只需要在Load脚本前完成其对应的ILoader准备即可.

Please forgive my lack of English, the following content is from the robot.

  • In fact, the GetComponent(TS Type) method is implemented, and AddComponent is not necessary. xor.TsComponent is implemented to collaborate with Unity Serialization, and AddComponent cannot be added with any Serialization information. You can use xor.TsBehaviour to call Unity lifecycle functions.

  • You can add any of the serialized data types supported by Unity without modifying the framework code. The sample code can be viewed here. Serializing ts type references can be costly, cause unexpected problems, and the framework can't handle their instantiation order when they loop references.

  • xor.guid is automatically assigned by TsComponents Services without manual processing.

  • TsComponent will first try to get the ts constructor using xor.guid('guid value') and will try to load the cached script path if guid does not exist. The script path depends on the configuration of tsconfig.json and is usually a relative path to the files in the src/ directory. If you are using a builder such as webpack, you will be responsible for loading the entry script yourself, and the guid of all the constructors will be registered.

    The default path is project/TsProject tsconfig.json, you can through the menu Tools/XOR/Settings - Project Path to modify.

  • XOR.Application.Loader is XOR.MixerLoader, which allows multiple Puerts.ILoader instances to be added, and it calls them serially when in use. Each Puerts.ILoader instance can have its own implementation method, such as XOR.CacheLoader in the framework, you can download the script resource pack from the local cache, the network and extract the script content and then give it to him. You only need to prepare the corresponding ILoader before the Load script.

  • In fact, the GetComponent(TS Type) method is tried here , and AddComponent is unnecessary. xor.TsComponent is implemented to cooperate with Unity Serialization, and AddComponent cannot carry any Serialization information. You can use xor.TsBehaviour to call Unity life periodic function.

  • Without modifying the framework code, you can add any serialized data type supported by Unity. The sample code can be viewed here .
    The cost of serializing ts type references can be terrible, causing unexpected problems, and when they The framework cannot handle their instantiation order when circular references occur.

  • xor.guid is automatically assigned by TsComponents Services, no manual processing is required.

  • TsComponent will first try xor.guid( 'guid value' )to get the ts constructor, and when the guid does not exist, it will try to load the cached script path. The script path depends on the configuration of tsconfig.json, usually a src/relative path to the file in the directory. If you use webpack this Class builder, at this time you need to be responsible for loading the entry script, and then the guids of all constructors will be registered. The

    default path of the framework is project/TsProject/tsconfig.json, you can Tools/XOR/Settings - Project Pathmodify it through the menu.

  • XOR.Application.Loader is XOR.MixerLoader, which allows adding multiple Puerts.ILoader instances, which will be called serially when used. Each Puerts.ILoader instance can have its own different implementation method, such as XOR in the framework. CacheLoader, you can download the script resource package from the local cache or the network and decompress it to obtain the script content and then hand it to it. You only need to complete its corresponding ILoader preparation before loading the script.

Appreciated your answer. The question for AddComponent(TS Type) is mainly for runtime behavior, what if a user wanted to add the TS Component at runtime?

Try the following example:

class ClassA extends xor.TsBehaviour {
    protected Update(deltaTime?: number): void {
        console.log("Update is called every frame.");
    }
}

let unityObject: CS.UnityEngine.GameObject | CS.UnityEngine.Transform;
let obj = new ClassA(unityObject);

You need to manage the obj instance manually, and you should also avoid accessing it in C#, otherwise there may be a memory leak.


试试以下示例:

class ClassA extends xor.TsBehaviour {
    protected Update(deltaTime?: number): void {
        console.log("Update is called every frame.");
    }
}

let unityObject: CS.UnityEngine.GameObject | CS.UnityEngine.Transform;
let obj = new ClassA(unityObject);

你需要手动管理obj实例, 也应该避免在C#中直接访问它, 否则可能带来额外的内存泄漏问题.

Try the following example:

class ClassA extends xor.TsBehaviour {
    protected Update(deltaTime?: number): void {
        console.log("Update is called every frame.");
    }
}

let unityObject: CS.UnityEngine.GameObject | CS.UnityEngine.Transform;
let obj = new ClassA(unityObject);

You need to manage the obj instance manually, and you should also avoid accessing it in C#, otherwise there may be a memory leak.

试试以下示例:

class ClassA extends xor.TsBehaviour {
    protected Update(deltaTime?: number): void {
        console.log("Update is called every frame.");
    }
}

let unityObject: CS.UnityEngine.GameObject | CS.UnityEngine.Transform;
let obj = new ClassA(unityObject);

你需要手动管理obj实例, 也应该避免在C#中直接访问它, 否则可能带来额外的内存泄漏问题.

Thank you! does using constructor style adding work for adding to an existing GameObject?

Update: Tested and the syntax with constructor only works for TsBehavior not for TsComponent. Would be great if it worked for both! In general doesn't look like a hard thing to add?

Notes:

  • Constructor works but it assumes there's only a single TsBehavior on the GameObject. It should probably always assume you're adding a new component if you didn't pass the TsBehavior or TsComponent to the constructor.
  • TsComponent constructor seems to always assume you're working with an existing TsComponent so can't add dynamically at runtime, seems like an easy fix but have to modify .ts and typing.