PBXGroup.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. namespace cn.sharesdk.unity3d.sdkporter
  5. {
  6. public class PBXGroup : PBXObject
  7. {
  8. protected const string NAME_KEY = "name";
  9. protected const string CHILDREN_KEY = "children";
  10. protected const string PATH_KEY = "path";
  11. protected const string SOURCETREE_KEY = "sourceTree";
  12. #region Constructor
  13. public PBXGroup( string name, string path = null, string tree = "SOURCE_ROOT" ) : base()
  14. {
  15. this.Add( NAME_KEY, name );
  16. this.Add( CHILDREN_KEY, new PBXList() );
  17. if( path != null ) {
  18. this.Add( PATH_KEY, path );
  19. this.Add( SOURCETREE_KEY, tree );
  20. }
  21. else {
  22. this.Add( SOURCETREE_KEY, "<group>" );
  23. }
  24. }
  25. public PBXGroup( string guid, PBXDictionary dictionary ) : base( guid, dictionary )
  26. {
  27. }
  28. #endregion
  29. #region Properties
  30. public string name {
  31. get {
  32. if( !ContainsKey( NAME_KEY ) ) {
  33. return null;
  34. }
  35. return (string)_data[NAME_KEY];
  36. }
  37. }
  38. public PBXList children {
  39. get {
  40. if( !ContainsKey( CHILDREN_KEY ) ) {
  41. this.Add( CHILDREN_KEY, new PBXList() );
  42. }
  43. return (PBXList)_data[CHILDREN_KEY];
  44. }
  45. }
  46. public string path {
  47. get {
  48. if( !ContainsKey( PATH_KEY ) ) {
  49. return null;
  50. }
  51. return (string)_data[PATH_KEY];
  52. }
  53. }
  54. public string sourceTree {
  55. get {
  56. return (string)_data[SOURCETREE_KEY];
  57. }
  58. }
  59. #endregion
  60. public string AddChild( PBXObject child )
  61. {
  62. if( child is PBXFileReference || child is PBXGroup ) {
  63. children.Add( child.guid );
  64. return child.guid;
  65. }
  66. return null;
  67. }
  68. public void RemoveChild( string id )
  69. {
  70. if( !IsGuid( id ) )
  71. return;
  72. children.Remove( id );
  73. }
  74. public bool HasChild( string id )
  75. {
  76. if( !ContainsKey( CHILDREN_KEY ) ) {
  77. this.Add( CHILDREN_KEY, new PBXList() );
  78. return false;
  79. }
  80. if( !IsGuid( id ) )
  81. return false;
  82. return ((PBXList)_data[ CHILDREN_KEY ]).Contains( id );
  83. }
  84. public string GetName()
  85. {
  86. return (string)_data[ NAME_KEY ];
  87. }
  88. // class PBXGroup(PBXObject):
  89. // def add_child(self, ref):
  90. // if not isinstance(ref, PBXDict):
  91. // return None
  92. //
  93. // isa = ref.get('isa')
  94. //
  95. // if isa != 'PBXFileReference' and isa != 'PBXGroup':
  96. // return None
  97. //
  98. // if not self.has_key('children'):
  99. // self['children'] = PBXList()
  100. //
  101. // self['children'].add(ref.id)
  102. //
  103. // return ref.id
  104. //
  105. // def remove_child(self, id):
  106. // if not self.has_key('children'):
  107. // self['children'] = PBXList()
  108. // return
  109. //
  110. // if not PBXObject.IsGuid(id):
  111. // id = id.id
  112. //
  113. // self['children'].remove(id)
  114. //
  115. // def has_child(self, id):
  116. // if not self.has_key('children'):
  117. // self['children'] = PBXList()
  118. // return False
  119. //
  120. // if not PBXObject.IsGuid(id):
  121. // id = id.id
  122. //
  123. // return id in self['children']
  124. //
  125. // def get_name(self):
  126. // path_name = os.path.split(self.get('path',''))[1]
  127. // return self.get('name', path_name)
  128. //
  129. // @classmethod
  130. // def Create(cls, name, path=None, tree='SOURCE_ROOT'):
  131. // grp = cls()
  132. // grp.id = cls.GenerateId()
  133. // grp['name'] = name
  134. // grp['children'] = PBXList()
  135. //
  136. // if path:
  137. // grp['path'] = path
  138. // grp['sourceTree'] = tree
  139. // else:
  140. // grp['sourceTree'] = '<group>'
  141. //
  142. // return grp
  143. }
  144. }