Пример #1
0
    public static float GetAvailMemory()
    {
        long size = 0;

#if UNITY_EDITOR
        size = 9999;
#elif UNITY_ANDROID
        try
        {
            string sig = AndroidJNIHelper.GetSignature <long>(new object[0]);
            var    ptr = AndroidJNI.GetStaticMethodID(GamePluginMgrPtr, "GetAvailMemory", sig);
            size = AndroidJNI.CallStaticLongMethod(GamePluginMgrPtr, ptr, new jvalue[0]);
            size = size / 1024 / 1024;
        }
        catch (Exception exception)
        {
            //ssLogger.Log(exception.Message);
        }
#elif UNITY_IPHONE
        // Object-C long 是32位,转换后再取回来
        //size = GetAvailableMemory();
        //ssLogger.LogWarning("AvailMemory: {0} M", size);
        size = 9999; //IOS的不管
#endif
        return((float)size);
    }
Пример #2
0
        long ISyncAPI.GetTimeLeftForReconnection(ulong playerId)
        {
            var javaClass  = AndroidJNI.FindClass("com/skillz/SkillzSync");
            var javaMethod = AndroidJNI.GetStaticMethodID(javaClass, "getTimeLeftForReconnection", "(J)J");

            jvalue[] jArgs = AndroidJNIHelper.CreateJNIArgArray(new object[] { (long)playerId });
            return(AndroidJNI.CallStaticLongMethod(javaClass, javaMethod, jArgs));
        }
Пример #3
0
        public static T StaticInvokeCall <T>(string type, string name, string sig, params object[] args)
        {
            Type   t        = typeof(T);
            IntPtr rawClass = AndroidJNI.FindClass(type);
            IntPtr method   = AndroidJNI.GetStaticMethodID(rawClass, name, sig);

            jvalue[] jArgs = ConstructArgArray(args);

            if (t == typeof(bool))
            {
                return((T)(object)AndroidJNI.CallStaticBooleanMethod(
                           rawClass, method, jArgs));
            }
            else if (t == typeof(string))
            {
                return((T)(object)AndroidJNI.CallStaticStringMethod(
                           rawClass, method, jArgs));
            }
            else if (t == typeof(int))
            {
                return((T)(object)AndroidJNI.CallStaticIntMethod(
                           rawClass, method, jArgs));
            }
            else if (t == typeof(float))
            {
                return((T)(object)AndroidJNI.CallStaticFloatMethod(
                           rawClass, method, jArgs));
            }
            else if (t == typeof(double))
            {
                return((T)(object)AndroidJNI.CallStaticDoubleMethod(
                           rawClass, method, jArgs));
            }
            else if (t == typeof(byte))
            {
                return((T)(object)AndroidJNI.CallStaticByteMethod(
                           rawClass, method, jArgs));
            }
            else if (t == typeof(char))
            {
                return((T)(object)AndroidJNI.CallStaticCharMethod(
                           rawClass, method, jArgs));
            }
            else if (t == typeof(long))
            {
                return((T)(object)AndroidJNI.CallStaticLongMethod(
                           rawClass, method, jArgs));
            }
            else if (t == typeof(short))
            {
                return((T)(object)AndroidJNI.CallStaticShortMethod(
                           rawClass, method, jArgs));
            }
            else
            {
                return(StaticInvokeObjectCall <T>(type, name, sig, args));
            }
        }
 public static long CallStaticLongMethod(IntPtr clazz, IntPtr methodId, jvalue[] args)
 {
     try {
         return(AndroidJNI.CallStaticLongMethod(clazz, methodId, args));
     }
     finally {
         CheckException();
     }
 }
