UGUI 5.0 一些笔记
1.加载资源路径
在Assets路径里创建Resources文件夹
a.加载配置好的界面
GameObject obj = (GameObject)Resources.Load ("config/backbg");
if (obj) {
Debug.Log ("Debug-------Debug--------");
obj = Instantiate (obj);
obj.transform.localScale = new Vector3 (1, 1, 1);
obj.transform.localPosition = new Vector3 (1, 1, 1);
}
b.加载场景
SceneManager.LoadScene("scence_1");
c.加载控件
//查找控件---【文本框】
GameObject obj = GameObject.Find ("bind_gold_label");
//类型转换
Text bindGold = obj.GetComponent<Text>();
bindGold.text = "45678 <color=\"0xffff00\">zxxxczvc</color> "; //【按钮】
GameObject.Find ("Button").GetComponent<Button>().onClick.AddListener(delegate() {
this.onBtnClick();
}) ; //【复选框】
Toggle Toggle3 = GameObject.Find ("Toggle3").GetComponent<Toggle> ();
Toggle1.onValueChanged.AddListener(delegate(bool isTrue) {
onToggleClick(isTrue);
}) ; //【图片】, 资源路径 从Resources开始查询,不需要写文件后缀名
GameObject.Find ("gold").GetComponent<Image> ().sprite = Resources.Load("UI/mainui/coin", typeof(Sprite))as Sprite; //【RawImage】原生图片
GameObject.Find ("RawImage").GetComponent<RawImage> ().texture = Resources.Load ("UI/mainui/bg",typeof(Texture)) as Texture; //进度条
Slider sld = GameObject.Find ("Slider").GetComponent<Slider> ();
sld.value = 0.30f; //滑动条
Scrollbar scb = GameObject.Find ("Scrollbar").GetComponent<Scrollbar> ();
scb.value = 0.30f; //下拉框
Dropdown dropdown = GameObject.Find ("Dropdown").GetComponent<Dropdown> ();
2.疑难杂症
a.在画布(Canvas)上显示3D模型,需要添加一个摄像头(ui_Camera),观察这个界面
设置ui_Camera属性: <Clear nFlags> 为 【Depth only】
<Culling Mask> 为 【UI, Default】(勾选两项)
<Depth> 为 【1】
主摄像机属性: <Culling Mask> 不勾选 【UI】
b.获取某个ugui界面的实例类型GameObject获取挂载的脚本
GameObject obj;
obj.GetComponent<脚本类名>(); //根据这个获得脚本下public的变量和方法
3.常用的
//---------------------------------
// 获取控件宽高
// 1.用作悬浮窗点击范围判断
// 2.
//--------------------------------- Rect rect = GetComponent<RectTransform> ().rect; //---------------------------------
// 控件隐藏
//--------------------------------- Text ttext = new Text();
ttext.SetActive (false); //隐藏,反之显示
4.ugui 子节点坐标 与 点击坐标 的坐标系处于一致性
//参数是 画布上某个控件的子节点。
private bool checkRect(UnityEngine.GameObject obj){ Vector2 touchpos;
Vector2 pos;
Canvas UI = GetComponent<Canvas> (); //画布
Rect rect = obj.GetComponent<RectTransform> ().rect;
RectTransformUtility.ScreenPointToLocalPointInRectangle(UI.transform as RectTransform, Input.mousePosition, UI.worldCamera, out touchpos);
RectTransformUtility.ScreenPointToLocalPointInRectangle (UI.transform as RectTransform, obj.transform.position, UI.worldCamera, out pos);
// Debug.Log("-------------touch---------------------"+ touchpos.x +" " + touchpos.y +" pos L" + pos); if ( touchpos.x > pos.x + rect.width/2 || touchpos.x < pos.x - rect.width/2 || touchpos.y > pos.y + rect.height/2 || touchpos.y < pos.y - rect.height/2 ){
return false; //触摸点之外
}
return true; //触摸点之内
}
UGUI 5.0 一些笔记的更多相关文章
- DirectX 总结和DirectX 9.0 学习笔记
转自:http://www.cnblogs.com/graphics/archive/2009/11/25/1583682.html DirectX 总结 DDS DirectXDraw Surfac ...
- The Implementation of Lua 5.0 阅读笔记(一)
没想到Lua的作者理论水平这么高,这篇文章读的我顿生高屋建瓴之感.云风分享了一篇中译:http://www.codingnow.com/2000/download/The%20Implementati ...
- 一起学ASP.NET Core 2.0学习笔记(二): ef core2.0 及mysql provider 、Fluent API相关配置及迁移
不得不说微软的技术迭代还是很快的,上了微软的船就得跟着她走下去,前文一起学ASP.NET Core 2.0学习笔记(一): CentOS下 .net core2 sdk nginx.superviso ...
- 第64节:Java中的Spring Boot 2.0简介笔记
Java中的Spring Boot 2.0简介笔记 spring boot简介 依赖java8的运行环境 多模块项目 打包和运行 spring boot是由spring framework构建的,sp ...
- HTTP2.0 简明笔记
前言 RFC2616发布以来,一直是互联网发展的基石.HTTP协议也成为了可以在任何领域使用的核心协议,基于这个协议人们设计和部署了越来越多的应用.HTTP的简单本质是其快速发展的关键,但随着越来越多 ...
- vue2.0学习笔记之路由(二)路由嵌套+动画
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- vue2.0学习笔记之路由(二)路由嵌套
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- spss v21.0 使用笔记
spss v21.0 使用笔记 有问题,戳官方帮助文档 神经网络 分析-神经网络-多层感知机 变量. 分析-神经网络-多层感知机-变量 预测变量可指定为因子(分类)或协变量(刻度). 在因变量框输入预 ...
- hdcms v5.7.0学习笔记
hdcms v5.7.0学习笔记 https://note.youdao.com/ynoteshare1/index.html?id=c404d63ac910eb15a440452f73d6a6db& ...
随机推荐
- React 生命周期简介
React 中组件的生命周期会经历如下三个过程:装载过程.更新过程.卸载过程. 装载过程:组件实例被创建和插入 DOM 树的过程: 更新过程:组件被重新渲染的过程: 卸载过程:组件从 DOM 树 ...
- Jquery的动态切换图片
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- edgedb 内部pg 数据存储的探索 (一)基本环境搭建
edgedb 是基于pg 上的对象关系数据库,已经写过使用docker 运行的demo,为了探索内部的原理,做了一下尝试,开启pg 访问 后边会进一步的学习 环境准备 为了测试,使用yum 安装 安装 ...
- taro 报错及解决
1.解决:taro 升级到最新版(npm install -g @tarojs/cli) 错误 组件编译 组件src/pages/xxx/xxx.tsx编译失败! TypeError: callee. ...
- Inno Setup打包带有MSI文件的程序
[Setup] ; 注: AppId的值为单独标识该应用程序. ; 不要为其他安装程序使用相同的AppId值. ; (生成新的GUID,点击 工具|在IDE中生成GUID.) AppId={{47A1 ...
- Window服务项目脚手架
本人最近工作用到window服务程序,于是尝试分享下经验,开源了一个window服务脚手架项目,把window服务程序必不可少的组件集成进去,如日志组件log4net,window服务挂在后台,用日志 ...
- git bash的一些使用经验
1.最开始使用git的时候, git remote -v 查看远程仓库 报了一个错误fatal: not a git repository (or any of the parent director ...
- 京东饭粒捡漏V1.0.8
20180617 更新 V1.0.81.捡漏策略更新:自动检测商品,有货后自动下单:2.加车自动使用最优满减券组合: 功能介绍1.京东商城专用,支持饭粒模式下单,自己获得京豆返利 2.捡漏模式:帮助用 ...
- elasticSearch 2.3 delete-by-query plugin
The delete-by-query plugin adds support for deleteing all of the documents which match the specified ...
- P1041 传染病控制(dfs)
P1041 传染病控制 题目背景 近来,一种新的传染病肆虐全球.蓬莱国也发现了零星感染者,为防止该病在蓬莱国大范围流行,该国政府决定不惜一切代价控制传染病的蔓延.不幸的是,由于人们尚未完全认识这种传染 ...