预设池(滑雪大冒险)

using System;
using System.Collections.Generic;
using UnityEngine;

public class Pool : MonoBehaviour
{
    public static Pool Instance;
    [SerializeField]
    private List<PoolTable> items = new List<PoolTable>();
    private Dictionary<GameObject, PoolTable> overriddenPoolTables = new Dictionary<GameObject, PoolTable>();
    private Dictionary<GameObject, PoolInstance> poolInstances = new Dictionary<GameObject, PoolInstance>();
    private Dictionary<GameObject, PoolTable> poolTables = new Dictionary<GameObject, PoolTable>();
    public Preallocation[] preallocations;

    private void Awake()
    {
        Instance = this;
        foreach (Preallocation preallocation in this.preallocations)
        {
            this.DoPreallocate(preallocation.prefab, preallocation.count);
        }
    }

    public static void Despawn(GameObject obj)
    {
        if (Instance != null)
        {
            Instance.DoDespawn(obj);
        }
    }

    public static void Despawn<T>(T obj) where T: Component
    {
        if (Instance != null)
        {
            Instance.DoDespawn(obj.gameObject);
        }
    }

    public static void DespawnAll()
    {
        if (Instance != null)
        {
            Instance.DoDespawnAll();
        }
    }

    private void DoDespawn(GameObject obj)
    {
        PoolInstance instance;
        if (this.poolInstances.TryGetValue(obj, out instance))
        {
            PoolTable table = instance.Table;
            if (table != null)
            {
                instance.InUse = false;
                table.Despawn(obj);
                base.enabled = true;
                return;
            }
        }
        UnityEngine.Object.Destroy(obj);
    }

    private void DoDespawnAll()
    {
        foreach (KeyValuePair<GameObject, PoolInstance> pair in this.poolInstances)
        {
            PoolInstance instance = pair.Value;
            if (instance.Table != null)
            {
                instance.InUse = false;
                instance.Table.Despawn(pair.Key);
            }
        }
        base.enabled = true;
    }

    private void DoPreallocate(GameObject prefab, int count)
    {
        this.GetOrCreateTable(prefab).Preallocate(count);
    }

    private void DoReplace(GameObject prefab, GameObject otherPrefab)
    {
        PoolTable table;
        if (!this.poolTables.TryGetValue(prefab, out table))
        {
            Debug.LogError("Prefab does not exist to replace: " + prefab.name + " with: " + otherPrefab.name);
        }
        else if (table.Prefab != otherPrefab)
        {
            PoolTable table2;
            foreach (KeyValuePair<GameObject, PoolInstance> pair in this.poolInstances)
            {
                if (pair.Value.Table == table)
                {
                    pair.Value.InUse = false;
                    table.Despawn(pair.Key);
                }
            }
            Instance.enabled = true;
            if (this.overriddenPoolTables.TryGetValue(otherPrefab, out table2))
            {
                this.overriddenPoolTables.Remove(otherPrefab);
            }
            else
            {
                table2 = new PoolTable(otherPrefab);
                this.items.Add(table2);
                table2.Preallocate(table.ActiveCount + table.FreeCount);
            }
            this.overriddenPoolTables[table.Prefab] = table;
            this.poolTables[prefab] = table2;
        }
    }

    private GameObject DoSpawn(GameObject prefab, Vector3 position, Quaternion rotation)
    {
        base.enabled = true;
        PoolTable orCreateTable = this.GetOrCreateTable(prefab);
        GameObject instance = orCreateTable.Spawn(position, rotation);
        this.poolInstances[instance] = new PoolInstance(instance, true, orCreateTable);
        return instance;
    }

    public int GetActiveCount(GameObject prefab)
    {
        PoolTable table;
        if (this.poolTables.TryGetValue(prefab, out table))
        {
            return table.ActiveCount;
        }
        return 0;
    }

    private PoolTable GetOrCreateTable(GameObject prefab)
    {
        PoolTable table;
        if (!this.poolTables.TryGetValue(prefab, out table))
        {
            table = new PoolTable(prefab);
            this.poolTables[prefab] = table;
            this.items.Add(table);
        }
        return table;
    }

    public PoolInstance GetPoolInstance(GameObject obj)
    {
        PoolInstance instance;
        this.poolInstances.TryGetValue(obj, out instance);
        return instance;
    }

    public static PoolTable GetTable(GameObject prefab)
    {
        return ((Instance == null) ? null : Instance.GetOrCreateTable(prefab));
    }

    private void LateUpdate()
    {
        foreach (PoolTable table in this.items)
        {
            table.Update();
        }
        base.enabled = false;
    }

    public static void Replace(GameObject prefab, GameObject otherPrefab)
    {
        if (Instance != null)
        {
            Instance.DoReplace(prefab, otherPrefab);
        }
    }

    public static void Revert(GameObject prefab)
    {
        if (Instance != null)
        {
            Instance.DoReplace(prefab, prefab);
        }
    }

    public static GameObject Spawn(GameObject prefab)
    {
        return ((Instance == null) ? null : Instance.DoSpawn(prefab, Vector3.zero, Quaternion.identity));
    }

