简单的贴图融合
来源:互联网 发布:试客系统整站源码 编辑:程序博客网 时间:2024/04/30 01:52
一张是墙面的图片,一张时弹孔的图片,鼠标点击墙面,打孔的图片取代你鼠标点击的那部分墙面图片,过段时间后墙面回复原状
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class WallScript : MonoBehaviour {
Texture2D copy_wallTexture;
Texture2D wall_texture ;
public Texture2D bullet_texture;
float wall_Width;
float wall_Height;
float bullet_Width;
float bullet_Height;
Queue<Vector2> UV;
void Start () {
wall_texture = (Texture2D) GetComponent<MeshRenderer> ().material.mainTexture;
//获得墙面图标的宽度和高度
wall_Width = wall_texture.width;
wall_Height = wall_texture.height;
//子弹图片的宽度和高度
bullet_Width = bullet_texture.width;
bullet_Height = bullet_texture.height;
拷贝一张未加弹孔图片的墙壁图片
copy_wallTexture = Instantiate (wall_texture)as Texture2D;
UV = new Queue<Vector2> ();
}
RaycastHit hit;
void Update () {
if (Input.GetMouseButton (0)) {
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
bool result = Physics.Raycast (ray, out hit);
if (result) {
if (hit.transform.name == "Wall") {
//获取射线在墙上的UV坐标
Vector2 uv = hit.textureCoord2;
UV.Enqueue (uv);
//将Uv坐标转换成墙上的坐标 -- 代表子弹的中心
float x = uv.x * wall_Width;
float y = uv.y * wall_Height;
for (int i = 0; i < bullet_Width; i++) {
for (int j = 0; j < bullet_Height; j++) {
//获取wall上的坐标
float X = x - bullet_Width / 2.0f + i;
float Y = y - bullet_Height / 2.0f + j;
Color wall_color = wall_texture.GetPixel ((int)X, (int)Y);
Color bullet_color = bullet_texture.GetPixel (i, j);
wall_texture.SetPixel((int)X,(int)Y,bullet_color * wall_color);
}
}
}
wall_texture.Apply ();
//3秒后执行GoBack这个方法
Invoke ("GoBack", 3);
}
}
}
void GoBack()
{
if (UV.Count > 0) {
Vector2 uv= UV.Dequeue ();
float x = uv.x * wall_Width;
float y = uv.y * wall_Height;
for (int i = 0; i < bullet_Width; i++) {
for (int j = 0; j < bullet_Height; j++) {
float X = x - bullet_Width / 2 + i;
float Y = y - bullet_Height / 2 + j;
Color Copy_color = copy_wallTexture.GetPixel ((int)X, (int)Y);
wall_texture.SetPixel ((int)X, (int)Y, Copy_color);
}
}
wall_texture.Apply ();
}
}
}
- 简单的贴图融合
- 简单的图像融合
- 简单的按钮贴图
- Unity中贴图融合之弹痕融合
- chapter13_2图片的简单融合
- 简单的GDI贴图应用
- OpenG: 简单的纹理贴图
- Unity的简单贴图动画的应用
- Android学习02简单的贴图
- 最简单的自绘贴图按钮
- 【图像融合】简单加权融合
- 简单图像融合1
- 简单图像融合2
- OpenCV - 简单图像融合
- 简单加权融合
- 简单纹理贴图
- 简单纹理贴图
- 简单纹理贴图
- pycharm注册, pycharm激活
- t-SNE初学
- UGUI -- 原生Sprite 处理小扩展
- Java基础知识-if条件语句的使用介绍
- USACO 3.1 Humble Numbers丑数
- 简单的贴图融合
- [工具]VS2013下载地址
- IQKeyboardManager简单实用
- HDU 1003 最大连续子段和
- shell中$@和$*的区别
- 5.Git代码<安装与配置>-2(自我整理) 2016/11/12
- 火力点
- 最优化方法综述
- [转]swift, unwind segue回传数据