Beispiel #1
0
    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);
                    }));
                }
            }
        }
    }
Beispiel #2
0
    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);
    }
Beispiel #3
0
    // 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);
        }
    }
Beispiel #4
0
    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);
    }