Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

[CODE] Get all Entities structure

Discussion in 'Project Tiny' started by TheFordeD, Feb 13, 2019.

  1. TheFordeD

    TheFordeD

    Joined:
    Jul 9, 2018
    Posts:
    32
    This code get a child-parent Entity structure:
    Code (JavaScript):
    1. static getChildStructure(world: ut.World, entity: ut.Entity): any[] {
    2.             var childCount = ut.Core2D.TransformService.countChildren(world, entity);
    3.             var entities: any[] = [];
    4.             for(var i = 0; i < childCount; i++) {
    5.                 var Entity: any = ut.Core2D.TransformService.getChild(world, entity, i);
    6.                 var childEntityCount = ut.Core2D.TransformService.countChildren(world, Entity);
    7.                 if(childEntityCount > 0) {
    8.                     var childEntities = this.getChildStructure(world, Entity);
    9.                     Entity.childNode = childEntities;
    10.                 }
    11.                 entities.push(Entity);
    12.             }
    13.  
    14.             return entities;
    15.         }
    var EntityTree = this.getChildStructure(this.world, RootEntityRef); 
    console.log(EntityTree.childNode.length);