public bool RemoveFish(PlayerInteractionController playerControllerScript, GameData.FishType fishType) { if (currentLevelSchools.ContainsKey(fishType)) { FishSchoolController schoolController = currentLevelSchools[fishType]; if (schoolController != null) { if (schoolController.FishInSchool.Count > 0) { GameObject fishToRemove = schoolController.RemoveFishFromSchool(0); FishMovementController fishMovementController = fishToRemove.GetComponent <FishMovementController>(); if (fishMovementController != null) { fishMovementController.SetEnabled(false); FishController fishController = fishToRemove.GetComponent <FishController>(); if (fishController != null) { fishController.SetEnabled(true); playerControllerScript.PickUpObject(fishToRemove); return(true); } } } } } return(false); }
public void StoreFish(GameObject fishToStore, GameData.FishType fishType) { if (fishToStore != null) { FishSchoolController schoolController = currentLevelSchools[fishType]; if (schoolController != null) { FishController fishController = fishToStore.GetComponent <FishController>(); if (fishController != null) { fishController.StartSlowPanic(); fishController.SetEnabled(false); FishMovementController fishMovementController = fishToStore.GetComponent <FishMovementController>(); if (fishMovementController != null) { fishMovementController.SetEnabled(true); fishMovementController.Initialise(); schoolController.AddFishToSchool(fishToStore); fishToStore.transform.position = holdSlot.transform.position; } // I don't know why I must do this, but I must delay setting the parent else it will force set itself to no parent StartCoroutine(GameController.ActivateCallbackAfterDelayCoroutine(1f, () => { fishController.transform.SetParent(schoolController.transform); })); } } } }
// Use this for initialization void Start() { currentState = State.Idle; currentSecondaryState = SecondaryState.Idle; currentResearchProtocol = 0; //Get own rigidbody component. rb = this.GetComponent <Rigidbody>(); // Get own movement controller fishMovementController = GetComponent <FishMovementController>(); StatusIcon.enabled = false; PanicBarRect.gameObject.SetActive(false); panicBarWidth = PanicBarRect.rect.width; panicTimer = GameData.GetFishParameters(fishType).panicTimerLength; currentPanicRate = slowPanicRate; if (fishType != GameData.FishType.None) { fishRenderer = GetComponentInChildren <SkinnedMeshRenderer>(); Setup(); } SetEnabled(false); }
public void AddFishToSchool(GameObject fish) { fishSchoolGoalLocation = new Vector3 ( transform.position.x + Random.Range(-zoneX, zoneX), transform.position.y + Random.Range(-zoneY, zoneY), transform.position.z + Random.Range(-zoneZ, zoneZ) ); FishMovementController fishMovementScript = (FishMovementController)fish.GetComponent(typeof(FishMovementController)); if (fishMovementScript != null) { fishMovementScript.FishSchoolController = this; fishInSchool.Add(fish); } }
public GameObject RemoveFishFromSchool(int index) { GameObject fish = null; if (index >= 0 && index < fishInSchool.Count) { fish = fishInSchool[index]; if (fish != null) { FishMovementController fishMovementScript = (FishMovementController)fish.GetComponent(typeof(FishMovementController)); if (fishMovementScript != null) { fishInSchool.RemoveAt(index); } } } return(fish); }
public GameObject RemoveFishFromSchool(GameObject fishToRemove) { GameObject fish = null; if (fishToRemove != null) { fish = fishInSchool[fishInSchool.IndexOf(fishToRemove)]; if (fish != null) { FishMovementController fishMovementScript = (FishMovementController)fish.GetComponent(typeof(FishMovementController)); if (fishMovementScript != null) { fishInSchool.RemoveAt(fishInSchool.IndexOf(fishToRemove)); } } } return(fish); }
/* * private void OnTriggerExit(Collider other) * { * if (other.tag == "Zone" && other.gameObject.name == fishSchoolController.zoneName) * { * outOfBounds = true; * } * //if (other.tag != "FishObject") * //turning = false; * } */ private void School() { if (fishSchoolController != null) { List <GameObject> fishInSchool = fishSchoolController.FishInSchool; Vector3 centralVector = Vector3.zero; Vector3 avoidanceVector = Vector3.zero; Vector3 goalLocation = fishSchoolController.GoalLocation; float groupSpeed = 0.1f; float distanceToOther; int groupSize = 0; foreach (GameObject otherFish in fishInSchool) { if (otherFish != this.gameObject) { distanceToOther = Vector3.Distance(otherFish.transform.position, this.transform.position); if (distanceToOther <= minNeighbourDistance) { centralVector += otherFish.transform.position; groupSize++; if (distanceToOther < 1.0f) { avoidanceVector = avoidanceVector + (this.transform.position - otherFish.transform.position); } FishMovementController otherFishMovementController = otherFish.GetComponent <FishMovementController>(); if (otherFishMovementController != null) { groupSpeed = groupSpeed + otherFishMovementController.Speed; } } } } if (groupSize > 0) { centralVector = centralVector / groupSize + (goalLocation - this.transform.position); speed = groupSpeed / groupSize; Vector3 finalDirection = (centralVector + avoidanceVector) - this.transform.position; if (finalDirection != Vector3.zero) { this.transform.rotation = Quaternion.Slerp ( this.transform.rotation, Quaternion.LookRotation(finalDirection), rotationSpeed * Time.deltaTime ); } } else { this.transform.rotation = Quaternion.Slerp ( this.transform.rotation, randomRotation, rotationSpeed * Time.deltaTime ); if (Mathf.Abs(Quaternion.Angle(this.transform.rotation, randomRotation)) < 0.2f) { randomRotation = Random.rotation; } } } }
// Use this for initialization void Start() { warningText.SetActive(false); previousSchools = new List <FishSchoolController>(); for (int i = 0; i < PersistentData.Obj.savedSchools.Count; i++) { PersistentData.AquariumSchoolData persistentData = PersistentData.Obj.savedSchools[i]; GameData.FishType fishTypeToSpawn = persistentData.fishType; GameData.FishParameters fishParameters = GameData.GetFishParameters(fishTypeToSpawn); GameObject newFishSchool = (GameObject)Instantiate(fishSchool); newFishSchool.transform.position = holdSlot.transform.position; newFishSchool.transform.SetParent(gameObject.transform); FishSchoolController fishSchoolController = newFishSchool.GetComponent <FishSchoolController>(); fishSchoolController.zoneX = 20; fishSchoolController.zoneY = 10; fishSchoolController.zoneZ = 5; for (int j = 0; j < persistentData.numberOfFishes; j++) { FishController newFish = GameData.CreateNewFish(fishTypeToSpawn, newFishSchool.transform); FishMovementController fishMovementController = newFish.GetComponent <FishMovementController>(); fishMovementController.Initialise ( fishParameters.minSpeed, fishParameters.maxSpeed, fishParameters.minRotationSpeed, fishParameters.maxRotationSpeed, fishParameters.minNeighbourDistance ); fishMovementController.SetEnabled(true); newFish.SetRigidbody(false); newFish.gameObject.transform.position = holdSlot.transform.position + new Vector3(Random.Range(-2, 2), Random.Range(-2, 2), Random.Range(-2, 2)); fishSchoolController.AddFishToSchool(newFish.gameObject); } previousSchools.Add(fishSchoolController); } currentLevelSchools = new Dictionary <GameData.FishType, FishSchoolController>(); fishResearchRequirements = new Dictionary <GameData.FishType, GameObject>(); if (isTutorial) { researchRequirementsForLevel = GameData.GetResearchRequirementsForLevel(0); } else { researchRequirementsForLevel = GameData.GetResearchRequirementsForLevel(GameController.Obj.CurrentLevel); } for (int i = 0; i < researchRequirementsForLevel.Length; i++) { GameObject newFishSchool = (GameObject)Instantiate(fishSchool); newFishSchool.transform.position = holdSlot.transform.position; newFishSchool.transform.SetParent(GameController.Obj.AquariumHolder); FishSchoolController fishSchoolController = newFishSchool.GetComponent <FishSchoolController>(); fishSchoolController.zoneX = 10; fishSchoolController.zoneY = 5; fishSchoolController.zoneZ = 10; currentLevelSchools.Add(researchRequirementsForLevel[i], fishSchoolController); Transform newFishResearchRequirements = Instantiate(GameData.GetSelectableFish(researchRequirementsForLevel[i])); newFishResearchRequirements.SetParent(researchReqAnchor.transform, false); newFishResearchRequirements.Translate(0 + (i * 5), 0, 0); newFishResearchRequirements.GetComponent <ResearchRequirementsController>().Init(researchRequirementsForLevel[i]); fishResearchRequirements.Add(researchRequirementsForLevel[i], newFishResearchRequirements.gameObject); } }
protected IEnumerator SpawnSchools() { while (schoolsDone < numSchools) { int rand = Random.Range(MINIMUM_SCHOOL_SIZE, MAXIMUM_SCHOOL_SIZE); for (int i = 0; i < rand; i++) { if (schoolsDone >= numSchools) { break; } GameData.FishType fishTypeToSpawn; if (fishTypesToSpawn.Length > 0) { fishTypeToSpawn = fishTypesToSpawn [Random.Range(0, fishTypesToSpawn.Length)]; } else { fishTypeToSpawn = (GameData.FishType)Random.Range(0, GameData.TOTAL_NUMBER_OF_FISHTYPES); } GameData.FishParameters fishParameters = GameData.GetFishParameters(fishTypeToSpawn); GameObject newFishSchool = (GameObject)Instantiate(fishSchoolTemplate, SpawnPoint); newFishSchool.transform.position = transform.position; FishSchoolController fishSchoolController = newFishSchool.GetComponent <FishSchoolController>(); fishSchoolController.zoneX = zoneX; fishSchoolController.zoneY = zoneY; fishSchoolController.zoneZ = zoneZ; fishSchoolController.zoneName = zoneCollider.name; int schoolSize = Random.Range(fishParameters.minSchoolSize, fishParameters.maxSchoolSize); Vector3 schoolPos = gameObject.transform.position + new Vector3(Random.Range(-zoneX, zoneX), Random.Range(-zoneY, zoneY), Random.Range(-zoneZ, zoneZ)); for (int j = 0; j < schoolSize; j++) { FishController newFish = GameData.CreateNewFish(fishTypeToSpawn, newFishSchool.transform); FishMovementController fishMovementController = newFish.GetComponent <FishMovementController>(); fishMovementController.Initialise ( fishParameters.minSpeed, fishParameters.maxSpeed, fishParameters.minRotationSpeed, fishParameters.maxRotationSpeed, fishParameters.minNeighbourDistance ); fishMovementController.SetEnabled(true); newFish.SetRigidbody(false); newFish.gameObject.transform.position = schoolPos + new Vector3(Random.Range(-5, 5), Random.Range(-5, 5), Random.Range(-5, 5)); fishSchoolController.AddFishToSchool(newFish.gameObject); } fishSchools[fishTypeToSpawn].Add(newFishSchool); schoolsDone++; } yield return(new WaitForEndOfFrame()); } finishSpawning = true; yield return(null); }