using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;

public class mainGameOneImageView : mainGameView
{
    // Start is called before the first frame update
    public GameObject oneImg = null;
    
    private Dictionary<string, Color[]> allColor2 = new Dictionary<string, Color[]>();
    private Dictionary<string, Vector2Short> allColorSize = new Dictionary<string, Vector2Short>();
    private Color defColor = new Color(1, 1, 1, 1);
    private bool InitEndIsShowLine = true;
    private float changBet = 2f;
    private List<int> allBianLun = new List<int>();
    void Start()
    {
    }

    void Update()
    {
        baseUpdate();
    }
    public void onLineAndSelectBack()
    {
        if(allColor2.ContainsKey("outColor") == false)
        {
            utilsTools.addTimer_Update(gameObject, "waitOutColorInit", (String name) =>
            {
                if (allColor2.ContainsKey("outColor") == false) return true;
                onLineAndSelectBack();
                return false;
            }, 4,0xffffff);
            return;
        }
        Vector2Short vector2Short = allColorSize["outColor"];
        int width = vector2Short.x;
        int height = vector2Short.y;
        loopAddTaskBack(width, 300, (System.Object[] param) =>
        {
            int start = (int)param[0];
            int step = (int)param[1];
            float x = 1.0f;
            float y = 1.0f;
            int a1 = utilsTools.getTotalMillisecond();
            Vector2Short vector2Short2 = allColorSize["final"];

            utilsTools.sendEventObjectParams("inGameLoadingValue", 6f, false);
            
            for (int y1 = 0; y1 < height; y1++)
            {
                y = y1;
                for (int x1 = start; x1 < (start + step); x1++)
                {
                    x = x1;
                    int index = y1 * width + x1;
                    short value = digitMatrix.Data[x1, y1];
                    if (value.Equals(bianlun)){
                        allColor2["outColor"][index] = allColor2["line"][index];
                    }
                    else if(value.Equals(fullShow))
                    {
                        int index2 = (int)(x / (float)width  * vector2Short2.x + y / (float)height * vector2Short2.y);
                        Color color1 = allColor2["final"][index2];
                        allColor2["outColor"][index] = new Color(color1.r,color1.g,color1.b,1f);
                    }
                }
            }
        });
        TaskManages tm =  TaskManages.getInstance();
        tm.addTask(this, (System.Object[] _) => {
            onOutColorEndHandler();
        });
    }
    public void onOutColorEndHandler()
    {
        if(this.gameidJsondata == null)
        {
            utilsTools.addTimer_Update(gameObject, "waitJsonInit", (String name) =>
            {
                if (this.gameidJsondata == null) return true;
                onOutColorEndHandler();
                return false;
            }, 4);
            return;
        }
        checkAddAreaId();
        checkSelectColors();
    }
    protected override void onShowAreaByNoAnimation(short aid)
    {
        int cout = GroupByAreaPtInfos.mapAllDatas[aid].Count;
        var pts = GroupByAreaPtInfos.mapAllDatas[aid];
        Color[] outColors = allColor2["outColor"];
        Color[] final = allColor2["final"];
        Color[] thumbnail = allColor2["thumbnail"];
        Vector2Short finalSize = allColorSize["final"];
        Vector2Short outSize = allColorSize["outColor"];
        for (int i = 0; i < cout; i++)
        {
            int value = pts[i];
            short x = (short)(value % gameidJsondata.width);
            short y = (short)(value / gameidJsondata.height);
            int x1 = (int)((float)(x / outSize.fx) * finalSize.fx);
            int y1 = (int)((float)(y / outSize.fy) * finalSize.fy);
            int finalIdx = y1 * finalSize.x + x1;
            Color color = final[y1 * finalSize.x + x1];
            color.a = 1f;
            digitMatrix.Data[x, y] = fullShow;
            outColors[value] = color;
            thumbnail[finalIdx] = color;
        }
        Apply();
        TaskManages.getInstance().addTask(this, (System.Object[] _) =>
        {
            if (utilsTools.isEqualByValue(gameScenUseInfo.progress, 1.0, 0.0000002f))
            {
                TaskManages.getInstance().addTask(this, (System.Object[] parma) =>
                {
                    utilsTools.setGDataByKey("enableZoomMove", false);
                    if (lowImg != null) lowImg.SetActive(false);
                    if (areaIdBase != null) areaIdBase.SetActive(false);
                    utilsTools.sendEventObjectParams("gamePlayerEndHandler");
                });
            }
        });
        drawThumbnailByAid(new List<short>() { aid });
    }
    protected override void onShowAnimationHandler()
    {
        if(showAreaAnimationDatas.Count > 0)
        {
            Color[] outColors = allColor2["outColor"];
            Color[] final = allColor2["final"];
            Color[] thumbnail = allColor2["thumbnail"];
            Vector2Short finalSize = allColorSize["final"];
            Vector2Short outSize = allColorSize["outColor"];

            List<short> removeAids = new List<short>();
            int cout1 = 0;
            int dt001 = utilsTools.getTotalMillisecond();
            foreach (var item in showAreaAnimationDatas)
            {
                short gid = gameidJsondata.getAid(item.m_aid).gid;
                short nowCheckId = (short)(item.m_aid + 20);
                var groupPtInfo = groupPtInfos[gid];
                int cout = 0;
                utilsTools.Ring(item.m_x, item.m_y, item.m_fpsEnd, item.m_fpsStart,  gameidJsondata.width, gameidJsondata.height,(int x, int y, int idx) =>
                {
                    short nowValue = digitMatrix.Data[x, y];
                    if(!nowValue.Equals(nowCheckId))
                    {
                        return false;
                    }
                    cout++;
                    cout1++;
                    digitMatrix.Data[x, y] = fullShow;
                    int x1 = (int)((x / outSize.fx) * finalSize.fx);
                    int y1 = (int)((y / outSize.fy) * finalSize.fy);
                    Color color = final[y1 * finalSize.x + x1];
                    color.a = 1;
                    outColors[idx] = color;
                    return true;
                });
                if (cout == 0)
                {
                    //没有可渲染区域
                    removeAids.Add(item.m_aid);
                    List<Vector2Short> tempLineColors = new List<Vector2Short>();
                    groupPtInfo.getLineByAid(item.m_aid,ref tempLineColors);
                    foreach (var item1 in tempLineColors)
                    {
                        if (digitMatrix.Data[item1.x, item1.y].Equals(bianlun))
                        {
                            cout++;
                            int idx = (gameidJsondata.width - item1.x + 1) * gameidJsondata.width + (gameidJsondata.height - item1.y + 1);
                            digitMatrix.Data[item1.x, item1.y] = fullShow;
                            int x1 = (int)((item1.x / outSize.fx) * finalSize.fx);
                            int y1 = (int)((item1.y / outSize.fy) * finalSize.fy);
                            Color color = final[y1 * finalSize.x + x1];
                            color.a = 1f;
                            outColors[idx] = color;
                        }
                    }
                    groupPtInfo.removeAid(item.m_aid);

                }
                else
                {
                    short diff = (short)(item.m_fpsEnd - item.m_fpsStart);
                    item.m_fpsStart = item.m_fpsEnd;
                    item.m_fpsEnd += diff;
                }
            }

            int dt002 = utilsTools.getTotalMillisecond();
            if (cout1 > 0)
            {
                Apply();
                
            }
            if (removeAids.Count > 0)
            {
                
                //移除已经播放完成
                foreach (var aid in removeAids)
                {
                    for (int i = 0; i < showAreaAnimationDatas.Count; i++)
                    {
                        if (showAreaAnimationDatas[i].m_aid.Equals(aid) == true)
                        {
                            showAreaAnimationDatas.RemoveAt(i);
                            break;
                        }
                    }
                }
                drawThumbnailByAid(removeAids);
                if (showAreaAnimationDatas.Count == 0)
                {
                    //保存一次缩略遮罩图
                    if (utilsTools.isEqualByValue(gameScenUseInfo.progress, 1.0, 0.0000002f))
                    {
                        TaskManages.getInstance().addTask(this, (System.Object[] parma) =>
                        {
                            utilsTools.setGDataByKey("enableZoomMove", false);
                            if (lowImg != null) lowImg.SetActive(false);
                            if (areaIdBase != null) areaIdBase.SetActive(false);
                            utilsTools.sendEventObjectParams("gamePlayerEndHandler");
                        });
                    }
                }
            }
        }
    }
    public void checkSelectColors()
    {
        if (allColor2.ContainsKey("select") == false)
        {
            utilsTools.addTimer_Update(gameObject, "waitSelectColorInit", (String name) =>
            {
                if (allColor2.ContainsKey("select") == false) return true;
                checkSelectColors();
                return false;
            }, 4);
            return;
        }
        //为缩略图准备
        Vector2Short vector2Short = allColorSize["final"];
        Vector2Short vector2ShortOut = allColorSize["outColor"];
        Color[] colors = new Color[vector2Short.x  * vector2Short.y];
        for (int x = 0;x < vector2Short.x; x++)
        {
            float x1 = (float)x;
            int x2 = (int)(x1 * (float)vector2ShortOut.x / (float)vector2Short.x);
            for (int y = 0; y < vector2Short.y; y++)
            {
                float y1 = (float)y;
                int index = y * vector2Short.x + x;
                int y2 = (int)(y1 * (float)vector2ShortOut.y / (float)vector2Short.y);
                int index2 = y2 * vector2ShortOut.x + x2;
                colors[index] = allColor2["outColor"][index2];
            }
        }
        thumbnailTexture2d = new Texture2D(vector2Short.x, vector2Short.y, TextureFormat.RGBA32, false);
        allColor2.Add("thumbnail", colors);
        allColorSize.Add("thumbnail", new Vector2Short(vector2Short.x, vector2Short.y));
        TaskManages.getInstance().addTask(this, (System.Object[] _) =>
        {
            if (InitEndIsShowLine)
            {
                utilsTools.addTimer_Update(gameObject, "applyOut", (String name) =>
                {
                    Apply();
                    return false;
                }, 3);
            }
            nowSelectgid = -1;
            resetSize();
            onInitEndHandler();

        });
    }
    protected override void onInitEndHandler()
    {
        utilsTools.sendEventObjectParams("gameViewOnInitEnd", allColor2["outColor"],gameidJsondata.width,gameidJsondata.height);
    }
    public void showAllArea()
    {
        lineTexture2d.SetPixels(allColor2["finalAlls"]);
        lineTexture2d.Apply();
    }
    public Color[] getfinalAllColor()
    {
        return allColor2["finalAlls"];
    }
    public Color[] getColorByKey(string key = "outColor") { 
        return allColor2[key];
    }
    public override void showArea(int areaId, OnAreaHandler onAreaHandler = null,bool isApply = true)
    {
        if (areaId == -1)
        {
            lineImg.SetActive(false);
            return;
        }
        //显示指定区域
        if (GroupByAreaPtInfos.mapAllDatas.ContainsKey((short)areaId))
        {
            gameAreaItem areaItem1 = gameidJsondata.getAid((short)areaId);
            List<Vector2Short> areaAllPts = new List<Vector2Short>();
            Vector2Short size1 = allColorSize["outColor"];
            Vector2Short size2 = allColorSize["final"];
            Color color = new Color(1, 1, 1, 0);
            groupPtInfos_All[areaItem1.gid].getDataByAid(areaItem1.id, ref areaAllPts, true);
            foreach (var item in areaAllPts)
            {
                int idx = item.y * size1.x + item.x;
                float temp = item.x * size2.x;
                int x =  (int)(temp / (float)size1.x);
                temp = item.y * size2.y;
                int y = (int)(temp / (float)size1.y);
                color = allColor2["final"][y * size2.x + x];
                color.a = 1f;
                allColor2["outColor"][idx] = color;
                allColor2["thumbnail"][y * size2.x + x] = color;
            }
            //边缘怎么弄?
            if (isApply == true)
            {
                Apply();
            }
        }
        else if (onAreaHandler != null)
        {
            onAreaHandler(areaId, false);
        }
    }
    
