Exemplo n.º 1
0
 ////////////////////////////////////////////////////////////////////////////////////////////////
 public T Find <T>(string funcName)
 {
     UnityEngine.RuntimePlatform platform = UnityEngine.Application.platform;
     if (platform == UnityEngine.RuntimePlatform.WindowsEditor)
     {
         IntPtr address = GetProcAddressWindows(handle_, funcName);
         if (address == IntPtr.Zero)
         {
             throw new Exception(String.Format("GetProcAddress {0}", funcName));
         }
         return((T)(object)Marshal.GetDelegateForFunctionPointer(address, typeof(T)));
     }
     else if (platform == UnityEngine.RuntimePlatform.OSXEditor)
     {
         IntPtr address = GetProcAddressOSX(handle_, funcName);
         if (address == IntPtr.Zero)
         {
             throw new Exception(String.Format("dlsym {0}", funcName));
         }
         return((T)(object)Marshal.GetDelegateForFunctionPointer(address, typeof(T)));
     }
     else
     {
         throw new Exception("Can't look for function in library for current platform");
     }
 }
Exemplo n.º 2
0
        public static bool IsAvailableOn(UnityEngine.RuntimePlatform platform)
        {
            bool available = false;

            available = UnityEngine.Application.platform == platform;

            return(available);
        }