Пример #5
0
        public static T StaticInvokeCall <T>(string type, string name, string sig, params object[] args)
        {
            T      local;
            Type   type2    = typeof(T);
            IntPtr clazz    = AndroidJNI.FindClass(type);
            IntPtr methodID = AndroidJNI.GetStaticMethodID(clazz, name, sig);

            jvalue[] jvalueArray = ConstructArgArray(args);
            try
            {
                if (type2 == typeof(bool))
                {
                    return((T)AndroidJNI.CallStaticBooleanMethod(clazz, methodID, jvalueArray));
                }
                if (type2 == typeof(string))
                {
                    return((T)AndroidJNI.CallStaticStringMethod(clazz, methodID, jvalueArray));
                }
                if (type2 == typeof(int))
                {
                    return((T)AndroidJNI.CallStaticIntMethod(clazz, methodID, jvalueArray));
                }
                if (type2 == typeof(float))
                {
                    return((T)AndroidJNI.CallStaticFloatMethod(clazz, methodID, jvalueArray));
                }
                if (type2 == typeof(double))
                {
                    return((T)AndroidJNI.CallStaticDoubleMethod(clazz, methodID, jvalueArray));
                }
                if (type2 == typeof(byte))
                {
                    return((T)AndroidJNI.CallStaticByteMethod(clazz, methodID, jvalueArray));
                }
                if (type2 == typeof(char))
                {
                    return((T)AndroidJNI.CallStaticCharMethod(clazz, methodID, jvalueArray));
                }
                if (type2 == typeof(long))
                {
                    return((T)AndroidJNI.CallStaticLongMethod(clazz, methodID, jvalueArray));
                }
                if (type2 == typeof(short))
                {
                    return((T)AndroidJNI.CallStaticShortMethod(clazz, methodID, jvalueArray));
                }
                local = StaticInvokeObjectCall <T>(type, name, sig, args);
            }
            finally
            {
                AndroidJNIHelper.DeleteJNIArgArray(args, jvalueArray);
            }
            return(local);
        }
Пример #6
0
    public static long GetTimeLeftForReconnection(UInt64 playerId)
    {
        IntPtr javaClass  = AndroidJNI.FindClass("com/skillz/SkillzSync");
        IntPtr javaMethod = AndroidJNI.GetStaticMethodID(javaClass, "getTimeLeftForReconnection", "(J)J");

        object[] args = new object[1];
        args[0] = (long)playerId;
        jvalue[] jArgs = AndroidJNIHelper.CreateJNIArgArray(args);
        long     timeLeftForReconnection = AndroidJNI.CallStaticLongMethod(javaClass, javaMethod, jArgs);

        return(timeLeftForReconnection);
    }
Пример #7
0
        private long AndroidJNISafeCallStaticLongMethod(IntPtr clazz, IntPtr methodID, jvalue[] args)
        {
            long result;

            try
            {
                result = AndroidJNI.CallStaticLongMethod(clazz, methodID, args);
            }
            finally
            {
                AndroidJNISafeCheckException();
            }
            return(result);
        }
Пример #8
0
    public static long GetAndroidSystemFreeSizeKb()
    {
#if UNITY_ANDROID && !UNITY_EDITOR
        try
        {
            string sig = AndroidJNIHelper.GetSignature <long>(new object[0]);
            var    ptr = AndroidJNI.GetStaticMethodID(GamePluginMgrPtr, "GetSystemFreeSizeKb", sig);
            long   kb  = AndroidJNI.CallStaticLongMethod(GamePluginMgrPtr, ptr, new jvalue[0]);
            return(kb);
        }
        catch (Exception exception)
        {
            //ssLogger.Log(exception.Message);
        }
#endif
        return(0);
    }
Пример #9
0
    public static long getThreadCpuUsageInNanoAndroid()
    {
#if UNITY_ANDROID && !UNITY_EDITOR
        try
        {
            IntPtr cls = AndroidJNI.FindClass("android/os/Debug");
            IntPtr allocSize = AndroidJNI.GetStaticMethodID(cls, "threadCpuTimeNanos", "()J");
            return AndroidJNI.CallStaticLongMethod(cls, allocSize, new jvalue[0]);
        }
        catch (Exception)
        {
            return 0;
        }
#else
        return 0;
#endif
    }
