Exemple #1
0
        public bool RandomizeObjectPosition_2(Spawnable spnbl)
        {
            Vector2Int cellSize = new Vector2Int
            {
                x = Mathf.CeilToInt(spnbl.physicsCollider.bounds.extents.x / mainGraph.nodeSize),
                y = Mathf.CeilToInt(spnbl.physicsCollider.bounds.extents.y / mainGraph.nodeSize)
            };

            var offset = new Vector2Int
            {
                x = Mathf.CeilToInt(spnbl.physicsCollider.offset.x / mainGraph.nodeSize),
                y = Mathf.CeilToInt(spnbl.physicsCollider.offset.y / mainGraph.nodeSize)
            };

            var randomPerlinNode = RandomPerlinNode + offset;
            var selectedNode     = mainGraph.GetNode(randomPerlinNode.x, randomPerlinNode.y);

            if (selectedNode == null)
            {
                Debug.Log("null selected node");
                return(false);
            }


            IntRect bounds = new IntRect
            {
                xmin = randomPerlinNode.x - cellSize.x,
                ymin = randomPerlinNode.y - cellSize.y,
                xmax = randomPerlinNode.x + cellSize.x,
                ymax = randomPerlinNode.y + cellSize.y
            };


            var buffer = new GridNodeBase[10];
            var pts    = mainGraph.GetNodesInRegion(bounds, buffer);

            for (int i = 0; i < pts; i++)
            {
                buffer[i].Walkable = false;
            }

            Debug.Log(selectedNode.position);
            Debug.Log((Vector3)selectedNode.position);

            spnbl.transform.position = (Vector3)selectedNode.position;
            return(true);
        }
Exemple #2
0
        private void AnyRandomizeObjectPosition(Spawnable spnble, Func <Vector2> randomMethod)
        {
            var spnbleCollider = spnble.physicsCollider;
            var boundsSize     = spnbleCollider.bounds.size + (Vector3)(spnble.Radius * Vector2.one);

            for (int i = 0; i < MAX_ITERATIONS; i++)
            {
                var newPos = randomMethod();
                spnble.transform.position = newPos;
                var takenNodes = IsFree(new Bounds(newPos + spnbleCollider.offset, boundsSize));
                if (takenNodes != null)
                {
                    spnble.takenNodes = takenNodes;
                    return;
                }
            }
            Debug.LogError(gameObject.name + " Couldn't find free space for " + spnble.name);
        }
Exemple #3
0
        private void SpawnableDeath(Spawnable spawnable)
        {
            spawnable.onThisDeath -= SpawnableDeath;
            currentSpawned.Remove(spawnable);

            if (spawnable.takenNodes == null)
            {
                return;
            }
            if (AstarData.active == null)
            {
                return;
            }
            foreach (var g in spawnable.takenNodes.TakeWhile(g => g != null))
            {
                g.Walkable = true;
            }
            ListPool <GraphNode> .Release(spawnable.takenNodes);

            spawnable.takenNodes = null;
        }
Exemple #4
0
 private void SpawnableDeath(Spawnable spawnable)
 {
     queuePool.Enqueue(spawnable.spawnerIndex);
 }
Exemple #5
0
 public void PerlinRandomizeObjectPosition(Spawnable spnble) =>
 AnyRandomizeObjectPosition(spnble, GetRandomPointWithinSpawnerPerlinNoise);
Exemple #6
0
 public void RandomizeObjectPosition(Spawnable spnble) =>
 AnyRandomizeObjectPosition(spnble, GetRandomPointWithinSpawner);