Пример #1
0
 // This method initializes the galaxy by setting seed number, creating a new dictionary, setting galaxy view to true and setting star count to 0
 void InitializeGalaxy()
 {
     starToObjectMap = new Dictionary <Star, GameObject>();
     Random.InitState(seedNumber);
     galaxyView         = true;
     starCount          = 0;
     availableStarNames = TextAssetManager.TextToList(starNames);
 }
Пример #2
0
    public void CreateGalaxy()
    {
        Random.InitState(seedNumber);
        CurrentCourse = SpaceObjects.CreateCoursePath(CoursePathPrefab, this.transform);
        CurrentCourse.SetActive(true);
        if (PathView)
        {
            TogglePathView();
        }
        GalaxyView         = true;
        starToObjectMap    = new Dictionary <Star, GameObject>();
        availableStarNames = TextAssetManager.TextToList(StarNames);
        int failCount = 0;

        for (int i = 0; i < numberOfStars; i++)
        {
            float distance = Random.Range(0, maximumRadius);
            float angle    = Random.Range(0, 2 * Mathf.PI);
            float altitude = Random.Range(-maximumHeight, maximumHeight) * (1 - distance / maximumRadius);

            var position = new Vector3(distance * Mathf.Cos(angle), altitude, distance * Mathf.Sin(angle));

            var positionCollider = Physics.OverlapSphere(position, mininumProximity);

            if (positionCollider.Length == 0)
            {
                var name           = availableStarNames[i];
                var starData       = new Star(name, Random.Range(0, maximumPlanets), Random.Range(3f, 6f), i % SpaceObjects.StarColors.Length, i % 10);
                var starGameObject = SpaceObjects.CreateSphereObject(starData.StarName, position, _defaultStarSize, this.transform);

                starGameObject.GetComponent <Renderer>().material.color = SpaceObjects.StarColors[starData.ColorIndex];

                starToObjectMap.Add(starData, starGameObject);
                CreatePlanetData(starData);

                failCount = 0;
            }
            else
            {
                failCount++;
                i--;
            }
            if (failCount > numberOfStars)
            {
                Debug.Log("Failed to generate star due to proximity validation check");
                break;
            }
        }
        pathViewButton.interactable = true;
        CurrentCourse.SetActive(false);
    }