public void SpawnCollectiblesAroundObjects(Universe universe) { List <GameObject> universeObjects = universe.GetUniverseObjects(); for (int collectibleNum = 0; collectibleNum < NumStartingOfAroundCollectibles; collectibleNum++) { int randomElementIndex = Random.Range(0, Collectibles.Count); GameObject collectible = GameObject.Instantiate(Collectibles[randomElementIndex]); randomElementIndex = Random.Range(0, universeObjects.Count); CellCoordPosition randomObjectPosition = universeObjects[randomElementIndex].GetComponent <CellCoordPosition>(); CellCoordPosition cellCoordPosition = (CellCoordPosition)collectible.AddComponent(typeof(CellCoordPosition)); cellCoordPosition.SetCellSize(universe.GetCellSize()); cellCoordPosition.SetLocalPosition(randomObjectPosition.GetLocalPos().x + Random.Range(0, universe.GetCellSize()), randomObjectPosition.GetLocalPos().y + Random.Range(0, universe.GetCellSize()), randomObjectPosition.GetLocalPos().z + Random.Range(0, universe.GetCellSize())); cellCoordPosition.SetGlobalPosition((long)randomObjectPosition.GetGlobalPos().x + Random.Range(-1, 1), (long)randomObjectPosition.GetGlobalPos().y + Random.Range(-1, 1), (long)randomObjectPosition.GetGlobalPos().z + Random.Range(-1, 1)); collectible.transform.position = cellCoordPosition.GetRealPosition(); universe.AddUniverseObject(collectible); } }
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); }
public void TranslateObject(GameObject universeObject, Vector3 playerGlobalPos) { CellCoordPosition cellCoordPosition = (CellCoordPosition)universeObject.GetComponent(typeof(CellCoordPosition)); Vector3 globalPosDif = cellCoordPosition.GetGlobalPos() - playerGlobalPos; Transform transform = (Transform)(universeObject.GetComponent(typeof(Transform))); transform.position = (globalPosDif * CellSize) + cellCoordPosition.GetLocalPos(); }
void Start() { universe = (Universe)GameObject.Find("GameManager").GetComponent(typeof(Universe)); cellCoordPosition = gameObject.GetComponent <CellCoordPosition>(); shadowManager = gameObject.GetComponent <ShadowManager>(); int i = 0; foreach (PrefabCoord planet in planets) { planet.GlobalX += (long)cellCoordPosition.GetGlobalPos().x; planet.GlobalY += (long)cellCoordPosition.GetGlobalPos().y; planet.GlobalZ += (long)cellCoordPosition.GetGlobalPos().z; planet.LocalX += cellCoordPosition.GetLocalPos().x; planet.LocalY += cellCoordPosition.GetLocalPos().y; planet.LocalZ += cellCoordPosition.GetLocalPos().z; GameObject instantiatedPlanet = universe.InstatntiateUniverseObject(planet); instantiatedPlanets.Add(instantiatedPlanet); shadowManager.planet[i] = instantiatedPlanet; i++; } shadowManager.Init(i); }
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); } }
public void SnapCamera() { cellCoordPosition.UpdateGlobalPos(); cellCoordPosition.SnapCoordsBackToCell(); transform.position = cellCoordPosition.GetLocalPos(); }