//this function is called when the user double taps an atom public void setCameraCoordinates(Transform objTransform) { CreateEnvironment createEnvironment = Camera.main.GetComponent <CreateEnvironment> (); createEnvironment.centerPos = objTransform.position; transform.LookAt(objTransform); }
//this function checks the position of all of the atoms to make sure they are inside of the box void CheckAtomVolumePositions() { CreateEnvironment createEnvironment = Camera.main.GetComponent <CreateEnvironment>(); for (int i = 0; i < Atom.AllAtoms.Count; i++) { Atom currAtom = Atom.AllAtoms[i]; Vector3 newPosition = currAtom.transform.position; if (currAtom.transform.position.x > CreateEnvironment.bottomPlane.transform.position.x + (createEnvironment.width / 2.0f) - createEnvironment.errorBuffer) { newPosition.x = CreateEnvironment.bottomPlane.transform.position.x + (createEnvironment.width / 2.0f) - createEnvironment.errorBuffer; } if (currAtom.transform.position.x < CreateEnvironment.bottomPlane.transform.position.x - (createEnvironment.width / 2.0f) + createEnvironment.errorBuffer) { newPosition.x = CreateEnvironment.bottomPlane.transform.position.x - (createEnvironment.width / 2.0f) + createEnvironment.errorBuffer; } if (currAtom.transform.position.y > CreateEnvironment.bottomPlane.transform.position.y + (createEnvironment.height) - createEnvironment.errorBuffer) { newPosition.y = CreateEnvironment.bottomPlane.transform.position.y + (createEnvironment.height) - createEnvironment.errorBuffer; } if (currAtom.transform.position.y < CreateEnvironment.bottomPlane.transform.position.y + createEnvironment.errorBuffer) { newPosition.y = CreateEnvironment.bottomPlane.transform.position.y + createEnvironment.errorBuffer; } if (currAtom.transform.position.z > CreateEnvironment.bottomPlane.transform.position.z + (createEnvironment.depth / 2.0f) - createEnvironment.errorBuffer) { newPosition.z = CreateEnvironment.bottomPlane.transform.position.z + (createEnvironment.depth / 2.0f) - createEnvironment.errorBuffer; } if (currAtom.transform.position.z < CreateEnvironment.bottomPlane.transform.position.z - (createEnvironment.depth / 2.0f) + createEnvironment.errorBuffer) { newPosition.z = CreateEnvironment.bottomPlane.transform.position.z - (createEnvironment.depth / 2.0f) + createEnvironment.errorBuffer; } currAtom.transform.position = newPosition; } }
void Awake() { CreateEnvironment.myEnvironment = this; atomTouchGUI = Camera.main.GetComponent <AtomTouchGUI> (); atomTouchGUI.changingTemp = false; atomTouchGUI.changingVol = false; //when first started, pause timer StaticVariables.pauseTime = true; centerPos = Vector3.zero; initialCenterPos = centerPos; //figure out the dimensions of the box based on the volume width = Mathf.Pow(volume, (1.0f / 3.0f)); height = Mathf.Pow(volume, (1.0f / 3.0f)); depth = Mathf.Pow(volume, (1.0f / 3.0f)); vx = new Vector3(width, 0.0f, 0.0f); vy = new Vector3(0.0f, height, 0.0f); vz = new Vector3(0.0f, 0.0f, depth); CreatePlanes(); CreateAllLines(); }
//this function checks the position of an atom, and if its outside of the box, simply place the atom back inside the box Vector3 CheckPosition(Vector3 position) { CreateEnvironment myEnvironment = CreateEnvironment.myEnvironment; Vector3 bottomPlanePos = CreateEnvironment.bottomPlane.transform.position; if (position.y > bottomPlanePos.y + (myEnvironment.height) - myEnvironment.errorBuffer) { position.y = bottomPlanePos.y + (myEnvironment.height) - myEnvironment.errorBuffer; } if (position.y < bottomPlanePos.y + myEnvironment.errorBuffer) { position.y = bottomPlanePos.y + myEnvironment.errorBuffer; } if (position.x > bottomPlanePos.x + (myEnvironment.width / 2.0f) - myEnvironment.errorBuffer) { position.x = bottomPlanePos.x + (myEnvironment.width / 2.0f) - myEnvironment.errorBuffer; } if (position.x < bottomPlanePos.x - (myEnvironment.width / 2.0f) + myEnvironment.errorBuffer) { position.x = bottomPlanePos.x - (myEnvironment.width / 2.0f) + myEnvironment.errorBuffer; } if (position.z > bottomPlanePos.z + (myEnvironment.depth / 2.0f) - myEnvironment.errorBuffer) { position.z = bottomPlanePos.z + (myEnvironment.depth / 2.0f) - myEnvironment.errorBuffer; } if (position.z < bottomPlanePos.z - (myEnvironment.depth / 2.0f) + myEnvironment.errorBuffer) { position.z = bottomPlanePos.z - (myEnvironment.depth / 2.0f) + myEnvironment.errorBuffer; } return(position); }
public void AddGoldAtom() { if (Input.mousePosition.x < Screen.width && Input.mousePosition.x > 0 && Input.mousePosition.y > 0 && Input.mousePosition.y < Screen.height) { //Vector3 curPosition = new Vector3 (createEnvironment.centerPos.x + (UnityEngine.Random.Range (-(createEnvironment.width / 2.0f) + createEnvironment.errorBuffer, (createEnvironment.width / 2.0f) - createEnvironment.errorBuffer)), createEnvironment.centerPos.y + (UnityEngine.Random.Range (-(createEnvironment.height / 2.0f) + createEnvironment.errorBuffer, (createEnvironment.height / 2.0f) - createEnvironment.errorBuffer)), createEnvironment.centerPos.z + (UnityEngine.Random.Range (-(createEnvironment.depth / 2.0f) + createEnvironment.errorBuffer, (createEnvironment.depth / 2.0f) - createEnvironment.errorBuffer))); CreateEnvironment myEnvironment = CreateEnvironment.myEnvironment; myEnvironment.createAtom(goldPrefab); } TryEnableAddAtomBtns(); }
private void Awake() { instance = this; moneyText = GameObject.Find("MoneyText").GetComponent <TextMeshProUGUI>(); if (GameObject.Find("GameManager") != null) { createEnvironment = GameObject.Find("GameManager").GetComponent <CreateEnvironment>(); } }
private void Awake() { if (instance != null) { Debug.LogError("More than a one buildmanager in the scene"); return; } instance = this; player = GameObject.Find("Player").GetComponent <Player>(); createEnvironment = this.gameObject.GetComponent <CreateEnvironment>(); inventoryBuilding = GameObject.Find("TypesOfBuildings").GetComponent <InventoryBuilding>(); //destroyParticle = destroyParticlePrefab.GetComponentInChildren<ParticleSystem>(); }
public void ChangeAtomVolume() { CreateEnvironment createEnvironment = CreateEnvironment.myEnvironment; //these are in angstroms float offset = StaticVariables.maxVol + StaticVariables.minVol; createEnvironment.width = Math.Abs(offset - volSliderComponent.value * 10.0f); createEnvironment.height = Math.Abs(offset - volSliderComponent.value * 10.0f); createEnvironment.depth = Math.Abs(offset - volSliderComponent.value * 10.0f); createEnvironment.volume = createEnvironment.width * createEnvironment.height * createEnvironment.depth; //to nm^3 //since slider is upside down... float realVol = createEnvironment.width * 0.1f; ChangePlaneMaterial(realVol); changingVol = true; }
public void ResetAll() { CreateEnvironment myEnvironment = CreateEnvironment.myEnvironment; myEnvironment.InitAtoms(); Atom.EnableSelectAtomGroup(false); //reset temp and vol tempSliderComponent.value = StaticVariables.tempRangeHigh - StaticVariables.tempDefault; volSliderComponent.value = StaticVariables.volRangeHigh - StaticVariables.volDefault; SnapTempToInterval(10.0f); SnapVolumeToInterval(0.5f); //ChangeTimeScaleWithTemperature(oldTemperaure); changingVol = false; changingTemp = false; //SettingsControl.renderAtoms = true; }
public void SaveGeneralInfo() { BinaryFormatter bf = new BinaryFormatter(); FileStream file; file = File.Create(Application.persistentDataPath + "/generalInfo.dat"); GeneralInfo info = new GeneralInfo(); CreateEnvironment ce = GameObject.Find("GameManager").GetComponent <CreateEnvironment>(); WeatherController weather = GameObject.Find("GameManager").GetComponent <WeatherController>(); Player player = GameObject.Find("Player").GetComponent <Player>(); info.money = player.totalCurrency; info.days = weather.fakeDays; info.hour = weather.fakeHour; info.minute = weather.fakeMinutes; info.month = weather.actualMonthNumber; info.night = weather.isNight; info.firstTimeCoal = firstTimeCoal; info.tutorial = tutorial; info.unlockIslandCoal = player.unlockCoal; info.unlockIslandGas = player.unlockGas; info.unlockIslandSolar = player.unlockSolar; info.unlockIslandWind = player.unlockWind; bf.Serialize(file, info); file.Close(); }
void Awake() { atomTouchGUI = Camera.main.GetComponent<AtomTouchGUI>(); createEnvironment = Camera.main.GetComponent<CreateEnvironment> (); }
// this method creates a new atom from the type of the preFab and checks the position to have a far enough distance from other atoms public void createAtom(Rigidbody preFab) { int preFabID = preFab.GetInstanceID(); if (preFabID == atomTouchGUI.copperPrefab.GetInstanceID()) { Copper.count++; atomTouchGUI.copperCount.GetComponent <Text>().text = "Cu: " + Copper.count; } else if (preFabID == atomTouchGUI.goldPrefab.GetInstanceID()) { Gold.count++; atomTouchGUI.goldCount.GetComponent <Text>().text = "Au: " + Gold.count; } else if (preFabID == atomTouchGUI.platinumPrefab.GetInstanceID()) { Platinum.count++; atomTouchGUI.platinumCount.GetComponent <Text>().text = "Pt: " + Platinum.count; } CreateEnvironment myEnvironment = CreateEnvironment.myEnvironment; Quaternion curRotation = Quaternion.Euler(0, 0, 0); preFab.gameObject.GetComponent <MeshRenderer>().enabled = SettingsControl.renderAtoms; Instantiate(preFab, myEnvironment.centerPos, curRotation); int i = Atom.AllAtoms.Count - 1; Atom currAtom = Atom.AllAtoms[i]; currAtom.gameObject.name = currAtom.GetInstanceID().ToString(); //Debug.Log(currAtom.GetInstanceID()); currAtom.GetComponent <Rigidbody>().freezeRotation = true; currAtom.GetComponent <TrailRenderer>().enabled = SettingsControl.mySettings.trailsToggle.isOn; float realWidth = myEnvironment.width - 2.0f * myEnvironment.errorBuffer; float realHeight = myEnvironment.height - 2.0f * myEnvironment.errorBuffer; float realDepth = myEnvironment.depth - 2.0f * myEnvironment.errorBuffer; Vector3 centerPos = myEnvironment.centerPos; int tryNumber = 0; bool proximityFlag = false; while ((proximityFlag == false) && (tryNumber < 100)) { tryNumber++; currAtom.position = new Vector3(centerPos.x + (UnityEngine.Random.Range(-realWidth / 2.0f, realWidth / 2.0f)), centerPos.y + (UnityEngine.Random.Range(-realHeight / 2.0f, realHeight / 2.0f)), centerPos.z + (UnityEngine.Random.Range(-realDepth / 2.0f, realDepth / 2.0f))); proximityFlag = myEnvironment.checkProximity(currAtom); } currAtom.transform.position = currAtom.position; //kick it atomTouchGUI.AtomKick(i); Potential.myPotential.calculateVerletRadius(currAtom); if ((tryNumber == 100) && (proximityFlag == false)) { Atom.UnregisterAtom(currAtom); Destroy(currAtom.gameObject); Debug.Log("No space for atoms!"); } }
public void Save() { SaveGeneralInfo(); BinaryFormatter bf = new BinaryFormatter(); FileStream file; if (SceneManager.GetActiveScene().name == "CoalIsland") { file = File.Create(Application.persistentDataPath + "/coalIslandInfo.dat"); firstTimeCoal = false; } else if (SceneManager.GetActiveScene().name == "GasIsland") { file = File.Create(Application.persistentDataPath + "/gasIslandInfo.dat"); } else if (SceneManager.GetActiveScene().name == "SolarIsland") { file = File.Create(Application.persistentDataPath + "/solarIslandInfo.dat"); } else if (SceneManager.GetActiveScene().name == "WindIsland") { file = File.Create(Application.persistentDataPath + "/windIslandInfo.dat"); } else if (SceneManager.GetActiveScene().buildIndex == 1) { file = File.Create(Application.persistentDataPath + "/mainIslandInfo.dat"); } else { Debug.Log("Ni uno ni otro"); return; } LevelData data = new LevelData(); CreateEnvironment ce = GameObject.Find("GameManager").GetComponent <CreateEnvironment>(); WeatherController weather = GameObject.Find("GameManager").GetComponent <WeatherController>(); Player player = GameObject.Find("Player").GetComponent <Player>(); stageSizeX = ce.GetStageX(); stageSizeY = ce.GetStageY(); data.stageSizeX = stageSizeX; data.stageSizeY = stageSizeY; gridSizeX = ce.GetRows(); gridSizeY = ce.GetColumns(); data.gridSizeX = gridSizeX; data.gridSizeY = gridSizeY; data.levelCity = player.levelCity; data.sizeXPlane = ce.planeLimit.transform.localScale.x; data.sizeYPlane = ce.planeLimit.transform.localScale.z; data.energy = player.totalEnergy; data.maxEnergy = (int)player.levelObject.maxValue; data.pollution = player.totalPollution; data.maxPollution = (int)player.pollutionSlider.maxValue; data.happiness = player.totalHappiness; data.cantCompletedQuest = player.cantCompletedQuest; // data.money = player.totalCurrency; // data.days = weather.fakeDays; // data.hour = weather.fakeHour; // data.minute = weather.fakeMinutes; // data.month = weather.actualMonthNumber; // data.night = weather.isNight; Node[,] aux = ce.GetMatrixNode(); information = new NodeInformation[gridSizeX, gridSizeY]; for (int f = 1; f < gridSizeX; f++) { for (int c = 1; c < gridSizeY; c++) { if (aux[f, c].idBuilding == 0) { information[f, c].isUnlock = false; information[f, c].haveWater = false; information[f, c].idBuilding = 0; //continue; } else { information[f, c].idBuilding = aux[f, c].idBuilding; information[f, c].isUnlock = true; information[f, c].haveWater = false; } } } data.information = information; // data.money = GameObject.Find("Player").GetComponent<Player>().totalCurrency; if (information.Length != 0) { Debug.Log("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); } bf.Serialize(file, data); file.Close(); Debug.Log("Se ha creado archivo de guardado"); }
public void SaveGasIsland() { BinaryFormatter bf = new BinaryFormatter(); FileStream file; file = File.Create(Application.persistentDataPath + "/gasIslandInfo.dat"); LevelData data = new LevelData(); CreateEnvironment ce = GameObject.Find("GameManager").GetComponent <CreateEnvironment>(); WeatherController weather = GameObject.Find("GameManager").GetComponent <WeatherController>(); Player player = GameObject.Find("Player").GetComponent <Player>(); stageSizeX = ce.GetStageX(); stageSizeY = ce.GetStageY(); data.stageSizeX = stageSizeX; data.stageSizeY = stageSizeY; gridSizeX = ce.GetRows(); gridSizeY = ce.GetColumns(); data.gridSizeX = gridSizeX; data.gridSizeY = gridSizeY; data.levelCity = player.levelCity; data.sizeXPlane = ce.planeLimit.transform.localScale.x; data.sizeYPlane = ce.planeLimit.transform.localScale.z; data.energy = player.totalEnergy; data.maxEnergy = (int)player.levelObject.maxValue; data.pollution = player.totalPollution; data.maxPollution = (int)player.pollutionSlider.maxValue; data.happiness = player.totalHappiness; data.cantCompletedQuest = player.cantCompletedQuest; Node[,] aux = ce.GetMatrixNode(); information = new NodeInformation[gridSizeX, gridSizeY]; for (int f = 1; f < gridSizeX; f++) { for (int c = 1; c < gridSizeY; c++) { if (aux[f, c].idBuilding == 0) { information[f, c].isUnlock = false; information[f, c].haveWater = false; information[f, c].idBuilding = 0; //continue; } else { information[f, c].idBuilding = aux[f, c].idBuilding; information[f, c].isUnlock = true; information[f, c].haveWater = false; } } } data.information = information; // data.money = GameObject.Find("Player").GetComponent<Player>().totalCurrency; if (information.Length != 0) { Debug.Log("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); } bf.Serialize(file, data); file.Close(); Debug.Log("Se ha creado archivo de guardado"); }
//this function handles the zooming in and out of the camera. the camera actually doesnt zoom, its z-coorindate simply changes void Update() { if (SettingsControl.GamePaused) { return; } bool beingHeld = false; doubleTappedAtom = null; for (int i = 0; i < Atom.AllAtoms.Count; i++) { Atom currAtom = Atom.AllAtoms[i]; if (currAtom.held) { beingHeld = true; } if (currAtom.doubleTapped) { doubleTappedAtom = Atom.AllAtoms[i].gameObject; } } if (Application.isMobilePlatform && Input.touchCount == 2 && !beingHeld) { Touch touchZero = Input.GetTouch(0); Touch touchOne = Input.GetTouch(1); Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition; Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition; float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude; float touchDeltaMag = (touchZero.position - touchOne.position).magnitude; float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag; Quaternion cameraRotation = GetComponent <Camera>().transform.rotation; if (doubleTappedAtom != null) { Vector3 projectPosition = GetComponent <Camera>().transform.position; float zChange = deltaMagnitudeDiff * touchPerspectiveZoomSpeed; //enforce a maximum value that the camera can move in one frame //this is to avoid going "through" the minimum and maximum distances of the box if (zChange > 3.0f) { zChange = 3.0f; } else if (zChange < -3.0f) { zChange = -3.0f; } projectPosition -= (cameraRotation * new Vector3(0.0f, 0.0f, zChange)); //enforce a minimum and maximum distance from the center of the box that the user can scroll if (Vector3.Distance(projectPosition, doubleTappedAtom.transform.position) > 1.0f) { GetComponent <Camera>().transform.position = projectPosition; } } else { Vector3 projectPosition = GetComponent <Camera>().transform.position; float zChange = deltaMagnitudeDiff * touchPerspectiveZoomSpeed; //enforce a maximum value that the camera can move in one frame //this is to avoid going "through" the minimum and maximum distances of the box if (zChange > 3.0f) { zChange = 3.0f; } else if (zChange < -3.0f) { zChange = -3.0f; } projectPosition -= (cameraRotation * new Vector3(0.0f, 0.0f, zChange)); CreateEnvironment createEnvironment = Camera.main.GetComponent <CreateEnvironment>(); Vector3 centerPos = new Vector3(CreateEnvironment.bottomPlane.transform.position.x, CreateEnvironment.bottomPlane.transform.position.y + (createEnvironment.height / 2.0f), CreateEnvironment.bottomPlane.transform.position.z); //enforce a minimum and maximum distance from the center of the box that the user can scroll if (Vector3.Distance(projectPosition, centerPos) < 70.0f && Vector3.Distance(projectPosition, centerPos) > 10.0f) { GetComponent <Camera>().transform.position = projectPosition; } } } else if (!Application.isMobilePlatform && !beingHeld) { float deltaMagnitudeDiff = Input.GetAxis("Mouse ScrollWheel"); Quaternion cameraRotation = GetComponent <Camera>().transform.rotation; if (doubleTappedAtom != null) { Vector3 projectPosition = GetComponent <Camera>().transform.position; float zChange = deltaMagnitudeDiff * pcPerspectiveZoomSpeed; //enforce a maximum value that the camera can move in one frame //this is to avoid going "through" the minimum and maximum distances of the box if (zChange > 3.0f) { zChange = 3.0f; } else if (zChange < -3.0f) { zChange = -3.0f; } projectPosition -= (cameraRotation * new Vector3(0.0f, 0.0f, zChange)); //enforce a minimum and maximum distance from the center of the box that the user can scroll if (Vector3.Distance(projectPosition, doubleTappedAtom.transform.position) > 1.0f) { GetComponent <Camera>().transform.position = projectPosition; } } else { Vector3 projectPosition = GetComponent <Camera>().transform.position; float zChange = deltaMagnitudeDiff * pcPerspectiveZoomSpeed; //enforce a maximum value that the camera can move in one frame //this is to avoid going "through" the minimum and maximum distances of the box if (zChange > 3.0f) { zChange = 3.0f; } else if (zChange < -3.0f) { zChange = -3.0f; } projectPosition -= (cameraRotation * new Vector3(0.0f, 0.0f, zChange)); CreateEnvironment createEnvironment = Camera.main.GetComponent <CreateEnvironment>(); Vector3 centerPos = new Vector3(CreateEnvironment.bottomPlane.transform.position.x, CreateEnvironment.bottomPlane.transform.position.y + (createEnvironment.height / 2.0f), CreateEnvironment.bottomPlane.transform.position.z); //enforce a minimum and maximum distance from the center of the box that the user can scroll if (Vector3.Distance(projectPosition, centerPos) < 70.0f && Vector3.Distance(projectPosition, centerPos) > 10.0f) { GetComponent <Camera>().transform.position = projectPosition; } } } }
void Start() { text = GetComponent<Text>(); createEnvironment = CreateEnvironment.myEnvironment; }
void Awake() { CreateEnvironment.myEnvironment = this; atomTouchGUI = Camera.main.GetComponent<AtomTouchGUI> (); atomTouchGUI.changingTemp = false; atomTouchGUI.changingVol = false; //when first started, pause timer StaticVariables.pauseTime = true; centerPos = Vector3.zero; initialCenterPos = centerPos; //figure out the dimensions of the box based on the volume width = Mathf.Pow (volume, (1.0f / 3.0f)); height = Mathf.Pow (volume, (1.0f / 3.0f)); depth = Mathf.Pow (volume, (1.0f / 3.0f)); vx = new Vector3(width,0.0f,0.0f); vy = new Vector3(0.0f,height, 0.0f); vz = new Vector3(0.0f,0.0f, depth); CreatePlanes(); CreateAllLines(); }
void Start() { text = GetComponent <Text>(); createEnvironment = CreateEnvironment.myEnvironment; }
//scene selector callback public void OnLoad_PresetAtoms(string filename) { CreateEnvironment env = CreateEnvironment.myEnvironment; env.LoadPresetAtoms(filename); }
void Awake() { atomTouchGUI = Camera.main.GetComponent <AtomTouchGUI>(); createEnvironment = Camera.main.GetComponent <CreateEnvironment> (); }