private void GetAlphaMeshCollider()
 {
     alphaMeshCollider = script.GetComponent("AlphaMeshCollider");
     if(alphaMeshCollider == null) {
         //Debug.LogWarning("No AlphaMeshCollider component was found on Sprite! SF2DCGHelper requires an AlphaMeshCollider component.");
         initialized = false;
         return;
     }
     initialized = true;
 }
        static int _m_GetComponentInParent(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


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



                {
                    System.Type _t = (System.Type)translator.GetObject(L, 2, typeof(System.Type));

                    var gen_ret = gen_to_be_invoked.GetComponentInParent(_t);
                    translator.Push(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
        static int _m_CompareTag(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


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



                {
                    string _tag = LuaAPI.lua_tostring(L, 2);

                    bool gen_ret = gen_to_be_invoked.CompareTag(_tag);
                    LuaAPI.lua_pushboolean(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
        static int _m_AddComponent(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


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



                {
                    System.Type componentType = (System.Type)translator.GetObject(L, 2, typeof(System.Type));

                    UnityEngine.Component __cl_gen_ret = __cl_gen_to_be_invoked.AddComponent(componentType);
                    translator.Push(L, __cl_gen_ret);



                    return(1);
                }
            } catch (System.Exception __gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + __gen_e));
            }
        }
Example #5
0
        static StackObject *GetComponentInParent_9(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            CSHotFix.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);
            System.Type @t = (System.Type) typeof(System.Type).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

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

            var result_of_this_method = instance_of_this_method.GetComponentInParent(@t);

            object obj_result_of_this_method = result_of_this_method;

            if (obj_result_of_this_method is CrossBindingAdaptorType)
            {
                return(ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance));
            }
            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
Example #6
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);
        }
Example #7
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);
            }
        }
Example #8
0
        static internal int Lua_System_Comparison_1_UnityEngine_Component(LuaFunction ld, UnityEngine.Component a1, UnityEngine.Component a2)
        {
            IntPtr l     = ld.L;
            int    error = pushTry(l);

            pushValue(l, a1);
            pushValue(l, a2);
            ld.pcall(2, error);
            int ret;

            checkType(l, error + 1, out ret);
            LuaDLL.lua_settop(l, error - 1);
            return(ret);
        }
Example #9
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);
        }
        static int _m_SendMessageUpwards(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


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


                int gen_param_count = LuaAPI.lua_gettop(L);

                if (gen_param_count == 2 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING))
                {
                    string _methodName = LuaAPI.lua_tostring(L, 2);

                    gen_to_be_invoked.SendMessageUpwards(_methodName);



                    return(0);
                }
                if (gen_param_count == 3 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING) && translator.Assignable <object>(L, 3))
                {
                    string _methodName = LuaAPI.lua_tostring(L, 2);
                    object _value      = translator.GetObject(L, 3, typeof(object));

                    gen_to_be_invoked.SendMessageUpwards(_methodName, _value);



                    return(0);
                }
                if (gen_param_count == 3 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING) && translator.Assignable <UnityEngine.SendMessageOptions>(L, 3))
                {
                    string _methodName = LuaAPI.lua_tostring(L, 2);
                    UnityEngine.SendMessageOptions _options; translator.Get(L, 3, out _options);

                    gen_to_be_invoked.SendMessageUpwards(_methodName, _options);



                    return(0);
                }
                if (gen_param_count == 4 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING) && translator.Assignable <object>(L, 3) && translator.Assignable <UnityEngine.SendMessageOptions>(L, 4))
                {
                    string _methodName = LuaAPI.lua_tostring(L, 2);
                    object _value      = translator.GetObject(L, 3, typeof(object));
                    UnityEngine.SendMessageOptions _options; translator.Get(L, 4, out _options);

                    gen_to_be_invoked.SendMessageUpwards(_methodName, _value, _options);



                    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.Component.SendMessageUpwards!"));
        }
