Example #1
0
    public void Fill(MapsTiles type)
    {
        IntVector2 p = new IntVector2();

        for (int i = 0; i < m_size.x; i++)
        {
            p.x = i;
            for (int j = 0; j < m_size.y; j++)
            {
                p.y = j;
                AddBlock(type, p);
            }
        }
    }
Example #2
0
    void OnGUI()
    {
        wantsMouseMove = true;
        m_material     = (Material)EditorGUILayout.ObjectField("1", m_material, typeof(Material));
        m_grid_shader  = (Material)EditorGUILayout.ObjectField("2", m_grid_shader, typeof(Material));
        t    = (Transform)EditorGUILayout.ObjectField("Stone template", t, typeof(Transform));
        b    = (Transform)EditorGUILayout.ObjectField("Breakable template", b, typeof(Transform));
        size = EditorGUILayout.Vector2Field("Grid Size", size);

        if (GUILayout.Button("generate maps"))
        {
            Maps.s_material  = m_material;
            Maps.s_grid      = m_grid_shader;
            Maps.s_stone     = t;
            Maps.s_breakable = b;
            if (maps != null)
            {
                maps.Clear();
            }
            maps = new Maps(new IntVector2((int)size.x, (int)size.y));
            maps.Generate();
        }
        pos  = (Vector2)EditorGUILayout.Vector2Field("position : ", pos);
        type = (MapsTiles)EditorGUILayout.EnumPopup("type : ", type);
        //Debug.Log("try to add a block");
        if (GUILayout.Button("add block to maps"))
        {
            Debug.Log("try to add a block");
            if (maps != null)
            {
                Debug.Log("add " + type + " block to maps");
                maps.AddBlock(type, new IntVector2((int)pos.x, (int)pos.y));
            }
        }

        path = EditorGUILayout.TextField("Path :", path);
        if (GUILayout.Button("Save to"))
        {
            maps.SaveToFile(path);
        }

        if (GUILayout.Button("load to"))
        {
            maps = Maps.LoadMapsFromFile(path);
        }
    }
Example #3
0
    public void AddBlock(MapsTiles type, IntVector2 pos)
    {
        if (m_maps[pos.x][pos.y] != null)
        {
            if (m_maps[pos.x][pos.y].m_type == type)
            {
                return;
            }
            if (m_maps[pos.x][pos.y].block != null)
            {
                //Workaround to enforce collider exit
                m_maps[pos.x][pos.y].block.gameObject.transform.position = Vector3.up * 1000;
                GameObject todelete = m_maps[pos.x][pos.y].block.gameObject;
                GameObject.Destroy(todelete, 5);
            }
            m_maps[pos.x][pos.y].m_type = type;
            Transform obj = null;


            Vector3 b_pos = new Vector3(pos.x + (Size.x % 2 == 0 ? 0.5f : 0) - m_size_2.x, 0.5f, pos.y + (Size.y % 2 == 0 ? 0.5f : 0f) - m_size_2.y);
            switch (type)
            {
            case MapsTiles.SOLID_BLOCK:
                obj = (Transform)Transform.Instantiate(s_stone, b_pos, new Quaternion());
                break;

            case MapsTiles.DESTRUCTIBLE_BLOCK:
                obj = (Transform)Transform.Instantiate(s_breakable, b_pos, new Quaternion());
                break;
            }
            if (obj != null)
            {
                obj.parent = m_gameMaps.transform;
            }
            //Debug.Log("add block at " + pos + " type : " + type);
            m_maps[pos.x][pos.y].block = obj;
        }
    }
Example #4
0
 public Tile(MapsTiles type, IntVector2 pos)
 {
     m_type     = type;
     m_position = pos;
 }