static object PerformMemberwiseClone(ref object o)
        {
            var ins = new UnityEngine.HideFlags();

            ins = (UnityEngine.HideFlags)o;
            return(ins);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reads the child.
        /// </summary>
        /// <returns>The child.</returns>
        /// <param name="parent">Parent.</param>
        public virtual UnityEngine.GameObject ReadChild(UnityEngine.GameObject parent)
        {
            if (parent == null || !m_Reader.ReadBoolean())
            {
                return(null);
            }
            else
            {
                // Skip save game type start
                m_Reader.ReadByte();
                m_Reader.ReadInt64();

                int    layer    = ReadProperty <int>();
                bool   isStatic = ReadProperty <bool>();
                string tag      = ReadProperty <string>();
                string name     = ReadProperty <string>();
                UnityEngine.HideFlags hideFlags = ReadProperty <UnityEngine.HideFlags>();

                // Skip save game type end
                m_Reader.ReadByte();

                UnityEngine.GameObject gameObject = new UnityEngine.GameObject(name)
                {
                    layer     = layer,
                    isStatic  = isStatic,
                    tag       = tag,
                    hideFlags = hideFlags
                };
                gameObject.transform.SetParent(parent.transform);

                m_Reader.ReadString();
                int count = m_Reader.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    string typeName                 = m_Reader.ReadString();
                    Type   componentType            = Type.GetType(typeName);
                    UnityEngine.Component component = gameObject.GetComponent(componentType);
                    if (componentType != typeof(UnityEngine.Transform) && componentType.BaseType != typeof(UnityEngine.Transform))
                    {
                        UnityEngine.Component newComponent = gameObject.AddComponent(componentType);
                        if (newComponent != null)
                        {
                            component = newComponent;
                        }
                    }
                    ReadInto(component);
                }

                m_Reader.ReadString();
                count = m_Reader.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    ReadChild(gameObject);
                }
                return(gameObject);
            }
        }
Exemplo n.º 3
0
 public static int get_hideFlags(System.IntPtr L)
 {
     if (true && LuaAPI.IsObject(L, 1))
     {
         UnityEngine.Object    arg0 = (UnityEngine.Object)LuaCallback.ToObject(L, 1);
         UnityEngine.HideFlags res  = arg0.hideFlags;
         LuaCallback.PushNumber(L, (double)res);
         return(1);
     }
     return(0);
 }
Exemplo n.º 4
0
 public static int set_hideFlags(System.IntPtr L)
 {
     if (true && LuaAPI.IsObject(L, 1) && LuaAPI.IsNumber(L, 3))
     {
         UnityEngine.Object    arg0 = (UnityEngine.Object)LuaCallback.ToObject(L, 1);
         UnityEngine.HideFlags arg1 = (UnityEngine.HideFlags)LuaCallback.ToNumber(L, 3);
         arg0.hideFlags = arg1;
         return(0);
     }
     return(0);
 }
        static void WriteBackInstance(CSHotFix.Runtime.Enviorment.AppDomain __domain, StackObject *ptr_of_this_method, IList <object> __mStack, ref UnityEngine.HideFlags instance_of_this_method)
        {
            ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method);
            switch (ptr_of_this_method->ObjectType)
            {
            case ObjectTypes.Object:
            {
                __mStack[ptr_of_this_method->Value] = instance_of_this_method;
            }
            break;

            case ObjectTypes.FieldReference:
            {
                var ___obj = __mStack[ptr_of_this_method->Value];
                if (___obj is ILTypeInstance)
                {
                    ((ILTypeInstance)___obj)[ptr_of_this_method->ValueLow] = instance_of_this_method;
                }
                else
                {
                    var t = __domain.GetType(___obj.GetType()) as CLRType;
                    t.SetFieldValue(ptr_of_this_method->ValueLow, ref ___obj, instance_of_this_method);
                }
            }
            break;

            case ObjectTypes.StaticFieldReference:
            {
                var t = __domain.GetType(ptr_of_this_method->Value);
                if (t is ILType)
                {
                    ((ILType)t).StaticInstance[ptr_of_this_method->ValueLow] = instance_of_this_method;
                }
                else
                {
                    ((CLRType)t).SetStaticFieldValue(ptr_of_this_method->ValueLow, instance_of_this_method);
                }
            }
            break;

            case ObjectTypes.ArrayReference:
            {
                var instance_of_arrayReference = __mStack[ptr_of_this_method->Value] as UnityEngine.HideFlags[];
                instance_of_arrayReference[ptr_of_this_method->ValueLow] = instance_of_this_method;
            }
            break;
            }
        }
Exemplo n.º 6
0
    static int set_hideFlags(IntPtr L)
    {
        UnityEngine.Object    obj  = (UnityEngine.Object)ToLua.ToObject(L, 1);
        UnityEngine.HideFlags arg0 = (UnityEngine.HideFlags)ToLua.CheckObject(L, 2, typeof(UnityEngine.HideFlags));

        try
        {
            obj.hideFlags = arg0;
        }
        catch (Exception e)
        {
            return(LuaDLL.luaL_error(L, obj == null ? "attempt to index hideFlags on a nil value" : e.Message));
        }

        return(0);
    }
