コード例 #1
0
    private Vector3 GetSpawnLocation(DeployableUnit unit)
    {
        // TODO use unit.UnitPrefab.GetComponent<Collider>().bounds to find more info about space needs
        var stepCount = Mathf.RoundToInt(SpawnScanAngle / SpawnAngleStep);

        for (var i = 0; i < stepCount; i++)
        {
            // Does the ray intersect any objects excluding the player layer
            var  angle = transform.eulerAngles.y - SpawnScanAngle / 2 + SpawnAngleStep * i;
            var  dir   = DirectionFromAngle(angle, true);
            var  hits  = Physics.RaycastAll(gameObject.transform.position, dir, MaxUnitSpawnDistance);
            bool open  = false;
            foreach (var hit in hits)
            {
                //Hit anything that wasnt deployable itself
                if (hit.collider.gameObject != gameObject)
                {
                    open = false;
                    break;
                }
            }
            if (open)
            {
                return(transform.position + dir + new Vector3(size.x, 0, size.z));
            }
        }
        //TODO make a TryGet and then report if the entire area is full of stuff
        return(transform.position + new Vector3(size.x, 10f, size.z));
    }
コード例 #2
0
 private void SpawnUnit(DeployableUnit unit)
 {
     Instantiate(unit.UnitPrefab, GetSpawnLocation(unit), Quaternion.identity, null);
 }
コード例 #3
0
 public DeployProgress(DeployableUnit unit)
 {
     Unit = unit;
     SceneTimeStartSeconds = Time.time;
 }