using System;
using System.IO;
using System.Text;
using UnityEngine;
using UnityEngine.UI;
//暂时实现点击一个位置这个位置就显示出来，如果这个位置已经显示了不再显示扩展圆形
public class tempzhangs : MonoBehaviour
{

    ////Start is called before the first frame update
    ////private Texture2D clickTexture2D;

    ////public Color color = Color.magenta;
    ////private Vector2 size = new Vector2();
    ////private Vector2 nowOperPos = new Vector2();
    ////private Image image0 = null;
    ////public Color checkColor = new Color();//允许的颜色
    ////public List<List<short>> datas = new List<List<short>>();
    ////public int circleR = 25;
    ////private int operColorSize = 0;
    ////private int nowOperSize = 0;
    ////private DigitMatrix dm = null;
    ////private Vector3 startPos = new Vector3();
    ////private int lastOperX = 0;
    ////private int lastOperY = 0;
    ////private void OnDisable()
    ////{
    ////    clickTexture2D = null;
    ////}
    ////public UnityEngine.Color getColor(int x, int y)
    ////{
    ////    返回坐标(x, y) 处的像素颜色
    ////    return clickTexture2D.GetPixel(x, y);
    ////}
    ////public void setColor(int x, int y, UnityEngine.Color c)
    ////{
    ////    设置坐标(x, y) 处的像素颜色
    ////    clickTexture2D.SetPixel(x, y, c);
    ////}

    ////void Start()
    ////{
    ////    Quaternion quaternion = new Quaternion();
    ////    var rectTransform = gameObject.GetComponent<RectTransform>();
    ////    rectTransform.GetLocalPositionAndRotation(out startPos, out quaternion);
    ////    size = rectTransform.rect.size;
    ////    nowOperPos.x = -1;
    ////    nowOperPos.y = -1;
    ////    checkColor.a = 0;
    ////    utilsTools.addTimer_Sec(gameObject, "nextFps", (string name) =>
    ////    {
    ////        image0 = GetComponent<Image>();
    ////        clickTexture2D = image0.sprite.texture;
    ////        dm = new DigitMatrix(clickTexture2D.width, clickTexture2D.height);
    ////        clearFlgs(0, 0, 0, 0, 0);
    ////        return false;
    ////    }, 5);

    ////}
    ////void OnPopulateMesh(VertexHelper vh, Vector2 p1, Vector2 p2, Vector2 p3)
    ////{
    ////    vh.Clear();
    ////    vh.AddVert(p1, Color.white, Vector2.zero);
    ////    vh.AddVert(p2, Color.white, Vector2.zero);
    ////    vh.AddVert(p3, Color.white, Vector2.zero);
    ////    vh.AddTriangle(0, 1, 2);

    ////}
    ////bool floatEquals(float a, float b, double wucha)
    ////{
    ////    if (a >= b)
    ////    {
    ////        return (a - b) < wucha;
    ////    }
    ////    return (b - a) < wucha;
    ////}
    ////void clearFlgs(int startx, int starty, int w, int h, short val)
    ////{
    ////    Color tempColor = new Color();
    ////    Debug.Log("开始尝试循环赋值");
    ////    int nobai = 0;
    ////    for (int i = 0; i < clickTexture2D.width; i++)
    ////    {
    ////        for (int j = 0; j < clickTexture2D.height; j++)
    ////        {
    ////            tempColor = getColor(i, j);
    ////            if (tempColor.a == 0)
    ////            {
    ////                dm.Data[i, j] = -99;
    ////                continue;
    ////            }
    ////            if (tempColor.r > 0.95 && tempColor.g > 0.95)
    ////            {
    ////                tempColor.r = 1;
    ////                tempColor.g = 1;
    ////                tempColor.b = 1;
    ////                dm.Data[i, j] = 1;
    ////            }
    ////            else
    ////            {
    ////                dm.Data[i, j] = -100;
    ////            }
    ////            tempColor.a = 1;
    ////            setColor(i, j, tempColor);
    ////        }
    ////    }
    ////    Debug.Log("结束循环赋值 nobai = " + nobai);
    ////    updateUIMask();
    ////}
    ////void clearAllData()
    ////{
    ////    datas = new List<List<short>>();
    ////}
    ////Update is called once per frame
    ////void Update()
    ////{
    ////    if (Input.GetMouseButtonDown(0))
    ////    {
    ////        if (clickTexture2D == null)
    ////        {
    ////            image0 = GetComponent<Image>();
    ////            clickTexture2D = image0.sprite.texture;
    ////            dm = new DigitMatrix(clickTexture2D.width, clickTexture2D.height);
    ////            clearFlgs(0, 0, 0, 0, 0);
    ////        }
    ////        var pos1 = ScreenToUILocalPos(this.transform as RectTransform, Input.mousePosition);
    ////        transform.Find("Image").localPosition = pos1;
    ////        int x = Convert.ToInt32(pos1.x + 250);
    ////        int y = Convert.ToInt32(pos1.y + 340);
    ////        if (x < 0 || y < 0 || x >= size.x || y >= size.y) return;
    ////        将位置转成相对坐标
    ////        color = this.getColor(x, y);
    ////        CaculateVector2(x, y);
    ////    }
    ////}
    ////private void CaculateVector2(int x, int y)
    ////{
    ////    if (dm.Data[x, y] != 1) return;
    ////    Debug.Log("开始绘制圆形");
    ////    operColorSize = 0;
    ////    lastOperX = -1;
    ////    dm.FloodFill8WithStack((short)x, (short)y, -100, 1, (short x1, short y1, short value) =>
    ////    {
    ////        if (value == -100)
    ////        {
    ////            operColorSize++;
    ////            setColor(x1, y1, checkColor);
    ////        }
    ////        return true;
    ////    });
    ////    if (operColorSize == 0) return;
    ////    updateUIMask();

