public static void Destroy(IMovingPlanet planet)
 {
     PlanetData.RemovePlanet(planet);
     Object.Destroy(planet.gameObject);
     PlanetData.SelectedPlanet = null;
     Factory.GetUIController().RefreshSelectPlanetDropdown();
 }
Beispiel #2
0
    public static void Load(string saveName)
    {
        if (!File.Exists(saveName + ".txt"))
        {
            return;
        }

        //Czyszczenie układu z planet
        while (PlanetData.Planets.Count != 0)
        {
            PlanetManager.Destroy(PlanetData.Planets[0]);
        }

        using (StreamReader sr = new StreamReader(saveName + ".txt"))
        {
            while (!sr.EndOfStream)
            {
                IMovingPlanet planet = PlanetManager.Create();
                planet.PlanetName  = sr.ReadLine();
                planet.Size        = float.Parse(sr.ReadLine());
                planet.Mass        = float.Parse(sr.ReadLine());
                planet.Speed       = float.Parse(sr.ReadLine());
                planet.SunDistance = float.Parse(sr.ReadLine());
                planet.Material    = sr.ReadLine();
            }
        }

        Factory.GetUIController().RefreshSelectPlanetDropdown();
    }
Beispiel #3
0
    public static void Set(IMovingPlanet planet, string materialName)
    {
        MeshRenderer mesh         = planet.gameObject.GetComponent <MeshRenderer>();
        string       materialPath = string.Format("PlanetMaterials\\{0}", materialName);

        mesh.material = Resources.Load(materialPath) as Material;
    }
Beispiel #4
0
    /// <summary>
    /// Spojrzenie kamery na planetę
    /// </summary>
    /// <param name="transform">Wybrany obiekt</param>
    /// <param name="saveCameraPosition">Określa czy zapisać pozycję kamery, którą później będzie można wykorzystać do powrotu</param>
    public static void OnPlanet(IMovingPlanet planet, bool saveCameraPosition)
    {
        //if (state != CameraState.Free)
        //     return;

        PlanetData.SelectedPlanet = (Planet)planet;

        camera.State = CameraState.Focusing;

        //Zapisanie poprzedniej pozycji i rotacji kamery
        if (saveCameraPosition)
        {
            previousCameraPosition = camera.transform.position;
            previousCameraRotation = camera.transform.rotation;
        }

        //Zapisanie rotacji planety
        PlanetData.SaveRotation(planet);

        //Ustawienie planety w taki sposób, aby "patrzyła się" na kamerę. Dzięki temu łatwo poprowadzić od niej potrzebne wektory
        planet.transform.LookAt(camera.transform);

        //Określenie wielkośći planety
        float planetSize = planet.transform.localScale.x;

        //Punkt do którego kamera ma dotrzeć
        newCameraPosition = planet.transform.position + (planet.transform.forward * planetSize * 2);

        //Punkt na który kamera ma spojrzeć
        lookAtPoint = planet.transform.position - (planet.transform.right * planetSize);

        //Rotacja kamery obliczona na podstawie wektora między punktem dotarcia a punktem patrzenia
        lookAtDirection = Quaternion.LookRotation(lookAtPoint - newCameraPosition);

        //Przywrócenie poprzedniej rotacji planety
        PlanetPositioner.ResetRotation(planet);

        //Wyświetl menu edycji planety
        MenuSwitcher.Switch(MenuState.PlanetEdit);
    }
Beispiel #5
0
 /// <summary>
 /// Resetuje rotację planety do poprzedniej
 /// </summary>
 public static void ResetRotation(IMovingPlanet planet)
 {
     planet.transform.rotation = PlanetData.previousPlanetRotation;
 }
Beispiel #6
0
 /// <summary>
 /// Ustawienie rotacji planety
 /// </summary>
 /// <param name="planet">Planeta</param>
 /// <param name="rotation">Rotacja</param>
 public static void SetRotation(IMovingPlanet planet, Quaternion rotation)
 {
     planet.transform.rotation = rotation;
 }
Beispiel #7
0
    /// <summary>
    /// Dodawanie planety do układu słonecznego
    /// </summary>
    private void AddPlanetButtonClick()
    {
        IMovingPlanet planet = (Planet)PlanetManager.Create();

        CameraFocus.OnPlanet(planet, true);
    }
 /// <summary>
 /// Zapisuje rotacje planety
 /// </summary>
 public static void SaveRotation(IMovingPlanet planet)
 {
     previousPlanetRotation = planet.transform.rotation;
 }
 /// <summary>
 /// Funkcja usuwająca planetę z listy
 /// </summary>
 /// <param name="planet"></param>
 public static void RemovePlanet(IMovingPlanet planet)
 {
     Planets.Remove(planet);
 }
 /// <summary>
 /// Funkcja dodająca planetę na listę
 /// </summary>
 /// <param name="planet"></param>
 public static void AddPlanet(IMovingPlanet planet)
 {
     Planets.Add(planet);
 }