Commit 40e5d431 authored by Ever's avatar Ever

分时处理小图片

parent 16732197
......@@ -45,6 +45,7 @@ public class GameEditor
fs.Close();
}
}
string savePath = AssetDatabase.GetAssetPath(Selection.activeInstanceID) + "/" + rd.name + ".bin";
FileStream saveFs = File.Open(savePath, FileMode.Create);
BinaryFormatter saveBf = new BinaryFormatter();
......
......@@ -10,7 +10,7 @@ using UnityEngine.UI;
public class MainData : MonoBehaviour, IDragHandler, IEndDragHandler, IBeginDragHandler
{
public List<ExRoomDatas> erdList = new List<ExRoomDatas>();
public ExRoomDatas erd;
public static int gunSize = 50;
......@@ -36,48 +36,26 @@ public class MainData : MonoBehaviour, IDragHandler, IEndDragHandler, IBeginDrag
png = _png;
jpg = _jpg;
json = _json;
erdList = new List<ExRoomDatas>();
Split();
GoOn();
}
#region 解析图片
public void Split()
{
for (int i = 0; i < json.roomDatas.Count; i++)
{
RoomDatas temp = json.roomDatas[i];
ExRoomDatas erd = new ExRoomDatas();
erdList.Add(erd);
Vector2 v = new Vector2(temp.px, temp.py);
if (png.GetPixel((int)v.x, (int)v.y).a <= 0.35f)
{
FunDo(v, erd);
}
}
png.Apply();
}
public void FunDo(Vector2 _v, ExRoomDatas erd)
public void GoOn()
{
stackVector2.Push(_v);
Vector2[] d = new Vector2[4] { new Vector2(0, -1), new Vector2(0, 1), new Vector2(-1, 0), new Vector2(1, 0) };
Vector2 v_1;
Vector2 v_2;
while (stackVector2.Count > 0)
List<int> list = json.list;
for (int i = 0; i < list.Count; i++)
{
v_1 = stackVector2.Pop();
erd.AddData(v_1);
png.SetPixel((int)v_1.x, (int)v_1.y, Color.white);
for (int i = 0; i < d.Length; i++)
int id = list[i];
for (int j = 0; j < json.roomDatas.Count; j++)
{
v_2 = v_1 + d[i];
if (v_2.x >= 0 && v_2.x < png.width && v_2.y >= 0 && v_2.y < png.height && png.GetPixel((int)v_2.x, (int)v_2.y).a <= 0f)
RoomDatas rd = json.roomDatas[j];
if (rd.id == id)
{
stackVector2.Push(v_2);
OnClickPixel(rd.px, rd.py);
}
}
}
}
#endregion
#region 拖拽
private bool isDrag = false;
......@@ -187,20 +165,26 @@ public class MainData : MonoBehaviour, IDragHandler, IEndDragHandler, IBeginDrag
});
for (int i = 0; i < list.Count; i++)
{
bool b = OnClickPos(list[i]);
if (b)
if (OnClickPixel(list[i]))
{
return;
}
}
}
public bool OnClickPixel(float x, float y)
{
Vector2 v = new Vector2(x + png.width / 2, y + png.height / 2);
return OnClickPos(v);
}
public bool OnClickPixel(Vector2 v)
{
v.x = v.x + png.width / 2;
v.y = v.y + png.height / 2;
return OnClickPos(v);
}
public bool OnClickPos(Vector2 v)
{
v.x = (int)v.x + png.width / 2;
v.y = (int)v.y + png.height / 2;
if (v.x < 0 || v.x >= png.width)
{
//Debug.Log("x越界:" + v.x);
......@@ -216,20 +200,7 @@ public class MainData : MonoBehaviour, IDragHandler, IEndDragHandler, IBeginDrag
//Debug.Log("涂过了");
return false;
}
ExRoomDatas erd = null;
for (int i = 0; i < erdList.Count; i++)
{
if (erdList[i].Contains(v))
{
//Debug.Log("在第" + i + "组数据中");
erd = erdList[i];
}
}
if (erd == null)
{
//Debug.Log("组数据为空");
return false;
}
FunDo(v);
GameMgr.Ins.Create(this, erd, v);
......@@ -240,4 +211,26 @@ public class MainData : MonoBehaviour, IDragHandler, IEndDragHandler, IBeginDrag
png.Apply();
return true;
}
public void FunDo(Vector2 _v)
{
erd = new ExRoomDatas();
stackVector2.Push(_v);
Vector2[] d = new Vector2[4] { new Vector2(0, -1), new Vector2(0, 1), new Vector2(-1, 0), new Vector2(1, 0) };
Vector2 v_1;
Vector2 v_2;
while (stackVector2.Count > 0)
{
v_1 = stackVector2.Pop();
erd.AddData(v_1);
png.SetPixel((int)v_1.x, (int)v_1.y, Color.white);
for (int i = 0; i < d.Length; i++)
{
v_2 = v_1 + d[i];
if (v_2.x >= 0 && v_2.x < png.width && v_2.y >= 0 && v_2.y < png.height && png.GetPixel((int)v_2.x, (int)v_2.y).a <= 0.35f)
{
stackVector2.Push(v_2);
}
}
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment