Пример #1
0
    void Update()
    {
        if (!dorfsSpawned)
        {
            dorfsSpawned = true;
            for (int i = 0; i < 1; i++)
            {
                Vector3Int middleOfMap = new Vector3Int(GridMap.Instance.GetSize().x / 2, 0, GridMap.Instance.GetSize().z / 2);
                spawnedDorfs.Add(DorfComponent.InstantiateDorf(middleOfMap).gameObject);
            }
        }

        if (GridMap.Instance.IsGenerationDone() && correctDorfPositions)
        {
            correctDorfPositions = false;
            foreach (GameObject g in spawnedDorfs)
            {
                GridActor  actor  = g.GetComponent <GridActor>();
                Vector3Int pos    = actor.Position;
                Vector3Int newPos = Vector3Int.zero;
                for (int y = 0; y < GridMap.Instance.GetSize().y; y++)
                {
                    newPos = new Vector3Int(pos.x, y, pos.z);
                    if (GridMap.Instance.GetBlock(newPos).SupportsWalkingThrough())
                    {
                        break;
                    }
                }

                actor.Move(newPos);
            }
        }
    }
Пример #2
0
    public static DorfComponent InstantiateDorf(Vector3Int spawnPos)
    {
        GameObject prefabObj = PrefabLoader.GetPrefab <GameObject>(prefabName);
        GameObject obj       = Instantiate(prefabObj) as GameObject;

        obj.name = "Dorf_" + obj.GetInstanceID().ToString();
        if (!obj)
        {
            throw new System.Exception("Could not instantiate prefab " + prefabName);
        }
        DorfComponent dorf = obj.GetComponent <DorfComponent>();

        if (!dorf)
        {
            throw new System.Exception("No DorfController Component on " + prefabName);
        }
        dorf.gridActor = dorf.GetComponent <GridActor>();
        if (!dorf.gridActor)
        {
            throw new System.Exception("No GridActor on prefab " + prefabName);
        }
        dorf.gridActor.Move(spawnPos);
        dorf.logger = new LilLogger(obj.name);
        return(dorf);
    }