示例#1
0
 public void Create()
 {
     Cursor.visible = false;
     WorldCreate worldConstructor = new WorldCreate ();
     worldConstructor.LoadWorld (wType);
     isShown = true;
 }
示例#2
0
    /// <summary>
    /// 矫正坐标
    /// </summary>
    private static Vector3 CorrectPos(Vector3 pos)
    {
        WorldCreate world = WorldCreate.instance;
        float       x     = (Mathf.Floor(pos.x / world.scale) + 0.5f) * world.scale;
        float       z     = (Mathf.Floor(pos.z / world.scale) + 0.5f) * world.scale;

        return(new Vector3(x, 0, z));
    }
示例#3
0
    /// <summary>
    /// 是否一样的坐标
    /// </summary>
    private static bool IsSame(Vector3 a, Vector3 b)
    {
        WorldCreate world = WorldCreate.instance;
        int         ax    = (int)(Mathf.Floor(a.x / world.scale));
        int         az    = (int)(Mathf.Floor(a.z / world.scale));
        int         bx    = (int)(Mathf.Floor(b.x / world.scale));
        int         bz    = (int)(Mathf.Floor(b.z / world.scale));

        if (ax == bx && az == bz)
        {
            return(true);
        }
        return(false);
    }
示例#4
0
 private void Awake()
 {
     instance = this;
     Init();
 }
 void Start()
 {
     wc = FindObjectOfType <WorldCreate>();
 }