Example #11
0
 public static UnityEngine.Component CloneComponent(UnityEngine.Component c)
 {
     throw new NotImplementedException("This function was automatically generated by Mockery and has no real implementation yet.");
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TranslationEventBuilder"/> class.
 /// </summary>
 /// <param name="component">The component.</param>
 /// <param name="eventInfo">The event information.</param>
 public TranslationEventBuilder(UnityEngine.Component component, EventInfo eventInfo)
 {
     this.component = component;
     this.eventInfo = eventInfo;
 }
Example #13
0
 /// <summary> Attaches a component to the given component's game object. </summary>
 /// <param name="component">Component.</param>
 /// <returns>Newly attached component.</returns>
 public static T AddComponent <T>(this UnityEngine.Component component) where T : UnityEngine.Component =>
 component.gameObject.AddComponent <T>();
Example #14
0
 protected override void DoAction(UnityEngine.Component other)
 {
 }
Example #15
0
        static internal bool Lua_System_Predicate_1_UnityEngine_Component(LuaFunction ld, UnityEngine.Component a1)
        {
            IntPtr l     = ld.L;
            int    error = pushTry(l);

            pushValue(l, a1);
            ld.pcall(1, error);
            bool ret;

            checkType(l, error + 1, out ret);
            LuaDLL.lua_settop(l, error - 1);
            return(ret);
        }
        /// <summary>
        /// Initializes the adapter (the adapter is reused)
        /// </summary>
        /// <param name="component"></param>

        public void Initialize(Component component)
        {
            _component = component;
        }
Example #17
0
        static internal void Lua_System_Action_1_UnityEngine_Component(LuaFunction ld, UnityEngine.Component a1)
        {
            IntPtr l     = ld.L;
            int    error = pushTry(l);

            pushValue(l, a1);
            ld.pcall(1, error);
            LuaDLL.lua_settop(l, error - 1);
        }
Example #18
0
 /// <summary>
 ///     Gets a component attached to the given component's game object.If one isn't found, a new one is attached and
 ///     returned.
 /// </summary>
 /// <param name="component">Component.</param>
 /// <returns>Previously or newly attached component.</returns>
 public static T GetOrAddComponent <T>(this UnityEngine.Component component) where T : UnityEngine.Component =>
 component.GetComponent <T>() ?? component.AddComponent <T>();
Example #19
0
        private void Rebuild2DCGCollider()
        {
            try {
                Init();
                if (!initialized)
                {
                    return;
                }

                float ppu = GetPPU();                                                   // get pixels per unit from GameSettings
                SpriteFactory.SF2DColliderGenHelper.Data data = script.CheckCollider(); // get the data we need from the helper script
                if (data == null)
                {
                    throw new System.Exception();
                }


                UnityEngine.Component alphaMeshCollider = script.GetComponent("AlphaMeshCollider");
                if (alphaMeshCollider == null)
                {
                    throw new System.Exception("No AlphaMeshCollider component was found on Sprite! If you have removed the 2D Collider Gen collider, please remove the helper component");
                }
                System.Type type_alphaMeshCollider = alphaMeshCollider.GetType();

                // Verify the 2D Collider Gen fields we need exist
                Verify2DCGFields(type_alphaMeshCollider);

                // Get the serialized objects
                UnityEditor.SerializedObject   so = new UnityEditor.SerializedObject(alphaMeshCollider);
                UnityEditor.SerializedProperty sp;
                so.Update();

                // CUSTOM TEX
                sp = so.FindProperty("mRegionIndependentParameters.mCustomTex");
                if (sp == null)
                {
                    FieldException("Required field not found!");
                }

                UnityEngine.Texture2D tex = FindFrameTexture(data.masterSprite);
                if (tex == null)
                {
                    UnityEngine.Debug.LogWarning("Frame texture not found! 2D Collider Gen mesh collider will not generate correctly.");
                }
                sp.objectReferenceValue = tex;

                // CUSTOM SCALE
                sp = so.FindProperty("mRegionIndependentParameters.mCustomScale");
                if (sp == null)
                {
                    FieldException("Required field not found!");
                }

                UnityEngine.Vector2 scale = data.pixelScale / ppu; // convert pixel scale to units
                sp.vector2Value = scale;                           // update scale

                // FLIP
                UnityEngine.Vector2 offset = data.unitOffset; // get offset which is affected by flip

                // FLIP X
                sp = so.FindProperty("mRegionIndependentParameters.mFlipHorizontal");
                if (sp == null)
                {
                    FieldException("Required field not found!");
                }

                if (sp.boolValue != data.isFlippedX)
                {
                    sp.boolValue = data.isFlippedX;
                }
                if (data.isFlippedX)
                {
                    offset.x *= -1.0f;
                }

                // FLIP Y
                sp = so.FindProperty("mRegionIndependentParameters.mFlipVertical");
                if (sp == null)
                {
                    FieldException("Required field not found!");
                }

                if (sp.boolValue != data.isFlippedY)
                {
                    sp.boolValue = data.isFlippedY;
                }
                if (data.isFlippedY)
                {
                    offset.y *= -1.0f;
                }

                // CUSTOM OFFSET
                sp = so.FindProperty("mRegionIndependentParameters.mCustomOffset");
                if (sp == null)
                {
                    FieldException("Required field not found!");
                }

                sp.vector3Value = offset; // update offset

                // Finish up with the serialized object
                so.ApplyModifiedProperties();

                // Rebuild the 2DCG collider
                type_alphaMeshCollider.InvokeMember("RecalculateCollider", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.InvokeMethod, null, alphaMeshCollider, null);
            } catch (System.Exception e) {
                UnityEngine.Debug.LogError(e.Message);
                UnityEngine.Debug.LogError("STACK TRACE: " + e.StackTrace);
            }
        }
Example #20
0
 /// <summary> Checks whether a component's game object has a component of type T attached. </summary>
 /// <param name="component">Component.</param>
 /// <returns>True when component is attached.</returns>
 public static bool HasComponent <T>(this UnityEngine.Component component) where T : UnityEngine.Component =>
 component.GetComponent <T>() != null;
        static IEnumerator PublishUnityObjectValueChanged <TSource, TProperty>(UnityEngine.Object unityObject, TProperty firstValue, Func <TSource, TProperty> propertySelector, IEqualityComparer <TProperty> comparer, IObserver <TProperty> observer, CancellationToken cancellationToken, bool fastDestroyCheck)
        {
            TProperty currentValue = default(TProperty);
            TProperty prevValue    = firstValue;

            TSource source = (TSource)(object)unityObject;

            if (fastDestroyCheck)
            {
                ObservableDestroyTrigger destroyTrigger = null;
                {
                    UnityEngine.GameObject gameObject = unityObject as UnityEngine.GameObject;
                    if (gameObject == null)
                    {
                        UnityEngine.Component comp = unityObject as UnityEngine.Component;
                        if (comp != null)
                        {
                            gameObject = comp.gameObject;
                        }
                    }

                    // can't use faster path
                    if (gameObject == null)
                    {
                        goto STANDARD_LOOP;
                    }

                    destroyTrigger = GetOrAddDestroyTrigger(gameObject);
                }

                // fast compare path
                while (!cancellationToken.IsCancellationRequested)
                {
                    bool isDestroyed = destroyTrigger.IsActivated
                        ? !destroyTrigger.IsCalledOnDestroy
                        : (unityObject != null);

                    if (isDestroyed)
                    {
                        try
                        {
                            currentValue = propertySelector(source);
                        }
                        catch (Exception ex)
                        {
                            observer.OnError(ex);
                            yield break;
                        }
                    }
                    else
                    {
                        observer.OnCompleted();
                        yield break;
                    }

                    if (!comparer.Equals(currentValue, prevValue))
                    {
                        observer.OnNext(currentValue);
                        prevValue = currentValue;
                    }

                    yield return(null);
                }

                yield break;
            }

STANDARD_LOOP:
            while (!cancellationToken.IsCancellationRequested)
            {
                if (unityObject != null)
                {
                    try
                    {
                        currentValue = propertySelector(source);
                    }
                    catch (Exception ex)
                    {
                        observer.OnError(ex);
                        yield break;
                    }
                }
                else
                {
                    observer.OnCompleted();
                    yield break;
                }

                if (!comparer.Equals(currentValue, prevValue))
                {
                    observer.OnNext(currentValue);
                    prevValue = currentValue;
                }

                yield return(null);
            }
        }
Example #22
0
        /// <summary>
        /// Create several new entities for a joint associated with the specified authoring component.
        /// Other systems can later find these joints by using <see cref="GetJointEntities"/>.
        /// Use this method instead of <see cref="CreateJointEntity"/> when the behavior specified by the authoring component requires multiple <see cref="PhysicsJoint"/> components to describe.
        /// The new entities will have all required component types, <see cref="PhysiscsJointCompanion"/> buffers, as well as readable names in the Entity Debugger.
        /// </summary>
        /// <param name="authoringComponent">An authoring component being converted.</param>
        /// <param name="constrainedBodyPair">A component describing the bodies constrained by the joints.</param>
        /// <param name="joints">The set of reference frames and corresponding constraints to apply to the bodies.</param>
        /// <param name="newJointEntities">An optional list to populate with all of the new entities.</param>
        public void CreateJointEntities(
            UnityComponent authoringComponent,
            PhysicsConstrainedBodyPair constrainedBodyPair,
            NativeArray <PhysicsJoint> joints,
            NativeList <Entity> newJointEntities = default
            )
        {
            if (!joints.IsCreated || joints.Length == 0)
            {
                return;
            }

            if (newJointEntities.IsCreated)
            {
                newJointEntities.Clear();
            }
            else
            {
                newJointEntities = new NativeList <Entity>(joints.Length, Allocator.Temp);
            }

            // find existing joints associated with the authoring component, if any
            if (!m_JointEntitiesPerAuthoringComponent.TryGetValue(authoringComponent, out var allJointEntities))
            {
                m_JointEntitiesPerAuthoringComponent[authoringComponent]
                      = allJointEntities
                      = new NativeList <Entity>(joints.Length, Allocator.Persistent);
            }

            // create all new joints
            var multipleJoints = joints.Length > 1;

#if UNITY_EDITOR
            var nameEntityA = DstEntityManager.GetName(constrainedBodyPair.EntityA);
            var nameEntityB = constrainedBodyPair.EntityB == Entity.Null
                ? "PhysicsWorld"
                : DstEntityManager.GetName(constrainedBodyPair.EntityB);
            var baseName = $"Joining {nameEntityA} + {nameEntityB}";
#endif
            for (var i = 0; i < joints.Length; ++i)
            {
                var jointEntity = CreateAdditionalEntity(authoringComponent);
#if UNITY_EDITOR
                DstEntityManager.SetName(jointEntity, $"{baseName} ({joints[i].JointType})");
#endif

                DstEntityManager.AddComponents(
                    jointEntity, multipleJoints ? k_JointComponentsMultiple : k_JointComponentsSingle
                    );

                DstEntityManager.SetComponentData(jointEntity, constrainedBodyPair);
                DstEntityManager.SetComponentData(jointEntity, joints[i]);

                newJointEntities.Add(jointEntity);
                allJointEntities.Add(jointEntity);
            }

            if (!multipleJoints)
            {
                return;
            }

            // set companion buffers for new joints
            for (var i = 0; i < joints.Length; ++i)
            {
                var companions = DstEntityManager.GetBuffer <PhysicsJointCompanion>(newJointEntities[i]);
                for (var j = 0; j < joints.Length; ++j)
                {
                    if (i == j)
                    {
                        continue;
                    }
                    companions.Add(new PhysicsJointCompanion {
                        JointEntity = newJointEntities[j]
                    });
                }
            }
        }
Example #23
0
 public override void RestoreValues(UnityEngine.Component component)
 {
     typeof(ZSerializer.PersistentMonoBehaviour).GetField("groupID", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(component, groupID);
     typeof(ZSerializer.PersistentMonoBehaviour).GetField("autoSync", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(component, autoSync);
 }
Example #24
0
 public static UdpNetBehaviour GetUdpNetwork(this UnityEngine.Component c)
 {
     return(c.GetComponent <UdpNetBehaviour>());
 }
Example #25
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);
            }
        }
