PBXDictionary.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. namespace cn.sharesdk.unity3d.sdkporter
  5. {
  6. public class PBXDictionary : Dictionary<string, object>
  7. {
  8. public void Append( PBXDictionary dictionary )
  9. {
  10. foreach( var item in dictionary) {
  11. this.Add( item.Key, item.Value );
  12. }
  13. }
  14. public void Append<T>( PBXDictionary<T> dictionary ) where T : PBXObject
  15. {
  16. foreach( var item in dictionary) {
  17. this.Add( item.Key, item.Value );
  18. }
  19. }
  20. }
  21. public class PBXDictionary<T> : Dictionary<string, T> where T : PBXObject
  22. {
  23. public PBXDictionary()
  24. {
  25. }
  26. public PBXDictionary( PBXDictionary genericDictionary )
  27. {
  28. foreach( KeyValuePair<string, object> currentItem in genericDictionary ) {
  29. if( ((string)((PBXDictionary)currentItem.Value)[ "isa" ]).CompareTo( typeof(T).Name ) == 0 ) {
  30. T instance = (T)System.Activator.CreateInstance( typeof(T), currentItem.Key, (PBXDictionary)currentItem.Value );
  31. this.Add( currentItem.Key, instance );
  32. }
  33. }
  34. }
  35. public void Add( T newObject )
  36. {
  37. this.Add( newObject.guid, newObject );
  38. }
  39. public void Append( PBXDictionary<T> dictionary )
  40. {
  41. foreach( KeyValuePair<string, T> item in dictionary) {
  42. this.Add( item.Key, (T)item.Value );
  43. }
  44. }
  45. }
  46. }