Beispiel #1
0
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            NativeArray <Entity> entityArray = chunk.GetNativeArray(entityType);
            NativeArray <ToParallelCordonFormComponent> pCordonArray    = chunk.GetNativeArray(pCordonType);
            NativeArray <PoliceOfficerNumber>           officerNumArray = chunk.GetNativeArray(officerNumType);
            NativeArray <PoliceOfficerPoliceLineNumber> lineNumArray    = chunk.GetNativeArray(lineNumType);

            for (int i = 0; i < chunk.Count; i++)
            {
                Entity entity = entityArray[i];
                ToParallelCordonFormComponent pCordon       = pCordonArray[i];
                PoliceOfficerNumber           officerNumber = officerNumArray[i];
                PoliceOfficerPoliceLineNumber lineNumber    = lineNumArray[i];

                int officersInLine;
                if (lineNumber.Value == 0)
                {
                    officersInLine = pCordon.NumOfficersInLine1;
                }
                else if (lineNumber.Value == 1)
                {
                    officersInLine = pCordon.NumOfficersInLine2;
                }
                else
                {
                    officersInLine = pCordon.NumOfficersInLine3;
                }

                float xLocation;
                float leftside;
                float xOffset;

                if (officersInLine % 2 == 1) // if there are an odd number of police officers
                {
                    leftside = -((officersInLine / 2) * pCordon.OfficerSpacing + (officersInLine / 2) * pCordon.OfficerWidth);
                }
                else  // if there are an even number of police officers
                {
                    leftside = -(((officersInLine / 2) - 0.5f) * pCordon.OfficerSpacing + (officersInLine / 2) * pCordon.OfficerWidth);
                }
                xOffset   = (officerNumber.Value + 0.5f) * pCordon.OfficerWidth + officerNumber.Value * pCordon.OfficerSpacing;
                xLocation = leftside + xOffset;

                float topPosition = 1.5f * pCordon.OfficerLength + pCordon.LineSpacing;
                float zOffset     = -(lineNumber.Value * pCordon.LineSpacing + (0.5f + lineNumber.Value) * pCordon.OfficerLength);
                float zLocation   = topPosition + zOffset;

                commandBuffer.AddComponent <FormationLocation>(chunkIndex, entity, new FormationLocation {
                    Value = new float3(xLocation, 0f, zLocation)
                });
                commandBuffer.AddComponent <FormationRotation>(chunkIndex, entity, new FormationRotation {
                    Value = quaternion.RotateY(math.radians(0)) // rotate to forward
                });
                commandBuffer.AddComponent <PoliceOfficerOutOfFormation>(chunkIndex, entity, new PoliceOfficerOutOfFormation {
                });
                commandBuffer.RemoveComponent <ToParallelCordonFormComponent>(chunkIndex, entity);
            }
        }
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            NativeArray <Entity> entityArray = chunk.GetNativeArray(entityType);
            NativeArray <ToWedgeFormComponent>          wedgeArray      = chunk.GetNativeArray(wedgeType);
            NativeArray <PoliceOfficerNumber>           officerNumArray = chunk.GetNativeArray(officerNumType);
            NativeArray <PoliceOfficerPoliceLineNumber> lineNumArray    = chunk.GetNativeArray(lineNumType);

            for (int i = 0; i < chunk.Count; i++)
            {
                Entity entity = entityArray[i];
                ToWedgeFormComponent          wedge         = wedgeArray[i];
                PoliceOfficerNumber           officerNumber = officerNumArray[i];
                PoliceOfficerPoliceLineNumber lineNumber    = lineNumArray[i];

                int officerNumInUnit = 1;

                if (lineNumber.Value == 0) // if in the first line
                {
                    officerNumInUnit += officerNumber.Value;
                }
                else if (lineNumber.Value == 1) // if in the second line
                {
                    officerNumInUnit += officerNumber.Value + wedge.NumOfficersInLine1;
                }
                else   // if in the third line
                {
                    officerNumInUnit += officerNumber.Value + wedge.NumOfficersInLine1 + wedge.NumOfficersInLine2;
                }

                int relNumToFront = officerNumInUnit - wedge.MiddleOfficerNum;

                float frontOfficerZPos = ((float)wedge.MiddleOfficerNum / 2) * wedge.OfficerLength;
                float zOffset          = math.abs(relNumToFront) * wedge.OfficerLength;
                float zLocation        = frontOfficerZPos - zOffset;

                float xLocation = relNumToFront * wedge.OfficerLength * math.tan(math.radians(wedge.Angle / 2));

                quaternion formRot = quaternion.RotateY(math.radians(0));



                float3 formLocation = new float3(xLocation, 0f, zLocation);

                commandBuffer.AddComponent <FormationLocation>(chunkIndex, entity, new FormationLocation {
                    Value = formLocation
                });
                commandBuffer.AddComponent <FormationRotation>(chunkIndex, entity, new FormationRotation {
                    Value = formRot
                });
                commandBuffer.AddComponent <PoliceOfficerOutOfFormation>(chunkIndex, entity, new PoliceOfficerOutOfFormation {
                });
                commandBuffer.RemoveComponent <ToWedgeFormComponent>(chunkIndex, entity);
            }
        }
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            NativeArray <Entity> entityArray = chunk.GetNativeArray(entityType);
            NativeArray <ToSingleCordonFormComponent>   sCordonArray    = chunk.GetNativeArray(sCordonType);
            NativeArray <PoliceOfficerNumber>           officerNumArray = chunk.GetNativeArray(officerNumType);
            NativeArray <PoliceOfficerPoliceLineNumber> lineNumArray    = chunk.GetNativeArray(lineNumType);

            for (int i = 0; i < chunk.Count; i++)
            {
                Entity entity = entityArray[i];
                ToSingleCordonFormComponent   sCordon       = sCordonArray[i];
                PoliceOfficerNumber           officerNumber = officerNumArray[i];
                PoliceOfficerPoliceLineNumber lineNumber    = lineNumArray[i];


                int offNumInUnit = officerNumber.Value;

                if (lineNumber.Value >= 1)
                {
                    offNumInUnit += sCordon.NumOfficersInLine1;
                }
                if (lineNumber.Value == 2)
                {
                    offNumInUnit += sCordon.NumOfficersInLine2;
                }

                float leftPos   = (sCordon.NumOfficersInUnit - 1) * 0.5f * (sCordon.OfficerWidth + sCordon.OfficerSpacing);
                float xOffset   = offNumInUnit * (sCordon.OfficerWidth + sCordon.OfficerSpacing);
                float xLocation = -leftPos + xOffset;


                commandBuffer.AddComponent <FormationLocation>(chunkIndex, entity, new FormationLocation {
                    Value = new float3(xLocation, 0f, 0f)
                });
                commandBuffer.AddComponent <FormationRotation>(chunkIndex, entity, new FormationRotation {
                    Value = quaternion.RotateY(math.radians(0)) // rotate to forward
                });
                commandBuffer.AddComponent <PoliceOfficerOutOfFormation>(chunkIndex, entity, new PoliceOfficerOutOfFormation {
                });
                commandBuffer.RemoveComponent <ToSingleCordonFormComponent>(chunkIndex, entity);
            }
        }
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            NativeArray <Entity> entityArray = chunk.GetNativeArray(entityType);
            NativeArray <To3SidedBoxFormComponent>      boxArray        = chunk.GetNativeArray(boxType);
            NativeArray <PoliceOfficerNumber>           officerNumArray = chunk.GetNativeArray(officerNumType);
            NativeArray <PoliceOfficerPoliceLineNumber> lineNumArray    = chunk.GetNativeArray(lineNumType);

            for (int i = 0; i < chunk.Count; i++)
            {
                Entity entity = entityArray[i];
                To3SidedBoxFormComponent      box           = boxArray[i];
                PoliceOfficerNumber           officerNumber = officerNumArray[i];
                PoliceOfficerPoliceLineNumber lineNumber    = lineNumArray[i];


                int largerNumOfficers; // find the side line that has the bigger number of officers in it
                if (box.NumOfficersInLine1 > box.NumOfficersInLine3)
                {
                    largerNumOfficers = box.NumOfficersInLine1;
                }
                else
                {
                    largerNumOfficers = box.NumOfficersInLine3;
                }

                float backOfFrontLine = ((largerNumOfficers + 1f) / 2f) * box.OfficerSpacing + (largerNumOfficers / 2f) * box.OfficerWidth;

                float      xLocation;
                float      zLocation;
                int        officersInLine;
                float3     formLocation;
                quaternion formRot;

                if (lineNumber.Value == 0) // if on the left side of the box
                {
                    officersInLine = box.NumOfficersInLine1;
                    //xLocation = -backOfFrontLine + (officerNumber.Value+1) * box.OfficerSpacing + (officerNumber.Value + 0.5f) * box.OfficerWidth;
                    zLocation    = backOfFrontLine - ((box.NumOfficersInLine1 - officerNumber.Value) * box.OfficerSpacing + (box.NumOfficersInLine1 - 1 - officerNumber.Value + 0.5f) * box.OfficerWidth);
                    xLocation    = -(((box.NumOfficersInLine2 - 1f) / 2f) * (box.OfficerWidth + box.OfficerSpacing));
                    formLocation = new float3(xLocation, 0f, zLocation);
                    formRot      = quaternion.RotateY(math.radians(-90));
                    //formLocation = math.mul(formRot,formLocation);
                }
                else if (lineNumber.Value == 1) // if on the front side of the box
                {
                    officersInLine = box.NumOfficersInLine2;
                    zLocation      = backOfFrontLine + box.OfficerLength / 2f;
                    float leftside = -(((officersInLine - 1f) / 2f) * box.OfficerWidth + ((officersInLine - 1f) / 2f) * box.OfficerSpacing);
                    xLocation    = leftside + officerNumber.Value * box.OfficerWidth + officerNumber.Value * box.OfficerSpacing;
                    formLocation = new float3(xLocation, 0f, zLocation);
                    formRot      = quaternion.RotateY(math.radians(0));
                }
                else   // if on the right side of the box
                {
                    officersInLine = box.NumOfficersInLine3;
                    //xLocation = backOfFrontLine - ((box.NumOfficersInLine1 - officerNumber.Value + 1) *box.OfficerSpacing + (box.NumOfficersInLine1 - officerNumber.Value + 0.5f) * box.OfficerWidth);

                    zLocation    = backOfFrontLine - (officerNumber.Value + 1f) * box.OfficerSpacing - (officerNumber.Value + 0.5f) * box.OfficerWidth;
                    xLocation    = ((box.NumOfficersInLine2 - 1f) / 2f) * (box.OfficerWidth + box.OfficerSpacing);
                    formLocation = new float3(xLocation, 0f, zLocation);
                    formRot      = quaternion.RotateY(math.radians(90));
                    //formLocation = math.mul(formRot,formLocation);
                }

                commandBuffer.AddComponent <FormationLocation>(chunkIndex, entity, new FormationLocation {
                    Value = formLocation
                });
                commandBuffer.AddComponent <FormationRotation>(chunkIndex, entity, new FormationRotation {
                    Value = formRot
                });
                commandBuffer.AddComponent <PoliceOfficerOutOfFormation>(chunkIndex, entity, new PoliceOfficerOutOfFormation {
                });
                commandBuffer.RemoveComponent <To3SidedBoxFormComponent>(chunkIndex, entity);
            }
        }