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 static double SqrDistance(ref CellCoordPosition a, ref CellCoordPosition b, long CellSize) { var x = b.LocalX - a.LocalX + (b.GlobalX - a.GlobalX) * CellSize; var y = b.LocalY - a.LocalY + (b.GlobalY - a.GlobalY) * CellSize; var z = b.LocalZ - a.LocalZ + (b.GlobalZ - a.GlobalZ) * CellSize; return(x * x + y * y + z * z); }
public static double Distance(CellCoordPosition a, CellCoordPosition b, long CellSize) { var x = b.LocalX - a.LocalX + (b.GlobalX - a.GlobalX) * CellSize; var y = b.LocalY - a.LocalY + (b.GlobalY - a.GlobalY) * CellSize; var z = b.LocalZ - a.LocalZ + (b.GlobalZ - a.GlobalZ) * CellSize; return(System.Math.Sqrt(x * x + y * y + z * z)); }
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() { playerPosition = (CellCoordPosition)GameObject.Find("Player").GetComponent(typeof(CellCoordPosition)); lodObjectPosition = (CellCoordPosition)gameObject.GetComponent(typeof(CellCoordPosition)); foreach (PrefabDistance prefabDistance in prefabDistances) { prefabDistance.CalculateMaxDistance(lodObjectPosition.GetCellSize()); prefabDistance.CalculateMinDistance(lodObjectPosition.GetCellSize()); } }
public static CellCoordPosition Lerp(CellCoordPosition a, CellCoordPosition b, double t, long CellSize) { var o = a; o.LocalX += ((b.GlobalX - a.GlobalX) * CellSize + b.LocalX - a.LocalX) * t; o.LocalY += ((b.GlobalY - a.GlobalY) * CellSize + b.LocalY - a.LocalY) * t; o.LocalZ += ((b.GlobalZ - a.GlobalZ) * CellSize + b.LocalZ - a.LocalZ) * t; o.SnapLocal(); return(o); }
public static bool Equal(ref CellCoordPosition a, ref CellCoordPosition b) { if (a.GlobalX == b.GlobalX && a.GlobalY == b.GlobalY && a.GlobalZ == b.GlobalZ) { if (a.LocalX == b.LocalX && a.LocalY == b.LocalY && a.LocalZ == b.LocalZ) { return(true); } } return(false); }
public static CellCoordPosition Delta(ref CellCoordPosition a, ref CellCoordPosition b) { var o = default(CellCoordPosition); o.LocalX = a.LocalX - b.LocalX; o.LocalY = a.LocalY - b.LocalY; o.LocalZ = a.LocalZ - b.LocalZ; o.GlobalX = a.GlobalX - b.GlobalX; o.GlobalY = a.GlobalY - b.GlobalY; o.GlobalZ = a.GlobalZ - b.GlobalZ; return(o); }
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); }
public static Vector3 Vector(CellCoordPosition a, CellCoordPosition b, long CellSize) { var ax = a.LocalX + a.GlobalX * CellSize; var ay = a.LocalY + a.GlobalY * CellSize; var az = a.LocalZ + a.GlobalZ * CellSize; var bx = b.LocalX + b.GlobalX * CellSize; var by = b.LocalY + b.GlobalY * CellSize; var bz = b.LocalZ + b.GlobalZ * CellSize; var x = bx - ax; var y = by - ay; var z = bz - az; return(new Vector3((float)x, (float)y, (float)z)); }
public static Vector3 Direction(ref CellCoordPosition a, ref CellCoordPosition b, long CellSize) { var x = b.LocalX - a.LocalX + (b.GlobalX - a.GlobalX) * CellSize; var y = b.LocalY - a.LocalY + (b.GlobalY - a.GlobalY) * CellSize; var z = b.LocalZ - a.LocalZ + (b.GlobalZ - a.GlobalZ) * CellSize; var m = System.Math.Sqrt(x * x + y * y + z * z); if (m > 0.0) { x /= m; y /= m; z /= m; } return(new Vector3((float)x, (float)y, (float)z)); }
public void SpawnStartingCollectibles(Universe universe) { for (int collectibleNum = 0; collectibleNum < NumStartingOfCollectibles; collectibleNum++) { int randomElementIndex = Random.Range(0, Collectibles.Count); GameObject collectible = GameObject.Instantiate(Collectibles[randomElementIndex]); CellCoordPosition cellCoordPosition = (CellCoordPosition)collectible.AddComponent(typeof(CellCoordPosition)); cellCoordPosition.SetCellSize(universe.GetCellSize()); cellCoordPosition.SetLocalPosition(Random.Range(0, universe.GetCellSize()), Random.Range(0, universe.GetCellSize()), Random.Range(0, universe.GetCellSize())); cellCoordPosition.SetGlobalPosition(Random.Range(-SpawnAreaSize, SpawnAreaSize), Random.Range(-SpawnAreaSize, SpawnAreaSize), Random.Range(-SpawnAreaSize, SpawnAreaSize)); 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>(); 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); }
void Start() { universe = (Universe)GameObject.Find("GameManager").GetComponent(typeof(Universe)); clusterCenter = gameObject.GetComponent <CellCoordPosition>(); InstantiateStarCluster(); }
void Start() { cellCoordPosition = (CellCoordPosition)gameObject.GetComponent(typeof(CellCoordPosition)); }
void Start() { cellCoordPosition = (CellCoordPosition)gameObject.GetComponent(typeof(CellCoordPosition)); playerPosition = (CellCoordPosition)GameObject.Find("Player").GetComponent(typeof(CellCoordPosition)); }