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();
        }
    }
}

  

转载于:https://www.cnblogs.com/wolfsky6/p/3515127.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值