zoukankan      html  css  js  c++  java
  • 对象池

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using Assets.Script.nn;
    
    /// <summary>
    /// 卡牌池
    /// </summary>
    public class CardPool:MonoBehaviour
    {
        static Stack<GameObject> objectPool = new Stack<GameObject>();
        
        /// <summary>
        /// 清空池子
        /// </summary>
        public static void Clear()
        {
            objectPool.Clear();
    
            foreach(GameObject go in objectPool)
            {
                Destroy(go);
            }
        }
        /// <summary>
        ////// </summary>
        /// <returns></returns>
        public static GameObject Pop()
        {
            if (objectPool.Count == 0)
            {
                GameObject newcard = Instantiate(Resources.Load<GameObject>("nn/3DCard/Card"));
    
                objectPool.Push(newcard);
            }
    
            GameObject card = objectPool.Pop();
            card.SetActive(true);
            card.transform.position = Vector3.zero;
            return card;
        }
    
        /// <summary>
        ////// </summary>
        /// <param name="obj"></param>
        public static void Release(GameObject obj)
        {
            if (objectPool.Contains(obj))
                throw new System.Exception("对象已经放入池内!");
            objectPool.Push(obj);
            obj.GetComponent<Assets.Script.nn.Card>().ResetCardState();
            obj.SetActive(false);
            obj.transform.localScale = new Vector3(0.7f,0.7f,0.7f);
    
        }
    
    }
  • 相关阅读:
    iframeUpload
    获取当前文件路径。
    ie6 overflow 失效
    ie8 vml不显示
    json转换
    nodejs for windows
    模块化管理组件(2012/05/09)
    模块化管理组件v0.1
    Firefox和IE之间7个JavaScript的差异
    c输入函数细节
  • 原文地址:https://www.cnblogs.com/0315cz/p/8315914.html
Copyright © 2011-2022 走看看