Example #26
0
 public static void Deactivate(this UnityEngine.Component c)
 {
     c.gameObject.SetActive(false);
 }
Example #27
0
 public static void Register()
 {
     if (doNotModify)
     {
         return;
     }
     object o = null;
     {
         UnityEngine.MonoBehaviour v = (UnityEngine.MonoBehaviour)o;
         v = new UnityEngine.MonoBehaviour();
         var p1 = v.tag;
         v.tag = (System.String)o;
         var p2 = v.name;
         v.name = (System.String)o;
         v.IsInvoking();
         v.CancelInvoke();
         v.Invoke((System.String)o, (System.Single)o);
         v.InvokeRepeating((System.String)o, (System.Single)o, (System.Single)o);
         v.CancelInvoke((System.String)o);
         v.IsInvoking((System.String)o);
         v.StartCoroutine((System.String)o);
         v.StartCoroutine((System.String)o, (System.Object)o);
         v.StartCoroutine((System.Collections.IEnumerator)o);
         v.StopCoroutine((System.Collections.IEnumerator)o);
         v.StopCoroutine((UnityEngine.Coroutine)o);
         UnityEngine.MonoBehaviour.print((System.Object)o);
         v.GetComponent((System.Type)o);
         UnityEngine.Component p3 = (UnityEngine.Component)o;
         v.TryGetComponent((System.Type)o, out p3);
         v.GetComponentInChildren((System.Type)o, (System.Boolean)o);
         v.GetComponentInChildren((System.Type)o);
         v.GetComponentsInChildren((System.Type)o, (System.Boolean)o);
         v.GetComponentsInChildren((System.Type)o);
         v.GetComponentInParent((System.Type)o);
         v.GetComponentsInParent((System.Type)o, (System.Boolean)o);
         v.GetComponentsInParent((System.Type)o);
         v.GetComponents((System.Type)o);
         v.GetComponents((System.Type)o, (System.Collections.Generic.List <UnityEngine.Component>)o);
         v.CompareTag((System.String)o);
         v.SendMessageUpwards((System.String)o, (System.Object)o);
         v.SendMessageUpwards((System.String)o);
         v.SendMessageUpwards((System.String)o, (UnityEngine.SendMessageOptions)o);
         v.SendMessage((System.String)o, (System.Object)o);
         v.SendMessage((System.String)o);
         v.SendMessage((System.String)o, (UnityEngine.SendMessageOptions)o);
         v.BroadcastMessage((System.String)o, (System.Object)o);
         v.BroadcastMessage((System.String)o);
         v.BroadcastMessage((System.String)o, (UnityEngine.SendMessageOptions)o);
         v.GetInstanceID();
         v.GetHashCode();
         v.Equals((System.Object)o);
         v.ToString();
     }
     {
         UnityEngine.Transform v = (UnityEngine.Transform)o;
         var p4 = v.position;
         v.position = (UnityEngine.Vector3)o;
         var p5 = v.localPosition;
         v.localPosition = (UnityEngine.Vector3)o;
         var p6 = v.eulerAngles;
         v.eulerAngles = (UnityEngine.Vector3)o;
         var p7 = v.localEulerAngles;
         v.localEulerAngles = (UnityEngine.Vector3)o;
         var p8 = v.right;
         v.right = (UnityEngine.Vector3)o;
         var p9 = v.up;
         v.up = (UnityEngine.Vector3)o;
         var pA = v.forward;
         v.forward = (UnityEngine.Vector3)o;
         var pB = v.rotation;
         v.rotation = (UnityEngine.Quaternion)o;
         var pC = v.localRotation;
         v.localRotation = (UnityEngine.Quaternion)o;
         var pD = v.localScale;
         v.localScale = (UnityEngine.Vector3)o;
         var pE = v.parent;
         v.parent = (UnityEngine.Transform)o;
         var pF  = v.worldToLocalMatrix;
         var p10 = v.localToWorldMatrix;
         var p11 = v.root;
         var p12 = v.lossyScale;
         var p13 = v.hierarchyCapacity;
         v.hierarchyCapacity = (System.Int32)o;
         var p14 = v.hierarchyCount;
         var p15 = v.tag;
         v.tag = (System.String)o;
         var p16 = v.name;
         v.name = (System.String)o;
         v.SetParent((UnityEngine.Transform)o);
         v.SetPositionAndRotation((UnityEngine.Vector3)o, (UnityEngine.Quaternion)o);
         v.Translate((UnityEngine.Vector3)o, (UnityEngine.Space)o);
         v.Translate((UnityEngine.Vector3)o);
         v.Translate((System.Single)o, (System.Single)o, (System.Single)o, (UnityEngine.Space)o);
         v.Translate((System.Single)o, (System.Single)o, (System.Single)o);
         v.Translate((UnityEngine.Vector3)o, (UnityEngine.Transform)o);
         v.Translate((System.Single)o, (System.Single)o, (System.Single)o, (UnityEngine.Transform)o);
         v.Rotate((UnityEngine.Vector3)o, (UnityEngine.Space)o);
         v.Rotate((UnityEngine.Vector3)o);
         v.Rotate((System.Single)o, (System.Single)o, (System.Single)o, (UnityEngine.Space)o);
         v.Rotate((System.Single)o, (System.Single)o, (System.Single)o);
         v.Rotate((UnityEngine.Vector3)o, (System.Single)o, (UnityEngine.Space)o);
         v.Rotate((UnityEngine.Vector3)o, (System.Single)o);
         v.RotateAround((UnityEngine.Vector3)o, (UnityEngine.Vector3)o, (System.Single)o);
         v.LookAt((UnityEngine.Transform)o, (UnityEngine.Vector3)o);
         v.LookAt((UnityEngine.Transform)o);
         v.LookAt((UnityEngine.Vector3)o, (UnityEngine.Vector3)o);
         v.LookAt((UnityEngine.Vector3)o);
         v.TransformDirection((UnityEngine.Vector3)o);
         v.TransformDirection((System.Single)o, (System.Single)o, (System.Single)o);
         v.InverseTransformDirection((UnityEngine.Vector3)o);
         v.InverseTransformDirection((System.Single)o, (System.Single)o, (System.Single)o);
         v.TransformVector((UnityEngine.Vector3)o);
         v.TransformVector((System.Single)o, (System.Single)o, (System.Single)o);
         v.InverseTransformVector((UnityEngine.Vector3)o);
         v.InverseTransformVector((System.Single)o, (System.Single)o, (System.Single)o);
         v.TransformPoint((UnityEngine.Vector3)o);
         v.TransformPoint((System.Single)o, (System.Single)o, (System.Single)o);
         v.InverseTransformPoint((UnityEngine.Vector3)o);
         v.InverseTransformPoint((System.Single)o, (System.Single)o, (System.Single)o);
         v.Find((System.String)o);
         v.GetEnumerator();
         v.GetComponent((System.Type)o);
         UnityEngine.Component p17 = (UnityEngine.Component)o;
         v.TryGetComponent((System.Type)o, out p17);
         v.GetComponentInChildren((System.Type)o, (System.Boolean)o);
         v.GetComponentInChildren((System.Type)o);
         v.GetComponentsInChildren((System.Type)o, (System.Boolean)o);
         v.GetComponentsInChildren((System.Type)o);
         v.GetComponentInParent((System.Type)o);
         v.GetComponentsInParent((System.Type)o, (System.Boolean)o);
         v.GetComponentsInParent((System.Type)o);
         v.GetComponents((System.Type)o);
         v.GetComponents((System.Type)o, (System.Collections.Generic.List <UnityEngine.Component>)o);
         v.CompareTag((System.String)o);
         v.SendMessageUpwards((System.String)o, (System.Object)o);
         v.SendMessageUpwards((System.String)o);
         v.SendMessageUpwards((System.String)o, (UnityEngine.SendMessageOptions)o);
         v.SendMessage((System.String)o, (System.Object)o);
         v.SendMessage((System.String)o);
         v.SendMessage((System.String)o, (UnityEngine.SendMessageOptions)o);
         v.BroadcastMessage((System.String)o, (System.Object)o);
         v.BroadcastMessage((System.String)o);
         v.BroadcastMessage((System.String)o, (UnityEngine.SendMessageOptions)o);
         v.GetInstanceID();
         v.GetHashCode();
         v.Equals((System.Object)o);
         v.ToString();
     }
 }
