资源简介
unity版本2018.2.7,这是自己在unity中写的图片填充功能,使用的是泛洪算法,需要的可以下载。

代码片段和文件信息
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Demo_texture : MonoBehaviour
{
//计算鼠标点击位置 对应的像素位置,一个是image的左下角,一个是图片的右上角
public Transform textureOrigin;
public Transform textureUPEnd;
//存储点击的图片的texture2D getpixel() 使用
private Texture2D clickTexture2D;
//存储鼠标点击位置的像素值
private Color testColor;
//存储计算出来的像素点的位置
private Vector2 colorPos;
//存储图片定位点的屏幕坐标
private Vector3 textureOriginScreenPosition;
private Vector3 textureEndUPScreenPosition;
//测试用的显示颜色的图片
public Image image;
private void Start()
{
textureOriginScreenPosition = Camera.main.WorldToScreenPoint(textureOrigin.position);
textureEndUPScreenPosition = Camera.main.WorldToScreenPoint(textureUPEnd.position);
}
private void Update()
{
Ray r = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Input.GetMouseButtonDown(0))
{
if (Physics.Raycast(r out hit))
{
HitColorChooseImage(hit);
}
}
}
private void HitColorChooseImage(RaycastHit hit)
{
// print(hit.collider.name);
if (hit.collider.name == “Image“)
{
// print(3);
clickTexture2D = hit.collider.gameobject.GetComponent().sprite.texture;
CaculateVector2();
}
}
public Stack stackX = new Stack();
public Stack stackY = new Stack();
private void CaculateVector2()
{
colorPos.x = (Input.mousePosition.x - textureOriginScreenPosition.x) / (textureEndUPScreenPosition.x - textureOriginScreenPosition.x) * clickTexture2D.width;
colorPos.y = (Input.mousePosition.y - textureOriginScreenPosition.y) / (textureEndUPScreenPosition.y - textureOriginScreenPosition.y) * clickTexture2D.height;
// print(“x:--“ + colorPos.x + “--y:---“ + colorPos.y);
if (!(getColor((int)colorPos.x (int)colorPos.y) == Color.white))
{
return;
}
int[] dx = new int[8] { 0 1 1 1 0 -1 -1 -1 };
int[] dy = new int[8] { -1 -1 0 1 1 1 0 -1 };
stackX.Push((int)colorPos.x);
stackY.Push((int)colorPos.y);
int x;
int y;
int xx;
int yy;
print(clickTexture2D.width + “_“ + clickTexture2D.height);
while (stackX.Count > 0)
{
x = stackX.Pop();
y = stackY.Pop();
setColor(x y Color.green);
for (int i = 0; i < 8; i++)
{
xx = x + dx[i];
yy = y + dy[i];
if (xx > 0 && xx < clickTexture2D.width && yy > 0 && yy < clickTexture2D.height && getColor(xx yy) == Color.white)
{
stackX.Push(xx);
stackY.Push(yy);
}
}
}
clickTexture2D.Apply();
}
public Color get
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-08-09 17:26 Statck_image\
目录 0 2019-06-18 18:19 Statck_image\obj\
目录 0 2019-08-09 17:06 Statck_image\obj\Debug\
文件 0 2019-08-09 11:25 Statck_image\obj\Debug\Assembly-CSharp.csproj.CopyComplete
文件 7680 2019-08-09 11:25 Statck_image\obj\Debug\Assembly-CSharp.dll
文件 1752 2019-08-09 11:25 Statck_image\obj\Debug\Assembly-CSharp.pdb
文件 41 2019-08-09 10:12 Statck_image\obj\Debug\Assembly-CSharp.csproj.CoreCompileInputs.cache
文件 19745 2019-08-09 10:12 Statck_image\obj\Debug\Assembly-CSharp.csproj.FileListAbsolute.txt
文件 350887 2019-08-09 17:06 Statck_image\obj\Debug\Assembly-CSharp.csprojAssemblyReference.cache
文件 922 2019-06-18 18:19 Statck_image\Statck_image.sln
目录 0 2019-06-18 18:19 Statck_image\ProjectSettings\
文件 17798 2019-06-18 18:18 Statck_image\ProjectSettings\ProjectSettings.asset
文件 6088 2018-08-30 10:03 Statck_image\ProjectSettings\InputManager.asset
文件 195 2018-08-30 10:03 Statck_image\ProjectSettings\TimeManager.asset
文件 1937 2018-08-30 10:03 Statck_image\ProjectSettings\GraphicsSettings.asset
文件 355 2018-08-30 10:03 Statck_image\ProjectSettings\PresetManager.asset
文件 812 2019-06-18 18:19 Statck_image\ProjectSettings\UnityConnectSettings.asset
文件 643 2018-08-30 10:03 Statck_image\ProjectSettings\EditorSettings.asset
文件 268 2018-08-30 10:03 Statck_image\ProjectSettings\EditorBuildSettings.asset
文件 120 2018-08-30 10:03 Statck_image\ProjectSettings\ClusterInputManager.asset
文件 421 2018-08-30 10:03 Statck_image\ProjectSettings\TagManager.asset
文件 1399 2018-08-30 10:03 Statck_image\ProjectSettings\NavMeshAreas.asset
文件 1997 2018-08-30 21:06 Statck_image\ProjectSettings\Physics2DSettings.asset
文件 159 2018-08-30 10:03 Statck_image\ProjectSettings\NetworkManager.asset
文件 377 2018-08-30 10:03 Statck_image\ProjectSettings\AudioManager.asset
文件 1044 2018-08-30 21:06 Statck_image\ProjectSettings\DynamicsManager.asset
文件 5037 2018-08-30 10:03 Statck_image\ProjectSettings\QualitySettings.asset
文件 28 2019-06-18 18:18 Statck_image\ProjectSettings\ProjectVersion.txt
目录 0 2019-08-09 17:26 Statck_image\Library\
文件 17798 2019-06-18 18:18 Statck_image\Library\ProjectSettings.asset
文件 14 2019-06-18 18:18 Statck_image\Library\AssetImportState
............此处省略1335个文件信息
- 上一篇:51单片机100例 汇编
- 下一篇:加油站客户信息管理系统的设计与实现计算机毕业设计
评论
共有 条评论