    //回放使用
    public void showAreaPrveClear(bool isfirst) {
        if(InitEndIsShowLine == false)
        {
            Image image = oneImg.GetComponent<Image>();
            image.sprite = Sprite.Create(lineTexture2d, new Rect(0, 0, lineTexture2d.width, lineTexture2d.height), new Vector2(0.5f, 0.5f));
            Apply();
        }
        if(isfirst == false)
        {
            for (int i = 0; i < gameidJsondata.width; i++)
            {
                for (int j = 0; j < gameidJsondata.height; j++)
                {
                    int idx = j * gameidJsondata.width + i;
                    if(allColor2["outColor"][idx].a > 0.7)
                    {
                        if (digitMatrix.Data[i,j].Equals(bianlun) == false)
                            allColor2["outColor"][idx].a = 0f;
                    }
                }
            }
            Apply();
        }
    }
    public void Apply()
    {
        lineTexture2d.SetPixels(allColor2["outColor"]);
        lineTexture2d.Apply();
    }
    public override void resetSize()
    {
        //怎么保持宽高比
        if (InitEndIsShowLine == true)
        {
            float width = gameidJsondata.width;
            float height = gameidJsondata.height;
            float bet = width / height;
            RectTransform rectTransform = oneImg.GetComponent<RectTransform>();
            RectTransform baseTransform = rectTransform.transform.parent.GetComponent<RectTransform>();
            if (width.Equals(height))
            {
                width = utilsTools.DisplaySize.x * 1;
                height = width;
            }
            else
            {
                width = utilsTools.DisplaySize.x * 0.65f;
                height = width * 2;
            }
            //确定好宽高后赋值
            GameObject[] gameObjects = { oneImg, areaIdBase };
            Vector3 tempPos = rectTransform.localPosition;
            if (width.Equals(height) == false)
            {
                tempPos.y = tempPos.y - 40;
            }
            foreach (var item in gameObjects)
            {
                if (item == null) continue;
                var temp = item.GetComponent<RectTransform>();
                temp.sizeDelta = new Vector2(width, height);
            }
            checkAddAreaId();
            updateScaleView();
        }
    }

