Пример #1
0
    protected void InitAnimals()
    {
        AnimalGenerator animalGenerator = FindObjectOfType <AnimalGenerator>();

        for (int x = 0; x < UnityEngine.Random.Range(0, 3); x++)
        {
            float posX = UnityEngine.Random.Range(coord.x * 10.0f - 5, coord.x * 10.0f + 5);
            float posZ = UnityEngine.Random.Range(coord.z * 10.0f - 5, coord.z * 10.0f + 5);

            Ray ray = new Ray(new Vector3(posX, (coord.y * 10 - 5), posZ), new Vector3(0, -1, 0));
            if (Physics.Raycast(ray, out RaycastHit hit, 10))
            {
                if (hit.transform.tag.Equals("chunk") && hit.point.y > -1 && hit.point.y < 5)
                {
                    Vector3    position     = hit.point;
                    GameObject animalPrefab = animalGenerator.animal;
                    Quaternion rotation     = Quaternion.Euler(new Vector3(0, UnityEngine.Random.Range(0, 360), 0));

                    GameObject animal = Instantiate(animalPrefab, position, rotation);
                    animal.transform.parent = this.transform;

                    entities.Add(new EntityData(position, rotation, EntityType.Animal));
                }
            }
        }
    }
Пример #2
0
 public void Inherit(AnimalGenerator parent)
 {
     this.color = parent.color;
     this.Body  = parent.Body;
     this.Head  = parent.Head;
     this.Tail  = parent.Tail;
     Generation = parent.Generation + 1;
 }
Пример #3
0
    public void Load()
    {
        BinaryFormatter bf          = new BinaryFormatter();
        String          fileName    = "chunk_" + coord.x + "_" + coord.y + "_" + coord.z + ".dat";
        String          destination = Application.persistentDataPath + "/" + fileName;
        FileStream      file;

        if (File.Exists(destination))
        {
            file = File.Open(destination, FileMode.Open);
        }
        else
        {
            Debug.LogError("File not found");
            return;
        }

        ChunkData chunkData = bf.Deserialize(file) as ChunkData;

        file.Close();

        numPoints    = chunkData.numPoints;
        entities     = new List <EntityData>(chunkData.entityData);
        pointsBuffer = new ComputeBuffer(numPoints, sizeof(float));
        pointsBuffer.SetData(chunkData.realPointsBuffer);
        mesh = new Mesh();
        Debug.Log(destination + " loaded");

        // Load entities
        TreeGenerator   treeGenerator   = FindObjectOfType <TreeGenerator>();
        AnimalGenerator animalGenerator = FindObjectOfType <AnimalGenerator>();

        foreach (EntityData entity in entities)
        {
            Vector3    position = entity.position;
            Quaternion rotation = entity.rotation;

            switch (entity.entityType)
            {
            case EntityType.Tree:
                GameObject treeType   = treeGenerator.shortTrees[UnityEngine.Random.Range(0, treeGenerator.shortTrees.Length)];
                GameObject treeObject = Instantiate(treeType, position, rotation);
                treeObject.transform.parent = this.transform;
                break;

            case EntityType.Animal:
                GameObject animalPrefab = animalGenerator.animal;
                GameObject animal       = Instantiate(animalPrefab, position, rotation);
                animal.transform.parent = this.transform;
                break;
            }
        }
    }
Пример #4
0
        static void Main()
        {
            var dogs = AnimalGenerator.GenerateDogs(10);

            Console.WriteLine("Average Age of Dogs: ".PadRight(30, '-') + " {0:F2}", Animal.AverageAge(dogs));

            var cats = AnimalGenerator.GenerateCats(10);

            Console.WriteLine("Average Age of Cats: ".PadRight(30, '-') + " {0:F2}", Animal.AverageAge(cats));

            var frogs = AnimalGenerator.GenerateFrogs(10);

            Console.WriteLine("Average Age of Frogs: ".PadRight(30, '-') + " {0:F2}", Animal.AverageAge(frogs));

            var kittens = AnimalGenerator.GenerateKittens(10);

            Console.WriteLine("Average Age of Kittens: ".PadRight(30, '-') + " {0:F2}", Animal.AverageAge(kittens));

            var tomcats = AnimalGenerator.GenerateTomCats(10);

            Console.WriteLine("Average Age of Tomcats: ".PadRight(30, '-') + " {0:F2}", Animal.AverageAge(tomcats));
        }
Пример #5
0
 // Start is called before the first frame update
 void Start()
 {
     _AnimalGenerator   = GameObject.Find("AnimalGenerator");
     _AnimalGeneratorSc = _AnimalGenerator.GetComponent <AnimalGenerator>();
 }