Inheritance: MonoBehaviour
    private void Start()
    {
        int len = matRandomizations.Length;

        for (int i = 0; i < len; i++)
        {
            RandomMaterial matRandomization = matRandomizations[i];
            Renderer       renderer         = matRandomization.renderer;
            Material[]     mats             = matRandomization.mats;

            if (renderer == null)
            {
                renderer = gameObject.GetComponent <Renderer>();
            }
            if (renderer != null && mats.Length > 0)
            {
                renderer.material = mats[Random.Range(0, mats.Length)];
            }
        }

        len = tintRandomizations.Length;
        for (int i = 0; i < len; i++)
        {
            RandomTint tint = tintRandomizations[i];
            tint.material.color = tint.colors[Random.Range(0, tint.colors.Length)];
        }

        if (destroyScript)
        {
            Destroy(this);
        }
    }
Esempio n. 2
0
    IEnumerator dataPlanetRestGet()
    {
        PlanetType      dataPlanet = null;
        UnityWebRequest api        = UnityWebRequest.Get(restUrl + "/planettype/" + this.planetMass.ToString() + "&" + this.planetRadio.ToString() + "&" + this.solarTemp.ToString()
                                                         + "&" + this.solarTemp.ToString() + "&" + this.solarMass.ToString() + "&" + this.mayorAxis);

        yield return(api.SendWebRequest());

        if (api.isNetworkError || api.isHttpError)
        {
            Debug.Log(api.error);
        }
        else
        {
            dataPlanet = JsonUtility.FromJson <PlanetType>(api.downloadHandler.text);
        }
        float      solarMass   = starProvider.GetComponent <StarProvider>().uniqueStar().GetComponent <Star>().masa;
        float      starRadius  = starProvider.GetComponent <StarProvider>().uniqueStar().GetComponent <Star>().radio;
        float      rocheLimit  = starRadius * 0.0046f * Mathf.Pow((2.0f * bodyDensity(solarMass * 1.989f * Mathf.Pow(10, 30), starRadius * 695510000f)) / bodyDensity(planetMass * 5.972f * Mathf.Pow(10, 24), planetRadio * 6371000), 1 / 3f);
        GameObject planetNewGO = Instantiate(planet, transform.position, Quaternion.Euler(-90, 0, 0));
        GameObject botonNewGO  = Instantiate(botonPlaneta, contenedor) as GameObject;

        botonNewGO.GetComponent <BotonNaveUI>().Inicializar(planetNewGO.GetComponent <RecursosPlaneta>(), this.planeta);
        float  radioUnity = (1 + (0.1f * planetRadio)) * 0.05f;
        Planet planetNew  = planetNewGO.GetComponent <Planet>();

        planetNew.transform.localScale = Vector3.one * 2 * radioUnity;
        RandomMaterial randomPlanet = planetNewGO.GetComponent <RandomMaterial>();
        string         type         = dataPlanet.type;

        /* switch (type)
         * {
         *       case "Gaseoso":
         *               randomPlanet.tipo = TipoPlaneta.gaseoso;
         *               break;
         *       case "Habitable":
         *               randomPlanet.tipo = TipoPlaneta.habitable;
         *               break;
         *       case "Solido":
         *               randomPlanet.tipo = TipoPlaneta.solido;
         *               break;
         *       default:
         *               randomPlanet.tipo = TipoPlaneta.luna;
         *               break;
         * }*/
        print("TIPO: " + type);
        randomPlanet.AsignarTipo(type);
        randomPlanet.Generar();

        StarProvider starprov = starProvider.GetComponent <StarProvider>();
        Star         star     = starprov.uniqueStar().GetComponent <Star>();

        planetNew.setParameters(planeta, mayorAxis, excentricity, planetRadio, star, rocheLimit, type);
        planetList.Add(planetNewGO);
    }