Best way to associate Svelto Components with UnityGameObject #93
-
When creating UnityGameObject, it needs to be registered in OOPManager, and then SyncGameObject Render in xxxEngine is more convenient. Then there is a problem that when registering in OOPManager, it needs to return a globally unique ID, but When operating Svelto's Component in xxxEngine, the unique ID cannot be obtained, because the unique ID of GameObject is not recorded in Svelto's Component. What should I do in this situation? Because the Components obtained through entitiesDB.QueryEntities<> in xxxEngine are not I don't know which UnityGameObject it is. Here's a concrete example: I want to operate the alpha value of a game object. FadeoutComponent.cs
OOPManager.cs
InputEngine.cs
PlayerFadeoutHandleEngine.cs
My question is in the last line, what do I need to do to retrieve the corresponding UnityObject through the FadeoutComponent. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You can make a component that holds unique id of game object, such as ObjectIndexComponent here. (Maybe your public struct ObjectIndexComponent : IEntityComponent
{
public uint index;
public readonly PrimitiveType type;
public ObjectIndexComponent(PrimitiveType type) : this() { this.type = type; }
} Which can be assigned when GameObject is created. Such as here in SyncEntityCreation Engine. public void Add(ref ObjectIndexComponent entityComponent, EGID egid)
{
entityComponent.index = _oopManager.RegisterEntity(entityComponent.type);
} Then query both public void Step()
{
var (objectIndex, fadeout, count) = entitiesDB.QueryEntities<ObjectIndexComponent, FadeoutComponent>(PlayerTag.BuildGroup);
for (int i = 0; i < count; ++i)
{
this.m_oopManager.SetRenderAlpha(objectIndex[i].index, fadeout[i].AlphaValue);
}
} |
Beta Was this translation helpful? Give feedback.
You can make a component that holds unique id of game object, such as ObjectIndexComponent here. (Maybe your
GameObjectComponent
is doing the same thing?)Which can be assigned when GameObject is created. Such as here in SyncEntityCreation Engine.
Then query both
ObjectIndexComponent
andFadeoutComponent
fromPlayerFadeou…