예제 #1
0
    protected void UpdateNeighborOffsets(bool forceRecalculation)
    {
        Vector3 zoneDimensions = this.GetComponent <LevelAttributes> ().zoneDimensions;

        if (forceRecalculation || zoneDimensions != this.lastUsedZoneDimensions)
        {
            this.neighborOffsets.Clear();

            this.foreignNeighborOffsets.Clear();

            this.lastUsedZoneDimensions = zoneDimensions;

            //update the neighbors
            foreach (Vector3 nextLoc in this.neighborsRelativeGridLocation)
            {
                Vector3 neighborPosition = VectorOperators.Multiply(nextLoc, zoneDimensions);

                this.neighborOffsets.Add(neighborPosition);
            }

            //now update foreign neighbors
            foreach (Vector3 nextLoc in this.foreignNeighborRelativeGridLocation)
            {
                Vector3 fNeighborPosition = VectorOperators.Multiply(nextLoc, zoneDimensions);

                this.foreignNeighborOffsets.Add(fNeighborPosition);
            }
        }
    }
예제 #2
0
    protected void CreateSpawnAreaAtMatrixCoords(
        Vector3 matrixPosition, Vector3 matrixMinPoint, RegionAttributes attributes)
    {
        /*
         * Debug.Log (
         *      "Creating A Spawn Area Within Matrix Cell\n"
         + "\t matrixPosition:[" + matrixPosition.x + "," + matrixPosition.y + "," + matrixPosition.z + "]"
         + "\t matrixMinPoint:[" + matrixMinPoint.x + "," + matrixMinPoint.y + "," + matrixMinPoint.z + "]"
         + );
         */

        Transform nextSpawnAreaTransform = this.region.spawnAreaPool.Spawn(this.spawnAreaPrefab);

        if (nextSpawnAreaTransform != null)
        {
            SpawnArea nextSpawnArea = nextSpawnAreaTransform.GetComponent <SpawnArea> ();

            if (nextSpawnArea != null)
            {
                //ready to calculate the center point
                Vector3 nextSpawnAreaCenter =
                    VectorOperators.Multiply(attributes.spawnerSize, matrixPosition) + matrixMinPoint;

                /*
                 * Debug.Log (
                 *      "Placing The Spawn Area" + nextSpawnArea.ToString () + "\n"
                 + "\t nextSpawnAreaCenter:[" + nextSpawnAreaCenter.x
                 + "," + nextSpawnAreaCenter.y
                 + "," + nextSpawnAreaCenter.z + "]"
                 + );
                 */

                /*
                 * we know that if nextSpawnArea is not null, it has a BoxCollider because it is a
                 * required component
                 */
                BoxCollider bbox = nextSpawnArea.GetComponent <BoxCollider> ();

                bbox.size = attributes.spawnerSize;

                bbox.center = nextSpawnAreaCenter;

                this.ZonePopulator.spawnAreas.Add(nextSpawnArea);

                return;                 //we can exit now, as we have completed successfully
            }
        }

        //something went wrong, and we didn't create the spawn area as expected
        Debug.LogError(
            "Unable to create a new spawn area at "
            + (matrixPosition + matrixMinPoint).ToString()
            );
    }