Ejemplo n.º 1
0
    /// <summary>
    /// Tries to spawn life at a given mesh vertex.
    /// </summary>
    /// <param name="index">The index of the vertex to use as a spawn point.</param>
    /// <param name="printDebug">Whether or not to print out when spawning new life</param>
    /// <returns>If successful, return true. Otherwise, return false.</returns>
    bool SpawnLifeAtVertex(int index, bool printDebug = false)
    {
        if (index < 0)
        {
            return(false);
        }
        if (index >= mesh.mesh.vertexCount)
        {
            return(false);
        }

        Vector3    pos    = mesh.mesh.vertices[index] + transform.position;
        Color      color  = mesh.mesh.colors[index];
        Vector3    normal = mesh.mesh.normals[index];
        Quaternion rot    = Quaternion.FromToRotation(Vector3.up, normal);

        Biome biome = Biome.FromColor(color);

        if (printDebug)
        {
            print("Spawning life in " + biome.owner + "'s biome...");
        }

        // TODO: add a kind of "proximity" check to ensure that plants aren't growing too close to each other

        GameObject prefab = null;

        if (biome.owner == BiomeOwner.Andrew)
        {
            prefab = prefabCoralGlow;
        }
        if (biome.owner == BiomeOwner.Cameron)
        {
            prefab = (Random.Range(0f, 5f) >= 3) ? prefabCoralCrystal : (Random.Range(0f, 10f) > 9f) ? prefabCrystalFlower : prefabCrystalRock;
        }
        if (biome.owner == BiomeOwner.Chris)
        {
            prefab = (Random.Range(0f, 5f) > 1f) ? prefabCoralTubeWorm : (Random.Range(0f, 2f) > 1) ? prefabPlantDrifter : prefabOtherAnchor;
            if (Random.Range(0f, 5f) < 1f)
            {
                SpawnPrefab(prefabCreatureBlindShrimp, pos, rot, 1);
            }
        }
        if (biome.owner == BiomeOwner.Dominic)
        {
            prefab = prefabCoralVoronoi;
        }
        if (biome.owner == BiomeOwner.Eric)
        {
            prefab = prefabCoralTree;
        }
        if (biome.owner == BiomeOwner.Josh)
        {
            //chance of spawning pyramid, or plant
            //   prefab = (Random.Range(1, 5) > 3) ? prefabCoralPyramid : prefabPlantLeaf;
            int rand = Random.Range(1, 10);
            if (rand < 2)
            {
                prefab = prefabCoralPyramid;
            }
            else if (rand > 8)
            {
                prefab = prefabPlantLeaf;
            }
            else
            {
                prefab = prefabSeaDragon;
            }
        }
        if (biome.owner == BiomeOwner.Jess)
        {
            prefab = (Random.Range(1, 5) >= 3) ? prefabCoralBroccoli : prefabPlantSeagrass;
        }

        if (biome.owner == BiomeOwner.Justin)
        {
            prefab = prefabCoralBauble;
        }
        if (biome.owner == BiomeOwner.Jesse)
        {
            int num = Random.Range(1, 7) + Random.Range(1, 7);
            if (num > 7)
            {
                prefab = prefabCoralFingers;
            }
            else if (num > 3)
            {
                prefab = prefabFishGobies;
            }
            else
            {
                prefab = prefabObjectChest;
            }
        }

        if (biome.owner == BiomeOwner.Justin)
        {
            prefab = (Random.Range(1, 5) >= 3) ? prefabCoralBauble: prefabCoralFlower;

            if (Random.Range(0f, 5f) < 1f)
            {
                SpawnPrefab(prefabCreatureMinnow, pos, rot, 1);
            }
        }
        if (biome.owner == BiomeOwner.Kaylee)
        {
            prefab = (Random.Range(0f, 5f) >= 3) ? prefabCoralPurpleFan : (Random.Range(0f, 10f) > 5f) ? prefabMossBall : prefabSeaUrchin;
        }
        if (biome.owner == BiomeOwner.Kyle)
        {
            prefab = (Random.Range(1, 5) > 3) ? prefabCreatureSeaStar : prefabPlantKelp;
        }

        //if (biome.owner == BiomeOwner.Zach) prefab = ;
        if (biome.owner == BiomeOwner.Keegan)
        {
            prefab = prefabCoralPrecious;
        }

        float scale = Random.Range(.1f, .75f) + Random.Range(.1f, .75f);

        if (prefab != null)
        {
            //spawn prefab
            GameObject obj = SpawnPrefab(prefab, pos, rot, 1);

            // instantiate Coroutine for adding mesh collider
            IEnumerator cr = AddMeshCollider(obj);
            StartCoroutine(cr);
        }
        return(true);
    }