Example #1
0
    void ShowInformations(float x, float y, PlanetUpdater pu)
    {
        labels = controler.GetComponentsInChildren <UILabel>();

        Pos.text    = x.ToString() + "," + y.ToString();
        planet.text = pu.name.ToString();

        //creation de la fenetre dynamic
        mat.items.Clear();
        foreach (var t in pu.materials)
        {
            if (selectedMat == null || pu.materials[selectedMat] == null)
            {
                selectedMat = t.Key;
            }
            mat.items.Add(t.Key);
        }
        mat.selection = selectedMat;

        Texture2D texture = pu.materials[selectedMat];

        Color c = ((Texture2D)texture).GetPixel((int)x, (int)y);

        //print("materiel selectionne : " + c.r + " " + c.g + " " + c.b);
        materiel.text = selectedMat + " : " + ((int)(((c.r + c.g + c.b) / 3.0F * 100.0F))).ToString() + 'p';
        //OnSelectionChange(selectedMat);
        //foreach (var t in pu.materials)
        //{
        //    p.selection = t.Key;
        //    Color c = ((Texture2D)t.Value).GetPixel ((int)x, (int)y);
        //    print("materiel selectionne : " + c.r + " " + c.g + " " + c.b);
        //    materiel.text = t.Key + " : " + ((int)(((c.r  + c.g  + c.b ) / 3.0F * 100.0F))).ToString() + 'p';
        //    return;
        //}
    }
Example #2
0
    void OnClick()
    {
        GameObject   manager = GameObject.Find("Manager");
        SystemLoader sys     = manager.GetComponent <SystemLoader>();

        foreach (GameObject p in sys.planets)
        {
            if (astre.selection == p.name)
            {
                planet = p.name;
                time   = w.elapsed;
                res.Add(time);
                PlanetUpdater updater = p.GetComponent <PlanetUpdater>();
                extraction(planet, time, updater.evolutions);
            }
        }
    }
Example #3
0
    public void setCamLookAt(GameObject planet)
    {
        print("setCamLookAt");
        if (planetLookedAt == planet)
        {
            return;
        }
        GameObject manager = GameObject.Find("Manager");

        if (manager && manager.GetComponent <UniverseTime>())
        {
            UniverseTime time = manager.GetComponent <UniverseTime>();
            time.Stop();
        }
        print("setCamLookAt does it");
        PlanetUpdater po  = planet.GetComponent <PlanetUpdater>();
        GameObject    cam = GameObject.Find("Main Camera");

        //if (cam.transform.parent == po.gameObject.transform)
        // return;
//        setCamFree();

        priv_indicator.SetActive(false);
        cam.GetComponent <SGT_CameraFreeLook>().enabled  = false;
        cam.GetComponent <SGT_CameraFreeOrbit>().enabled = true;
        float avgScale = (float)((planet.gameObject.transform.localScale.x + planet.gameObject.transform.localScale.y + planet.gameObject.transform.localScale.z) / 3.0);

        cam.GetComponent <SGT_CameraFreeOrbit>().Distance = (float)(avgScale + avgScale);
        print(cam.GetComponent <SGT_CameraFreeOrbit>().Distance);
        cam.GetComponent <SGT_CameraFreeOrbit>().DistanceMin = cam.GetComponent <SGT_CameraFreeOrbit>().Distance;
        cam.GetComponent <SGT_CameraFreeOrbit>().DistanceMax = cam.GetComponent <SGT_CameraFreeOrbit>().Distance;
        cam.transform.LookAt(planet.transform);
        planetLookedAt = planet;
//        cam.transform.position = cam.transform.position + (cam.transform.forward * (cam.transform.DistanceTo(planet.transform.position) - 1000));
        cam.transform.parent.transform.position = planet.transform.position;
    }
Example #4
0
    // Update is called once per frame
    void Update()
    {
        timer();
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (menuInGame.GetComponent <UIPanel>().alpha == 0)
            {
                menuInGame.GetComponent <UIPanel>().alpha = 1;
                menuInGame.SetActive(true);
            }
            else
            {
                menuInGame.GetComponent <UIPanel>().alpha = 0;
            }
        }
        if (Input.GetButton("Fire1"))
        {
            extractOK.SetActive(false);

            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            //// TODO: singletooon !
            GameObject   manager = GameObject.Find("Manager");
            SystemLoader sys     = manager.GetComponent <SystemLoader>();
            if (!sys || !sys.hasLoaded)
            {
                print("planet not leaded yet");
                return;
            }

            UniverseTime w = manager.GetComponent <UniverseTime>();

            if (controler.activeInHierarchy)
            {
                initPlanetList();
                foreach (GameObject p in sys.planets)
                {
                    Collider planetCollider = p.collider;
                    if (planetCollider != null && planetCollider.Raycast(ray, out hit, 1000.0f))
                    {
                        {
                            //Debug.DrawLine (ray.origin, hit.point);
                            //print ("hit! ");
                            Vector2 textureCoord = hit.textureCoord;
                            pu = p.GetComponent <PlanetUpdater>();
                            foreach (var t in pu.materials)
                            {
                                if (selectedMat == null || pu.materials[selectedMat] == null)
                                {
                                    selectedMat = t.Key;
                                }
                            }
                            textureCoord.x *= pu.materials[selectedMat].width;
                            textureCoord.y *= pu.materials[selectedMat].height;
                            //print(hit.textureCoord);
                            x = (int)textureCoord.x;
                            y = (int)textureCoord.y;
                            //print("pixel rock : " + pu.materials["rock"].GetPixel(x, y));
                            //print("pixel water : " + pu.materials["water"].GetPixel(x, y));
                            if (controler.activeInHierarchy)
                            {
                                ShowInformations(x, y, pu);

                                // parent the camera to the object looked at
                                //setCamFree();
                                setCamLookAt(p);

                                // update the local indicator
                                priv_indicator.SetActive(true);

                                priv_indicator.transform.parent        = pu.gameObject.transform;
                                priv_indicator.transform.localPosition = Vector3.zero;
                                priv_indicator.transform.localRotation = Quaternion.Euler(Vector3.zero);
                                priv_indicator.transform.localScale    = new Vector3(1, 1, 1);
                                // average of each scales (x and y and z)


                                priv_indicator.GetComponentInChildren <ParticleSystem>().startSpeed = initial_particle_speed * priv_indicator.transform.parent.localScale.x;
                                //print(hit.normal);
                                Quaternion quatHit = Quaternion.FromToRotation(Vector3.up, hit.point - pu.transform.position);

                                //print("quatHit: " + quatHit);

                                priv_indicator.transform.rotation = quatHit;
                                //print("rotation: " + priv_indicator.transform.rotation);

                                return;
                            }
                        }
                    }
                }
            }
        }
    }
