public WorldData(ControllerScript controller) { time = controller.time; ambientTemperature = controller.ambientTemperature; playerTemperature = controller.playerTemperature; currentSeason = controller.currentSeason; currentDay = controller.currentDay; currentDayInSeason = controller.currentDayInSeason; health = controller.playerInventoryScript.GetComponent <PlayerScript> ().health; hunger = controller.playerInventoryScript.GetComponent <PlayerScript> ().hunger; happiness = controller.playerInventoryScript.GetComponent <PlayerScript> ().happiness; droppedItems = new SaveSystem.MyDroppedItem[controller.GetComponent <SaveSystemScript>().items.Length]; terrains = new SaveSystem.MyTerrain[controller.GetComponent <SaveSystemScript> ().terrains.Length]; buildings = new SaveSystem.Buildings.BasicBuildingSaveProperties[controller.GetComponent <SaveSystemScript>().buildings.Length]; mobs = new SaveSystem.Mobs.BasicMobAttributes[controller.GetComponent <SaveSystemScript>().mobs.Length]; playerPosition = new MyVector3(controller.playerInventoryScript.transform.position); playerInventory = new SerializedInventoryItem[controller.playerInventoryScript.playerInventory.Length]; for (int i = 0; i < playerInventory.Length; i++) { playerInventory [i] = controller.playerInventoryScript.playerInventory [i].convertToSave(); } for (int i = 0; i < droppedItems.Length; i++) { if (controller.GetComponent <SaveSystemScript> ().items [i] != null) { droppedItems [i] = new SaveSystem.MyDroppedItem(controller.GetComponent <SaveSystemScript> ().items [i].transform.GetChild(0).GetComponent <DroppedItemScript> ().myValue.name, controller.GetComponent <SaveSystemScript> ().items [i].transform.GetChild(0).GetComponent <DroppedItemScript> ().myValue.quantity, new MyVector3(controller.GetComponent <SaveSystemScript> ().items [i].transform.position)); } } for (int i = 0; i < terrains.Length; i++) { if (controller.GetComponent <SaveSystemScript> ().terrains [i] != null) { GameObject terrain = controller.GetComponent <SaveSystemScript> ().terrains [i]; terrains [i] = new SaveSystem.MyTerrain(terrain.GetComponent <TerrainScript> ().terrainName, terrain.transform.position); } } for (int i = 0; i < mobs.Length; i++) { if (controller.GetComponent <SaveSystemScript> ().mobs [i] != null) { GameObject mob = controller.GetComponent <SaveSystemScript> ().mobs [i]; if (mob.GetComponent <PassiveFourLegs> () != null) { mobs [i] = new SaveSystem.Mobs.BasicMobAttributes(mob.GetComponent <PassiveFourLegs>().mobName, mob.GetComponent <PassiveFourLegs> ().health, mob.GetComponent <PassiveFourLegs> ().maxHealth, mob.transform.position, mob.transform.eulerAngles); } else if (mob.GetComponent <Sheep> () != null) { mobs [i] = new SaveSystem.Mobs.Sheep(mob.GetComponent <Sheep>().mobName, mob.GetComponent <Sheep> ().health, mob.GetComponent <Sheep> ().maxHealth, mob.transform.position, mob.transform.eulerAngles); } } } for (int i = 0; i < buildings.Length; i++) { if (controller.GetComponent <SaveSystemScript> ().buildings [i] != null) { GameObject building = controller.GetComponent <SaveSystemScript> ().buildings [i]; TreeScript treeScript = null; BoulderScript boulderScript = null; GrassScript grassScript = null; BushScript bushScript = null; BerryBushScript berryBushScript = null; FireScript fireScript = null; GroundFoodScript naturalFoodScript = null; if (building.GetComponent <TreeScript> () != null) { treeScript = building.GetComponent <TreeScript> (); } if (building.GetComponent <BoulderScript> () != null) { boulderScript = building.GetComponent <BoulderScript> (); } if (building.GetComponent <GrassScript> () != null) { grassScript = building.GetComponent <GrassScript> (); } if (building.GetComponent <BushScript> () != null) { bushScript = building.GetComponent <BushScript> (); } if (building.GetComponent <BerryBushScript> () != null) { berryBushScript = building.GetComponent <BerryBushScript> (); } if (building.GetComponent <FireScript> () != null) { fireScript = building.GetComponent <FireScript> (); } if (building.GetComponent <GroundFoodScript> () != null) { naturalFoodScript = building.GetComponent <GroundFoodScript> (); } if (treeScript != null || boulderScript != null) { //natural barriers if (treeScript != null) { buildings [i] = new SaveSystem.Buildings.NaturalBarriers("tree", treeScript.transform.position, treeScript.transform.eulerAngles, treeScript.health); } else if (boulderScript != null) { buildings [i] = new SaveSystem.Buildings.NaturalBarriers("boulder", boulderScript.transform.position, boulderScript.transform.eulerAngles, boulderScript.health); } } else if (grassScript != null || bushScript != null || berryBushScript != null) { if (grassScript != null) { buildings [i] = new SaveSystem.Buildings.NaturalCrops("grassPatch", grassScript.transform.position, grassScript.transform.eulerAngles, grassScript.cut, grassScript.growTimer); } if (bushScript != null) { buildings [i] = new SaveSystem.Buildings.NaturalCrops("bush", bushScript.transform.position, bushScript.transform.eulerAngles, bushScript.cut, bushScript.growTimer); } else if (berryBushScript != null) { buildings [i] = new SaveSystem.Buildings.NaturalCrops("berryBush", berryBushScript.transform.position, berryBushScript.transform.eulerAngles, berryBushScript.cut, berryBushScript.growTimer); } } else if (fireScript != null) { buildings [i] = new SaveSystem.Buildings.Campfire("campfire", fireScript.transform.position, fireScript.transform.eulerAngles, fireScript.fuel); } else if (naturalFoodScript != null) { buildings [i] = new SaveSystem.Buildings.BasicBuildingSaveProperties(naturalFoodScript.buildingIDName, naturalFoodScript.transform.position, naturalFoodScript.transform.eulerAngles); } } } }
// Update is called once per frame void Update() { bool buttonDown = false; bool inputEnded = false; Vector2 screenPosition = Vector2.zero; if (gameState == GameState.PICKING) { #if UNITY_WSA if (Input.touchCount > 0) { Touch firstTouch = Input.touches[0]; if (firstTouch.phase == TouchPhase.Began) { buttonDown = true; } else if (firstTouch.phase == TouchPhase.Ended) { inputEnded = true; } screenPosition = firstTouch.position; } #else buttonDown = Input.GetMouseButtonDown(0); if (!buttonDown) { inputEnded = Input.GetMouseButtonUp(0); } screenPosition = Input.mousePosition; #endif if (buttonDown) { RaycastHit rayHit; screenPositionStart = screenPosition; screenPositionHold = screenPosition; Ray ray = Camera.main.ScreenPointToRay(screenPosition); if (Physics.Raycast(ray, out rayHit, 200)) { hitObject = rayHit.collider.gameObject; Debug.Log(hitObject.name); } else { hitObject = null; } } else if (inputEnded) { if (hitObject == null) { return; } //For some reason it treats mouse position as a vector 3 so I can't create mouseDifference in 1 line Vector2 inputDifference = screenPosition; inputDifference -= screenPositionStart; inputDifference.x = Mathf.Abs(inputDifference.x); inputDifference.y = Mathf.Abs(inputDifference.y); if (inputDifference.y > swipeThreshold && hitObject.GetComponent <GrassScript>() != null) { GrassScript objectScript = hitObject.GetComponent <GrassScript>(); objectScript.PullGrass(); grassPlucked++; } else if (inputDifference.x > swipeThreshold && hitObject.GetComponent <LeafScript>() != null) { LeafScript objectScript = hitObject.GetComponent <LeafScript>(); objectScript.BrushLeaf(true); leavesBrushed++; } else if (hitObject.GetComponent <MushroomScript>() != null) { currentMushroom = hitObject.GetComponent <MushroomScript>(); currentMushroom.BringToCamera(); gameState = GameState.INSPECTING; ShowInspectionOptions(); } hitObject = null; } } else if (gameState == GameState.INSPECTING) { #if UNITY_WSA if (Input.acceleration.x > 0.5) { TossIt(); return; } else if (Input.acceleration.x < -0.5) { KeepIt(); return; } else if (Input.acceleration.z > 0.5) { EatIt(); return; } if (Input.touchCount > 0) { Touch firstTouch = Input.touches[0]; if (firstTouch.phase == TouchPhase.Began || firstTouch.phase == TouchPhase.Moved) { buttonDown = true; } screenPosition = firstTouch.position; } #else buttonDown = Input.GetMouseButton(0); screenPosition = Input.mousePosition; #endif if (buttonDown) { Vector2 screenDifference = screenPosition; screenDifference -= screenPositionHold; float turnSpeed = 0.2f; Vector3 rotatePosition = new Vector3(screenDifference.y * turnSpeed, 0, screenDifference.x * turnSpeed); currentMushroom.Rotate(rotatePosition); } screenPositionHold = screenPosition; } }