Exemplo n.º 1
0
        public static void GenerateGalaxy(Vector3 position, SunSystem sunSystem, Navigation navigation, ICollection <SpaceBody> outGeneratedObjects, AsyncProcessor asyncProcessor)
        {
            List <Obstacle> obstacles = new List <Obstacle>();

            var sun = ((SunBehaviour)GameObject.Instantiate(Resources.Load <SunBehaviour>(@"Environment\Sun"), position, Quaternion.identity));

            outGeneratedObjects.Add(sun);

            Color sunColor = new Color(.5f, .5f, .5f) + new Color(Random.value, Random.value, Random.value) * .5f;

            sun.Initialize(sunColor, sunSystem.sun.radius, asyncProcessor);

            sun.AddMyComponent <WorldlGravity>();
            var obstacle = sun.AddMyComponent <Obstacle>();

            obstacle.radius = sunSystem.sun.radius;
            obstacles.Add(obstacle);

            PlanetBehaviour planet = Resources.Load <PlanetBehaviour>(@"Environment\Planet");

            Vector3 axisRight = MyVector.RandomAxis3();
            Vector3 axisUp    = Vector3.Cross(sun.transform.up, axisRight);

            foreach (var pl in sunSystem.planets)
            {
                var p = GameObject.Instantiate(planet, sun.transform.position + axisRight * pl.axisOffset, Quaternion.identity);

                p.transform.RotateAround(sun.transform.position, axisUp, Random.value * 360);

                p.Initialize(sun, axisUp, pl.radius, asyncProcessor);

                if (Random.value < .1f)
                {
                    p.InitializeAtmosphere(sunColor, sun.transform.position, sunSystem.sun.radius, pl.radius, asyncProcessor);
                }

                p.AddMyComponent <WorldlGravity>();
                obstacle        = p.AddMyComponent <Obstacle>();
                obstacle.radius = pl.radius;
                obstacles.Add(obstacle);

                outGeneratedObjects.Add(p);
            }

            navigation.AddObstacles(obstacles);
        }