Esempio n. 1
0
    public bool isModelGood()
    {
        int count = 0;

        for (int i = 0; i < width; i++)
        {
            if (model.Sample(i, i) == 0)
            {
                count++;
            }
        }
        return(count < width / 2);
    }
 public virtual void Draw()
 {
     if (output == null)
     {
         return;
     }
     if (group == null)
     {
         return;
     }
     undrawn = false;
     try{
         for (int y = 0; y < depth; y++)
         {
             for (int x = 0; x < width; x++)
             {
                 if (rendering[x, y] == null)
                 {
                     int v = (int)model.Sample(x, y);
                     if (v != 99 && v < training.tiles.Length)
                     {
                         Vector3    pos = new Vector3(x * gridsize, y * gridsize, 0f);
                         int        rot = (int)training.RS[v];
                         GameObject fab = training.tiles[v] as GameObject;
                         if (fab != null)
                         {
                             GameObject tile   = (GameObject)Instantiate(fab, new Vector3(), Quaternion.identity);
                             Vector3    fscale = tile.transform.localScale;
                             tile.transform.parent           = group;
                             tile.transform.localPosition    = pos;
                             tile.transform.localEulerAngles = new Vector3(0, 0, 360 - (rot * 90));
                             tile.transform.localScale       = fscale;
                             rendering[x, y] = tile;
                         }
                     }
                     else
                     {
                         undrawn = true;
                     }
                 }
             }
         }
     } catch (IndexOutOfRangeException) {
         model = null;
         return;
     }
 }
Esempio n. 3
0
    public void Draw(bool staircase = false)
    {
        if (output == null)
        {
            return;
        }
        if (group == null)
        {
            return;
        }
        undrawn = false;
        try
        {
            for (int z = 0; z < 1; z++)
            {
                for (int y = 0; y < depth; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        if (rendering[x, y, z] == null)
                        {
                            int v = (int)model.Sample(x, y);
                            if (v != 99 && v < training.tiles.Length)
                            {
                                Vector3    pos = new Vector3(x * gridsize, y * gridsize, z * gridsize);
                                int        rot = (int)training.RS[v];
                                GameObject fab = training.tiles[v] as GameObject;
                                if (fab != null)
                                {
                                    GameObject tile   = (GameObject)Instantiate(fab, new Vector3(), Quaternion.identity);
                                    Vector3    fscale = tile.transform.localScale;
                                    tile.transform.parent           = group;
                                    tile.transform.localPosition    = pos;
                                    tile.transform.localEulerAngles = new Vector3(0, 0, 360 - (rot * 90)); //----mark rotation !----
                                    tile.transform.localScale       = fscale;
                                    rendering[x, y, z] = tile;

                                    if (staircase && x % 3 == 0 && y % 5 == 0)
                                    {
                                        DrawStaircase(tile);
                                    }
                                }
                            }
                            else
                            {
                                undrawn = true;
                            }
                        }
                    }
                }
            }
        } catch (IndexOutOfRangeException e) {
            Debug.Log(e);
            model = null;
            return;
        }

        //---------Sorting and delete plateforms----------
        for (int z = 0; z < 1; z++)
        {
            for (int y = 0; y < depth; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    if (rendering[x, y, z] != null)
                    {
                        //Debug.Log(rendering[x, y, z].name.Replace("(Clone)", "") + " | " + repMur.name);
                        //------
                        if (rendering[x, y, z].name.Replace("(Clone)", "") == repMur.name)
                        {
                            //--the following deletes the 'flying room' if it is one--

                            bool    flying = true;                    //--------------- does the room have a path to it? we suppose it has not and whenever a path is found,
                            int     v      = (int)model.Sample(x, y); //--- switch flying to false, we then delete the room is flying hasn't been changed by the algorythm
                            Vector3 pos    = new Vector3(x * gridsize, y * gridsize, z * gridsize);
                            int     rot    = (int)training.RS[v];
                            pos = rendering[x, y, 0].transform.position;
                            //pos.x += 1;
                            GameObject currentObj = null; //-> = renderingxyz transform.gameobject
                            while (currentObj == null)
                            {
                                Collider[] hitColliders = Physics.OverlapSphere(rendering[x, y, 0].transform.position, 1f);

                                if (hitColliders.Length != 0)
                                {
                                    for (int i = 0; i < hitColliders.Length; i++)
                                    {
                                        if (hitColliders[i].gameObject.name != null)
                                        {
                                            currentObj = hitColliders[i].gameObject;
                                            if (currentObj.name.Replace("(Clone)", "") == repMur5.name || currentObj.name.Replace("(Clone)", "") == repMur6.name)
                                            {
                                                flying = false;
                                                //Debug.Log("+1 not flying house");
                                            }
                                        }
                                    }
                                }
                                //-----faire une chenille qui est "periodic output frendly"------
                            }
                        }

                        if (rendering[x, y, z].name == "cube3(Clone)" || rendering[x, y, z].name == "cube2(Clone)")
                        {
                            Collider[] hitColliders = Physics.OverlapSphere(rendering[x, y, z].transform.position, 1.0f);
                            if (hitColliders.Length != 0)
                            {
                                for (int i = 0; i < hitColliders.Length; i++)
                                {
                                    if (hitColliders[i].name == "cube1(Clone)")
                                    {
                                        hitColliders[i].name = "porte";
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }