Unity_给滚动视图动态添加子物体_066
来源:互联网 发布:局域网协作软件 编辑:程序博客网 时间:2024/06/02 05:32
ScrollView 的父子层次如下:
在ScrollView中添加的组件如下
在ViewPort中添加的组件如下:
在Content中添加的组件如下:
在ScrollView 中绑定的脚本如下:
using UnityEngine;using System.Collections;using UnityEngine.UI;using UnityEngine.EventSystems;using System;public class ScrollViewTest : MonoBehaviour,IBeginDragHandler,IEndDragHandler { private ScrollRect scrollRect; private float[] rateArr; //获取Content的RectTransform private RectTransform contentTransform; //设置添加的预制体 public RectTransform itemTransform; // Use this for initialization void Start () { //获取自身的ScrollRect组件 scrollRect = GetComponent<ScrollRect>(); contentTransform = transform.Find("ViewPort").Find("Content").GetComponent<RectTransform>(); } // Update is called once per frame void Update () { //按A键添加子物体 if (Input.GetKeyDown(KeyCode.A)) { Transform temp = Instantiate(itemTransform).transform; temp.SetParent(contentTransform); temp.localPosition = Vector3.zero; temp.localRotation = Quaternion.identity; temp.localScale = Vector3.one; } }}
阅读全文
0 0
- Unity_给滚动视图动态添加子物体_066
- unity3d给子物体添加MeshCollider
- Unity通过脚本实现给一个物体添加子物体
- 给子视图添加手势无效
- 在滚动视图上添加子视图(UIScrollView)
- UGUI +ScrollRect下实现动态添加grid子物体
- 8.MVC模式给根视图添加子视图和移除子视图
- 为一个物体添加子物体
- iOS开发-自定义重用机制给ScrollerView添加子视图
- 删除添加子父物体动态添加代码等Unity的小功能
- 动态添加子视图 UIView 的正确方法
- 给视图添加阴影
- 给视图添加控件
- 给视图添加阴影
- 给视图添加控件
- 添加子视图
- imageview添加子视图
- MFC : 给主菜单动态添加删除一级子菜单
- 栈和队列——设计一个有getMin功能的栈(二)
- hello,world
- 【笔记】Android5.0前后的Camera和Camera2 预览、拍照、摄像头切换
- 详解一个ThreadLocal 的谜题
- CodeFroces 175B. Plane of Tanks: Pro (构造)
- Unity_给滚动视图动态添加子物体_066
- redis-cli远程连接redis-server服务器的问题
- onMeasure的宽高生成解析
- rbd export V2
- Linux下查看二进制文件的工具
- Handle消息机制
- 稍微总结一下Python中集合的用法
- 如何写代码 —— 编程内功心法
- React框架快速入门