Ejemplo n.º 1
0
    void Start()
    {
        JSONserializer json = new JSONserializer();

        locations = json.LoadLocations(PlayerInfo.currentPlanet.locations, PlayerInfo.currentPlanet.name);
        float planetScale = PlayerInfo.currentPlanet.planetScale; //Size of the planet

        planetMesh.transform.localScale = new Vector3(planetScale, planetScale, planetScale);
        planetMesh.material.SetTexture("_MainTex", PlayerInfo.currentPlanet.texture); //chnages the texture of the planet
        itemLibrary itL = new itemLibrary();

        itL.CreateLibraryFile();    //Temporary test, creates the JSON file of all the available items in the game

        foreach (Location location in locations)
        {
            GameObject gObject   = Instantiate(locationIcon);
            Vector3    planetPos = planetMesh.transform.position;
            gObject.transform.position = planetPos + location.position * planetScale * 0.5f;
            gObject.transform.parent   = planetMesh.transform;
            gObject.GetComponent <LocationIcon>().location = location;

            gObject.transform.rotation = Quaternion.LookRotation(-location.position);
        }
        float f = Random.Range(0.0f, 360.0f);

        planetMesh.transform.Rotate(Vector3.up, f);
        planetLight.transform.Rotate(Vector3.up, -f);
    }
Ejemplo n.º 2
0
    public void GenerateNewInventory(int amount)
    {
        itemLibrary    itL     = new itemLibrary();
        JSONserializer json    = new JSONserializer();
        List <Item>    itemLib = json.LoadItemLibrary(); //The list of all available items in the game, this should be moved somewhere where it won't be reloaded repeatedly

        int libraryLength = itemLib.Count;

        for (int i = 0; i < amount; i++)
        {
            int index = Random.Range(0, libraryLength);
            AddItem(itemLib[index]);
        }
    }
Ejemplo n.º 3
0
    public List <Item> LoadItemLibrary()
    {
        List <Item> items;

        try
        {
            string      location = Application.persistentDataPath + "/Data/ItemList.txt";
            string      s        = File.ReadAllText(location);            //Loads all the text in the file
            itemLibrary itemLib  = JsonUtility.FromJson <itemLibrary>(s); //DeSerializes the string just loaded
            items = itemLib.items;
        }
        catch
        {
            itemLibrary itemLib = new itemLibrary();
            itemLib.CreateLibraryFile();

            string location = Application.persistentDataPath + "/Data/ItemList.txt";
            string s        = File.ReadAllText(location);    //Loads all the text in the file
            itemLib = JsonUtility.FromJson <itemLibrary>(s); //DeSerializes the string just loaded
            items   = itemLib.items;
        }
        return(items);
    }
Ejemplo n.º 4
0
    public void CreateLibraryFile()
    {
        Directory.CreateDirectory(Application.persistentDataPath + "/Data");
        List <string> itemnames = new List <string>
        {
            "Robotics", "Resources", "Ship Parts", "Consumer Goods"
        };

        itemLibrary itemLib = new itemLibrary();

        foreach (string itName in itemnames)
        {
            Item item = new Item()
            {
                name = itName
            };
            itemLib.items.Add(item);
        }
        string outputString = JsonUtility.ToJson(itemLib);
        string location     = Application.persistentDataPath + "/Data/ItemList.txt";

        File.WriteAllText(location, outputString);
    }