/* Distribute resources from contracts to zones if they're low */ private void DistributeResources() { if (CurrentRainyDay != RainyDayType.MAX_TYPES) { return; //Only allow contract consumption when no rainy day issues are active } bool contractBeingWorked = false; foreach (GameObject Contract in ContractsInside) { ContractInShip ContractMeta = Contract.GetComponent <ContractInShip>(); if (ContractMeta.State == ContractState.BEING_WORKED_ON) { contractBeingWorked = true; if (!workingAudio.isPlaying) { workingAudio.Play(); } ZoneInShip ThisZone = null; switch (ContractMeta.Assignee) { case ContractAssignee.BLUE: ThisZone = BlueZone.gameObject.GetComponent <ZoneInShip>(); break; case ContractAssignee.GREEN: ThisZone = GreenZone.gameObject.GetComponent <ZoneInShip>(); break; case ContractAssignee.RED: ThisZone = RedZone.gameObject.GetComponent <ZoneInShip>(); break; case ContractAssignee.YELLOW: ThisZone = YellowZone.gameObject.GetComponent <ZoneInShip>(); break; } if (ThisZone == null) { continue; } if (ThisZone.ResourceCount >= ThisZone.ResourceMax) { continue; } ThisZone.ResourceCount += ResourceDepletionRate[(int)ContractMeta.Assignee]; ContractMeta.ResourceRemaining -= ResourceDepletionRate[(int)ContractMeta.Assignee]; if (ContractMeta.ResourceRemaining <= 0.0f) { ContractMeta.State = ContractState.OUT_OF_JUICE; } } } if (!contractBeingWorked) { workingAudio.Stop(); } }
/* Handle dragging of contracts */ private void ContractInteraction() { PrevContractTouch = ActiveContractTouch; //Work out what contract we're interacting with Touch UserTouch = new Touch(); int ContractIndex = 0; ActiveContractTouch = -1; foreach (GameObject Contract in ContractsInside) { if (TouchManager.instance.GetTouch(Contract, ref UserTouch)) { ActiveContractTouch = ContractIndex; break; } ContractIndex++; } //Just released contract if (ActiveContractTouch == -1 && PrevContractTouch != -1) { Vector3 ContractPosition = ContractsInside[PrevContractTouch].transform.position; ContractInShip ContractMeta = ContractsInside[PrevContractTouch].GetComponent <ContractInShip>(); if (RedZone.bounds.Contains(ContractPosition)) { ContractMeta.Assignee = ContractAssignee.RED; } else if (GreenZone.bounds.Contains(ContractPosition)) { ContractMeta.Assignee = ContractAssignee.GREEN; } else if (BlueZone.bounds.Contains(ContractPosition)) { ContractMeta.Assignee = ContractAssignee.BLUE; } else if (YellowZone.bounds.Contains(ContractPosition)) { ContractMeta.Assignee = ContractAssignee.YELLOW; } else { ContractMeta.Assignee = ContractAssignee.NONE; } if (ContractMeta.Assignee == ContractAssignee.NONE) { ContractMeta.State = ContractState.IN_IDLE_SPOT; } else { ContractMeta.State = ContractState.BEING_WORKED_ON; } ContractsInside[PrevContractTouch].transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); ContractsInside[PrevContractTouch].transform.Find("LIGHT").gameObject.SetActive(false); return; } if (ActiveContractTouch == -1) { return; } //Still interacting with contract ContractsInside[ActiveContractTouch].transform.position = UserTouch.position; ContractsInside[ActiveContractTouch].GetComponent <ContractInShip>().Assignee = ContractAssignee.NONE; ContractsInside[ActiveContractTouch].GetComponent <ContractInShip>().State = ContractState.BEING_DRAGGED; ContractsInside[ActiveContractTouch].transform.localScale = new Vector3(1.2f, 1.2f, 1.2f); ContractsInside[ActiveContractTouch].transform.Find("LIGHT").gameObject.SetActive(true); }