Esempio n. 1
0
    void Start()
    {
        universe          = (Universe)GameObject.Find("GameManager").GetComponent(typeof(Universe));
        cellCoordPosition = gameObject.GetComponent <CellCoordPosition>();
        shadowManager     = gameObject.GetComponent <ShadowManager>();
        for (int i = 0; i < numOfPlanets; i++)
        {
            int         randomIndex = Random.Range(0, planets.Count);
            GameObject  planet      = planets[randomIndex];
            PrefabCoord planetCoord = new PrefabCoord();
            planetCoord.prefab = planet;


            planetCoord.GlobalX = (long)Random.Range(-maxGlobalDistance, maxGlobalDistance);
            planetCoord.GlobalY = (long)Random.Range(-maxGlobalDistance, maxGlobalDistance);
            planetCoord.GlobalZ = 0;
            planetCoord.LocalX  = Random.Range(-cellCoordPosition.GetCellSize(), cellCoordPosition.GetCellSize());
            planetCoord.LocalY  = Random.Range(-cellCoordPosition.GetCellSize(), cellCoordPosition.GetCellSize());
            planetCoord.LocalZ  = 0;

            planetCoord.GlobalX += (long)cellCoordPosition.GetGlobalPos().x;
            planetCoord.GlobalY += (long)cellCoordPosition.GetGlobalPos().y;
            planetCoord.GlobalZ += (long)cellCoordPosition.GetGlobalPos().z;
            planetCoord.LocalX  += cellCoordPosition.GetLocalPos().x;
            planetCoord.LocalY  += cellCoordPosition.GetLocalPos().y;
            planetCoord.LocalZ  += cellCoordPosition.GetLocalPos().z;
            GameObject instantiatedPlanet = universe.InstatntiateUniverseObject(planetCoord);
            instantiatedPlanets.Add(instantiatedPlanet);
            shadowManager.planet[i] = instantiatedPlanet;
        }
        shadowManager.Init(numOfPlanets);
    }
Esempio n. 2
0
    public GameObject InstatntiateUniverseObject(PrefabCoord prefabCoord)
    {
        GameObject universeObject = GameObject.Instantiate(prefabCoord.prefab);

        CellCoordPosition cellCoordPosition = (CellCoordPosition)universeObject.AddComponent(typeof(CellCoordPosition));

        cellCoordPosition.SetCellSize(CellSize);
        cellCoordPosition.SetLocalPosition(prefabCoord.LocalX, prefabCoord.LocalY, prefabCoord.LocalZ);
        cellCoordPosition.SetGlobalPosition(prefabCoord.GlobalX, prefabCoord.GlobalY, prefabCoord.GlobalZ);
        universeObject.transform.position = cellCoordPosition.GetRealPosition();

        universeObjects.Add(universeObject);
        return(universeObject);
    }
    private void InstantiateStarCluster()
    {
        for (int StarSystemNumber = 0; StarSystemNumber < NumOfSolarSystems; StarSystemNumber++)
        {
            PrefabCoord StarSystemCoords = new PrefabCoord();
            StarSystemCoords.prefab = SolarSystem;

            StarSystemCoords.GlobalX = (long)Random.Range(-SizeOfStarCluster, SizeOfStarCluster) + (long)clusterCenter.GetGlobalPos().x;
            StarSystemCoords.GlobalY = (long)Random.Range(-SizeOfStarCluster, SizeOfStarCluster) + (long)clusterCenter.GetGlobalPos().y;
            StarSystemCoords.GlobalZ = (long)Random.Range(-SizeOfStarCluster, SizeOfStarCluster) + (long)clusterCenter.GetGlobalPos().z;
            StarSystemCoords.LocalX  = Random.Range(-universe.GetCellSize(), universe.GetCellSize()) + clusterCenter.GetLocalPos().x;
            StarSystemCoords.LocalY  = Random.Range(-universe.GetCellSize(), universe.GetCellSize()) + clusterCenter.GetLocalPos().y;
            StarSystemCoords.LocalZ  = Random.Range(-universe.GetCellSize(), universe.GetCellSize()) + clusterCenter.GetLocalPos().z;

            universe.InstatntiateUniverseObject(StarSystemCoords);
        }
    }