    public override bool getSize(out int width, out int height)
    {
        width = -1;
        height = -1;
        if (gameidJsondata == null)
            return false;
        width = gameidJsondata.width;
        height = gameidJsondata.height;
        return true;
    }
    public override void loadFileInfo(string url, string localpath, int typeId)
    {

        if (typeId == 1 || typeId == 2)
        {

            utilsTools.httpDOWNIMG(this, url, localpath, (string id, string url1, bool isSuccess, System.Object data) =>
            {
                if (isSuccess == false)
                {
                    utilsTools.addTimer_Sec(gameObject, url1, (string name1) =>
                    {
                        loadFileInfo(url1, localpath, typeId);
                        return false;
                    }, 5);
                    return 0;
                }
                else
                {
                    Texture2D texture2d = data as Texture2D;
                    if(typeId.Equals(1) || typeId.Equals(2))
                    {
                        if(texture2d.width.Equals(texture2d.height) == false)
                        {
                            if(changBet.Equals(2f) == false)
                            {
                                Texture2D temp1 = utilsTools.ScaleTexture(texture2d, texture2d.width, (int)(texture2d.width * changBet));
                                Destroy(texture2d);
                                texture2d = temp1;
                            }
                        }
                    }
                    if(typeId == 1)
                    {
                        allColor2.Add("line",texture2d.GetPixels());
                        allColorSize.Add("line", new Vector2Short((short)texture2d.width, (short)texture2d.height));
                        if (InitEndIsShowLine == true)
                        {
                            Image image = oneImg.GetComponent<Image>();
                            image.sprite = Sprite.Create(texture2d, new Rect(0, 0, texture2d.width, texture2d.height), new Vector2(0.5f, 0.5f));
                        }
                        lineTexture2d = texture2d;
                    }
                    else if(typeId == 2)
                    {
                        allColor2.Add("final", texture2d.GetPixels());
                        allColorSize.Add("final", new Vector2Short((short)texture2d.width, (short)texture2d.height));
                        allColor2.Add("finalAlls",utilsTools.ScaleTexture(texture2d, gameidJsondata.width, gameidJsondata.height, TextureFormat.RGBA32).GetPixels());
                    }
                    if(allColor2.ContainsKey("line") && allColor2.ContainsKey("final"))
                    {
                        onLineAndSelectBack();
                    }
                    return 1;
                }
            });
        }
        else if (typeId == 3)
        {
            utilsTools.httpDownText(this, url, localpath, (string id, string url1, bool isSuccess, System.Object data) =>
            {
                if (isSuccess == false)
                {
                    utilsTools.addTimer_Sec(gameObject, url1, (string name1) =>
                    {
                        loadFileInfo(url1, localpath, typeId);
                        return false;
                    }, 5);
                    return 0;
                }
                else
                {
                    utilsTools.setGDataByKey("downJsonBack", utilsTools.getTotalMillisecond());
                    utilsTools.sendEventObjectParams("inGameLoadingValue", 8f, false);
                    string jsondata = data as string;
                    gameIdJsonData gameidJsondata1 = JsonUtility.FromJson<gameIdJsonData>(jsondata);

                    int centerSize = gameidJsondata1.roomDatas.Count();
                    foreach (var item in aid2selectOrderIdx)
                    {
                        gameidJsondata1.roomDatas[item.Key].isShow = true;
                    }
                    for (int i = 0; i < gameidJsondata1.roomGroupsData.Count(); i++)
                    {
                        var group = gameidJsondata1.roomGroupsData[i];
                        group.isComplete = true;
                        for (int j = 0; j < group.roomIds.Count(); j++)
                        {
                            if (gameidJsondata1.roomDatas[group.roomIds[j]].isShow == false)
                            {
                                group.isComplete = false;
                                break;
                            }
                        }
                    }
                    utilsTools.sendEventObjectParams("inGameLoadingValue", 2f, false);
                    for (int i = 0; i < gameidJsondata1.roomGroupsData.Count; i++)
                    {
                        var group = gameidJsondata1.roomGroupsData[i];
                        for (int i1 = 0; i1 < group.roomIds.Count(); i1++)
                        {
                            gameidJsondata1.roomDatas[group.roomIds[i1]].gid = group.id;
                        }
                    }
                    gameidJsondata = gameidJsondata1;
                    utilsTools.setGDataByKey("allAreaSize", gameidJsondata1.getAllValidAreaItemSize());
                    utilsTools.setGDataByKey("downJsonAsynTask", utilsTools.getTotalMillisecond());
                    idHashPosToArrayPosEx();
                    //onLoadFileOk(typeId);
                    return 0;
                }
            });
        }
    }
    public void idHashPosToArrayPosEx()
    {
        idHashPosToArrayPos();
        //将边缘重复放入周边区域
        for (int i = 0; i < allBianLun.Count(); i++)
        {
            int idx = allBianLun[i];
            int x = idx % gameidJsondata.width;
            int y = idx / gameidJsondata.width;
            int idx1 = 0;
            for(int offR = 1;offR < 100;offR++)
            {
                if (x + offR >= gameidJsondata.width) break;
                idx1 = digitMatrix.Data[x + offR, y];
                if (idx1 > 0)
                {
                    short idx2 = (short)(idx1 - 20);
                    if (GroupByAreaPtInfos.mapAllDatas.ContainsKey(idx2)) {
                        GroupByAreaPtInfos.mapAllDatas[idx2].Add(idx);
                        break;
                    }
                }
            }
            for (int offL = 1; offL < 100; offL++)
            {
                if (x - offL < 0) break;
                idx1 = digitMatrix.Data[x - offL, y];
                if (idx1 > 0)
                {
                    short idx2 = (short)(idx1 - 20);
                    if (GroupByAreaPtInfos.mapAllDatas.ContainsKey(idx2))
                    {
                        GroupByAreaPtInfos.mapAllDatas[idx2].Add(idx);
                        break;
                    }
                }
            }
            for (int offT = 1; offT < 100; offT++)
            {
                if (y + offT >= gameidJsondata.height) break;
                idx1 = digitMatrix.Data[x, y + offT];
                if (idx1 > 0)
                {
                    short idx2 = (short)(idx1 - 20);
                    if (GroupByAreaPtInfos.mapAllDatas.ContainsKey(idx2))
                    {
                        GroupByAreaPtInfos.mapAllDatas[idx2].Add(idx);
                        break;
                    }
                }
            }
            for (int offD = 1; offD < 100; offD++)
            {
                if (y - offD < 0) break;
                idx1 = digitMatrix.Data[x, y - offD];
                if (idx1 > 0)
                {
                    short idx2 = (short)(idx1 - 20);
                    if (GroupByAreaPtInfos.mapAllDatas.ContainsKey(idx2))
                    {
                        GroupByAreaPtInfos.mapAllDatas[idx2].Add(idx);
                        break;
                    }
                }
            }
        }
    }
    public override bool switchShowAreaGroup(short gid, OnAreaHandler onAreaHandler = null)
    {
        if (gid == nowSelectgid)
        {
            if (onAreaHandler != null)
                onAreaHandler(gid, true);
            return true;
        }
        if (lowImg == null)
        {
            if (onAreaHandler != null)
                onAreaHandler(gid, false);
            return false;
        }
        if (!(digitMatrix != null && lineTexture2d != null && gameidJsondata != null && gameidJsondata.findGid(gid)))
        {
            if (onAreaHandler != null)
                onAreaHandler(gid, false);
            return false;
        }
        Color color = new Color(1, 1, 1, 0);
        gameAreaGroupItem jsonGroupInfo = null;
        GroupByAreaPtInfos groupPt = null;
        List<Vector2Short> tempData = new List<Vector2Short>();

        if (nowSelectgid > 0)
        {
            jsonGroupInfo = gameidJsondata.getRoomGroup(nowSelectgid);
            groupPt = groupPtInfos[nowSelectgid];

            for (int i = 0; i < jsonGroupInfo.roomIds.Count; i++)
            {
                var aid = jsonGroupInfo.roomIds[i];
                var areamItem = gameidJsondata.getAid(aid);
                if (areamItem.tempExKey.Equals(""))
                {
                    continue;
                }
                groupPt.getDataByAid(aid, ref tempData);
                foreach (var pt in tempData)
                {
                    if (digitMatrix.Data[pt.x, pt.y] == bianlun) continue;
                    color.a = 0f;
                    allColor2["outColor"][pt.y * gameidJsondata.width + pt.x] = defColor;
                }
            }
        }
        else
        {
            utilsTools.sendEventObjectParams("inGameLoadingValue", 100f, true);
            utilsTools.setGDataByKey("enableZoomMove", true);
        }
        nowSelectgid = gid;
        jsonGroupInfo = gameidJsondata.getRoomGroup(nowSelectgid);
        groupPt = groupPtInfos[gid];

        Vector2Short vector2Short = allColorSize["select"];
        for (int i = 0; i < jsonGroupInfo.roomIds.Count; i++)
        {
            var aid = jsonGroupInfo.roomIds[i];
            var areamItem = gameidJsondata.getAid(aid);
            if (areamItem.tempExKey.Equals(""))
            {
                continue;
            }
            groupPt.getDataByAid(aid, ref tempData);
            foreach (var pt in tempData)
            {
                if (digitMatrix.Data[pt.x, pt.y] == bianlun) continue;
                int x1 = (int)((float)pt.x / (gameidJsondata.width) * (float)vector2Short.x);
                int y1 = (int)((float)pt.y / (gameidJsondata.height) * (float)vector2Short.y);
                allColor2["outColor"][pt.y* gameidJsondata.width + pt.x] = allColor2["select"][y1 * vector2Short.x + x1];
            }
        }
        //lowImgTexture2d.SetPixels(0, 0, lowImgTexture2d.width, lowImgTexture2d.height, allColor["low"]);
        //lowImgTexture2d.Apply();
        if (onAreaHandler != null)
            onAreaHandler(gid, true);
        return true;
    }
    protected override void loadSelectImageTexture(Texture2D nowSelectTexture, NotifyEmptParam notify, int width = 0, int height = 0)
    {
        allColor2.Add("select", nowSelectTexture.GetPixels());
        allColorSize.Add("select",new Vector2Short((short)nowSelectTexture.width,(short)nowSelectTexture.height));
    }
    public bool loadGameImgId(GameScenUserInfo gameUserInfo,bool initEndIsLine,float changBet = 2.0f)
    {
        this.changBet = changBet;
        InitEndIsShowLine = initEndIsLine;
        return loadGameImgId(gameUserInfo);
    }
    //allBianLun
    protected override void bytesInitDigitMatrix(Byte[] bytes)
    {
        base.bytesInitDigitMatrix(bytes);
        int width = digitMatrix.RowCount;
        int height = digitMatrix.ColumnCount;
        for (short i = 0; i < width; i++)
        {
            for (short j = 0; j < height; j++)
            {
                if(digitMatrix.Data[i, j].Equals(bianlun))
                {
                    allBianLun.Add(j * width + i);
                }
            }
        }
        
    }
    public override bool loadGameImgId(GameScenUserInfo gameUserInfo)
    {
        string linePath = gameUserInfo.getLineImgLocalPath();
        string colorPath = gameUserInfo.getColorImgLocalPath();
        string jsonPath = gameUserInfo.getJsonLocalPath();
        string thumbnail = gameUserInfo.getLocalThumbnailPath();
        if (jsonPath.Equals("") || linePath.Equals("") || colorPath.Equals("") || thumbnail.Equals(""))
        {
            return false;
        }
        if (false == gameUserInfo.createWorkDirectory()) return false;

        utilsTools.sendEventObjectParams("inGameLoadingValue", 3f, false);
        for (short i = 0; i < gameUserInfo.areaInfoUseData.Count; i++)
        {
            var userAreaData = gameUserInfo.areaInfoUseData[i];
            aid2selectOrderIdx.Add(userAreaData.id, i);
        }
        utilsTools.setGDataByKey("loadBinBegin", utilsTools.getTotalMillisecond());
        string binpath = colorPath.Substring(0, linePath.Length - 4) + ".bin";
        if (utilsTools.IsPhone == false)
        {
            binpath = binpath.Replace("/", "\\");
        }
        Byte[] bytes = File.ReadAllBytes(binpath);
        bytesInitDigitMatrix(bytes);
        Debug.Log("bin初始化完成--------------");
        int start = 0;
        int step = BitConverter.GetBytes((short)2).Length;
        int stepInt = BitConverter.GetBytes(65539).Length;
        short width = BitConverter.ToInt16(bytes, start);
        start += step;
        short height = BitConverter.ToInt16(bytes, start);
        Color[] tempColor = new Color[width * height];
        loopAddTaskBack(width, 210, (System.Object[] param) =>
        {
            int start = (int)param[0];
            int step = (int)param[1];
            float x = 1.0f;
            float y = 1.0f;
            int a1 = utilsTools.getTotalMillisecond();
            utilsTools.sendEventObjectParams("inGameLoadingValue", 6f, false);
            for (int y1 = 0; y1 < height; y1++)
            {
                y = y1;
                for (int x1 = start; x1 < (start + step); x1++)
                {
                    x = x1;
                    int index = y1 * width + x1;
                    tempColor[index] = defColor;
                }
            }
        });
        TaskManages.getInstance().addTask(this, (System.Object[] _) =>
        {
            allColor2.Add("outColor", tempColor);
            allColorSize.Add("outColor", new Vector2Short(width, height));
        });
        utilsTools.setGDataByKey("loadBinEnd", utilsTools.getTotalMillisecond());
        utilsTools.setGDataByKey("downJson", utilsTools.getTotalMillisecond());
        loadFileInfo(gameUserInfo.json, jsonPath, 3);
        utilsTools.setGDataByKey("loadGaoQing", utilsTools.getTotalMillisecond());
        loadFileInfo(gameUserInfo.img, linePath, 1);
        utilsTools.setGDataByKey("loadJpg", utilsTools.getTotalMillisecond());
        loadFileInfo(gameUserInfo.finishImg, colorPath, 2);
        loadSelectImageTextureId(selectTextureIdx);
        return true;
    }
}
