Commit 01ebe7fa authored by lijin's avatar lijin

性能优化版

parent e23830ed
...@@ -103,7 +103,7 @@ public class GameEditor ...@@ -103,7 +103,7 @@ public class GameEditor
{ {
v_1 = stackVector2.Pop(); v_1 = stackVector2.Pop();
png.SetPixel(v_1.x, v_1.y, Color.white); png.SetPixel(v_1.x, v_1.y, Color.white);
rd.posIndex.Add((short)(v_1.x + v_1.y * png.width)); rd.posIndex.Add(v_1.x + v_1.y * png.width);
for (int i = 0; i < d.Length; i++) for (int i = 0; i < d.Length; i++)
{ {
v_2 = v_1 + d[i]; v_2 = v_1 + d[i];
......
...@@ -73,23 +73,23 @@ public class MainData : MonoBehaviour ...@@ -73,23 +73,23 @@ public class MainData : MonoBehaviour
if (FunDo(v, b)) if (FunDo(v, b))
{ {
sw.Stop(); sw.Stop();
Debug.Log("耗时:" + sw.ElapsedMilliseconds); Debug.Log("涂色全耗时:" + sw.ElapsedMilliseconds);
return true; return true;
} }
return false; return false;
} }
public bool FunDo(Vector2 v, bool b = false) public bool FunDo(Vector2 v, bool b = false)
{ {
System.Diagnostics.Stopwatch sw_1 = new System.Diagnostics.Stopwatch();
sw_1.Start();
RoomDatas rd = null; RoomDatas rd = null;
int index = (int)(v.x + v.y * png.width);
for (int i = 0; i < json.roomDatas.Count; i++) for (int i = 0; i < json.roomDatas.Count; i++)
{ {
List<short> l = json.roomDatas[i].posIndex; if(json.roomDatas[i].posIndex.Contains(index))
for (int j = 0; j < l.Count; j++)
{ {
if (l[j] == v.x + v.y * png.width) rd = json.roomDatas[i];
{ break;
rd = json.roomDatas[i];
}
} }
} }
if (rd == null) if (rd == null)
...@@ -97,6 +97,8 @@ public class MainData : MonoBehaviour ...@@ -97,6 +97,8 @@ public class MainData : MonoBehaviour
Debug.LogError("沒找到點:" + v.x + "-" + v.y); Debug.LogError("沒找到點:" + v.x + "-" + v.y);
return false; return false;
} }
sw_1.Stop();
Debug.Log("点转区ID耗时:" + sw_1.ElapsedMilliseconds);
if (dynamic.step.Contains(rd.id)) if (dynamic.step.Contains(rd.id))
{ {
Debug.LogError("點過了:" + rd.id); Debug.LogError("點過了:" + rd.id);
...@@ -104,7 +106,8 @@ public class MainData : MonoBehaviour ...@@ -104,7 +106,8 @@ public class MainData : MonoBehaviour
} }
if (rd.groupId == curGroupId || b) if (rd.groupId == curGroupId || b)
{ {
dynamic.AddData(rd.groupId, rd.id); System.Diagnostics.Stopwatch sw_2 = new System.Diagnostics.Stopwatch();
sw_2.Start();
Color[] c_png = png.GetPixels(); Color[] c_png = png.GetPixels();
for (int i = 0; i < rd.posIndex.Count; i++) for (int i = 0; i < rd.posIndex.Count; i++)
{ {
...@@ -112,11 +115,19 @@ public class MainData : MonoBehaviour ...@@ -112,11 +115,19 @@ public class MainData : MonoBehaviour
} }
png.SetPixels(c_png); png.SetPixels(c_png);
png.Apply(); png.Apply();
sw_2.Stop();
Debug.Log("涂色耗时:" + sw_2.ElapsedMilliseconds);
System.Diagnostics.Stopwatch sw_3 = new System.Diagnostics.Stopwatch();
sw_3.Start();
dynamic.AddData(rd.groupId, rd.id);
RoomGroupsData rgd = json.roomGroupsData[rd.groupId - 1]; RoomGroupsData rgd = json.roomGroupsData[rd.groupId - 1];
GameMgr.Ins.eiMgr.Create(new Color(rgd.R / 255f, rgd.G / 255f, rgd.B / 255f, 1), v); GameMgr.Ins.eiMgr.Create(new Color(rgd.R / 255f, rgd.G / 255f, rgd.B / 255f, 1), v);
GameMgr.Ins.tiMgr.CircleId(rd.id); GameMgr.Ins.tiMgr.CircleId(rd.id);
GameMgr.Ins.miMgr.Play(v, rd.id); GameMgr.Ins.miMgr.Play(v, rd.id);
EventDispatcher.Dispatch(EventName.Event.Event_GropuItemChange, rgd, dynamic); EventDispatcher.Dispatch(EventName.Event.Event_GropuItemChange, rgd, dynamic);
sw_3.Stop();
Debug.Log("效果耗时:" + sw_3.ElapsedMilliseconds);
return true; return true;
} }
return false; return false;
...@@ -130,6 +141,8 @@ public class MainData : MonoBehaviour ...@@ -130,6 +141,8 @@ public class MainData : MonoBehaviour
GameMgr.Ins.miMgr.CircleAll(); GameMgr.Ins.miMgr.CircleAll();
} }
Debug.Log("选中组:" + id); Debug.Log("选中组:" + id);
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
if (curGroupId == id) if (curGroupId == id)
{ {
return; return;
...@@ -150,6 +163,8 @@ public class MainData : MonoBehaviour ...@@ -150,6 +163,8 @@ public class MainData : MonoBehaviour
GameMgr.Ins.miMgr.Create(this, erd, rd.id, rd.groupId); GameMgr.Ins.miMgr.Create(this, erd, rd.id, rd.groupId);
} }
} }
sw.Stop();
Debug.Log("选组耗时:" + sw.ElapsedMilliseconds);
EventDispatcher.Dispatch(EventName.Event.Event_ChoiseGroupByPic, curGroupId); EventDispatcher.Dispatch(EventName.Event.Event_ChoiseGroupByPic, curGroupId);
} }
...@@ -173,7 +188,7 @@ public class MainData : MonoBehaviour ...@@ -173,7 +188,7 @@ public class MainData : MonoBehaviour
RoomDatas rd = null; RoomDatas rd = null;
for (int i = 0; i < json.roomDatas.Count; i++) for (int i = 0; i < json.roomDatas.Count; i++)
{ {
List<short> l = json.roomDatas[i].posIndex; List<int> l = json.roomDatas[i].posIndex;
for (int j = 0; j < l.Count; j++) for (int j = 0; j < l.Count; j++)
{ {
if (l[j] == v.x + v.y * png.width) if (l[j] == v.x + v.y * png.width)
......
...@@ -12,7 +12,7 @@ public class MaskItem : MonoBehaviour ...@@ -12,7 +12,7 @@ public class MaskItem : MonoBehaviour
public Image SP; public Image SP;
public RectTransform Rect; public RectTransform Rect;
public RectTransform SPRect; public RectTransform SPRect;
public Vector4 size;
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
...@@ -20,7 +20,7 @@ public class MaskItem : MonoBehaviour ...@@ -20,7 +20,7 @@ public class MaskItem : MonoBehaviour
{ {
return; return;
} }
Rect.sizeDelta += Time.deltaTime * Vector2.one * IsUse * 2f; Rect.sizeDelta += Time.deltaTime * Vector2.one * IsUse * 1f;
if (Rect.sizeDelta.x > IsUse * 1.05f && Rect.sizeDelta.y > IsUse * 1.5f) if (Rect.sizeDelta.x > IsUse * 1.05f && Rect.sizeDelta.y > IsUse * 1.5f)
{ {
gameObject.SetActive(false); gameObject.SetActive(false);
...@@ -72,9 +72,8 @@ public class MaskItem : MonoBehaviour ...@@ -72,9 +72,8 @@ public class MaskItem : MonoBehaviour
//初始处理 //初始处理
gameObject.SetActive(true); gameObject.SetActive(true);
Rect.sizeDelta = Vector2.zero; Rect.sizeDelta = Vector2.zero;
float a = Math.Max(erd.size.z - v.x, v.x - erd.size.x);
float b = Math.Max(erd.size.w - v.y, v.y - erd.size.y); size = erd.size;
IsUse = -Math.Max(a, b) * 2;
} }
public void Play(Vector3 v) public void Play(Vector3 v)
...@@ -89,6 +88,9 @@ public class MaskItem : MonoBehaviour ...@@ -89,6 +88,9 @@ public class MaskItem : MonoBehaviour
SPRect.SetParent(Rect); SPRect.SetParent(Rect);
IsUse *= -1; float a = Math.Max(size.z - v.x, v.x - size.x);
float b = Math.Max(size.w - v.y, v.y - size.y);
IsUse = Math.Max(a, b) * 2;
} }
} }
...@@ -91,7 +91,7 @@ public class ExtraMetaData //后面再看为啥json序列化失败 ...@@ -91,7 +91,7 @@ public class ExtraMetaData //后面再看为啥json序列化失败
public class RoomDatas public class RoomDatas
{ {
public int groupId = -1; public int groupId = -1;
public List<short> posIndex = new List<short>(); public List<int> posIndex = new List<int>();
public int id; public int id;
public int valid; public int valid;
......
fileFormatVersion: 2 fileFormatVersion: 2
guid: 9dceb814ec309594686d933949505996 guid: 5deef8a321f86c0459d749c0e87b24be
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}
......
fileFormatVersion: 2 fileFormatVersion: 2
guid: c8fb47e3e3c044946b746a24bcc7aac3 guid: dc863db1bf418db4aa501a7b4c1356ca
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}
userData: userData:
......
fileFormatVersion: 2 fileFormatVersion: 2
guid: a9f2a0a08bc1c89468426e4e75dad3ba guid: 3c8da2e0ddb5ceb4faf0b2605b091d61
TextureImporter: TextureImporter:
internalIDToNameTable: [] internalIDToNameTable: []
externalObjects: {} externalObjects: {}
......
fileFormatVersion: 2 fileFormatVersion: 2
guid: 443bdf89f2e136242a6868a9f657e6c6 guid: 126b61d0eeba82e4782699d7f91dbc07
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}
userData: userData:
......
fileFormatVersion: 2 fileFormatVersion: 2
guid: 80288066af556804fbb9659376a6d156 guid: bf3d014937afaa64e8c89f47c46c03e7
TextureImporter: TextureImporter:
internalIDToNameTable: [] internalIDToNameTable: []
externalObjects: {} externalObjects: {}
......
fileFormatVersion: 2 fileFormatVersion: 2
guid: 9fc579f1b0a9d81429afafbf7555d3a8 guid: 100c000cdcecb6d4cb3c956344d7b903
TextureImporter: TextureImporter:
internalIDToNameTable: [] internalIDToNameTable: []
externalObjects: {} externalObjects: {}
......
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