Beispiel #1
0
        int UnityEngineGameObject_m_GetComponents(RealStatePtr L, int gen_param_count)
        {
            ObjectTranslator translator = this;


            UnityEngine.GameObject gen_to_be_invoked = (UnityEngine.GameObject)translator.FastGetCSObj(L, 1);

            if (gen_param_count == 2 && translator.Assignable <System.Type>(L, 2))
            {
                System.Type _type = (System.Type)translator.GetObject(L, 2, typeof(System.Type));

                UnityEngine.Component[] gen_ret = gen_to_be_invoked.GetComponents(_type);
                translator.Push(L, gen_ret);



                return(1);
            }
            if (gen_param_count == 3 && translator.Assignable <System.Type>(L, 2) && translator.Assignable <System.Collections.Generic.List <UnityEngine.Component> >(L, 3))
            {
                System.Type _type = (System.Type)translator.GetObject(L, 2, typeof(System.Type));
                System.Collections.Generic.List <UnityEngine.Component> _results = (System.Collections.Generic.List <UnityEngine.Component>)translator.GetObject(L, 3, typeof(System.Collections.Generic.List <UnityEngine.Component>));

                gen_to_be_invoked.GetComponents(_type, _results);



                return(0);
            }


            return(LuaAPI.luaL_error(L, "invalid arguments to UnityEngine.GameObject.GetComponents!"));
        }
Beispiel #2
0
 private void PauseOrResumeBackgroudMusic(int is_pause, int index)
 {
     UnityEngine.GameObject go = UnityEngine.GameObject.Find("Audio");
     if (null != go)
     {
         UnityEngine.AudioSource[] audio_source = go.GetComponents <UnityEngine.AudioSource>();
         if (null == audio_source)
         {
             return;
         }
         for (int i = 0; i < audio_source.Length; i++)
         {
             if (i == index && null != audio_source[i])
             {
                 if (is_pause > 0)
                 {
                     if (audio_source[i].isPlaying)
                     {
                         audio_source[i].Pause();
                     }
                 }
                 else
                 {
                     if (!audio_source[i].isPlaying)
                     {
                         audio_source[i].Play();
                     }
                 }
             }
         }
     }
 }
        static int _m_GetComponents(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                UnityEngine.GameObject gen_to_be_invoked = (UnityEngine.GameObject)translator.FastGetCSObj(L, 1);


                int gen_param_count = LuaAPI.lua_gettop(L);

                if (gen_param_count == 2 && translator.Assignable <System.Type>(L, 2))
                {
                    System.Type _type = (System.Type)translator.GetObject(L, 2, typeof(System.Type));

                    UnityEngine.Component[] gen_ret = gen_to_be_invoked.GetComponents(
                        _type);
                    translator.Push(L, gen_ret);



                    return(1);
                }
                if (gen_param_count == 3 && translator.Assignable <System.Type>(L, 2) && translator.Assignable <System.Collections.Generic.List <UnityEngine.Component> >(L, 3))
                {
                    System.Type _type = (System.Type)translator.GetObject(L, 2, typeof(System.Type));
                    System.Collections.Generic.List <UnityEngine.Component> _results = (System.Collections.Generic.List <UnityEngine.Component>)translator.GetObject(L, 3, typeof(System.Collections.Generic.List <UnityEngine.Component>));

                    gen_to_be_invoked.GetComponents(
                        _type,
                        _results);



                    return(0);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }

            return(LuaAPI.luaL_error(L, "invalid arguments to UnityEngine.GameObject.GetComponents!"));
        }
