コード例 #1
0
    protected override void OnUpdate()
    {
        var commandBuffer = commandBufferSystem.CreateCommandBuffer();

        Entities.
        WithAll <UninitializedRobotTag>().
        ForEach((Entity entity, ref RobotMovementData robotMovementData, in Translation trans, in ParentGoliathData goliathData) =>
        {
            BuildMeshData buildMeshData = EntityManager.GetComponentObject <BuildMeshData>(goliathData.goliath);

            robotMovementData.lerpValue      = 0;
            robotMovementData.startPos       = trans.Value;
            robotMovementData.claimedPolygon = GetAndClaimNextFreePolygon(buildMeshData.freePolygons);
            robotMovementData.targetNormal   = GetNormalOfPolygon(robotMovementData.claimedPolygon, buildMeshData.buildMesh);
            robotMovementData.target         = GetCenterOfPolygon(robotMovementData.claimedPolygon, buildMeshData.buildMesh);
            robotMovementData.movementSpeed  = 5;

            FixedJoint joint = new FixedJoint();
            EntityManager.AddComponentObject(entity, joint);
            commandBuffer.AddComponent(entity, new Parent {
                Value = goliathData.goliath
            });
            commandBuffer.AddComponent(entity, new LocalToParent {
            });

            commandBuffer.RemoveComponent(entity, typeof(UninitializedRobotTag));
            commandBuffer.AddComponent(entity, typeof(FlyingRobotTag));
        })
コード例 #2
0
    int GetNrOfFreePolygons(BuildMeshData buildMeshData)
    {
        int nrOfFreePolygons = 0;

        for (int i = 0; i < buildMeshData.freePolygons.Length; i++)
        {
            if (buildMeshData.freePolygons[i] != -1)
            {
                nrOfFreePolygons++;
            }
        }
        return(nrOfFreePolygons);
    }