示例#1
0
文件: Tooltip.cs 项目: hc20k/Solar-AR
    void LoadInfo()
    {
        PlanetJSON data = JsonUtility.FromJson <PlanetJSON>(GameObject.Find("Manager").GetComponent <Manager>().planetInfoJSON.text);

        foreach (PlanetInfo _pInfo in data.planets)
        {
            if (_pInfo.name == planetName.ToLower())
            {
                planetInfo = _pInfo; break;
            }
        }

        if (planetInfo != null)
        {
            randomFunFact = planetInfo.fun_facts[Random.Range(0, planetInfo.fun_facts.Count)];
            descLabel.GetComponent <TextMeshProUGUI>().text    = planetInfo.description;
            funFactLabel.GetComponent <TextMeshProUGUI>().text = randomFunFact;
        }
        else
        {
            Debug.LogError("Failed to load info for " + planetName);
        }
    }
示例#2
0
    /*
     * CreateYear: Creates the year gameobject and instantiates the planets
     * Parameters: int yearIndex - Passes in the index of the selected year to grab from List<Year>
     */
    public void CreateYear(int yearIndex)
    {
        //Checks if the year the user is traveling to is the Home Year. No JSON file for the home year
        if (yearIndex != -1)
        {
            //Gets the name of the year in the list of years
            string yearName = list_years[yearIndex].yr_name;

            //Get the year object from the List via Index
            Year year = list_years[yearIndex];

            //Open the JSON file with the name yr_name parameter passed in
            //string jsonString = File.ReadAllText("VRClubUniverseData/" + yearName + ".json");
            string jsonString;

#if UNITY_EDITOR
            if (isOculus)
            {
                jsonString = File.ReadAllText(Application.dataPath + "/../Website/data/VRClubUniverseData/Oculus/" + yearName + ".json");
            }
            else
            {
                jsonString = File.ReadAllText(Application.dataPath + "/../Website/data/VRClubUniverseData/Vive/" + yearName + ".json");
            }
#elif UNITY_STANDALONE
            if (isOculus)
            {
                jsonString = File.ReadAllText(Application.dataPath + "/../VRClubUniverseData/Oculus/" + yearName + ".json");
            }
            else
            {
                jsonString = File.ReadAllText(Application.dataPath + "/../VRClubUniverseData/Vive/" + yearName + ".json");
            }
#endif

            //TESTING
            Debug.Log("Jsonstring is: " + jsonString);

            //Create a JSONPlanet array and read the JSON file
            PlanetJSON[] universe = JsonHelper.FromJson <PlanetJSON>(jsonString);

            //For each object in the JSONPlanet array
            //foreach (PlanetJSON json_planet in universe)
            List <string>     imagePaths = new List <string>();
            List <PassSprite> callbacks  = new List <PassSprite>();
            for (int i = 0; i < universe.Length; i++)
            {
                PlanetJSON json_planet = universe[i];

                //Instantiate a Planet object with a Planet component on it
                GameObject planet = Instantiate(prefab_planet, planetPosition, Quaternion.identity);

                //Set the name of the planet game object in hierarchy
                planet.name = "Planet";

                //Add a Planet component on the new planet game object to declare it a planet object
                PlanetController currPlanet = planet.GetComponent <PlanetController>();

                //Set the parent of the new Planet object to be the Planets gameobject
                planet.transform.parent = year.planets.transform;

                //Set the planet's name
                currPlanet.data.title = json_planet.Name;

                //Set the planet's creator
                currPlanet.data.creator = json_planet.Creator;

                //Set the planet's description
                currPlanet.data.description = json_planet.Description;

                //Set the planet's year
                currPlanet.data.year = json_planet.Year.ToString();

                //Set the planet's executable path
                currPlanet.data.executable = json_planet.Executable;

                //Set the planet's tags by creating a string array of the same length
                currPlanet.data.des_tag = new string[json_planet.Tags.Length];

                //For each tag in the json planet
                for (int j = 0; j < json_planet.Tags.Length; j++)
                {
                    // Set the tag of the current planet equal to the json tag
                    currPlanet.data.des_tag[j] = json_planet.Tags[j];
                }

                //Get the planet's image with path
                currPlanet.data.image_name = json_planet.Image;

                //Turn the image from path URL into a Sprite to set
                imagePaths.Add(ExecutableSwitch.GetFullPath(currPlanet.data.image_name, currPlanet.data.executable, currPlanet.data.year));
                callbacks.Add(currPlanet.ReceiveSprite);

                currPlanet.data.image = null;

                //Adds the read planet into the year
                year.list_planets.Add(currPlanet);

                Renderer rend     = currPlanet.GetComponent <Renderer>();
                Material material = Instantiate(rend.material);
                rend.material = material;
                ChangeValue val = GetComponentInChildren <ChangeValue>();
                if (i > universe.Length / 2)
                {
                    val.change(rend, currPlanet.data.title, int.Parse(currPlanet.data.year), false);
                }
                else
                {
                    val.change(rend, currPlanet.data.title, int.Parse(currPlanet.data.year), true);
                }
            }

            ImageLoader.GetInstance().LoadImages(imagePaths, callbacks);

            OrbitManager orbitManager = OrbitManager.GetOrbitManager();
            if (orbitManager != null)
            {
                orbitManager.PopulateOrbit(year.list_planets.ToArray());
            }
            else
            {
                Debug.LogError("Could not find OrbitManager to populate planets. Waiting for OrbitManager...");
                StartCoroutine(WaitForOrbit(year));

                /*
                 * orbitManager = OrbitManager.GetOrbitManager();
                 * if (orbitManager != null)
                 * {
                 *  orbitManager.PopulateOrbit(year.list_planets.ToArray());
                 * } else
                 * {
                 *  Debug.LogError("Still could not find OrbitManager to populate planets.");
                 * }
                 */
            }
        }

        // Handles case if the year traveling to is the new year
        else
        {
            // There shouldn't be any planets in the Home year
        }
    }