Example #28
0
 public static bool ExistComponentInChildren <T>(this UnityEngine.Component c) where T : UnityEngine.Component
 {
     return(!c.GetComponentInChildren <T>().IsNull());
 }
Example #29
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);
            }
        }
Example #30
0
 public static T GetOrAddComponent <T>(this UnityEngine.Component c) where T : UnityEngine.Component
 {
     return(c.GetComponent <T>() ?? c.gameObject.AddComponent <T>());
 }
Example #31
0
        static int BroadcastMessage(RealStatePtr L)
        {
            ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


            UnityEngine.Component __cl_gen_to_be_invoked = (UnityEngine.Component)translator.FastGetCSObj(L, 1);


            int __gen_param_count = LuaAPI.lua_gettop(L);

            try {
                if (__gen_param_count == 2 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING))
                {
                    string methodName = LuaAPI.lua_tostring(L, 2);

                    __cl_gen_to_be_invoked.BroadcastMessage(methodName);



                    return(0);
                }
                if (__gen_param_count == 3 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING) && translator.Assignable <object>(L, 3))
                {
                    string methodName = LuaAPI.lua_tostring(L, 2);
                    object parameter  = translator.GetObject(L, 3, typeof(object));

                    __cl_gen_to_be_invoked.BroadcastMessage(methodName, parameter);



                    return(0);
                }
                if (__gen_param_count == 3 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING) && translator.Assignable <UnityEngine.SendMessageOptions>(L, 3))
                {
                    string methodName = LuaAPI.lua_tostring(L, 2);
                    UnityEngine.SendMessageOptions options; translator.Get(L, 3, out options);

                    __cl_gen_to_be_invoked.BroadcastMessage(methodName, options);



                    return(0);
                }
                if (__gen_param_count == 4 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING) && translator.Assignable <object>(L, 3) && translator.Assignable <UnityEngine.SendMessageOptions>(L, 4))
                {
                    string methodName = LuaAPI.lua_tostring(L, 2);
                    object parameter  = translator.GetObject(L, 3, typeof(object));
                    UnityEngine.SendMessageOptions options; translator.Get(L, 4, out options);

                    __cl_gen_to_be_invoked.BroadcastMessage(methodName, parameter, options);



                    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.Component.BroadcastMessage!"));
        }
Example #32
0
        /// <summary>
        /// Initializes the adapter (the adapter is reused)
        /// </summary>
        /// <param name="component"></param>

        public void Initialize(Component component)
        {
            _component = component;
        }