Пример #10
0
    public static long getNativeUsedSizeAndroid()
    {
#if UNITY_ANDROID && !UNITY_EDITOR
        try
        {
            IntPtr cls = AndroidJNI.FindClass("android/os/Debug");
            IntPtr allocSize = AndroidJNI.GetStaticMethodID(cls, "getNativeHeapAllocatedSize", "()J");
            return AndroidJNI.CallStaticLongMethod(cls, allocSize, new jvalue[0]);
        }
        catch (Exception)
        {
            return 0;
        }
#else
        return 0;
#endif
    }
        public static T StaticInvokeCall <T>(string type, string name, string sig, params object[] args)
        {
            Type   typeFromHandle = typeof(T);
            IntPtr intPtr         = AndroidJNI.FindClass(type);
            IntPtr staticMethodID = AndroidJNI.GetStaticMethodID(intPtr, name, sig);

            jvalue[] array = ConstructArgArray(args);
            if (typeFromHandle == typeof(bool))
            {
                return((T)(object)AndroidJNI.CallStaticBooleanMethod(intPtr, staticMethodID, array));
            }
            if (typeFromHandle == typeof(string))
            {
                return((T)(object)AndroidJNI.CallStaticStringMethod(intPtr, staticMethodID, array));
            }
            if (typeFromHandle == typeof(int))
            {
                return((T)(object)AndroidJNI.CallStaticIntMethod(intPtr, staticMethodID, array));
            }
            if (typeFromHandle == typeof(float))
            {
                return((T)(object)AndroidJNI.CallStaticFloatMethod(intPtr, staticMethodID, array));
            }
            if (typeFromHandle == typeof(double))
            {
                return((T)(object)AndroidJNI.CallStaticDoubleMethod(intPtr, staticMethodID, array));
            }
            if (typeFromHandle == typeof(byte))
            {
                return((T)(object)AndroidJNI.CallStaticByteMethod(intPtr, staticMethodID, array));
            }
            if (typeFromHandle == typeof(char))
            {
                return((T)(object)AndroidJNI.CallStaticCharMethod(intPtr, staticMethodID, array));
            }
            if (typeFromHandle == typeof(long))
            {
                return((T)(object)AndroidJNI.CallStaticLongMethod(intPtr, staticMethodID, array));
            }
            if (typeFromHandle == typeof(short))
            {
                return((T)(object)AndroidJNI.CallStaticShortMethod(intPtr, staticMethodID, array));
            }
            return(StaticInvokeObjectCall <T>(type, name, sig, args));
        }
Пример #12
0
        public static T StaticInvokeCall <T>(string type, string name, string sig, params object[] args)
        {
            Type   type1          = typeof(T);
            IntPtr num            = AndroidJNI.FindClass(type);
            IntPtr staticMethodId = AndroidJNI.GetStaticMethodID(num, name, sig);

            jvalue[] jvalueArray = JavaObjWrapper.ConstructArgArray(args);
            if ((object)type1 == (object)typeof(bool))
            {
                return((T)(ValueType)AndroidJNI.CallStaticBooleanMethod(num, staticMethodId, jvalueArray));
            }
            if ((object)type1 == (object)typeof(string))
            {
                return((T)AndroidJNI.CallStaticStringMethod(num, staticMethodId, jvalueArray));
            }
            if ((object)type1 == (object)typeof(int))
            {
                return((T)(ValueType)AndroidJNI.CallStaticIntMethod(num, staticMethodId, jvalueArray));
            }
            if ((object)type1 == (object)typeof(float))
            {
                return((T)(ValueType)AndroidJNI.CallStaticFloatMethod(num, staticMethodId, jvalueArray));
            }
            if ((object)type1 == (object)typeof(double))
            {
                return((T)(ValueType)AndroidJNI.CallStaticDoubleMethod(num, staticMethodId, jvalueArray));
            }
            if ((object)type1 == (object)typeof(byte))
            {
                return((T)(ValueType)AndroidJNI.CallStaticByteMethod(num, staticMethodId, jvalueArray));
            }
            if ((object)type1 == (object)typeof(char))
            {
                return((T)(ValueType)AndroidJNI.CallStaticCharMethod(num, staticMethodId, jvalueArray));
            }
            if ((object)type1 == (object)typeof(long))
            {
                return((T)(ValueType)AndroidJNI.CallStaticLongMethod(num, staticMethodId, jvalueArray));
            }
            if ((object)type1 == (object)typeof(short))
            {
                return((T)(ValueType)AndroidJNI.CallStaticShortMethod(num, staticMethodId, jvalueArray));
            }
            return(JavaObjWrapper.StaticInvokeObjectCall <T>(type, name, sig, args));
        }