Beispiel #4
0
        /*
         * public static bool PostNotification<T>(object sender, T notification, bool bNotifyEntity = false) where T : Notification
         * {
         *  if (sender == null) throw new ArgumentNullException("sender");
         *  if (notification == null) throw new ArgumentNullException("notification");
         *
         *  if (sender is INotificationDispatcher)
         *  {
         *      return (sender as INotificationDispatcher).PostNotification<T>(notification, bNotifyEntity);
         *  }
         *  else if (GameObjectUtil.IsGameObjectSource(sender))
         *  {
         *      if (bNotifyEntity)
         *      {
         *          var dispatcher = GameObjectUtil.GetGameObjectFromSource(sender).AddOrGetComponent<GameObjectNotificationDispatcher>();
         *          return dispatcher.PostNotification<T>(notification, bNotifyEntity);
         *      }
         *      else
         *      {
         *          var dispatcher = GameObjectUtil.GetGameObjectFromSource(sender).GetComponent<GameObjectNotificationDispatcher>();
         *          return dispatcher != null && dispatcher.PostNotification<T>(notification, bNotifyEntity);
         *      }
         *  }
         *  else
         *  {
         *      throw new System.ArgumentException("Sender is not a NotificationDispatcher.", "sender");
         *  }
         * }
         */

        #endregion

        #region Purge/Clean Utilities

        public static void PurgeHandlers(UnityEngine.GameObject go)
        {
            using (var lst = com.spacepuppy.Collections.TempCollection.GetList <INotificationDispatcher>())
            {
                go.GetComponents <INotificationDispatcher>(lst);
                var e = lst.GetEnumerator();
                while (e.MoveNext())
                {
                    e.Current.Observers.PurgeHandlers();
                }
            }
        }