Exemplo n.º 3
0
        public void Dispose()
        {
            if (handle_ != IntPtr.Zero)
            {
                UnityEngine.RuntimePlatform platform = UnityEngine.Application.platform;
                if (platform == UnityEngine.RuntimePlatform.WindowsEditor)
                {
                    FreeLibraryWindows(handle_);

                    IntPtr handle = GetModuleHandleWindows(filename_);
                    if (handle != IntPtr.Zero)
                    {
                        Debug.LogWarning(String.Format("Forcing unload of {0}", filename_));

                        int count = 0;
                        while (handle != IntPtr.Zero && count++ < 10)
                        {
                            FreeLibraryWindows(handle_);
                            handle = GetModuleHandleWindows(filename_);
                        }

                        if (handle != IntPtr.Zero)
                        {
                            Debug.LogWarning(String.Format(
                                                 "Unable to unload {0}. Please, restart Unity", filename_));
                        }
                    }
                }
                else if (platform == UnityEngine.RuntimePlatform.OSXEditor)
                {
                    FreeLibraryOSX(handle_);

                    IntPtr handle = GetModuleHandleOSX(filename_);
                    if (handle != IntPtr.Zero)
                    {
                        Debug.LogWarning(String.Format("Forcing unload of {0}", filename_));

                        int count = 0;
                        while (handle != IntPtr.Zero && count++ < 10)
                        {
                            FreeLibraryOSX(handle_);
                            handle = GetModuleHandleOSX(filename_);
                        }

                        if (handle != IntPtr.Zero)
                        {
                            Debug.LogWarning(String.Format(
                                                 "Unable to unload {0}. Please, restart Unity", filename_));
                        }
                    }
                }

                handle_ = IntPtr.Zero;
            }

            System.GC.SuppressFinalize(this);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 获取平台定义
        /// </summary>
        /// <param name="platform"></param>
        /// <returns></returns>
        public static TinaX.Const.PlatformConst.E_Platform GetPlatform(UnityEngine.RuntimePlatform platform)
        {
            switch (platform)
            {
            case UnityEngine.RuntimePlatform.WindowsPlayer:
                return(Const.PlatformConst.E_Platform.Windows64);

            case UnityEngine.RuntimePlatform.LinuxPlayer:
                return(Const.PlatformConst.E_Platform.Linux64);

            case UnityEngine.RuntimePlatform.OSXPlayer:
                return(Const.PlatformConst.E_Platform.OSX);

            case UnityEngine.RuntimePlatform.Android:
                return(Const.PlatformConst.E_Platform.Android);

            case UnityEngine.RuntimePlatform.IPhonePlayer:
                return(Const.PlatformConst.E_Platform.iOS);

            case UnityEngine.RuntimePlatform.XboxOne:
                return(Const.PlatformConst.E_Platform.XBox);

            case UnityEngine.RuntimePlatform.Switch:
                return(Const.PlatformConst.E_Platform.NSwitch);

            case UnityEngine.RuntimePlatform.WebGLPlayer:
                return(Const.PlatformConst.E_Platform.WebGL);

            case UnityEngine.RuntimePlatform.WSAPlayerARM:
                return(Const.PlatformConst.E_Platform.UWP);

            case UnityEngine.RuntimePlatform.WSAPlayerX64:
                return(Const.PlatformConst.E_Platform.UWP);

            case UnityEngine.RuntimePlatform.WSAPlayerX86:
                return(Const.PlatformConst.E_Platform.UWP);

            //EDITORS
            case UnityEngine.RuntimePlatform.WindowsEditor:
                return(Const.PlatformConst.E_Platform.Windows64);

            case UnityEngine.RuntimePlatform.LinuxEditor:
                return(Const.PlatformConst.E_Platform.Linux64);

            case UnityEngine.RuntimePlatform.OSXEditor:
                return(Const.PlatformConst.E_Platform.OSX);


            default:
                return(Const.PlatformConst.E_Platform.Windows64);
            }
        }
Exemplo n.º 5
0
        public static string GetPlatformName(UnityEngine.RuntimePlatform platform)
        {
            switch (platform)
            {
            case UnityEngine.RuntimePlatform.WindowsPlayer:
                return(Const.PlatformConst.E_Platform.Windows64.ToString());

            case UnityEngine.RuntimePlatform.LinuxPlayer:
                return(Const.PlatformConst.E_Platform.Linux64.ToString());

            case UnityEngine.RuntimePlatform.OSXPlayer:
                return(Const.PlatformConst.E_Platform.OSX.ToString());

            case UnityEngine.RuntimePlatform.Android:
                return(Const.PlatformConst.E_Platform.Android.ToString());

            case UnityEngine.RuntimePlatform.IPhonePlayer:
                return(Const.PlatformConst.E_Platform.iOS.ToString());

            case UnityEngine.RuntimePlatform.XboxOne:
                return(Const.PlatformConst.E_Platform.XBox.ToString());

            case UnityEngine.RuntimePlatform.Switch:
                return(Const.PlatformConst.E_Platform.NSwitch.ToString());

            case UnityEngine.RuntimePlatform.WebGLPlayer:
                return(Const.PlatformConst.E_Platform.WebGL.ToString());

            case UnityEngine.RuntimePlatform.WSAPlayerARM:
                return(Const.PlatformConst.E_Platform.UWP.ToString());

            case UnityEngine.RuntimePlatform.WSAPlayerX64:
                return(Const.PlatformConst.E_Platform.UWP.ToString());

            case UnityEngine.RuntimePlatform.WSAPlayerX86:
                return(Const.PlatformConst.E_Platform.UWP.ToString());

            //EDITORS
            case UnityEngine.RuntimePlatform.WindowsEditor:
                return(Const.PlatformConst.E_Platform.Windows64.ToString());

            case UnityEngine.RuntimePlatform.LinuxEditor:
                return(Const.PlatformConst.E_Platform.Linux64.ToString());

            case UnityEngine.RuntimePlatform.OSXEditor:
                return(Const.PlatformConst.E_Platform.OSX.ToString());


            default:
                return(Const.PlatformConst.E_Platform.Windows64.ToString());
            }
        }
Exemplo n.º 6
0
        public bool IsCompatible(UnityEngine.RuntimePlatform p)
        {
            if ((p == UnityEngine.RuntimePlatform.WindowsEditor) ||
                (p == UnityEngine.RuntimePlatform.WindowsPlayer) ||
                (p == UnityEngine.RuntimePlatform.OSXEditor) ||
                (p == UnityEngine.RuntimePlatform.OSXPlayer)
                //||(p==UnityEngine.RuntimePlatform.OSXDashboardPlayer)
                //||(p==UnityEngine.RuntimePlatform.LinuxPlayer)
                )
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 7
0
        static void GetPlatform(Collection <CustomAttribute> CustomAttributes, System.Action <UnityEngine.RuntimePlatform> action)
        {
            CustomAttribute custom;

            for (int i = 0; i < CustomAttributes.Count; ++i)
            {
                custom = CustomAttributes[i];
                if (custom.AttributeType.FullName != "wxb.Platform")
                {
                    continue;
                }

                var param = custom.ConstructorArguments[0];
                UnityEngine.RuntimePlatform platform = (UnityEngine.RuntimePlatform)System.Enum.Parse(typeof(UnityEngine.RuntimePlatform), (string)param.Value);
                action(platform);
            }
        }
Exemplo n.º 8
0
        public Library(string filename)
        {
            UnityEngine.RuntimePlatform platform = UnityEngine.Application.platform;
            if (platform == UnityEngine.RuntimePlatform.WindowsEditor)
            {
#if UNITY_EDITOR_64
                filename_ = filename + "_64.dll";
#else
                filename_ = filename + ".dll";
#endif

                // Verify that library is not already loaded, otherwise something went wrong
                if (GetModuleHandleWindows(filename_) != IntPtr.Zero)
                {
                    throw new Exception(String.Format("Critical problem, {0} already loaded", filename_));
                }

                handle_ = LoadLibraryWindows(filename_);

                if (handle_ == IntPtr.Zero)
                {
                    throw new Exception(String.Format("LoadLibrary {0}", filename_));
                }
            }
            else if (platform == UnityEngine.RuntimePlatform.OSXEditor)
            {
                filename_ = filename + ".bundle/Contents/MacOS/Noesis";

                if (GetModuleHandleOSX(filename_) != IntPtr.Zero)
                {
                    throw new Exception(String.Format("Critical problem, {0} already loaded", filename_));
                }

                handle_ = LoadLibraryOSX(filename_);

                if (handle_ == IntPtr.Zero)
                {
                    throw new Exception(String.Format("dlopen {0}", filename + ".bundle"));
                }
            }
            else
            {
                throw new Exception(String.Format("Platform {0} not supported", UnityEngine.Application.platform));
            }
        }
Exemplo n.º 9
0
    public static void EncodeLuaFileForEditor(string srcFile, string outFile, UnityEngine.RuntimePlatform platform)
    {
        bool   isWin   = true;
        string luaexe  = string.Empty;
        string args    = string.Empty;
        string exedir  = string.Empty;
        string currDir = Directory.GetCurrentDirectory();

        if (platform == RuntimePlatform.WindowsEditor)
        {
            isWin  = true;
            luaexe = "luajit.exe";
            args   = "-b " + srcFile + " " + outFile;
            exedir = Application.dataPath.ToLower().Replace("assets", "") + "LuaEncoder/luajit/";
        }
        else if (platform == RuntimePlatform.OSXEditor)
        {
            isWin  = false;
            luaexe = "./luac";
            //args = "-o " + outFile + " " + srcFile;
            args   = "-b " + srcFile + " " + outFile;
            exedir = Application.dataPath.ToLower().Replace("assets", "") + "LuaEncoder/luavm/";
        }

        Directory.SetCurrentDirectory(exedir);
        System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
        info.FileName        = luaexe;
        info.Arguments       = args;
        info.WindowStyle     = System.Diagnostics.ProcessWindowStyle.Hidden;
        info.ErrorDialog     = true;
        info.UseShellExecute = isWin;

        System.Diagnostics.Process pro = System.Diagnostics.Process.Start(info);
        pro.WaitForExit();
        Directory.SetCurrentDirectory(currDir);
    }
Exemplo n.º 10
0
        //public object DefaultFontSelector(object parameters, params string []xx) { return null;}

        public bool IsCompatible(UnityEngine.RuntimePlatform p)
        {
            return((p == RuntimePlatform.Android) || (p == RuntimePlatform.IPhonePlayer));
        }
Exemplo n.º 11
0
 public bool IsConsideredEmbedded(UnityEngine.RuntimePlatform p)
 {
     return(false);
 }
Exemplo n.º 12
0
 public bool IsConsideredNative(UnityEngine.RuntimePlatform p)
 {
     return(true);
 }
Exemplo n.º 13
0
        // 自动注册
        static void AutoReplace(List <IType> types)
        {
            Dictionary <string, List <MethodInfo> > NameToSorted = new Dictionary <string, List <MethodInfo> >();
            List <UnityEngine.RuntimePlatform>      platforms    = new List <UnityEngine.RuntimePlatform>();

            UnityEngine.RuntimePlatform rp = GetCurrentPlatform();
            foreach (var ator in types)
            {
                ILType type = ator as ILType;
                if (type == null)
                {
                    continue;
                }

                NameToSorted.Clear();
                var         typeDefinition = type.TypeDefinition;
                System.Type rt             = GetReplaceType(typeDefinition.CustomAttributes);
                platforms.Clear();
                GetPlatform(typeDefinition.CustomAttributes, (p) => { platforms.Add(p); });
                if (platforms.Count != 0 && !platforms.Contains(rp))
                {
                    wxb.L.LogWarningFormat("platorms:{0} type:{1} not hotfix!", rp, type.Name);
                    continue; // 不属于此平台的
                }
                // 相同函数名排序问题
                foreach (var il in type.GetMethods())
                {
                    var ilMethod = il as ILMethod;
                    if (ilMethod == null)
                    {
                        continue;
                    }

                    var         method = ilMethod.Definition;
                    System.Type methodType;
                    string      methodFieldName;
                    if (!GetReplaceFunction(method.CustomAttributes, out methodType, out methodFieldName))
                    {
                        continue;
                    }

                    if (!ilMethod.IsStatic)
                    {
                        wxb.L.LogErrorFormat("type:{0} method:{1} is not static fun!", type.Name, method.Name);
                        continue;
                    }

                    platforms.Clear();
                    GetPlatform(method.CustomAttributes, (p) => { platforms.Add(p); });
                    if (platforms.Count != 0 && !platforms.Contains(rp))
                    {
                        wxb.L.LogWarningFormat("platorms:{0} type:{1}.{2} not hotfix!", rp, type.Name, ilMethod.Name);
                        continue; // 不属于此平台的
                    }

                    System.Type srcType = methodType != null ? methodType : rt;
                    if (srcType == null)
                    {
                        wxb.L.LogErrorFormat("type:{0} method:{1} not set srcType!", type.Name, method.Name);
                        continue;
                    }

                    string fieldName = methodFieldName;
                    if (string.IsNullOrEmpty(fieldName))
                    {
                        fieldName = "__Hotfix_" + method.Name;
                    }

                    var field = srcType.GetField(fieldName, bindingFlags);
                    if (field == null)
                    {
                        wxb.L.LogErrorFormat("hotType:{0} method:{1} not find srcType:{2}.{3} hot field!", type.Name, method.Name, srcType.FullName, fieldName);
                        continue;
                    }

                    var bridge = new global::IL.DelegateBridge(ilMethod.ReflectionMethodInfo);
                    field.SetValue(null, bridge);
                    Fields.Add(field);
                    wxb.L.LogFormat("type:{0} method:{1} Replace {2}.{3}!", type.Name, method.Name, srcType.Name, fieldName);

                    AutoSetFieldMethodValue(srcType, field, type, fieldName, bridge, NameToSorted);
                }
            }
        }
Exemplo n.º 14
0
 public bool IsCompatible(UnityEngine.RuntimePlatform p)
 {
     return(true);
 }
Exemplo n.º 15
0
        //public object DefaultFontSelector(object parameters, params string []xx) { return null;}

        public bool IsCompatible(UnityEngine.RuntimePlatform p)
        {
            return(true);
            //TextMesh tm;
            //tm.
        }
Exemplo n.º 16
0
        //public object DefaultFontSelector(object parameters, params string []xx) { return null;}

        public bool IsCompatible(UnityEngine.RuntimePlatform p)
        {
            return(p == RuntimePlatform.Android);
        }