• 对象池


    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);
    
        }
    
    }
  • 相关阅读:
    世界疫情可视化开发(一)
    世界疫情可视化开发(三)-- world.jsp
    团队冲刺5
    课下作业1-扩展阅读
    团队冲刺4
    团队冲刺3
    冲刺个人感想
    团队冲刺开始
    Android Studio Toast(吐司)的基本使用
    GridLayout(网格布局)
  • 原文地址:https://www.cnblogs.com/0315cz/p/8315914.html
Copyright © 2020-2023  润新知