Exemplo n.º 7
0
    static int get_hideFlags(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.Object    obj = (UnityEngine.Object)o;
            UnityEngine.HideFlags ret = obj.hideFlags;
            ToLua.Push(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index hideFlags on a nil value" : e.Message));
        }
    }
    static int get_hideFlags(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.Object    obj = (UnityEngine.Object)o;
            UnityEngine.HideFlags ret = obj.hideFlags;
            LuaDLL.lua_pushinteger(L, (int)ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index hideFlags on a nil value"));
        }
    }
Exemplo n.º 9
0
    static int set_hideFlags(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.Object    obj  = (UnityEngine.Object)o;
            UnityEngine.HideFlags arg0 = (UnityEngine.HideFlags)ToLua.CheckObject(L, 2, typeof(UnityEngine.HideFlags));
            obj.hideFlags = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index hideFlags on a nil value"));
        }
    }
Exemplo n.º 10
0
        static StackObject *set_hideFlags_18(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, 2);

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

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

            instance_of_this_method.hideFlags = value;

            return(__ret);
        }
Exemplo n.º 11
0
 public static bool HasFlag(this UnityEngine.HideFlags self, UnityEngine.HideFlags flag)
 {
     return((self & flag) == flag);
 }
Exemplo n.º 12
0
        /// <summary>
        /// Read the specified type.
        /// </summary>
        /// <param name="type">Type.</param>
        public override object Read(Type type)
        {
            Type   nullableType = null;
            object result       = null;

            if (type == null || string.IsNullOrEmpty(m_Json))
            {
                result = null;
            }
            else if (m_Json[m_Position] == 'n' && PeekString() == "null")
            {
                ReadString();
                result = null;
            }
            else
            {
                if (Nullable.GetUnderlyingType(type) != null)
                {
                    nullableType = type;
                    type         = Nullable.GetUnderlyingType(type);
                }
                bool isEnum         = false;
                bool isSerializable = false;
                bool isGeneric      = 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
                if (type == typeof(UnityEngine.GameObject))
                {
                    // Skip object start
                    m_Position++;

                    m_IsFirstProperty = true;
                    int    layer    = 0;
                    bool   isStatic = false;
                    string tag      = "";
                    string name     = "";
                    UnityEngine.HideFlags hideFlags = UnityEngine.HideFlags.None;
                    foreach (string property in Properties)
                    {
                        switch (property)
                        {
                        case "layer":
                            layer = ReadProperty <int>();
                            break;

                        case "isStatic":
                            isStatic = ReadProperty <bool>();
                            break;

                        case "tag":
                            tag = ReadProperty <string>();
                            break;

                        case "name":
                            name = ReadProperty <string>();
                            break;

                        case "hideFlags":
                            hideFlags = ReadProperty <UnityEngine.HideFlags>();
                            break;
                        }
                    }
                    UnityEngine.GameObject gameObject = new UnityEngine.GameObject(name);
                    gameObject.layer     = layer;
                    gameObject.isStatic  = isStatic;
                    gameObject.tag       = tag;
                    gameObject.name      = name;
                    gameObject.hideFlags = hideFlags;

                    // Skip comma
                    m_Position++;

                    ReadQoutedString();

                    // Skip colon and array start
                    m_Position += 2;

                    int  length  = GetArrayLength();
                    bool isFirst = true;
                    for (int i = 0; i < length; i++)
                    {
                        if (isFirst)
                        {
                            isFirst = false;
                        }
                        else
                        {
                            // Skip comma
                            m_Position++;
                        }

                        // Skip object start
                        m_Position++;

                        ReadQoutedString();

                        // Skip colon
                        m_Position++;

                        string typeFullName             = ReadQoutedString();
                        Type   componentType            = Type.GetType(typeFullName);
                        UnityEngine.Component component = gameObject.GetComponent(componentType);
                        if (componentType != typeof(UnityEngine.Transform) && componentType.BaseType != typeof(UnityEngine.Transform))
                        {
                            UnityEngine.Component newComponent = gameObject.AddComponent(componentType);
                            if (newComponent != null)
                            {
                                component = newComponent;
                            }
                        }

                        // Skip comma
                        m_Position++;

                        ReadQoutedString();

                        // Skip colon
                        m_Position++;

                        ReadInto(component);

                        // Skip object end
                        m_Position++;
                    }

                    // Skip comma and array end
                    m_Position += 2;

                    ReadQoutedString();

                    // Skip colon and array start
                    m_Position += 2;

                    length  = GetArrayLength();
                    isFirst = true;
                    for (int i = 0; i < length; i++)
                    {
                        if (isFirst)
                        {
                            isFirst = false;
                        }
                        else
                        {
                            // Skip comma
                            m_Position++;
                        }
                        ReadChild(gameObject);
                    }

                    result = gameObject;

                    // Skip object end
                    m_Position++;
                }
                else if (type == typeof(string))
                {
                    result = ReadQoutedString().UnEscapeStringJson();
                }
                else if (isEnum)
                {
                    result = Enum.Parse(type, ReadQoutedString().UnEscapeStringJson());
                }
                else if (type == typeof(bool))
                {
                    result = bool.Parse(ReadString());
                }
                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))
                {
                    result = Convert.ChangeType(ReadString(), type);
                }
                else if (type.IsArray)
                {
                    // Skip array start
                    m_Position++;

                    Type  elementType = type.GetElementType();
                    int   length      = GetArrayLength();
                    Array array       = Array.CreateInstance(elementType, length);
                    bool  isFirst     = true;
                    for (int i = 0; i < length; i++)
                    {
                        if (isFirst)
                        {
                            isFirst = false;
                        }
                        else
                        {
                            // Skip comma
                            m_Position++;
                        }
                        array.SetValue(Read(elementType), i);
                    }
                    result = array;

                    // Skip array end
                    m_Position++;
                }
                else if (type == typeof(DictionaryEntry))
                {
                    // Skip object start
                    m_Position++;

                    DictionaryEntry entry     = new DictionaryEntry();
                    bool            isFirst   = true;
                    Type            keyType   = null;
                    Type            valueType = null;
                    for (int i = 0; i < 4; i++)
                    {
                        if (isFirst)
                        {
                            isFirst = false;
                        }
                        else
                        {
                            // Skip comma
                            m_Position++;
                        }
                        string property = ReadQoutedString();

                        // Skip colon
                        m_Position++;

                        if (property == "KeyType")
                        {
                            keyType = Type.GetType(ReadQoutedString());
                        }
                        else if (property == "Key")
                        {
                            entry.Key = Read(keyType);
                        }
                        else if (property == "ValueType")
                        {
                            valueType = Type.GetType(ReadQoutedString());
                        }
                        else if (property == "Value")
                        {
                            entry.Value = Read(valueType);
                        }
                    }
                    result = entry;

                    // Skip object end
                    m_Position++;
                }
                else if (isGeneric && type.GetGenericTypeDefinition() == typeof(KeyValuePair <,>))
                {
                    // Skip object start
                    m_Position++;

                    Type[] genericArgs = type.GetGenericArguments();
                    object key         = null;
                    object value       = null;

                    string property = ReadQoutedString();

                    // Skip colon
                    m_Position++;

                    if (property == "Key")
                    {
                        key = Read(genericArgs[0]);
                    }
                    else
                    {
                        value = Read(genericArgs[1]);
                    }


                    // Skip comma
                    m_Position++;

                    property = ReadQoutedString();

                    // Skip colon
                    m_Position++;

                    if (property == "Key")
                    {
                        key = Read(genericArgs[0]);
                    }
                    else
                    {
                        value = Read(genericArgs[1]);
                    }
                    result = Activator.CreateInstance(type, key, value);

                    // Skip object end
                    m_Position++;
                }
                else if (isGeneric && type.GetGenericTypeDefinition() == typeof(List <>))
                {
                    // Skip array start
                    m_Position++;

                    Type[] genericArgs = type.GetGenericArguments();
                    int    length      = GetArrayLength();
                    IList  list        = (IList)Activator.CreateInstance(type);
                    bool   isFirst     = true;
                    for (int i = 0; i < length; i++)
                    {
                        if (isFirst)
                        {
                            isFirst = false;
                        }
                        else
                        {
                            // Skip comma
                            m_Position++;
                        }
                        list.Add(Read(genericArgs[0]));
                    }
                    result = list;

                    // Skip array end
                    m_Position++;
                }
                else if (isGeneric && type.GetGenericTypeDefinition() == typeof(LinkedList <>))
                {
                    // Skip array start
                    m_Position++;

                    Type[]     genericArgs = type.GetGenericArguments();
                    int        length      = GetArrayLength();
                    object     list        = Activator.CreateInstance(type);
                    MethodInfo addLast     = type.GetMethod("AddLast", genericArgs);
                    bool       isFirst     = true;
                    for (int i = 0; i < length; i++)
                    {
                        if (isFirst)
                        {
                            isFirst = false;
                        }
                        else
                        {
                            // Skip comma
                            m_Position++;
                        }
                        addLast.Invoke(list, new object[] { Read(genericArgs[0]) });
                    }
                    result = list;

                    // Skip array end
                    m_Position++;
                }
                else if (isGeneric && (type.GetGenericTypeDefinition() == typeof(Dictionary <,>) ||
                                       type.GetGenericTypeDefinition() == typeof(SortedDictionary <,>) ||
                                       type.GetGenericTypeDefinition() == typeof(SortedList <,>)))
                {
                    // Skip object start
                    m_Position++;

                    Type[]      genericArgs = type.GetGenericArguments();
                    int         length      = GetObjectLength();
                    bool        isFirst     = true;
                    IDictionary dictionary  = (IDictionary)Activator.CreateInstance(type);
                    for (int i = 0; i < length; i++)
                    {
                        if (isFirst)
                        {
                            isFirst = false;
                        }
                        else
                        {
                            // Skip comma
                            m_Position++;
                        }
                        object key = Read(genericArgs[0]);

                        // Skip colon
                        m_Position++;

                        object value = Read(genericArgs[1]);
                        dictionary.Add(key, value);
                    }
                    result = dictionary;

                    // Skip object end
                    m_Position++;
                }
                else if (isGeneric && type.GetGenericTypeDefinition() == typeof(Stack <>))
                {
                    // Skip array start
                    m_Position++;

                    Type[]     genericArgs = type.GetGenericArguments();
                    int        length      = GetArrayLength();
                    object     stack       = Activator.CreateInstance(type);
                    MethodInfo push        = type.GetMethod("Push");
                    bool       isFirst     = true;
                    for (int i = 0; i < length; i++)
                    {
                        if (isFirst)
                        {
                            isFirst = false;
                        }
                        else
                        {
                            // Skip comma
                            m_Position++;
                        }
                        push.Invoke(stack, new object[] { Read(genericArgs[0]) });
                    }
                    result = stack;

                    // Skip array end
                    m_Position++;
                }
                else if (isGeneric && type.GetGenericTypeDefinition() == typeof(Queue <>))
                {
                    // Skip array start
                    m_Position++;

                    Type[]     genericArgs = type.GetGenericArguments();
                    int        length      = GetArrayLength();
                    object     queue       = Activator.CreateInstance(type);
                    MethodInfo enqueue     = type.GetMethod("Enqueue");
                    bool       isFirst     = true;
                    for (int i = 0; i < length; i++)
                    {
                        if (isFirst)
                        {
                            isFirst = false;
                        }
                        else
                        {
                            // Skip comma
                            m_Position++;
                        }
                        enqueue.Invoke(queue, new object[] { Read(genericArgs[0]) });
                    }
                    result = queue;

                    // Skip array end
                    m_Position++;
                }
                else if (isGeneric && type.GetGenericTypeDefinition() == typeof(HashSet <>))
                {
                    // Skip array start
                    m_Position++;

                    Type[]     genericArgs = type.GetGenericArguments();
                    int        length      = GetArrayLength();
                    object     hashSet     = Activator.CreateInstance(type);
                    MethodInfo addMethod   = type.GetMethod("Add");
                    bool       isFirst     = true;
                    for (int i = 0; i < length; i++)
                    {
                        if (isFirst)
                        {
                            isFirst = false;
                        }
                        else
                        {
                            // Skip comma
                            m_Position++;
                        }
                        addMethod.Invoke(hashSet, new object[] { Read(genericArgs[0]) });
                    }
                    result = hashSet;

                    // Skip array end
                    m_Position++;
                }
                else if (type == typeof(Hashtable))
                {
                    // Skip array start
                    m_Position++;

                    bool      isFirst   = true;
                    Hashtable hashtable = new Hashtable();
                    int       length    = GetArrayLength();
                    for (int i = 0; i < length; i++)
                    {
                        if (isFirst)
                        {
                            isFirst = false;
                        }
                        else
                        {
                            // Skip comma
                            m_Position++;
                        }
                        DictionaryEntry entry = Read <DictionaryEntry>();
                        hashtable.Add(entry.Key, entry.Value);
                    }
                    result = hashtable;

                    // Skip array end
                    m_Position++;
                }
                else if (SaveGameTypeManager.HasType(type))
                {
                    // Skip object start
                    m_Position++;

                    m_IsFirstProperty = true;
                    SaveGameType saveGameType = SaveGameTypeManager.GetType(type);
                    result = saveGameType.Read(this);

                    // Skip object end
                    m_Position++;
                }
                else
                {
                    result = ReadObject(type);
                }
            }
