using UnityEngine;
using System.Collections;
/// <summary>
/// 脚本位置:预制体身上
/// </summary>
public class RoleItem : MonoBehaviour {
// role 卡片的深蓝背景
// active toggle激活的时候显示浅蓝的图片
// texture 人物图片
// 用来调整深度
public UIWidget[] widgets;
// 人物图片
public UITexture RenWutexture;
/// <summary>
/// tween完成后记录当前位置
/// </summary>
public void Finish()
{
TweenPosition tp = gameObject.GetComponent<TweenPosition>();
tp.from = gameObject.transform.localPosition;
// 正常动画播放一次就不能在播放了,使用这句代码可以是动画再次播放
tp.ResetToBeginning();
}
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// 脚本位置:ui摄像机
/// 脚本功能:生成人物卡牌数组,控制卡牌移动
/// </summary>
public class SelectRole : MonoBehaviour
{
// 卡牌数组的父物体
public GameObject cardsObj;
// 单边卡牌的数量(以最大数量为基数 + 中间卡牌数1)
private int halfCardNumber = 0;
// x轴的移动距离
private int _movX = 150;
// y轴的移动距离
private int _movY = 50;
// 一个人物卡牌上需要调整深度的组件数量
private int count = 3;
private List<RoleItem> _roleList = new List<RoleItem> ();
Texture[] textureList ;
// Use this for initialization
void Start ()
{
// 加载图片数组
textureList = Resources.LoadAll<Texture> ("Pictures");
// 最大深度也可以说是最前面那张图片的默认深度
int maxDepth = textureList.Length / 2 + 1;
// 单边卡牌数 既 计算的默认深度 (比如8张图,中间1张,左右一个4张,一个3张)
// 所以这个单边卡牌的数量就是4+1 = 5张
halfCardNumber = maxDepth;
// 遍历Resources加载到的所有图片
for (int i = 0; i < textureList.Length; i++) {
// 加载人物卡牌图片预设体(注意不能加载到UIRoot的外面,那样会自动创建多个UICamera)
GameObject card = Instantiate (Resources.Load<GameObject> ("Role"));
// 将生成的人物卡牌的父亲设置为卡牌数组
card.transform.parent = cardsObj.transform;
// 大小设置为1(根据自己当前需求更改父物体的大小即可)
card.transform.localScale = Vector3.one;
// NGUI和UGUI一样无法给预制体添加触发方法