PBXObject.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. namespace cn.sharesdk.unity3d.sdkporter
  5. {
  6. public class PBXObject
  7. {
  8. protected const string ISA_KEY = "isa";
  9. //
  10. protected string _guid;
  11. protected PBXDictionary _data;
  12. #region Properties
  13. public string guid {
  14. get {
  15. if( string.IsNullOrEmpty( _guid ) )
  16. _guid = GenerateGuid();
  17. return _guid;
  18. }
  19. }
  20. public PBXDictionary data {
  21. get {
  22. if( _data == null )
  23. _data = new PBXDictionary();
  24. return _data;
  25. }
  26. }
  27. #endregion
  28. #region Constructors
  29. public PBXObject()
  30. {
  31. _data = new PBXDictionary();
  32. _data[ ISA_KEY ] = this.GetType().Name;
  33. _guid = GenerateGuid();
  34. }
  35. public PBXObject( string guid ) : this()
  36. {
  37. if( IsGuid( guid ) )
  38. _guid = guid;
  39. }
  40. public PBXObject( string guid, PBXDictionary dictionary ) : this( guid )
  41. {
  42. // Debug.Log( "constructor parent " + this.GetType().Name );
  43. if( !dictionary.ContainsKey( ISA_KEY ) || ((string)dictionary[ ISA_KEY ]).CompareTo( this.GetType().Name ) != 0 )
  44. Debug.LogError( "PBXDictionary is not a valid ISA object" );
  45. foreach( KeyValuePair<string, object> item in dictionary ) {
  46. _data[ item.Key ] = item.Value;
  47. }
  48. }
  49. #endregion
  50. #region Static methods
  51. public static bool IsGuid( string aString )
  52. {
  53. return System.Text.RegularExpressions.Regex.IsMatch( aString, @"^[A-F0-9]{24}$" );
  54. }
  55. public static string GenerateGuid()
  56. {
  57. return System.Guid.NewGuid().ToString("N").Substring( 8 ).ToUpper();
  58. }
  59. #endregion
  60. #region Data manipulation
  61. public void Add( string key, object obj )
  62. {
  63. _data.Add( key, obj );
  64. }
  65. public bool Remove( string key )
  66. {
  67. return _data.Remove( key );
  68. }
  69. public bool ContainsKey( string key )
  70. {
  71. return _data.ContainsKey( key );
  72. }
  73. #endregion
  74. // class PBXObject(PBXDict):
  75. // def __init__(self, d=None):
  76. // PBXDict.__init__(self, d)
  77. //
  78. // if not self.has_key('isa'):
  79. // self['isa'] = self.__class__.__name__
  80. // self.id = None
  81. //
  82. // @staticmethod
  83. // def Convert(o):
  84. // if isinstance(o, list):
  85. // return PBXList(o)
  86. // elif isinstance(o, dict):
  87. // isa = o.get('isa')
  88. //
  89. // if not isa:
  90. // return PBXDict(o)
  91. //
  92. // cls = globals().get(isa)
  93. //
  94. // if cls and issubclass(cls, PBXObject):
  95. // return cls(o)
  96. //
  97. // print 'warning: unknown PBX type: %s' % isa
  98. // return PBXDict(o)
  99. // else:
  100. // return o
  101. }
  102. public class PBXNativeTarget : PBXObject
  103. {
  104. public PBXNativeTarget() : base() {
  105. }
  106. public PBXNativeTarget( string guid, PBXDictionary dictionary ) : base( guid, dictionary ) {
  107. }
  108. }
  109. public class PBXContainerItemProxy : PBXObject
  110. {
  111. public PBXContainerItemProxy() : base() {
  112. }
  113. public PBXContainerItemProxy( string guid, PBXDictionary dictionary ) : base( guid, dictionary ) {
  114. }
  115. }
  116. public class PBXReferenceProxy : PBXObject
  117. {
  118. public PBXReferenceProxy() : base() {
  119. }
  120. public PBXReferenceProxy( string guid, PBXDictionary dictionary ) : base( guid, dictionary ) {
  121. }
  122. }
  123. public class PBXVariantGroup : PBXObject
  124. {
  125. public PBXVariantGroup() : base() {
  126. }
  127. public PBXVariantGroup( string guid, PBXDictionary dictionary ) : base( guid, dictionary ) {
  128. }
  129. }
  130. }