Exemplo n.º 1
0
    void CreateChildObject(Material main, Material second, GameObject parent1, GameObject parent2)
    {
        GameObject       Child = new GameObject();
        AnimalStatistics stats = Child.AddComponent <AnimalStatistics>();
        AnimalMovement   move  = Child.AddComponent <AnimalMovement>();
        BoxCollider      coll  = Child.AddComponent <BoxCollider>();



        GameObject[] BodyParts = new GameObject[4];
        for (int i = 0; i < 4; ++i)
        {
            BodyParts[i] = (Random.value < 0.5f ? parent1.transform.GetChild(i).gameObject : parent2.transform.GetChild(i).gameObject);
        }


        GameObject Body = Instantiate(BodyParts[0]);

        Body.transform.parent = Child.transform;

        GameObject   NewPart;
        MeshRenderer TempMeshRend = Body.GetComponent <MeshRenderer>();

        ApplyMaterial(main, second, TempMeshRend);

        for (int i = 1; i < 4; ++i)
        {
            NewPart = Instantiate(BodyParts[i]);
            NewPart.transform.parent   = Child.transform;
            NewPart.transform.position = Body.transform.GetChild(i - 1).position;

            if (i == 2)
            {
                for (int j = 0; j < NewPart.transform.childCount; ++j)
                {
                    TempMeshRend = NewPart.transform.GetChild(j).GetComponent <MeshRenderer>();
                    ApplyMaterial(main, second, TempMeshRend);
                }
            }
            else
            {
                TempMeshRend = NewPart.GetComponent <MeshRenderer>();
                ApplyMaterial(main, second, TempMeshRend);
            }
        }

        PassInNewGeneralStats(ref stats, parent1.GetComponent <AnimalStatistics>(), parent2.GetComponent <AnimalStatistics>());
        PassInNewCollider(ref coll, (Random.value < 0.5f ? parent1.GetComponent <BoxCollider>() : parent2.GetComponent <BoxCollider>()));
        PassInNewMoveVars(ref move, (Random.value < 0.5f ? parent1.GetComponent <AnimalMovement>() : parent2.GetComponent <AnimalMovement>()));

        Child.tag = (Random.value < 0.5f ? parent1.tag : parent2.tag);
        Child.transform.position = (parent1.transform.position + parent2.transform.position) / 2f;
    }
Exemplo n.º 2
0
    IEnumerator UpdateParts(int terainStartX, int terainStartY)
    {
        //List<NewPart> newParts = new List<NewPart>();
        NewPart[] newPartsAr = new NewPart[((drawDist + drawDist + 1) * (drawDist + drawDist + 1))];
        int       num        = 0;
        // colect posible new tile positions
        Vector3 targetPos = target.position;

        for (int x = -drawDist; x < (drawDist + 1); x++)
        {
            for (int z = -drawDist; z < (drawDist + 1); z++)
            {
                float dist = Vector2.Distance(new Vector2(terainStartX + ((x * terainSize) - (terainSize * 0.5f)), terainStartY + ((z * terainSize) - (terainSize * 0.5f))), new Vector2(targetPos.x, targetPos.z));
                newPartsAr[num] = new NewPart(terainStartX + (x * (terainSize)), terainStartY + (z * (terainSize)), dist);
                num++;
            }
        }

        // start threaded sort job to sort possible new tiles by distance
        SortTerainGenByDistJob sortJob        = new SortTerainGenByDistJob(newPartsAr);
        ThreadedJobHandeler    sortJobHandler = new ThreadedJobHandeler();

        sortJobHandler.Init(sortJob);
        while (!sortJobHandler.JobDone)
        {
            sortJobHandler.Tick();
            yield return(null);
        }

        int currentPartsGenerated = 0;

        // generate max 2 new parts
        for (int i = 0; i < newPartsAr.Length; i++)
        {
            // generate parts
            if (GenPart(newPartsAr[i].xPart, newPartsAr[i].yPart))
            {
                currentPartsGenerated++;
            }
            ;

            if (currentPartsGenerated > 2)
            {
                break;
            }
        }
        yield return(null);

        UpdateTerain();
    }
Exemplo n.º 3
0
        void openModifyPartWindowExecute()
        {
            NewPart npWindow;

            if (selectedPart != null)
            {
                if (inQuotMode)
                {
                    npWindow = new NewPart(selectedPart, false);
                }
                else
                {
                    npWindow = new NewPart(selectedPart, true);
                }
                npWindow.Show();
            }
        }
    IEnumerator UpdateParts(int terainStartX, int terainStartY)
    {
        //List<NewPart> newParts = new List<NewPart>();
        NewPart[] newPartsAr = new NewPart[((drawDist + drawDist + 1) * (drawDist + drawDist + 1))];
        int num = 0;
        // colect posible new tile positions
        Vector3 targetPos = target.position;
        for (int x = -drawDist; x < (drawDist + 1); x++)
        {
            for (int z = -drawDist; z < (drawDist + 1); z++)
            {
                float dist = Vector2.Distance(new Vector2(terainStartX + ((x * terainSize) - (terainSize * 0.5f)), terainStartY + ((z * terainSize) - (terainSize * 0.5f))), new Vector2(targetPos.x, targetPos.z));
                newPartsAr[num] = new NewPart(terainStartX + (x * (terainSize)), terainStartY + (z * (terainSize)), dist);
                num++;
            }
        }

        // start threaded sort job to sort possible new tiles by distance
        SortTerainGenByDistJob sortJob = new SortTerainGenByDistJob(newPartsAr);
        ThreadedJobHandeler sortJobHandler = new ThreadedJobHandeler();
        sortJobHandler.Init(sortJob);
        while (!sortJobHandler.JobDone)
        {
            sortJobHandler.Tick();
            yield return null;
        }

        int currentPartsGenerated = 0;

        // generate max 2 new parts
        for (int i = 0; i < newPartsAr.Length; i++)
        {
            // generate parts
            if (GenPart(newPartsAr[i].xPart, newPartsAr[i].yPart))
            {
                currentPartsGenerated++;
            };

            if (currentPartsGenerated > 2)
            {
                break;
            }
        }
        yield return null;
        UpdateTerain();
    }
Exemplo n.º 5
0
        void openAddPartWindowExecute()
        {
            NewPart npWindow = new NewPart();

            npWindow.Show();
        }