123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- namespace cn.sharesdk.unity3d.sdkporter
- {
- public class PBXObject
- {
- protected const string ISA_KEY = "isa";
- //
- protected string _guid;
- protected PBXDictionary _data;
-
- #region Properties
-
- public string guid {
- get {
- if( string.IsNullOrEmpty( _guid ) )
- _guid = GenerateGuid();
-
- return _guid;
- }
- }
-
- public PBXDictionary data {
- get {
- if( _data == null )
- _data = new PBXDictionary();
-
- return _data;
- }
- }
-
-
- #endregion
- #region Constructors
-
- public PBXObject()
- {
- _data = new PBXDictionary();
- _data[ ISA_KEY ] = this.GetType().Name;
- _guid = GenerateGuid();
- }
-
- public PBXObject( string guid ) : this()
- {
- if( IsGuid( guid ) )
- _guid = guid;
- }
-
- public PBXObject( string guid, PBXDictionary dictionary ) : this( guid )
- {
- // Debug.Log( "constructor parent " + this.GetType().Name );
-
- if( !dictionary.ContainsKey( ISA_KEY ) || ((string)dictionary[ ISA_KEY ]).CompareTo( this.GetType().Name ) != 0 )
- Debug.LogError( "PBXDictionary is not a valid ISA object" );
-
- foreach( KeyValuePair<string, object> item in dictionary ) {
- _data[ item.Key ] = item.Value;
- }
- }
-
- #endregion
- #region Static methods
-
- public static bool IsGuid( string aString )
- {
- return System.Text.RegularExpressions.Regex.IsMatch( aString, @"^[A-F0-9]{24}$" );
- }
-
- public static string GenerateGuid()
- {
- return System.Guid.NewGuid().ToString("N").Substring( 8 ).ToUpper();
- }
-
-
- #endregion
- #region Data manipulation
-
- public void Add( string key, object obj )
- {
- _data.Add( key, obj );
- }
-
- public bool Remove( string key )
- {
- return _data.Remove( key );
- }
-
- public bool ContainsKey( string key )
- {
- return _data.ContainsKey( key );
- }
-
- #endregion
- // class PBXObject(PBXDict):
- // def __init__(self, d=None):
- // PBXDict.__init__(self, d)
- //
- // if not self.has_key('isa'):
- // self['isa'] = self.__class__.__name__
- // self.id = None
- //
- // @staticmethod
- // def Convert(o):
- // if isinstance(o, list):
- // return PBXList(o)
- // elif isinstance(o, dict):
- // isa = o.get('isa')
- //
- // if not isa:
- // return PBXDict(o)
- //
- // cls = globals().get(isa)
- //
- // if cls and issubclass(cls, PBXObject):
- // return cls(o)
- //
- // print 'warning: unknown PBX type: %s' % isa
- // return PBXDict(o)
- // else:
- // return o
- }
-
- public class PBXNativeTarget : PBXObject
- {
- public PBXNativeTarget() : base() {
- }
-
- public PBXNativeTarget( string guid, PBXDictionary dictionary ) : base( guid, dictionary ) {
- }
- }
- public class PBXContainerItemProxy : PBXObject
- {
- public PBXContainerItemProxy() : base() {
- }
-
- public PBXContainerItemProxy( string guid, PBXDictionary dictionary ) : base( guid, dictionary ) {
- }
- }
- public class PBXReferenceProxy : PBXObject
- {
- public PBXReferenceProxy() : base() {
- }
-
- public PBXReferenceProxy( string guid, PBXDictionary dictionary ) : base( guid, dictionary ) {
- }
- }
- public class PBXVariantGroup : PBXObject
- {
- public PBXVariantGroup() : base() {
- }
-
- public PBXVariantGroup( string guid, PBXDictionary dictionary ) : base( guid, dictionary ) {
- }
- }
- }
|