    ////}
    ////private void updateUIMask()
    ////{
    ////    Debug.Log("替换纹理");
    ////    Sprite sprite = Sprite.Create(clickTexture2D, new Rect(0, 0, clickTexture2D.width, clickTexture2D.height), new Vector2(0.5f, 0.5f));
    ////    sprite.name = "rand__temp__text_localFile";
    ////    image0.sprite = sprite;

    ////    var bytes = clickTexture2D.EncodeToPNG();
    ////    utilsTools.saveByteToPath(bytes, "Resources/rand__temp__text_localFile.png");
    //    Byte[] bytes1 = Encoding.UTF8.GetBytes("fileFormatVersion: 2\r\nguid: 54ac8b67ea1f6f14892bd14ea1caab62\r\nTextureImporter:\r\n  internalIDToNameTable: []\r\n  externalObjects: {}\r\n  serializedVersion: 12\r\n  mipmaps:\r\n    mipMapMode: 0\r\n    enableMipMap: 0\r\n    sRGBTexture: 1\r\n    linearTexture: 0\r\n    fadeOut: 0\r\n    borderMipMap: 0\r\n    mipMapsPreserveCoverage: 0\r\n    alphaTestReferenceValue: 0.5\r\n    mipMapFadeDistanceStart: 1\r\n    mipMapFadeDistanceEnd: 3\r\n  bumpmap:\r\n    convertToNormalMap: 0\r\n    externalNormalMap: 0\r\n    heightScale: 0.25\r\n    normalMapFilter: 0\r\n    flipGreenChannel: 0\r\n  isReadable: 0\r\n  streamingMipmaps: 0\r\n  streamingMipmapsPriority: 0\r\n  vTOnly: 0\r\n  ignoreMipmapLimit: 0\r\n  grayScaleToAlpha: 0\r\n  generateCubemap: 6\r\n  cubemapConvolution: 0\r\n  seamlessCubemap: 0\r\n  textureFormat: 1\r\n  maxTextureSize: 2048\r\n  textureSettings:\r\n    serializedVersion: 2\r\n    filterMode: 1\r\n    aniso: 1\r\n    mipBias: 0\r\n    wrapU: 1\r\n    wrapV: 1\r\n    wrapW: 1\r\n  nPOTScale: 0\r\n  lightmap: 0\r\n  compressionQuality: 50\r\n  spriteMode: 1\r\n  spriteExtrude: 1\r\n  spriteMeshType: 1\r\n  alignment: 0\r\n  spritePivot: {x: 0.5, y: 0.5}\r\n  spritePixelsToUnits: 1\r\n  spriteBorder: {x: 0, y: 0, z: 0, w: 0}\r\n  spriteGenerateFallbackPhysicsShape: 1\r\n  alphaUsage: 1\r\n  alphaIsTransparency: 1\r\n  spriteTessellationDetail: -1\r\n  textureType: 8\r\n  textureShape: 1\r\n  singleChannelComponent: 0\r\n  flipbookRows: 1\r\n  flipbookColumns: 1\r\n  maxTextureSizeSet: 0\r\n  compressionQualitySet: 0\r\n  textureFormatSet: 0\r\n  ignorePngGamma: 0\r\n  applyGammaDecoding: 0\r\n  swizzle: 50462976\r\n  cookieLightType: 0\r\n  platformSettings:\r\n  - serializedVersion: 3\r\n    buildTarget: DefaultTexturePlatform\r\n    maxTextureSize: 2048\r\n    resizeAlgorithm: 0\r\n    textureFormat: -1\r\n    textureCompression: 1\r\n    compressionQuality: 50\r\n    crunchedCompression: 0\r\n    allowsAlphaSplitting: 0\r\n    overridden: 0\r\n    ignorePlatformSupport: 0\r\n    androidETC2FallbackOverride: 0\r\n    forceMaximumCompressionQuality_BC6H_BC7: 0\r\n  - serializedVersion: 3\r\n    buildTarget: Standalone\r\n    maxTextureSize: 2048\r\n    resizeAlgorithm: 0\r\n    textureFormat: -1\r\n    textureCompression: 1\r\n    compressionQuality: 50\r\n    crunchedCompression: 0\r\n    allowsAlphaSplitting: 0\r\n    overridden: 0\r\n    ignorePlatformSupport: 0\r\n    androidETC2FallbackOverride: 0\r\n    forceMaximumCompressionQuality_BC6H_BC7: 0\r\n  - serializedVersion: 3\r\n    buildTarget: Server\r\n    maxTextureSize: 2048\r\n    resizeAlgorithm: 0\r\n    textureFormat: -1\r\n    textureCompression: 1\r\n    compressionQuality: 50\r\n    crunchedCompression: 0\r\n    allowsAlphaSplitting: 0\r\n    overridden: 0\r\n    ignorePlatformSupport: 0\r\n    androidETC2FallbackOverride: 0\r\n    forceMaximumCompressionQuality_BC6H_BC7: 0\r\n  - serializedVersion: 3\r\n    buildTarget: Android\r\n    maxTextureSize: 2048\r\n    resizeAlgorithm: 0\r\n    textureFormat: -1\r\n    textureCompression: 1\r\n    compressionQuality: 50\r\n    crunchedCompression: 0\r\n    allowsAlphaSplitting: 0\r\n    overridden: 0\r\n    ignorePlatformSupport: 0\r\n    androidETC2FallbackOverride: 0\r\n    forceMaximumCompressionQuality_BC6H_BC7: 0\r\n  spriteSheet:\r\n    serializedVersion: 2\r\n    sprites: []\r\n    outline: []\r\n    physicsShape: []\r\n    bones: []\r\n    spriteID: 5e97eb03825dee720800000000000000\r\n    internalID: 0\r\n    vertices: []\r\n    indices: \r\n    edges: []\r\n    weights: []\r\n    secondaryTextures: []\r\n    nameFileIdTable: {}\r\n  mipmapLimitGroupName: \r\n  pSDRemoveMatte: 0\r\n  userData: \r\n  assetBundleName: \r\n  assetBundleVariant: \r\n");
    //    utilsTools.saveByteToPath(bytes1, "Resources/rand__temp__text_localFile.png.meta");
    ////    utilsTools.loadLocalImage(this, image0, "Resources/rand__temp__text_localFile.png");
    ////    Debug.Log("替换纹理End");
    ////}
    ////private Vector2 ScreenToUILocalPos(RectTransform transform, Vector2 mousePos, Camera canvasCam = null)
    ////{
    ////    Vector2 uiLocalPos;
    ////    RectTransformUtility.ScreenPointToLocalPointInRectangle(transform, mousePos, canvasCam, out uiLocalPos);
    ////    return uiLocalPos;
    ////}

