Пример #1
0
    public static Renderer FindIngredients(bool canDrawGizmo = true)
    {
        Transform me = FindObjectOfType <Transform>();
        TerrainGeneratorUsingPerlin terrainGen = new TerrainGeneratorUsingPerlin();

        for (int y = 0; y < terrainGen.height; y++)
        {
            for (int x = 0; x < terrainGen.width; x++)
            {
                //foreach (GameObject ingredient in terrainGen.ingredients){
                //foreach (GameObject ingredient in gameObject.transform){
                for (int i = 0; i < me.childCount; i++)
                {
                    Transform ingredient = me.GetChild(i);
//					print(ingredient.name);
                    if (ingredient.position.x == x && ingredient.position.z == y)
                    {
//						print("x:"+x+", y:"+y);
                        Renderer rend   = ingredient.GetComponent <Renderer>();
                        Vector3  center = rend.bounds.center;
                        float    radius = rend.bounds.extents.magnitude;
                        if (canDrawGizmo)
                        {
                            Gizmos.color = Color.magenta;
                            Gizmos.DrawWireSphere(center, radius);
                        }
                        return(rend);
                    }
                }
            }
        }
        return(null);
    }
Пример #2
0
    public override void OnInspectorGUI()
    {
        TerrainGeneratorUsingPerlin myScript = (TerrainGeneratorUsingPerlin)target;

        if (DrawDefaultInspector())
        {
            if (myScript.autoUpdate)
            {
                myScript.RefreshTerrain();
            }
        }

        if (GUILayout.Button("Random Terrain"))
        {
            myScript.RefreshTerrain();
        }

        if (GUILayout.Button("Ingredients"))
        {
            myScript.SharpAvoidIngredients();
        }

        if (GUILayout.Button("smooth"))
        {
            myScript.SmoothAroundIngredients();
        }
    }
Пример #3
0
    public static Renderer FindIngredient(GameObject[] ingredients, int x, int y, bool canDrawGizmo = false)
    {
        TerrainGeneratorUsingPerlin terrainGen = new TerrainGeneratorUsingPerlin();

        print("~ingredients.Length :" + ingredients.Length);
        //foreach (GameObject ingredient in terrainGen.ingredients){
        //foreach (GameObject ingredient in gameObject.transform){
        for (int i = 0; i < ingredients.Length; i++)
        {
            Transform ingredient = ingredients[i].transform;
//					print(ingredient.name);
            if (ingredient.position.x == x && ingredient.position.z == y)
            {
//						print("x:"+x+", y:"+y);
                Renderer rend = ingredient.GetComponent <Renderer>();

                if (canDrawGizmo)
                {
                    Vector3 center = rend.bounds.center;
                    float   radius = rend.bounds.extents.magnitude;
                    Gizmos.color = Color.magenta;
                    Gizmos.DrawWireSphere(center, radius);
                }
                return(rend);
            }
        }

        return(null);
    }