ResDic.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import Sprite3D = Laya.Sprite3D;
  2. export default class ResDic {
  3. private _length:number;
  4. public _container:{[id:number]:Laya.Image};
  5. constructor(){
  6. this._container = {};
  7. this._length = 0;
  8. }
  9. public get container():{[id:number]:Laya.Image}{
  10. return this._container;
  11. }
  12. //获取字典长度
  13. public get size():number{
  14. return this._length;
  15. }
  16. //添加
  17. public set(key:any,value:any):void{
  18. if(!this._container.hasOwnProperty(key))
  19. {
  20. this._length++;
  21. }
  22. this._container[key] = value;
  23. }
  24. //查找
  25. public has(key:any):boolean{
  26. return this._container.hasOwnProperty(key)?true:false;
  27. }
  28. //获取
  29. public get(key:any):any{
  30. if(this._container.hasOwnProperty(key))
  31. {
  32. return this._container[key];
  33. }else
  34. {
  35. return undefined
  36. }
  37. }
  38. //删除
  39. public delete(key:any):void{
  40. if(this._container.hasOwnProperty(key))
  41. {
  42. delete this._container[key];
  43. this._length--;
  44. }
  45. }
  46. //清空
  47. public clear(){
  48. this._container = {};
  49. this._length = 0;
  50. }
  51. }