Commit 5c9a76ed authored by lijin's avatar lijin

图片颜色列表只获取一次

parent cddac77d
......@@ -8,6 +8,7 @@ using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using static Unity.Burst.Intrinsics.X86.Avx;
//System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
//sw.Start();
......@@ -29,6 +30,9 @@ public class MainData : MonoBehaviour
public Image imgpng;//线框图组件
public Image imgjpg;//彩色图组件
public Color[] c_png;
public Color[] c_map;
public RectTransform rect;//本节点
public int curGroupId = -1;//当前选组ID
......@@ -43,7 +47,11 @@ public class MainData : MonoBehaviour
map = _map;
json = _json;
dynamic = _dynamic;
json.JoinMap(map);//把点阵数据放进json配置以快速获取某个区域的所有点
c_png = png.GetPixels();
c_map = map.GetPixels();
json.JoinMap(c_map);//把点阵数据放进json配置以快速获取某个区域的所有点
imgjpg.sprite = jpg;//由layout组件自动适应大小
imgpng.sprite = Sprite.Create(png, new Rect(0, 0, json.width, json.height), new Vector2(0.5f, 0.5f));
......@@ -79,7 +87,6 @@ public class MainData : MonoBehaviour
//判断是否当前选组
if (rd.groupId != curGroupId && !b) { return false; }
//染色逻辑
Color[] c_png = png.GetPixels();
for (int i = 0; i < rd.posIndex.Count; i++)
{
c_png[rd.posIndex[i]] = Color.clear;
......@@ -128,15 +135,14 @@ public class MainData : MonoBehaviour
{
dynamic = new DynamicData();//动态数据直接舍弃
//重置染色
Color[] c = png.GetPixels();
for (int i = 0; i < c.Length; i++)
for (int i = 0; i < c_png.Length; i++)
{
if (c[i] == Color.clear)
if (c_png[i] == Color.clear)
{
c[i] = Color.white;
c_png[i] = Color.white;
}
}
png.SetPixels(c);
png.SetPixels(c_png);
png.Apply();
SaveManager.Instance.SaveRes(key, dynamic, png);//保存
}
......
......@@ -81,17 +81,16 @@ public class ResJsonData
public ExtraMetaData extraMetaData;
private static V2 v;
public void JoinMap(Texture2D map)
public void JoinMap(Color[] c_map)
{
if (isInit)
{
return;
}
isInit = true;
Color[] c = map.GetPixels();
for (int i = 0; i < c.Length; i++)
for (int i = 0; i < c_map.Length; i++)
{
V2 _v = ColorToV(c[i]);
V2 _v = ColorToV(c_map[i]);
if (_v.x != 0 || _v.y != 0)
{
roomDatas[_v.x].posIndex.Add(i);
......
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