コード例 #1
0
    private void OnTownPlaced(PlaceTownResponse response)
    {
        if (PlayerPrefs.GetInt(GlobalConstants.TUTORIAL_COMPLETE_PROPERTY) != 3)
        {
            return;
        }

        Debug.Log("First town placed, end tutorial");

        // first town placed. Register it and
        // set camera position to it (at least x and z coords, y coord should be set when terrain is ready)

        var newTown = new Gardarike.Town();

        newTown.X          = (long)response.Location.X;
        newTown.Y          = (long)response.Location.Y;
        newTown.Population = 0;
        newTown.OwnerName  = PlayerPrefs.GetString(GlobalConstants.COUNTRY_NAME_PROPERTY);
        newTown.Name       = PlayerPrefs.GetString(GlobalConstants.CAPITAL_NAME_PROPERTY);

        firstTown = newTown;

        PlayerPrefs.SetInt(GlobalConstants.TUTORIAL_COMPLETE_PROPERTY, 4);

        // LoadMap
        var chunkPos = Utility.ToChunkPos(Utility.FromServerCoords(newTown.X, newTown.Y, 0, 0));

        TerrainGenerator.instance.LoadMap(chunkPos.x, chunkPos.y);
    }
コード例 #2
0
    public GameObject RegisterServerTown(Gardarike.Town town, int chunkX, int chunkY)
    {
        Debug.Log(town);
        var gameCoords = Utility.FromServerCoords(town.X, town.Y, chunkX, chunkY);

        town.X = (long)gameCoords.x;
        town.Y = (long)gameCoords.z;
        return(InitTown(town, new Quaternion()));
    }
コード例 #3
0
    private Town ConfigureTownComponent(GameObject townObject, Gardarike.Town townParameters, Quaternion rotation)
    {
        //var component = townObject.AddComponent<Town>();
        var component = townObject.GetComponent <Town>();

        component.Init(townParameters);
        component.Rotate(rotation);

        return(component);
    }
コード例 #4
0
    private GameObject InitTown(Gardarike.Town town, Quaternion rotation)
    {
        var townObject = Instantiate(referenceTown);

        townObject.transform.position = Utility.GetGroundedPointForBuildings(town.X, town.Y);
        var townComponent = ConfigureTownComponent(townObject, town, rotation);

        townObject.transform.parent = this.transform;
        townObject.SetActive(true);

        towns.Add(townComponent);

        return(townObject);
    }
コード例 #5
0
    public void BuildTown(Transform transform)
    {
        var newTown = new Gardarike.Town();

        newTown.OwnerName  = PlayerPrefs.GetString(GlobalConstants.COUNTRY_NAME_PROPERTY);
        newTown.Name       = "New town " + Random.Range(0, 999);
        newTown.Population = 0;
        newTown.X          = (long)transform.position.x;
        newTown.Y          = (long)transform.position.z;

        InitTown(newTown, transform.localRotation);

        EventBus.instance.SendNewTownRequest(Utility.ToServerCoordinates(transform.position), newTown.Name, transform.rotation.y);
    }