| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | |
|
| | 4 | | namespace DCL |
| | 5 | | { |
| | 6 | | public class AssetLibrary_Mock : AssetLibrary<Asset_Mock> |
| | 7 | | { |
| | 8 | | public class RefCountedMockAsset |
| | 9 | | { |
| | 10 | | public Asset_Mock asset; |
| | 11 | | public int referenceCount; |
| | 12 | | } |
| | 13 | |
|
| 13 | 14 | | public Dictionary<object, RefCountedMockAsset> masterAssets = new Dictionary<object, RefCountedMockAsset>(); |
| | 15 | |
|
| | 16 | | public override bool Add(Asset_Mock asset) |
| | 17 | | { |
| 10 | 18 | | if (!masterAssets.ContainsKey(asset.id)) |
| 10 | 19 | | masterAssets.Add(asset.id, new RefCountedMockAsset() { referenceCount = 0, asset = asset }); |
| | 20 | |
|
| 10 | 21 | | return true; |
| | 22 | | } |
| | 23 | |
|
| | 24 | | public override bool Contains(object id) |
| | 25 | | { |
| 156 | 26 | | if (masterAssets == null || id == null) |
| 1 | 27 | | return false; |
| | 28 | |
|
| 155 | 29 | | return masterAssets.ContainsKey(id); |
| | 30 | | } |
| | 31 | |
|
| | 32 | | public override bool Contains(Asset_Mock asset) |
| | 33 | | { |
| 16 | 34 | | if (masterAssets == null || asset == null) |
| 2 | 35 | | return false; |
| | 36 | |
|
| 14 | 37 | | return masterAssets.ContainsKey(asset.id); |
| | 38 | | } |
| | 39 | |
|
| | 40 | | public override Asset_Mock Get(object id) |
| | 41 | | { |
| 60 | 42 | | if (Contains(id)) |
| | 43 | | { |
| 60 | 44 | | masterAssets[id].referenceCount++; |
| 60 | 45 | | return masterAssets[id].asset.Clone() as Asset_Mock; |
| | 46 | | } |
| | 47 | |
|
| 0 | 48 | | return null; |
| | 49 | | } |
| | 50 | |
|
| | 51 | | public override void Release(Asset_Mock asset) |
| | 52 | | { |
| 5 | 53 | | if (Contains(asset.id)) |
| | 54 | | { |
| 5 | 55 | | masterAssets[asset.id].referenceCount--; |
| 5 | 56 | | if (masterAssets[asset.id].referenceCount <= 0) |
| | 57 | | { |
| 2 | 58 | | masterAssets.Remove(asset.id); |
| | 59 | | } |
| | 60 | | } |
| 5 | 61 | | } |
| | 62 | |
|
| 0 | 63 | | public override void Cleanup() { throw new NotImplementedException(); } |
| | 64 | | } |
| | 65 | | } |