Example #5
0
    void loadFromAstralInfo(Dictionary <string, object> dictPlanet)
    {
        print("dictPlanet['name']: " + dictPlanet["name"]);
        GameObject instance;

        if (dictPlanet["type"].Equals("star"))
        {
            instance = Instantiate(Resources.Load("Prefabs/Star")) as GameObject;
        }
        else if (dictPlanet["type"].Equals("gazeous"))
        {
            instance = Instantiate(Resources.Load("Prefabs/Gas Giant")) as GameObject;
        }
        else
        {
            instance = Instantiate(Resources.Load("Prefabs/PlanetSphere")) as GameObject;
        }
        string evolutionInfo  = Load(rootFolder + dictPlanet["evolution"]);
        var    dictEvolutions = Json.Deserialize(evolutionInfo) as Dictionary <string, object>;
        var    evolutionList  = dictEvolutions["evolutions"] as List <object>;

        var dictEvolution = evolutionList[0] as Dictionary <string, object>;

        print("full position: " + ((Dictionary <string, object>)dictEvolution["pos"])["x"] + ";" + ((Dictionary <string, object>)dictEvolution["pos"])["y"] + ";" + ((Dictionary <string, object>)dictEvolution["pos"])["z"]);
        long x    = (long)((Dictionary <string, object>)dictEvolution ["pos"]) ["x"];
        long y    = (long)((Dictionary <string, object>)dictEvolution ["pos"]) ["y"];
        long z    = (long)((Dictionary <string, object>)dictEvolution ["pos"]) ["z"];
        long size = (long)dictEvolution ["radius"];

        instance.transform.position   = new Vector3(x, y, z);
        instance.transform.localScale = new Vector3(size, size, size);
        instance.name = (string)dictPlanet["name"];
        // print(dictPlanet["name"] + " : " + dictPlanet["type"] + "    (dictPlanet[\"type\"].Equals(\"star\") = " +  (dictPlanet["type"].Equals("star") ? "true" : "false"));
        PlanetUpdater updater = instance.AddComponent <PlanetUpdater>();

        updater.folder = resourceFolder;
        updater.setEvolutions(evolutionList, time);
        updater.definition = dictPlanet;

        if (dictPlanet["type"].Equals("planet"))
        {
            //Surface Displacement
            SGT_SurfaceDisplacement surfDisp = instance.AddComponent <SGT_SurfaceDisplacement>();
            surfDisp.SourceSurfaceMesh.GetMultiMesh(CubemapFace.PositiveX).Add((Mesh)Resources.Load("Sphere128 (Surface) (Sphere).asset"));

            //print ("folder:" + updater.folder);

            // materials evolution
            List <object> materialsEvolution = (dictEvolution["materials"]) as List <object>;


            print(dictEvolution["materials"]);
            for (int i = 0; i < materialsEvolution.Count; ++i)
            {
                Dictionary <string, object> materialEvolution = materialsEvolution[i] as Dictionary <string, object>;

                // TODO : this won't work on linux !
                var path = "file://" + Application.dataPath + "/Resources/" + resourceFolder + materialEvolution["file"].ToString() + ".png";
                print("path : " + path);
                var www = new WWW(path);
                while (!www.isDone)
                {
                    ;
                }
                updater.materials[materialEvolution["name"].ToString()] = www.texture;

                //print("tried to load : " + resourceFolder + materialEvolution["file"].ToString());
                //print(updater.materials[materialEvolution["name"].ToString()]);
            }
            updater.materialsDefinition = new Dictionary <string, object>(materialsDefinition);

            //TODO : put that in updater to update if materials evolve

            Texture2D t = TextureGenerator.generate(updater.materials, updater.materialsDefinition);
            // if (t == null)
            // WTF ???

            instance.GetComponent <SGT_Planet>().SurfaceTextureDay.SetTexture(t, 0);
            Texture2D t_n = TextureGenerator.MakeNight(t);
            instance.GetComponent <SGT_Planet>().SurfaceTextureNight.SetTexture(t_n, 0);
        }
        planets.Add(instance);
    }