AR 广告大屏虚拟礼物模块功能一
2017-07-28 11:30
309 查看
一、功能统计
二、关闭视频播放模块
三、打开虚拟礼物模块
四、创建两个脚本,UI_Manager(用于管理界面之间的分配)和G_Sc(礼物模块)
UI_Manager脚本的内容
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UI_Manager : MonoBehaviour {
void Start () {
}
void Update () {
}
//奇幻旅程按钮
public void Bt_M_V_Q()
{
//开始播放视频,调用UI_Manager所依附的物体上的V_Sc脚本中的StartVideo函数
gameObject.GetComponent<V_Sc>().StartVideo();
}
//拍照按钮
public void Bt_M_A_P()
{
//停止播放视频,调用UI_Manager所依附的物体上的V_Sc脚本中的StopVideo函数
gameObject.GetComponent<V_Sc>().StopVideo();
}
//获取贺卡的确认按钮
public void Bt_GIp_St()
{
//将输入的命令写到贺卡上
Debug.Log("Bt_GIp_St 1...................");
gameObject.GetComponent<G_Sc>().InputName();
Debug.Log("Bt_GIp_St 2...................");
//截取贺卡并保存
gameObject.GetComponent<G_Sc>().ScreenShot();
Debug.Log("Bt_GIp_St 3...................");
}
}
G_Sc的内容:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
public class G_Sc : MonoBehaviour {
//申请变量储存If_G_Ip这个组件
public InputField If_G_Ip;
//申请变量储存显示名字的Text组件
public Text Tx_G_Nm;
void Start () {
}
void Update () {
}
//将输入框的文字显示在贺卡处的函数
public void InputName()
{
//让贺卡中的Text组件中的文字变为输入框中输入的文字
Tx_G_Nm.text = If_G_Ip.text;
}
//截图功能
public void ScreenShot()
{
//Textture2D为内存中一种图片纹理格式
//第一第二个参数指定了纹理的宽高,第三个参数指定了纹理的格式
Texture2D texture2D = new Texture2D(600,800,TextureFormat.RGB24,false);
//读取屏幕像素,确认截图区域
texture2D.ReadPixels(new Rect(0,0,600,800),0,0,true);
//保存对TextTure2D的更改
texture2D.Apply();
//将Texture2D转换为PNG格式储存在byte数组中
byte[] bytes = texture2D.EncodeToPNG();
//将转换的PNG图片保存在资源管理器中,Application.dataPath为资源管理器路径
File.WriteAllBytes(Application.dataPath+"/ScreenShot.png",bytes);
}
}
五、创建一个空物体,重命名为Sc_Manager,将两个脚本挂载到该物体上,并将变量赋给相应的值
六、选中Bt_GIp_St确认按钮,在On Click()中添加相应的内容并选中相应的方法
七、运行后,在文本框输入内容并点击“确认”按钮
图片被保存成功
注:1.参考资料:http://edu.manew.com/course/216/learn#lesson/3294
2.遇到的问题:截屏中没有任何内容
截图功能的代码:
ReadPixels was called to read pixels from system frame buffer, while not inside drawing frame.
UnityEngine.Texture2D:ReadPixels(Rect, Int32, Int32, Boolean)
G_Sc:ScreenShot() (at Assets/Scripts/G_Sc.cs:44)
UI_Manager:Bt_GIp_St() (at Assets/Scripts/UI_Manager.cs:41)
UnityEngine.EventSystems.EventSystem:Update()
[d3d11] attempting to ReadPixels outside of RenderTexture bounds! Reading (0, 0, 600, 800) from (724, 526)
unity中Game视图的大小
原因:Texture2D和Rect中长宽不能超过724、526
解决办法:方法一、将两个参数都控制在724、526之内
方法二:Game视图所显示的就是屏幕的大小,将Game视图的窗口拖大,在运行时会出现问题,打包后可能不会出现该问题
点击保存后在Assets文件夹中查看图片的内容:
图片截图成功,但是坐标位置不对,所以显示的内容不对
二、关闭视频播放模块
三、打开虚拟礼物模块
四、创建两个脚本,UI_Manager(用于管理界面之间的分配)和G_Sc(礼物模块)
UI_Manager脚本的内容
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UI_Manager : MonoBehaviour {
void Start () {
}
void Update () {
}
//奇幻旅程按钮
public void Bt_M_V_Q()
{
//开始播放视频,调用UI_Manager所依附的物体上的V_Sc脚本中的StartVideo函数
gameObject.GetComponent<V_Sc>().StartVideo();
}
//拍照按钮
public void Bt_M_A_P()
{
//停止播放视频,调用UI_Manager所依附的物体上的V_Sc脚本中的StopVideo函数
gameObject.GetComponent<V_Sc>().StopVideo();
}
//获取贺卡的确认按钮
public void Bt_GIp_St()
{
//将输入的命令写到贺卡上
Debug.Log("Bt_GIp_St 1...................");
gameObject.GetComponent<G_Sc>().InputName();
Debug.Log("Bt_GIp_St 2...................");
//截取贺卡并保存
gameObject.GetComponent<G_Sc>().ScreenShot();
Debug.Log("Bt_GIp_St 3...................");
}
}
G_Sc的内容:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
public class G_Sc : MonoBehaviour {
//申请变量储存If_G_Ip这个组件
public InputField If_G_Ip;
//申请变量储存显示名字的Text组件
public Text Tx_G_Nm;
void Start () {
}
void Update () {
}
//将输入框的文字显示在贺卡处的函数
public void InputName()
{
//让贺卡中的Text组件中的文字变为输入框中输入的文字
Tx_G_Nm.text = If_G_Ip.text;
}
//截图功能
public void ScreenShot()
{
//Textture2D为内存中一种图片纹理格式
//第一第二个参数指定了纹理的宽高,第三个参数指定了纹理的格式
Texture2D texture2D = new Texture2D(600,800,TextureFormat.RGB24,false);
//读取屏幕像素,确认截图区域
texture2D.ReadPixels(new Rect(0,0,600,800),0,0,true);
//保存对TextTure2D的更改
texture2D.Apply();
//将Texture2D转换为PNG格式储存在byte数组中
byte[] bytes = texture2D.EncodeToPNG();
//将转换的PNG图片保存在资源管理器中,Application.dataPath为资源管理器路径
File.WriteAllBytes(Application.dataPath+"/ScreenShot.png",bytes);
}
}
五、创建一个空物体,重命名为Sc_Manager,将两个脚本挂载到该物体上,并将变量赋给相应的值
六、选中Bt_GIp_St确认按钮,在On Click()中添加相应的内容并选中相应的方法
七、运行后,在文本框输入内容并点击“确认”按钮
图片被保存成功
注:1.参考资料:http://edu.manew.com/course/216/learn#lesson/3294
2.遇到的问题:截屏中没有任何内容
截图功能的代码:
//截图功能 public void ScreenShot() { //Textture2D为内存中一种图片纹理格式 //第一第二个参数指定了纹理的宽高,第三个参数指定了纹理的格式 Texture2D texture2D = new Texture2D(600,800,TextureFormat.RGB24,false); //读取屏幕像素,确认截图区域 texture2D.ReadPixels(new Rect(0,0,600,800),0,0,true); //保存对TextTure2D的更改 texture2D.Apply(); //将Texture2D转换为PNG格式储存在byte数组中 byte[] bytes = texture2D.EncodeToPNG(); //将转换的PNG图片保存在资源管理器中,Application.dataPath为资源管理器路径 File.WriteAllBytes(Application.dataPath+"/ScreenShot.png",bytes); }unity中报的错误:
ReadPixels was called to read pixels from system frame buffer, while not inside drawing frame.
UnityEngine.Texture2D:ReadPixels(Rect, Int32, Int32, Boolean)
G_Sc:ScreenShot() (at Assets/Scripts/G_Sc.cs:44)
UI_Manager:Bt_GIp_St() (at Assets/Scripts/UI_Manager.cs:41)
UnityEngine.EventSystems.EventSystem:Update()
[d3d11] attempting to ReadPixels outside of RenderTexture bounds! Reading (0, 0, 600, 800) from (724, 526)
unity中Game视图的大小
原因:Texture2D和Rect中长宽不能超过724、526
解决办法:方法一、将两个参数都控制在724、526之内
方法二:Game视图所显示的就是屏幕的大小,将Game视图的窗口拖大,在运行时会出现问题,打包后可能不会出现该问题
点击保存后在Assets文件夹中查看图片的内容:
图片截图成功,但是坐标位置不对,所以显示的内容不对
相关文章推荐
- AR 广告大屏视频播放模块
- 如何利用Vuforia6.2.10,在Unity2017中来实现AR中的虚拟按钮功能
- 织梦DedeCMS广告管理模块增加图片上传功能插件
- Dede后台广告管理模块增加图片上传功能插件
- vsftp功能分析及虚拟用户服务
- 第三方登录功能分享&第三方登录模块开发(iOS)
- android中Handler与Runnable配合实现指定功能模块的定时循环地执行
- 一般企业网站建设常用到的功能模块介绍
- OpenCV的各模块功能
- S5PV210 sys_clock编程流程 系统时钟功能模块操作
- 最近发包给朋友,搞定软件小活儿、解决小功能模块的感受
- 实战3--设计管理模块, 第三步, 实现具体功能
- 开心网试水房产汽车虚拟广告营销
- js实现跟随鼠标移动且带关闭功能的图片广告实例
- [L-php]PHP功能模块——PHP解析XML,JSON
- 在编写软件功能模块 & 策划生活中的事情时。我们要学会画流程图
- 运维管理平台功能模块设计
- ASP.NET MVC 认证模块报错:“System.Configuration.Provider.ProviderException: 未启用角色管理器功能“
- 常规功能和模块自定义系统(cfcmms)—005开发环境搭建和创建项目
- Android Activity学习之 startActivityForResult() & 主界面连接多个子功能模块