示例#6
0
    void OnGUI()
    {
        if (world == null)
        {
            world = FindObjectOfType <WorldCreate>();
            if (world == null)
            {
                GUILayout.Label("没有地图数据");
                return;
            }
        }
        if (!world.has_units())
        {
            world.Init();
            this.size = world.size;
        }
        GUILayout.BeginHorizontal();
        GUILayout.Label("地图大小:");
        if (int.TryParse(GUILayout.TextField(this.size.ToString()), out int size))
        {
            this.size = size;
        }
        GUILayout.Space(40);
        if (GUILayout.Button("初始化"))
        {
            world.size  = size;
            world.units = new int[size * size];
            world.Init();
        }
        GUILayout.EndHorizontal();

        Color def = GUI.color;

        GUILayout.Space(20);
        GUILayout.BeginHorizontal();
        if (drawMode == DrawMode.Point)
        {
            GUI.color = Color.red;
        }
        else
        {
            GUI.color = def;
        }
        if (GUILayout.Button("点绘制"))
        {
            drawMode = DrawMode.Point;
        }
        if (drawMode == DrawMode.Rect)
        {
            GUI.color = Color.red;
        }
        else
        {
            GUI.color = def;
        }
        if (GUILayout.Button("矩形绘制"))
        {
            drawMode = DrawMode.Rect;
        }
        GUILayout.EndHorizontal();
        GUILayout.Space(20);


        GUILayout.BeginHorizontal();
        if (drawType == DrawType.Add)
        {
            GUI.color = Color.red;
        }
        else
        {
            GUI.color = def;
        }
        if (GUILayout.Button("增加模式"))
        {
            drawType = DrawType.Add;
        }
        if (drawType == DrawType.Remove)
        {
            GUI.color = Color.red;
        }
        else
        {
            GUI.color = def;
        }
        if (GUILayout.Button("移除模式"))
        {
            drawType = DrawType.Remove;
        }
        GUILayout.EndHorizontal();
        GUILayout.Space(20);



        if (unitMode == WorldUnit.None)
        {
            GUI.color = Color.red;
        }
        else
        {
            GUI.color = def;
        }
        if (GUILayout.Button("绘制空地"))
        {
            unitMode = WorldUnit.None;
        }
        if (unitMode == WorldUnit.Impede)
        {
            GUI.color = Color.red;
        }
        else
        {
            GUI.color = def;
        }
        if (GUILayout.Button("绘制障碍"))
        {
            unitMode = WorldUnit.Impede;
        }
        if (unitMode == WorldUnit.Monster)
        {
            GUI.color = Color.red;
        }
        else
        {
            GUI.color = def;
        }
        if (GUILayout.Button("绘制野怪"))
        {
            unitMode = WorldUnit.Monster;
        }
        if (unitMode == WorldUnit.City)
        {
            GUI.color = Color.red;
        }
        else
        {
            GUI.color = def;
        }
        if (GUILayout.Button("绘制城市"))
        {
            unitMode = WorldUnit.City;
        }
        if (unitMode == WorldUnit.Mountain)
        {
            GUI.color = Color.red;
        }
        else
        {
            GUI.color = def;
        }
        if (GUILayout.Button("绘制高山"))
        {
            unitMode = WorldUnit.Mountain;
        }
        if (unitMode == WorldUnit.NewVillage)
        {
            GUI.color = Color.red;
        }
        else
        {
            GUI.color = def;
        }
        if (GUILayout.Button("绘制新手村"))
        {
            unitMode = WorldUnit.NewVillage;
        }


        if (unitMode == WorldUnit.Level1)
        {
            GUI.color = Color.red;
        }
        else
        {
            GUI.color = def;
        }
        if (GUILayout.Button("绘制一级区域"))
        {
            unitMode = WorldUnit.Level1;
        }
        if (unitMode == WorldUnit.Level2)
        {
            GUI.color = Color.red;
        }
        else
        {
            GUI.color = def;
        }
        if (GUILayout.Button("绘制二级区域"))
        {
            unitMode = WorldUnit.Level2;
        }
        if (unitMode == WorldUnit.Level3)
        {
            GUI.color = Color.red;
        }
        else
        {
            GUI.color = def;
        }
        if (GUILayout.Button("绘制三级区域"))
        {
            unitMode = WorldUnit.Level3;
        }
        if (unitMode == WorldUnit.Level4)
        {
            GUI.color = Color.red;
        }
        else
        {
            GUI.color = def;
        }
        if (GUILayout.Button("绘制四级区域"))
        {
            unitMode = WorldUnit.Level4;
        }
        if (unitMode == WorldUnit.Level5)
        {
            GUI.color = Color.red;
        }
        else
        {
            GUI.color = def;
        }
        if (GUILayout.Button("绘制五级区域"))
        {
            unitMode = WorldUnit.Level5;
        }
        GUI.color = def;
        //EditorGUILayout.BeginHorizontal("box");
        //int sizeY = 100 * Mathf.CeilToInt(_items.Length / 4f);
        //_select = GUI.SelectionGrid(new Rect(new Vector2(0, 155), new Vector2(100 * 4, sizeY)), _select, _items, 4);//可以给出grid选择框,需要传入贴图数组_items}

        GUILayout.Space(20);
        GUILayout.Label("地图格子数:" + world.units_count());


        GUILayout.BeginHorizontal();
        if (GUILayout.Button("读取数据"))
        {
            byte[] byt = Tools.ReadAllBytes("config/map.data");
            world.units = Tools.DeserializeObject(byt) as int[];
            world.size  = (int)Mathf.Sqrt(world.units_count());
            world.Init();
        }
        if (GUILayout.Button("保存数据"))
        {
            byte[] byt = Tools.SerializeObject(world.units);
            Tools.WriteAllBytes("config/map.data", byt);
        }
        GUILayout.EndHorizontal();


        GUILayout.Space(20);
        if (GUILayout.Button("生成地点"))
        {
            PointCreate point = FindObjectOfType <PointCreate>();
            if (point)
            {
                point.Create();
            }
            else
            {
                Debug.LogError("找不到据点生成器");
            }
        }


        GUILayout.Space(20);
        if (GUILayout.Button("生成山脉"))
        {
            GameObjectCreate obj = FindObjectOfType <GameObjectCreate>();
            if (obj)
            {
                obj.CreateWorld();
            }
            else
            {
                Debug.LogError("找不到对象生成器");
            }
        }
    }
示例#7
0
 public GameWorldState(WorldCreate.WorldType type)
 {
     wType = type;
 }