Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        float wheel = 0;

        if ((wheel = Input.GetAxis("Mouse ScrollWheel")) < 0)
        {
            Camera.main.transform.position += new Vector3(0, -wheel * 2, 0);
        }
        else if ((wheel = Input.GetAxis("Mouse ScrollWheel")) > 0)
        {
            Camera.main.transform.position += new Vector3(0, -wheel * 2, 0);
            if (Camera.main.transform.position.y < maxZoom)
            {
                Camera.main.transform.position += new Vector3(0, 6 - Camera.main.transform.position.y, 0);
            }
        }
        float hit;

        Ray r;

        if (maps != null)
        {
            if (plane.Raycast(r = Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
            {
                Vector3 pos = r.GetPoint(hit);
                Vector3 o   = new Vector3(pos.x, pos.y, pos.z);
                pos.y = 0.52f;
                bool test;
                pos = maps.NormalizePosition(pos, out test);
                if (!test)
                {
                    return;
                }
                cursor.transform.position = pos;
                //Debug.Log(cursor.transform.position + " " + o);

                if (Input.GetMouseButton(0))
                {
                    IntVector2 tpos = maps.GetTilePosition(new Vector2(pos.x, pos.z));
                    if (tpos != null)
                    {
                        maps.AddBlock((MapsTiles)selGridInt, tpos);
                    }
                }
                else if (Input.GetMouseButton(1))
                {
                    IntVector2 tpos = maps.GetTilePosition(new Vector2(pos.x, pos.z));
                    if (tpos != null)
                    {
                        maps.AddBlock((MapsTiles)0, tpos);
                    }
                }
            }
        }
    }
Esempio n. 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);
        }
    }