NGUI DragablePanel与UiStretch的兼容
如题: 直接代码
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// 把panel单独取出来 重置其size
/// </summary>
[ExecuteInEditMode]
[RequireComponent(typeof(UIDraggablePanel))]
public class ClipPanelPlugin : MonoBehaviour {
public bool needReposition;
public enum ScrollDirection {
horizontal,
vertical
}
public ScrollDirection direction;
// Use this for initialization
void Start () {
StartCoroutine(startReset());
}
IEnumerator startReset() {
yield return new WaitForSeconds(2f);
resetPanel();
}
void resetPanel() {
//把panel 单独取出来
Transform parent = transform.parent;
List<Transform> children = new List<Transform>();
Transform child = null;
for (int i = 0, l = transform.childCount; i < l; i++) {
child = transform.GetChild(0);
child.parent = null;
children.Add(child);
}
transform.parent = null;
Vector3 scale = transform.localScale;
scale.y = scale.z = scale.x = direction == ScrollDirection.vertical ? scale.y : scale.x;
transform.localScale = scale;
foreach (Transform c in children) {
c.parent=transform;
}
transform.parent = parent;
#if UNITY_EDITOR
#else
enabled=false;
#endif
}
void LateUpdate() {
if (needReposition) {
needReposition = false;
resetPanel();
}
}
}
浙公网安备 33010602011771号