Beispiel #5
0
        static StackObject *GetComponents_12(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            UnityEngine.GameObject instance_of_this_method = (UnityEngine.GameObject) typeof(UnityEngine.GameObject).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.GetComponents <global::MonoBehaviourAdapter.Adaptor>();

            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
Beispiel #6
0
        internal Type[] GetAllComponents(UnityEngine.GameObject gameObject)
        {
            var result     = new List <Type>();
            var components = gameObject.GetComponents(typeof(UnityEngine.Component));

            foreach (var component in components)
            {
                var componentType = component.GetType();

                if (IsTypeOrNameNotExcluded(componentType, null))
                {
                    result.Add(componentType);
                }
            }
            return(result.ToArray());
        }
Beispiel #7
0
        private void GameObjectChildren(UnityEngine.GameObject gameObject, int indent)
        {
            var indentation = new string(' ', indent * 4);

            Info(indentation + " + " + gameObject.name);

            foreach (var component in gameObject.GetComponents <UnityEngine.Component>())
            {
                Info(indentation + " | - - " + component.GetType());
            }

            foreach (UnityEngine.Transform transform in gameObject.transform)
            {
                GameObjectChildren(transform.gameObject, indent + 1);
            }
        }
Beispiel #8
0
        private void InitBackgroudMusic(int scene_id)
        {
            Data_SceneConfig dsc = SceneConfigProvider.Instance.GetSceneConfigById(scene_id);

            if (null != dsc)
            {
                UnityEngine.GameObject go = UnityEngine.GameObject.Find("Audio");
                if (null != go)
                {
                    UnityEngine.AudioSource[] audio_source = go.GetComponents <UnityEngine.AudioSource>();
                    if (null == audio_source)
                    {
                        return;
                    }
                    for (int i = 0; i < audio_source.Length; i++)
                    {
                        if (null != audio_source[i])
                        {
                            if (audio_source[i].isPlaying)
                            {
                                continue;
                            }
                            string name   = "";
                            float  volume = 1.0f;
                            if (0 == i)
                            {
                                name   = dsc.m_BkMusic;
                                volume = dsc.m_BkMusicVolume;
                            }
                            else
                            {
                                name   = dsc.m_StoryMusic;
                                volume = dsc.m_StoryMusicVolume;
                            }
                            UnityEngine.AudioClip clip = (UnityEngine.AudioClip)UnityEngine.Resources.Load(name) as UnityEngine.AudioClip;
                            if (null != clip)
                            {
                                audio_source[i].clip   = clip;
                                audio_source[i].volume = dsc.m_BkMusicVolume * 0.0f; // tmp disable backgroud music
                            }
                        }
                    }
                }
            }
        }
Beispiel #9
0
        public static void LogHierarchy(UnityEngine.GameObject root, int depth = 0)
        {
            string prefix = "";

            for (int i = 0; i < depth; ++i)
            {
                prefix += "  ";
            }
            Log(prefix + "GameObject: " + root.name);
            foreach (var component in root.GetComponents <UnityEngine.Component>())
            {
                Log(prefix + "Component: " + component.GetType().Name);
            }

            foreach (UnityEngine.Transform child in root.transform)
            {
                LogHierarchy(child.gameObject, depth + 1);
            }
        }
        static void GetComponents(EntityManager entityManager, GameObject gameObject, bool includeGameObjectComponents, out ComponentType[] types, out Component[] components)
        {
            components = gameObject.GetComponents <Component>();

            var componentCount = 0;

            if (includeGameObjectComponents)
            {
                var gameObjectEntityComponent = gameObject.GetComponent <GameObjectEntity>();
                componentCount = gameObjectEntityComponent == null ? components.Length : components.Length - 1;
            }
            else
            {
                for (var i = 0; i != components.Length; i++)
                {
                    if (components[i] is ComponentDataWrapperBase)
                    {
                        componentCount++;
                    }
                }
            }

            types = new ComponentType[componentCount];

            var t = 0;

            for (var i = 0; i != components.Length; i++)
            {
                var com           = components[i];
                var componentData = com as ComponentDataWrapperBase;

                if (componentData != null)
                {
                    types[t++] = componentData.GetComponentType(entityManager);
                }
                else if (includeGameObjectComponents && !(com is GameObjectEntity))
                {
                    types[t++] = com.GetType();
                }
            }
        }
Beispiel #11
0
        public static int GetComponents(IntPtr L)
        {
            int result = 1;
            int count  = LuaDLL.lua_gettop(L);

            if (count == 2 &&
                LuaStatic.CheckType(L, typeof(Type), 2))
            {
                UnityEngine.GameObject obj = LuaStatic.GetObj(L, 1) as UnityEngine.GameObject;
                object      type1          = LuaStatic.GetObj(L, 2);
                Type        arg1           = LuaStatic.GetType(type1);
                IEnumerable objs           = (IEnumerable)obj.GetComponents(arg1);
                LuaDLL.lua_newtable(L);
                int num2 = 0;
                foreach (var item in objs)
                {
                    LuaStatic.addGameObject2Lua(L, (UnityEngine.Component)item, (string)type1);
                    LuaDLL.lua_pushnumber(L, (double)(++num2));
                    LuaDLL.lua_insert(L, -2);
                    LuaDLL.lua_settable(L, -3);
                }

                return(result);
            }
            if (count == 3 &&
                LuaStatic.CheckType(L, typeof(Type), 2) &&
                LuaStatic.CheckType(L, typeof(List <UnityEngine.Component>), 3))
            {
                UnityEngine.GameObject obj = LuaStatic.GetObj(L, 1) as UnityEngine.GameObject;
                object type1 = LuaStatic.GetObj(L, 2);
                Type   arg1  = LuaStatic.GetType(type1);
                List <UnityEngine.Component> arg2 = (List <UnityEngine.Component>)LuaStatic.GetObj(L, 3);
                obj.GetComponents(arg1, arg2);

                return(result);
            }
            LuaStatic.traceback(L, "count not enough");
            LuaDLL.lua_error(L);
            return(result);
        }
Beispiel #12
0
 private void StopBackgroudMusic()
 {
     UnityEngine.GameObject go = UnityEngine.GameObject.Find("Audio");
     if (null != go)
     {
         UnityEngine.AudioSource[] audio_source = go.GetComponents <UnityEngine.AudioSource>();
         if (null == audio_source)
         {
             return;
         }
         for (int i = 0; i < audio_source.Length; i++)
         {
             if (null != audio_source[i])
             {
                 if (audio_source[i].isPlaying)
                 {
                     audio_source[i].Stop();
                 }
             }
         }
     }
 }
Beispiel #13
0
        public void GameObjectHierarchy(UnityEngine.GameObject gameObject)
        {
            if (gameObject.transform != null)
            {
                if (gameObject.transform.parent != null)
                {
                    var parent = gameObject.transform.parent.gameObject;

                    if (parent != null)
                    {
                        GameObjectHierarchy(parent);
                    }
                }
            }

            Info(" + " + gameObject.name);

            foreach (var component in gameObject.GetComponents <UnityEngine.Component>())
            {
                Info("      " + component.GetType());
            }
        }
        /// <summary>
        /// Write the specified value.
        /// </summary>
        /// <param name="value">Value.</param>
        public override void Write(object value)
        {
            if (value == null)
            {
                m_Writer.Write("null");
            }
            else
            {
                Type type                = value.GetType();
                bool isEnum              = false;
                bool isSerializable      = false;
                bool isGeneric           = false;
                bool isGenericCollection = false;
#if (UNITY_WSA || UNITY_WINRT) && !UNITY_EDITOR
                TypeInfo info = type.GetTypeInfo();
                isEnum         = info.IsEnum;
                isSerializable = info.IsSerializable;
                isGeneric      = info.IsGenericType;
#else
                isEnum         = type.IsEnum;
                isSerializable = type.IsSerializable;
                isGeneric      = type.IsGenericType;
#endif
                isGenericCollection = type.GetInterfaces().Contains(typeof(ICollection <>));
                if (type == typeof(UnityEngine.GameObject))
                {
                    m_Writer.Write("{");
                    UnityEngine.GameObject gameObject = value as UnityEngine.GameObject;
                    m_IsFirstProperty = true;
                    WriteProperty("layer", gameObject.layer);
                    WriteProperty("isStatic", gameObject.isStatic);
                    WriteProperty("tag", gameObject.tag);
                    WriteProperty("name", gameObject.name);
                    WriteProperty("hideFlags", gameObject.hideFlags);
                    m_Writer.Write(",");
                    Write("components");
                    m_Writer.Write(":");
                    m_Writer.Write("[");
                    UnityEngine.Component[] components = gameObject.GetComponents <UnityEngine.Component>();
                    bool isFirst = true;
                    for (int i = 0; i < components.Length; i++)
                    {
                        if (isFirst)
                        {
                            isFirst = false;
                        }
                        else
                        {
                            m_Writer.Write(",");
                        }
                        m_Writer.Write("{");
                        Write("type");
                        m_Writer.Write(":");
                        Write(components[i].GetType().AssemblyQualifiedName);
                        m_Writer.Write(",");
                        Write("component");
                        m_Writer.Write(":");
                        Write(components[i]);
                        m_Writer.Write("}");
                    }
                    m_Writer.Write("]");
                    m_Writer.Write(",");
                    Write("childs");
                    m_Writer.Write(":");
                    List <UnityEngine.GameObject> childs = new List <UnityEngine.GameObject>();
                    for (int i = 0; i < gameObject.transform.childCount; i++)
                    {
                        childs.Add(gameObject.transform.GetChild(i).gameObject);
                    }
                    Write(childs);
                    m_Writer.Write("}");
                }
                else if (type == typeof(string) || isEnum)
                {
                    m_Writer.Write("\"{0}\"", value.ToString().EscapeStringJson());
                }
                else if (type == typeof(bool))
                {
                    m_Writer.Write(value.ToString().ToLower());
                }
                else if (type == typeof(short) || type == typeof(int) || type == typeof(long) ||
                         type == typeof(ushort) || type == typeof(uint) || type == typeof(ulong) ||
                         type == typeof(byte) || type == typeof(sbyte) || type == typeof(decimal) ||
                         type == typeof(double) || type == typeof(float))
                {
                    m_Writer.Write(Convert.ChangeType(value, typeof(string)));
                }
                else if (type == typeof(DictionaryEntry))
                {
                    DictionaryEntry entry = (DictionaryEntry)value;
                    m_Writer.Write("{");
                    Write("KeyType");
                    m_Writer.Write(":");
                    Write(entry.Key.GetType().AssemblyQualifiedName);
                    m_Writer.Write(",");
                    Write("Key");
                    m_Writer.Write(":");
                    Write(entry.Key);
                    m_Writer.Write(",");
                    Write("ValueType");
                    m_Writer.Write(":");
                    Write(entry.Value.GetType().AssemblyQualifiedName);
                    m_Writer.Write(",");
                    Write("Value");
                    m_Writer.Write(":");
                    Write(entry.Value);
                    m_Writer.Write("}");
                }
                else if (isGeneric && type.GetGenericTypeDefinition() == typeof(KeyValuePair <,>))
                {
                    m_Writer.Write("{");
                    Write("Key");
                    m_Writer.Write(":");
                    Write(type.GetProperty("Key").GetValue(value, null));
                    m_Writer.Write(",");
                    Write("Value");
                    m_Writer.Write(":");
                    Write(type.GetProperty("Value").GetValue(value, null));
                    m_Writer.Write("}");
                }
                else if (value is Hashtable)
                {
                    Hashtable hashtable = value as Hashtable;
                    bool      isFirst   = true;
                    m_Writer.Write("[");
                    foreach (DictionaryEntry entry in hashtable)
                    {
                        if (isFirst)
                        {
                            isFirst = false;
                        }
                        else
                        {
                            m_Writer.Write(",");
                        }
                        Write(entry);
                    }
                    m_Writer.Write("]");
                }
                else if (value is IDictionary)
                {
                    IDictionary dictionary = value as IDictionary;
                    bool        isFirst    = true;
                    m_Writer.Write("{");
                    foreach (var key in dictionary.Keys)
                    {
                        if (isFirst)
                        {
                            isFirst = false;
                        }
                        else
                        {
                            m_Writer.Write(",");
                        }
                        Write(key);
                        m_Writer.Write(":");
                        Write(dictionary[key]);
                    }
                    m_Writer.Write("}");
                }
                else if (value is IEnumerable && (value is ICollection || isGenericCollection))
                {
                    IEnumerable enumerable = value as IEnumerable;
                    IEnumerator e          = enumerable.GetEnumerator();
                    bool        isFirst    = true;
                    m_Writer.Write("[");
                    while (e.MoveNext())
                    {
                        if (isFirst)
                        {
                            isFirst = false;
                        }
                        else
                        {
                            m_Writer.Write(",");
                        }
                        Write(e.Current);
                    }
                    m_Writer.Write("]");
                }
                else
                {
                    WriteObject(value, type);
                }
            }
        }
Beispiel #15
0
        private bool CheckCondition(UnityEngine.GameObject objectToCheck, System.Collections.Generic.List <string> listOfConditions)
        {
            bool valid = true;

            foreach (var condition in listOfConditions)
            {
                var option = CheckOption(condition);
                switch (option)
                {
                case 1:    //name
                    var name = condition;
                    valid = objectToCheck.name.Equals(name);
                    break;

                case 2:    //tag
                    var tagName = condition.Substring(5, condition.Length - 5);
                    valid = objectToCheck.CompareTag(tagName);
                    break;

                case 3:    //layer
                    var layerName = condition.Substring(7, condition.Length - 7);
                    int layerId   = UnityEngine.LayerMask.NameToLayer(layerName);
                    valid = objectToCheck.layer.Equals(layerId);
                    break;

                case 4:    //component
                    var componentName = condition.Substring(11, condition.Length - 11);
                    var list          = objectToCheck.GetComponents(typeof(UnityEngine.Component));
                    valid = false;

                    for (int i = 0; i < list.Length; i++)
                    {
                        if (componentName.Equals(list[i].GetType().Name))
                        {
                            valid = true;
                            break;
                        }
                    }
                    break;

                case 5:    //id
                    var id = System.Convert.ToInt32(condition.Substring(4, condition.Length - 4));
                    valid = (objectToCheck.GetInstanceID() == id);
                    break;

                case 6:    //contains
                    var substring      = condition.Substring(9, condition.Length - 10);
                    var splitedValue   = substring.Split(',');
                    var selector       = splitedValue[0];
                    var value          = splitedValue[1];
                    var optionContains = CheckOption(selector);
                    switch (optionContains)
                    {
                    case 2:
                        valid = objectToCheck.tag.Contains(value);
                        break;

                    case 3:
                        var layerNm = UnityEngine.LayerMask.LayerToName(objectToCheck.layer);
                        valid = layerNm.Contains(value);
                        break;

                    case 4:
                        componentName = value;
                        list          = objectToCheck.GetComponents(typeof(UnityEngine.Component));
                        valid         = false;

                        for (int i = 0; i < list.Length; i++)
                        {
                            if (componentName.Contains(list[i].GetType().Name))
                            {
                                valid = true;
                                break;
                            }
                        }
                        break;

                    case 5:
                        var stringId = objectToCheck.GetInstanceID().ToString();
                        valid = stringId.Contains(value);
                        break;

                    case 8:
                        valid = objectToCheck.name.Contains(value);
                        break;

                    default:
                        throw new System.Exception("No such selector is implemented");
                    }
                    break;
                }
                if (!valid)
                {
                    break;
                }
            }
            return(valid);
        }
        /// <summary>
        /// Write the specified value.
        /// </summary>
        /// <param name="value">Value.</param>
        public virtual void Write(object value)
        {
            m_Writer.Write(value != null);
            if (value == null)
            {
                return;
            }
            else
            {
                Type type                = value.GetType();
                bool isPrimitive         = false;
                bool isEnum              = false;
                bool isSerializable      = false;
                bool isGeneric           = false;
                bool isGenericCollection = false;
#if (UNITY_WSA || UNITY_WINRT) && !UNITY_EDITOR
                TypeInfo info = type.GetTypeInfo();
                isPrimitive    = info.IsPrimitive;
                isEnum         = info.IsEnum;
                isSerializable = info.IsSerializable;
                isGeneric      = info.IsGenericType;
#else
                isPrimitive    = type.IsPrimitive;
                isEnum         = type.IsEnum;
                isSerializable = type.IsSerializable;
                isGeneric      = type.IsGenericType;
#endif
                isGenericCollection = type.GetInterfaces().Contains(typeof(ICollection <>));
                if (type == typeof(UnityEngine.GameObject))
                {
                    UnityEngine.GameObject gameObject = value as UnityEngine.GameObject;

                    m_Writer.BaseStream.WriteByte(BinaryFormatter.SaveGameTypeStart);
                    long position = m_Writer.BaseStream.Position;
                    m_Writer.Write(0L);

                    WriteProperty("layer", gameObject.layer);
                    WriteProperty("isStatic", gameObject.isStatic);
                    WriteProperty("tag", gameObject.tag);
                    WriteProperty("name", gameObject.name);
                    WriteProperty("hideFlags", gameObject.hideFlags);

                    long lastPosition = m_Writer.BaseStream.Position;
                    m_Writer.BaseStream.Position = position;
                    m_Writer.Write(lastPosition);
                    m_Writer.BaseStream.Position = lastPosition;
                    m_Writer.BaseStream.WriteByte(BinaryFormatter.SaveGameTypeEnd);

                    UnityEngine.Component[] components = gameObject.GetComponents <UnityEngine.Component>();
                    m_Writer.Write("components");
                    m_Writer.Write(components.Length);
                    for (int i = 0; i < components.Length; i++)
                    {
                        m_Writer.Write(components[i].GetType().AssemblyQualifiedName);
                        Write(components[i]);
                    }
                    components = null;
                    List <UnityEngine.GameObject> childs = new List <UnityEngine.GameObject>();
                    for (int i = 0; i < gameObject.transform.childCount; i++)
                    {
                        childs.Add(gameObject.transform.GetChild(i).gameObject);
                    }
                    m_Writer.Write("childs");
                    m_Writer.Write(childs.Count);
                    for (int i = 0; i < childs.Count; i++)
                    {
                        Write(childs[i]);
                    }
                    childs = null;
                }
                else if (isPrimitive || type == typeof(string) || type == typeof(decimal))
                {
                    if (type == typeof(string))
                    {
                        m_Writer.Write((string)value);
                    }
                    else if (type == typeof(decimal))
                    {
                        m_Writer.Write((decimal)value);
                    }
                    else if (type == typeof(short))
                    {
                        m_Writer.Write((short)value);
                    }
                    else if (type == typeof(int))
                    {
                        m_Writer.Write((int)value);
                    }
                    else if (type == typeof(long))
                    {
                        m_Writer.Write((long)value);
                    }
                    else if (type == typeof(ushort))
                    {
                        m_Writer.Write((ushort)value);
                    }
                    else if (type == typeof(uint))
                    {
                        m_Writer.Write((uint)value);
                    }
                    else if (type == typeof(ulong))
                    {
                        m_Writer.Write((ulong)value);
                    }
                    else if (type == typeof(double))
                    {
                        m_Writer.Write((double)value);
                    }
                    else if (type == typeof(float))
                    {
                        m_Writer.Write((float)value);
                    }
                    else if (type == typeof(byte))
                    {
                        m_Writer.Write((byte)value);
                    }
                    else if (type == typeof(sbyte))
                    {
                        m_Writer.Write((sbyte)value);
                    }
                    else if (type == typeof(char))
                    {
                        m_Writer.Write((char)value);
                    }
                    else if (type == typeof(bool))
                    {
                        m_Writer.Write((bool)value);
                    }
                }
                else if (isEnum)
                {
                    m_Writer.Write(value.ToString());
                }
                else if (type == typeof(DateTime))
                {
                    m_Writer.Write(((DateTime)value).ToBinary());
                }
                else if (type == typeof(TimeSpan))
                {
                    m_Writer.Write(((TimeSpan)value).ToString());
                }
                else if (type.IsArray)
                {
                    Array array   = value as Array;
                    int[] indices = new int[array.Rank];
                    m_Writer.Write(array.Rank);
                    for (int i = 0; i < array.Rank; i++)
                    {
                        m_Writer.Write(array.GetLength(i));
                        indices[i] = array.GetLowerBound(i);
                    }
                    indices[array.Rank - 1]--;
                    bool complete = false;
                    while (!complete)
                    {
                        indices[array.Rank - 1]++;
                        for (int i = array.Rank - 1; i >= 0; i--)
                        {
                            if (indices[i] > array.GetUpperBound(i))
                            {
                                if (i == 0)
                                {
                                    complete = true;
                                    break;
                                }
                                for (int j = i; j < array.Rank; j++)
                                {
                                    indices[j] = array.GetLowerBound(j);
                                }
                                indices[i - 1]++;
                            }
                        }
                        if (!complete)
                        {
                            Write(array.GetValue(indices));
                        }
                    }
                }
                else if (value is IEnumerable && (value is ICollection || isGenericCollection))
                {
                    IEnumerable enumerable = value as IEnumerable;
                    int         count      = (int)type.GetProperty("Count").GetValue(value, null);
                    IEnumerator e          = enumerable.GetEnumerator();
                    m_Writer.Write(count);
                    while (e.MoveNext())
                    {
                        Write(e.Current);
                    }
                }
                else if (type == typeof(DictionaryEntry))
                {
                    DictionaryEntry entry = (DictionaryEntry)value;
                    m_Writer.Write(entry.Key.GetType().AssemblyQualifiedName);
                    Write(entry.Key);
                    m_Writer.Write(entry.Value.GetType().AssemblyQualifiedName);
                    Write(entry.Value);
                }
                else if (isGeneric && type.GetGenericTypeDefinition() == typeof(KeyValuePair <,>))
                {
                    Write(type.GetProperty("Key").GetValue(value, null));
                    Write(type.GetProperty("Value").GetValue(value, null));
                }
                else
                {
                    WriteObject(value, type);
                }
            }
        }