物件池管理的學習

2021-10-20 18:18:02 字數 1976 閱讀 1579

知識點:

scriptableobject:可以實現建立物件時指令碼無需依賴於遊戲物件,所建立物件也要繼承該介面。

assetdatabase:操作unity資源的介面。

editor類:

using unityengine;

using system.collections;

using unityeditor;

public class poolmanagereditor

}

**建立類(無需依附遊戲物件)gameobjectpoollist類

using unityengine;

using system.collections;

using system.collections.generic;

public class gameobjectpoollist : scriptableobject

建立乙個池子的標準模板:

儲存模式為 string name+gameobject prefab(池子名稱+池子所儲存物件)的模式儲存。

gameobjectpool類

using unityengine;

using system.collections;

using system;

using system.collections.generic;

/// /// 資源池

///

[serializable]

public class gameobjectpool

}//多於限制例項的最大值需要刪除

if (golist.count >= maxamount)

//例項化乙個新的物件,並加入列表

gameobject temp = gameobject.instantiate(prefab) as gameobject;

golist.add(temp);

return temp;

}}

物件池管理類:poolmanager類

using unityengine;

using system.collections;

using system.collections.generic;

public class poolmanager

return _instance;}}

private static string poolconfigpathprefix = "assets/framework/resources/";

private const string poolconfigpathmiddle = "gameobjectpool";

private const string poolconfigpathpostfix = ".asset";

/// /// 生成路徑

///

public static string poolconfigpath

}private dictionarypooldict;

/// /// 讀取poollist到字典pooldict

///

private poolmanager()

}public void init()

/// /// 獲取乙個物件池

///

///

///

public gameobject getinst(string poolname)

debug.logwarning("pool : " + poolname + " is not exits!!!");

return null;

}}

物件池的使用:test類

poolmanager.instance.getinst("bullet");

CocosCreator物件池管理

import from resourcemanager const cc.decorator ccclass export class nodepoolmanager 物件池存 param pool 物件池 param num 數量 param pre 預設 static poolput pool ...

關於物件池的學習

關於物件池的學習 以及文章參考 個人理解 1.物件池的工廠 createobjectpool class,para 2.物件池 核心類 getobject 如果超過規定的大小,則等待,否則建立物件,放入池中,並且返回 如果池中沒有物件,則等待其他執行緒,然後取出firstelement,return...

Unity 通用 物件池管理

一般情況下我們使用物件池是物體的建立和管理。但在很多情況下需要批量建立的物體需要做一些邏輯處理,這樣我們需要記錄物件池對應的資料狀態。所以我們就直接把物件作為管理物件,這樣我們可以在物件裡面做一些邏輯處理還能便於物體管理。作為物件管理類,那麼我們必須要乙個同乙個父類作為管理的類別。在父類裡面包含一些...