    public static T Spawn<T>(T prefab) where T: Component
    {
        if (Instance != null)
        {
            GameObject obj2 = Instance.DoSpawn(prefab.gameObject, Vector3.zero, Quaternion.identity);
            if (obj2 != null)
            {
                return obj2.GetComponent<T>();
            }
        }
        return null;
    }

    public static GameObject Spawn(GameObject prefab, Vector3 position, Quaternion rotation)
    {
        return ((Instance == null) ? null : Instance.DoSpawn(prefab, position, rotation));
    }

    public static T Spawn<T>(T prefab, Vector3 position, Quaternion rotation) where T: Component
    {
        if (Instance != null)
        {
            GameObject obj2 = Instance.DoSpawn(prefab.gameObject, position, rotation);
            if (obj2 != null)
            {
                return obj2.GetComponent<T>();
            }
        }
        return null;
    }

    public List<PoolTable> Items
    {
        get
        {
            return this.items;
        }
    }

    [Serializable]
    public class Preallocation
    {
        public int count;
        public GameObject prefab;
    }
}
时间: 2024-10-01 00:28:43

预设池(滑雪大冒险)的相关文章

滑雪大冒险破解分析

载入JEB发现支付SDK好熟悉EgamePay 上次分析的一个游戏就是从支付SDK入手,回溯定位 所以直接进入EgamePay,对pay函数做交叉引用 定位到如下函数,但是我们操作了一下,Log.i的日志并没有输出 我们跟进那个listener 对其做交叉引用 然后去插入日志看哪些pay来了 可以看到我们pay111来了 修改onResult  直接调用OnSuccess并返回 最后修改成功 总结一下: 游戏的内购都是常见的支付sdk ,熟悉这些支付sdk 可以快速定位 来自为知笔记(Wiz)

HDU 2512 一卡通大冒险(dp)

一卡通大冒险 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2137    Accepted Submission(s): 1430 Problem Description 因为长期钻研算法, 无暇顾及个人问题,BUAA ACM/ICPC 训练小组的帅哥们大部分都是单身.某天,他们在机房商量一个绝妙的计划"一卡通大冒险".这个

HDU 2512 一卡通大冒险

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2512 Problem Description 因为长期钻研算法, 无暇顾及个人问题,BUAA ACM/ICPC 训练小组的帅哥们大部分都是单身.某天,他们在机房商量一个绝妙的计划"一卡通大冒险".这个计划是由wf最先提出来的,计划的内容是,把自己的联系方式写在校园一卡通的背面,然后故意将自己的卡"遗失"在某处(如水房,TD,食堂,主M....)他们希望能有MM看到他们

杭电 2512 一卡通大冒险

一卡通大冒险 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s):     Accepted Submission(s): Problem Description 因为长期钻研算法, 无暇顾及个人问题,BUAA ACM/ICPC 训练小组的帅哥们大部分都是单身.某天,他们在机房商量一个绝妙的计划"一卡通大冒险".这个计划是由wf最先

龙珠激斗大冒险掷筛子算法

今天玩儿龙珠激斗的大冒险时掷筛子的时候想了想掷筛子的算法,自己写着玩儿.代码如下: ''' 龙珠大冒险掷筛子介绍: 在地图中掷筛子 如果地图剩余格子数大于6则默认进行十连掷 十连掷不能超过剩余格子数否则进行最大次数连掷 如果地图剩余格子数小于等于6则进行单掷 如果单次掷筛子结果大于剩余格子数则进入下一张地图 输入: 剩余格子数 输出: 掷筛子的结果 ''' import random def throw_once(): return random.randint(1,6) def throw_t

日式冒险游戏《巫女小镜大冒险》PIC 图片转 BMP 图片

----------------------------------------------------------------------------- !!警告!! 游戏资源所有权,归游戏开发商所有 以下转换算法与代码,仅供学习交流使用,请勿用于非法或商业用途 由此引起的一切后果,与博主(我)无关 ----------------------------------------------------------------------------- 这游戏的资源本身没有被打包,直接就可以看

Python中小整数对象池和大整数对象池

1. 小整数对象池 整数在程序中的使用非常广泛,Python为了优化速度,使用了小整数对象池, 避免为整数频繁申请和销毁内存空间. Python 对小整数的定义是 [-5, 256] 这些整数对象是提前建立好的,不会被垃圾回收.在一个 Python 的程序中,所有位于这个范围内的整数使用的都是同一个对象. 同理,单个字母也是这样的.

java dbcp连接池,大数据处理循环多表操作插入事例

基础连接池类: package com.yl.sys.dao; import java.io.InputStream;import java.sql.Connection;import java.sql.SQLException;import java.util.Properties;import java.util.Vector; public class ConnectionPoolTool { private Vector<Connection> pool; private String

hdu 2521 一卡通大冒险 (斯特灵数,贝尔数)

/* 将N张卡分成若干个集合,集合不为空,有多少种分法. f[n][m]表示n张卡分成m组的种类数,那么f[n][m]=f[n-1][m-1]+f[n-1][m]*m,//第二类斯特灵数 而ans[n]=sum{f[n][l]}(1<=l<=m).//ans为贝尔数,Bell数是将P个元素集合分到非空且不可区分例子的划分个数. 其中:f[n-1][m-1]代表第n个人自成一堆: f[n-1][m]*m代表第n个人不自成一堆. */ # include <stdio.h> # inc