No, more like data for template objects (not only that, but now it is), which I do not want to multiply together with templates when instantiating them, also the possibility of throwing a certain data object on multiple templates.
In the last project, it was data for obstacles (one of usecases). On the actual object itself, there was only a reference to the data object (characteristics, various arrays), but to assign it i need either create the object in real time (which I did for level generation), or make a system identifiers (in case you need to support both real-time generation and simple placement of an obstacle on the stage, which you would like at least in the process of development and testing.
If I could create this data object at the file level (literally a ScriptableObject) instead of an entity, it would be much more convenient.
/// data can be more complex, but here is an example
var ObstacleData = pc.createScript('obstacleData');
ObstacleData.attributes.add('templateAsset', {type: 'asset', assetType:'template'});
ObstacleData.attributes.add('stepsWidth', {type: 'number', precision: 0, default: 1});
ObstacleData.attributes.add('hitSound', {type:'asset', assetType:'audio'})
ObstacleData.attributes.add('actions', {
type: 'json',
array: true,
schema: [
{
name: 'func',
type: 'string',
enum: [
{ 'hide': 'hide' },
{ 'applyDamage': 'applyDamage' },
{ 'delay': 'delay' },
{ 'addHealth': 'addHealth' },
{ 'addMoney': 'addMoney' },
{ 'addFire': 'addFire' },
{ 'addMagnet': 'addMagnet' },
]
},
{
name: 'param',
type: 'string',
},
]
});
ObstacleData.prototype.initialize = function() {
this.entity.data = this;
};
////some logic from pooling and data linking
const newPoolEntity = new pc.Entity(node.entity.name);
this.entity.addChild(newPoolEntity);
newPoolEntity.addComponent('script',)
const newPool = newPoolEntity.script.create('entityPool', {attributes:
{
templateAsset: node.entity.data.templateAsset,
startSize: node.poolCount,
}});
newPool.data = node.entity.data; // linking data data <- pool <- poolItem
this.poolsMap.set(node.entity.data.templateAsset.id, newPool);