    ////private void CaculateVector4(int x, int y)
    ////{
    ////    int minX = 0;
    ////    int minY = 0;
    ////    if (this.datas[x][y] != 0)
    ////    {
    ////        return;
    ////    }
    ////    Color tempColor = this.getColor(x, y);
    ////    if (tempColor != checkColor)
    ////    {
    ////        this.datas[x][y] = 1;
    ////    }
    ////    int dataW = datas.Count;
    ////    int dataH = datas[0].Count;
    ////    //第一步探索边界
    ////    for (int r = 1; r < 4096; r++)//找出每一个像素的最高
    ////    {

    ////    }
    ////    for (int r = 1; r < 4096; r++)
    ////    {
    ////        int cout = 0;
    ////        for (int x1 = 0 - r; x1 <= r; x1++)
    ////        {
    ////            if (x1 > 0 - r && x1 < r || (x + x1 < 0 || x + x1 >= dataW))
    ////            {
    ////                continue;
    ////            }
    ////            for (int y1 = 0 - 4; y1 <= r; y1++)
    ////            {
    ////                if (y1 > 0 - r && y1 < r || (y + y1 < 0 || y + y1 >= dataH))
    ////                {
    ////                    continue;
    ////                }
    ////                //怎么预防跨区域?
    ////                if (datas[x1 + x][])
    ////            }
    ////        }
    ////        if (cout == 0)
    ////        {
    ////            break;
    ////        }
    ////    }
    ////}

}