#if !(UNITY_WSA || UNITY_WINRT) || UNITY_EDITOR
            if (result is IDeserializationCallback)
            {
                (result as IDeserializationCallback).OnDeserialization(this);
            }
#endif
            if (nullableType != null)
            {
                Type genericType = type.GetNullableType();
                result = Activator.CreateInstance(genericType, result);
            }
            return(result);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Reads the child.
        /// </summary>
        /// <returns>The child.</returns>
        /// <param name="parent">Parent.</param>
        public virtual UnityEngine.GameObject ReadChild(UnityEngine.GameObject parent)
        {
            if (parent == null || string.IsNullOrEmpty(m_Json))
            {
                return(null);
            }
            else if (m_Json[m_Position] == 'n' && PeekString() == "null")
            {
                ReadString();
                return(null);
            }
            else
            {
                // Skip object start
                m_Position++;

                m_IsFirstProperty = true;
                int    layer    = 0;
                bool   isStatic = false;
                string tag      = "";
                string name     = "";
                UnityEngine.HideFlags hideFlags = UnityEngine.HideFlags.None;
                foreach (string property in Properties)
                {
                    switch (property)
                    {
                    case "layer":
                        layer = ReadProperty <int>();
                        break;

                    case "isStatic":
                        isStatic = ReadProperty <bool>();
                        break;

                    case "tag":
                        tag = ReadProperty <string>();
                        break;

                    case "name":
                        name = ReadProperty <string>();
                        break;

                    case "hideFlags":
                        hideFlags = ReadProperty <UnityEngine.HideFlags>();
                        break;
                    }
                }
                UnityEngine.GameObject gameObject = new UnityEngine.GameObject(name);
                gameObject.layer     = layer;
                gameObject.isStatic  = isStatic;
                gameObject.tag       = tag;
                gameObject.name      = name;
                gameObject.hideFlags = hideFlags;
                gameObject.transform.SetParent(parent.transform);

                // Skip comma
                m_Position++;

                ReadQoutedString();

                // Skip colon and array start
                m_Position += 2;

                int  length  = GetArrayLength();
                bool isFirst = true;
                for (int i = 0; i < length; i++)
                {
                    if (isFirst)
                    {
                        isFirst = false;
                    }
                    else
                    {
                        // Skip comma
                        m_Position++;
                    }

                    // Skip object start
                    m_Position++;

                    ReadQoutedString();

                    // Skip colon
                    m_Position++;

                    string typeFullName             = ReadQoutedString();
                    Type   componentType            = Type.GetType(typeFullName);
                    UnityEngine.Component component = gameObject.GetComponent(componentType);
                    if (componentType != typeof(UnityEngine.Transform) && componentType.BaseType != typeof(UnityEngine.Transform))
                    {
                        UnityEngine.Component newComponent = gameObject.AddComponent(componentType);
                        if (newComponent != null)
                        {
                            component = newComponent;
                        }
                    }

                    // Skip comma
                    m_Position++;

                    ReadQoutedString();

                    // Skip colon
                    m_Position++;

                    ReadInto(component);

                    // Skip object end
                    m_Position++;
                }

                // Skip comma and array end
                m_Position += 2;

                ReadQoutedString();

                // Skip colon and array start
                m_Position += 2;

                length  = GetArrayLength();
                isFirst = true;
                for (int i = 0; i < length; i++)
                {
                    if (isFirst)
                    {
                        isFirst = false;
                    }
                    else
                    {
                        // Skip comma
                        m_Position++;
                    }
                    ReadChild(gameObject);
                }

                // Skip object end
                m_Position++;
                return(gameObject);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Reads the data into the value.
        /// </summary>
        /// <param name="value">Value.</param>
        public override void ReadInto(object value)
        {
            if (value == null || string.IsNullOrEmpty(m_Json))
            {
                return;
            }
            else if (m_Json[m_Position] == 'n' && PeekString() == "null")
            {
                ReadString();
                return;
            }
            Type type      = value.GetType();
            bool isGeneric = false;

#if (UNITY_WSA || UNITY_WINRT) && !UNITY_EDITOR
            TypeInfo info = type.GetTypeInfo();
            isGeneric = info.IsGenericType;
#else
            isGeneric = type.IsGenericType;
#endif
            if (type == typeof(UnityEngine.GameObject))
            {
                // Skip object start
                m_Position++;

                m_IsFirstProperty = true;
                int    layer    = 0;
                bool   isStatic = false;
                string tag      = "";
                string name     = "";
                UnityEngine.HideFlags hideFlags = UnityEngine.HideFlags.None;
                foreach (string property in Properties)
                {
                    switch (property)
                    {
                    case "layer":
                        layer = ReadProperty <int>();
                        break;

                    case "isStatic":
                        isStatic = ReadProperty <bool>();
                        break;

                    case "tag":
                        tag = ReadProperty <string>();
                        break;

                    case "name":
                        name = ReadProperty <string>();
                        break;

                    case "hideFlags":
                        hideFlags = ReadProperty <UnityEngine.HideFlags>();
                        break;
                    }
                }
                UnityEngine.GameObject gameObject = value as UnityEngine.GameObject;
                gameObject.layer     = layer;
                gameObject.isStatic  = isStatic;
                gameObject.tag       = tag;
                gameObject.name      = name;
                gameObject.hideFlags = hideFlags;

                // Skip comma
                m_Position++;

                ReadQoutedString();

                // Skip colon and array start
                m_Position += 2;

                int  length  = GetArrayLength();
                bool isFirst = true;
                for (int i = 0; i < length; i++)
                {
                    if (isFirst)
                    {
                        isFirst = false;
                    }
                    else
                    {
                        // Skip comma
                        m_Position++;
                    }

                    // Skip object start
                    m_Position++;

                    ReadQoutedString();

                    // Skip colon
                    m_Position++;

                    string typeFullName             = ReadQoutedString();
                    Type   componentType            = Type.GetType(typeFullName);
                    UnityEngine.Component component = gameObject.GetComponent(componentType);
                    if (component == null)
                    {
                        component = gameObject.AddComponent(componentType);
                    }

                    // Skip comma
                    m_Position++;

                    ReadQoutedString();

                    // Skip colon
                    m_Position++;

                    ReadInto(component);

                    // Skip object end
                    m_Position++;
                }

                // Skip comma and array end
                m_Position += 2;

                ReadQoutedString();

                // Skip colon and array start
                m_Position += 2;

                length  = GetArrayLength();
                isFirst = true;
                for (int i = 0; i < length; i++)
                {
                    if (isFirst)
                    {
                        isFirst = false;
                    }
                    else
                    {
                        // Skip comma
                        m_Position++;
                    }
                    if (gameObject.transform.childCount > i)
                    {
                        UnityEngine.Transform childTransform = gameObject.transform.GetChild(i);
                        ReadInto <UnityEngine.GameObject>(childTransform.gameObject);
                    }
                    else
                    {
                        ReadChild(gameObject);
                    }
                }

                // Skip object end
                m_Position++;
            }
            else if (type.IsArray)
            {
                // Skip array start
                m_Position++;

                Type  elementType = type.GetElementType();
                int   length      = GetArrayLength();
                Array array       = value as Array;
                if (array.Length < length)
                {
                    array = Array.CreateInstance(elementType, length);
                }
                bool isFirst = true;
                for (int i = 0; i < array.Length; i++)
                {
                    if (isFirst)
                    {
                        isFirst = false;
                    }
                    else
                    {
                        // Skip comma
                        m_Position++;
                    }
                    object arrayValue = array.GetValue(i);
                    if (arrayValue == null)
                    {
                        array.SetValue(Read(elementType), i);
                    }
                    else
                    {
                        ReadInto(array.GetValue(i));
                    }
                }

                // Skip array end
                m_Position++;
            }
            else if (isGeneric && type.GetGenericTypeDefinition() == typeof(List <>))
            {
                // Skip array start
                m_Position++;

                Type[] genericArgs = type.GetGenericArguments();
                int    length      = GetArrayLength();
                IList  list        = value as IList;
                bool   isFirst     = true;
                for (int i = 0; i < length; i++)
                {
                    if (isFirst)
                    {
                        isFirst = false;
                    }
                    else
                    {
                        // Skip comma
                        m_Position++;
                    }
                    if (list.Count > i && list[i] != null)
                    {
                        ReadInto(list[i]);
                    }
                    else
                    {
                        list.Add(Read(genericArgs[0]));
                    }
                }

                // Skip array end
                m_Position++;
            }
            else if (value is ICollection && value is IEnumerable)
            {
                // Skip array start
                m_Position++;

                IEnumerable e       = value as IEnumerable;
                bool        isFirst = true;
                foreach (object subValue in e)
                {
                    if (isFirst)
                    {
                        isFirst = false;
                    }
                    else
                    {
                        // Skip comma
                        m_Position++;
                    }
                    ReadInto(subValue);
                }

                // Skip array end
                m_Position++;
            }
            else if (SaveGameTypeManager.HasType(type))
            {
                // Skip object start
                m_Position++;

                m_IsFirstProperty = true;
                SaveGameType saveGameType = SaveGameTypeManager.GetType(type);
                saveGameType.ReadInto(value, this);

                // Skip object end
                m_Position++;
            }
            else
            {
                ReadObject(type, value);
            }
        }
Exemplo n.º 15
0
 public static UnityEngine.HideFlags RemoveFlag(this UnityEngine.HideFlags self, UnityEngine.HideFlags flag)
 {
     return(self & ~flag);
 }
Exemplo n.º 16
0
 public static UnityEngine.HideFlags AddFlag(this UnityEngine.HideFlags self, UnityEngine.HideFlags flag)
 {
     return(self | flag);
 }
Exemplo n.º 17
0
 public static bool HasAnyFlag(this UnityEngine.HideFlags self, UnityEngine.HideFlags flags)
 {
     return((self & flags) > 0);
 }
Exemplo n.º 18
0
 public static UnityEngine.Object GetBuiltinResource(System.Type type, System.String path, UnityEngine.HideFlags flags)
 {
     throw new Exception("Unit tests should *not* be trying to do any real IO.");
 }
Exemplo n.º 19
0
 public static UnityEngine.GameObject CreateGameObjectWithHideFlags(System.String name, UnityEngine.HideFlags flags, System.Type[] components)
 {
     throw new NotImplementedException("This function was automatically generated by Mockery and has no real implementation yet.");
 }
Exemplo n.º 20
0
        /// <summary>
        /// Reads the data into the value.
        /// </summary>
        /// <param name="value">Value.</param>
        public virtual void ReadInto(object value)
        {
            if (value == null || !m_Reader.ReadBoolean())
            {
                return;
            }
            Type type      = value.GetType();
            bool isGeneric = false;

#if (UNITY_WSA || UNITY_WINRT) && !UNITY_EDITOR
            TypeInfo info = type.GetTypeInfo();
            isGeneric = info.IsGenericType;
#else
            isGeneric = type.IsGenericType;
#endif
            if (type == typeof(UnityEngine.GameObject))
            {
                // Skip save game type start
                m_Reader.ReadByte();
                m_Reader.ReadInt64();

                int    layer    = ReadProperty <int>();
                bool   isStatic = ReadProperty <bool>();
                string tag      = ReadProperty <string>();
                string name     = ReadProperty <string>();
                UnityEngine.HideFlags hideFlags = ReadProperty <UnityEngine.HideFlags>();

                // Skip save game type end
                m_Reader.ReadByte();

                UnityEngine.GameObject gameObject = value as UnityEngine.GameObject;
                gameObject.layer     = layer;
                gameObject.isStatic  = isStatic;
                gameObject.tag       = tag;
                gameObject.name      = name;
                gameObject.hideFlags = hideFlags;

                m_Reader.ReadString();
                int count = m_Reader.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    string typeName                 = m_Reader.ReadString();
                    Type   componentType            = Type.GetType(typeName);
                    UnityEngine.Component component = gameObject.GetComponent(componentType);
                    if (component == null)
                    {
                        component = gameObject.AddComponent(componentType);
                    }
                    ReadInto(component);
                }

                m_Reader.ReadString();
                count = m_Reader.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    if (gameObject.transform.childCount > i)
                    {
                        UnityEngine.Transform childTransform = gameObject.transform.GetChild(i);
                        ReadInto <UnityEngine.GameObject>(childTransform.gameObject);
                    }
                    else
                    {
                        ReadChild(gameObject);
                    }
                }
            }
            else if (type.IsArray)
            {
                Type  elementType = type.GetElementType();
                int   rank        = m_Reader.ReadInt32();
                int[] lengths     = new int[rank];
                for (int i = 0; i < rank; i++)
                {
                    lengths[i] = m_Reader.ReadInt32();
                }
                Array array   = Array.CreateInstance(elementType, lengths);
                int[] indices = new int[array.Rank];
                for (int i = 0; i < array.Rank; 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)
                    {
                        object arrayValue = array.GetValue(indices);
                        if (arrayValue == null)
                        {
                            array.SetValue(Read(elementType), indices);
                        }
                        else
                        {
                            ReadInto(array.GetValue(indices));
                        }
                    }
                }
            }
            else if (isGeneric && type.GetGenericTypeDefinition() == typeof(List <>))
            {
                Type[] genericArgs = type.GetGenericArguments();
                IList  list        = value as IList;
                int    length      = m_Reader.ReadInt32();
                for (int i = 0; i < length; i++)
                {
                    if (list.Count > i && list[i] != null)
                    {
                        ReadInto(list[i]);
                    }
                    else
                    {
                        list.Add(Read(genericArgs[0]));
                    }
                }
            }
            else if (value is ICollection && value is IEnumerable)
            {
                m_Reader.ReadInt32();
                IEnumerable e = value as IEnumerable;
                foreach (object subValue in e)
                {
                    ReadInto(subValue);
                }
            }
            else if (SaveGameTypeManager.HasType(type))
            {
                // Skip save game type start
                m_Reader.ReadByte();
                m_Reader.ReadInt64();

                SaveGameType saveGameType = SaveGameTypeManager.GetType(type);
                saveGameType.ReadInto(value, this);

                // Skip save game type End
                m_Reader.ReadByte();
            }
            else
            {
                ReadIntoObject(type, value);
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Read the specified type.
        /// </summary>
        /// <param name="type">Type.</param>
        public virtual object Read(Type type)
        {
            Type   nullableType = null;
            object result       = null;

            if (type == null || !m_Reader.ReadBoolean())
            {
                result = null;
            }
            else
            {
                if (Nullable.GetUnderlyingType(type) != null)
                {
                    nullableType = type;
                    type         = Nullable.GetUnderlyingType(type);
                }
                bool isPrimitive    = false;
                bool isEnum         = false;
                bool isSerializable = false;
                bool isGeneric      = 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
                if (type == typeof(UnityEngine.GameObject))
                {
                    // Skip save game type start
                    m_Reader.ReadByte();
                    m_Reader.ReadInt64();

                    int    layer    = ReadProperty <int>();
                    bool   isStatic = ReadProperty <bool>();
                    string tag      = ReadProperty <string>();
                    string name     = ReadProperty <string>();
                    UnityEngine.HideFlags hideFlags = ReadProperty <UnityEngine.HideFlags>();

                    // Skip save game type end
                    m_Reader.ReadByte();

                    UnityEngine.GameObject gameObject = new UnityEngine.GameObject(name)
                    {
                        layer     = layer,
                        isStatic  = isStatic,
                        tag       = tag,
                        hideFlags = hideFlags
                    };

                    m_Reader.ReadString();
                    int count = m_Reader.ReadInt32();
                    for (int i = 0; i < count; i++)
                    {
                        string typeName                 = m_Reader.ReadString();
                        Type   componentType            = Type.GetType(typeName);
                        UnityEngine.Component component = gameObject.GetComponent(componentType);
                        if (componentType != typeof(UnityEngine.Transform) && componentType.BaseType != typeof(UnityEngine.Transform))
                        {
                            UnityEngine.Component newComponent = gameObject.AddComponent(componentType);
                            if (newComponent != null)
                            {
                                component = newComponent;
                            }
                        }
                        ReadInto(component);
                    }

                    m_Reader.ReadString();
                    count = m_Reader.ReadInt32();
                    for (int i = 0; i < count; i++)
                    {
                        ReadChild(gameObject);
                    }
                    result = gameObject;
                }
                else if (isPrimitive || type == typeof(string) || type == typeof(decimal))
                {
                    if (type == typeof(string))
                    {
                        result = m_Reader.ReadString();
                    }
                    else if (type == typeof(decimal))
                    {
                        result = m_Reader.ReadDecimal();
                    }
                    else if (type == typeof(short))
                    {
                        result = m_Reader.ReadInt16();
                    }
                    else if (type == typeof(int))
                    {
                        result = m_Reader.ReadInt32();
                    }
                    else if (type == typeof(long))
                    {
                        result = m_Reader.ReadInt64();
                    }
                    else if (type == typeof(ushort))
                    {
                        result = m_Reader.ReadUInt16();
                    }
                    else if (type == typeof(uint))
                    {
                        result = m_Reader.ReadUInt32();
                    }
                    else if (type == typeof(ulong))
                    {
                        result = m_Reader.ReadUInt64();
                    }
                    else if (type == typeof(double))
                    {
                        result = m_Reader.ReadDouble();
                    }
                    else if (type == typeof(float))
                    {
                        result = m_Reader.ReadSingle();
                    }
                    else if (type == typeof(byte))
                    {
                        result = m_Reader.ReadByte();
                    }
                    else if (type == typeof(sbyte))
                    {
                        result = m_Reader.ReadSByte();
                    }
                    else if (type == typeof(char))
                    {
                        result = m_Reader.ReadChar();
                    }
                    else if (type == typeof(bool))
                    {
                        result = m_Reader.ReadBoolean();
                    }
                }
                else if (isEnum)
                {
                    result = Enum.Parse(type, m_Reader.ReadString());
                }
                else if (type == typeof(DateTime))
                {
                    result = DateTime.FromBinary(m_Reader.ReadInt64());
                }
                else if (type == typeof(TimeSpan))
                {
                    result = TimeSpan.Parse(m_Reader.ReadString());
                }
                else if (type.IsArray)
                {
                    Type  elementType = type.GetElementType();
                    int   rank        = m_Reader.ReadInt32();
                    int[] lengths     = new int[rank];
                    for (int i = 0; i < rank; i++)
                    {
                        lengths[i] = m_Reader.ReadInt32();
                    }
                    Array array   = Array.CreateInstance(elementType, lengths);
                    int[] indices = new int[array.Rank];
                    for (int i = 0; i < array.Rank; 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)
                        {
                            array.SetValue(Read(elementType), indices);
                        }
                    }
                    result = array;
                }
                else if (type == typeof(DictionaryEntry))
                {
                    DictionaryEntry entry   = new DictionaryEntry();
                    Type            keyType = Type.GetType(m_Reader.ReadString());
                    entry.Key = Read(keyType);
                    Type valueType = Type.GetType(m_Reader.ReadString());
                    entry.Value = Read(valueType);
                    result      = entry;
                }
                else if (isGeneric && type.GetGenericTypeDefinition() == typeof(KeyValuePair <,>))
                {
                    Type[] genericArgs = type.GetGenericArguments();
                    result = Activator.CreateInstance(type, Read(genericArgs[0]), Read(genericArgs[1]));
                }
                else if (isGeneric && type.GetGenericTypeDefinition() == typeof(List <>))
                {
                    Type[] genericArgs = type.GetGenericArguments();
                    IList  list        = (IList)Activator.CreateInstance(type);
                    int    length      = m_Reader.ReadInt32();
                    for (int i = 0; i < length; i++)
                    {
                        list.Add(Read(genericArgs[0]));
                    }
                    result = list;
                }
                else if (isGeneric && type.GetGenericTypeDefinition() == typeof(LinkedList <>))
                {
                    Type[]     genericArgs = type.GetGenericArguments();
                    object     linkedList  = Activator.CreateInstance(type);
                    MethodInfo addLast     = type.GetMethod("AddLast", genericArgs);
                    int        length      = m_Reader.ReadInt32();
                    for (int i = 0; i < length; i++)
                    {
                        addLast.Invoke(linkedList, new object[] { Read(genericArgs[0]) });
                    }
                    result = linkedList;
                }
                else if (isGeneric && (type.GetGenericTypeDefinition() == typeof(Dictionary <,>) ||
                                       type.GetGenericTypeDefinition() == typeof(SortedDictionary <,>) ||
                                       type.GetGenericTypeDefinition() == typeof(SortedList <,>)))
                {
                    Type[]       genericArgs      = type.GetGenericArguments();
                    IDictionary  dictionary       = (IDictionary)Activator.CreateInstance(type);
                    int          length           = m_Reader.ReadInt32();
                    Type         keyValuePairType = typeof(KeyValuePair <,>).MakeGenericType(genericArgs);
                    PropertyInfo keyProperty      = keyValuePairType.GetProperty("Key", TypeUtils.SavableBindingFlags);
                    PropertyInfo valueProperty    = keyValuePairType.GetProperty("Value", TypeUtils.SavableBindingFlags);
                    for (int i = 0; i < length; i++)
                    {
                        object keyValuePair = Read(keyValuePairType);
                        dictionary.Add(keyProperty.GetValue(keyValuePair, null), valueProperty.GetValue(keyValuePair, null));
                    }
                    result = dictionary;
                }
                else if (isGeneric && type.GetGenericTypeDefinition() == typeof(Stack <>))
                {
                    Type[]     genericArgs = type.GetGenericArguments();
                    object     stack       = Activator.CreateInstance(type);
                    MethodInfo push        = type.GetMethod("Push");
                    int        length      = m_Reader.ReadInt32();
                    for (int i = 0; i < length; i++)
                    {
                        push.Invoke(stack, new object[] { Read(genericArgs[0]) });
                    }
                    result = stack;
                }
                else if (isGeneric && type.GetGenericTypeDefinition() == typeof(Queue <>))
                {
                    Type[]     genericArgs = type.GetGenericArguments();
                    object     queue       = Activator.CreateInstance(type);
                    MethodInfo enqueue     = type.GetMethod("Enqueue");
                    int        length      = m_Reader.ReadInt32();
                    for (int i = 0; i < length; i++)
                    {
                        enqueue.Invoke(queue, new object[] { Read(genericArgs[0]) });
                    }
                    result = queue;
                }
                else if (isGeneric && type.GetGenericTypeDefinition() == typeof(HashSet <>))
                {
                    Type[]     genericArgs = type.GetGenericArguments();
                    object     hashSet     = Activator.CreateInstance(type);
                    MethodInfo addMethod   = type.GetMethod("Add");
                    int        length      = m_Reader.ReadInt32();
                    for (int i = 0; i < length; i++)
                    {
                        addMethod.Invoke(hashSet, new object[] { Read(genericArgs[0]) });
                    }
                    result = hashSet;
                }
                else if (type == typeof(Hashtable))
                {
                    Hashtable hashtable = new Hashtable();
                    int       length    = m_Reader.ReadInt32();
                    for (int i = 0; i < length; i++)
                    {
                        DictionaryEntry entry = Read <DictionaryEntry>();
                        hashtable.Add(entry.Key, entry.Value);
                    }
                    result = hashtable;
                }
                else if (SaveGameTypeManager.HasType(type))
                {
                    // Skip save game type start
                    m_Reader.ReadByte();
                    m_Reader.ReadInt64();

                    SaveGameType saveGameType = SaveGameTypeManager.GetType(type);
                    result = saveGameType.Read(this);

                    // Skip save game type end
                    m_Reader.ReadByte();
                }
                else
                {
                    result = ReadObject(type);
                }
            }
#if !(UNITY_WSA || UNITY_WINRT) || UNITY_EDITOR
            if (result is IDeserializationCallback)
            {
                (result as IDeserializationCallback).OnDeserialization(this);
            }
#endif
            if (nullableType != null)
            {
                Type genericType = type.GetNullableType();
                result = Activator.CreateInstance(genericType, result);
            }
            return(result);
        }