--- --- Generated by EmmyLua(https://github.com/EmmyLua) --- Created by Administrator. --- DateTime: 2022/5/30 11:36 --- local Loader = {} local BinaryFile = require("Binary/BinaryFile") local BinaryBytes = require("Binary/BinaryBytes") local LoaderType = { Bundle = 1, File = 2 } local UnityApplication = CS.UnityEngine.Application local UnityRuntimePlatform = CS.UnityEngine.RuntimePlatform local ExternalAgent = CS.BinaryExternalAgent; function Loader.New(path) local loader = {} setmetatable(loader, { __index = Loader }) local res = loader:Ctor(path) if not res then return nil end return loader; end function Loader:InitFromFile(filePath) self.FileBinary = BinaryFile.New(filePath) self.Type = LoaderType.File return self.FileBinary ~= nil end function Loader:InitFromBytes(filePath) self.Type = LoaderType.Bundle self.BytesBinary = BinaryBytes.New(self.TablePath) if ExternalAgent.USE_EXTERNAL_FILE == 1 and self.BytesBinary ~= nil and filePath ~= nil and filePath ~= "" then ExternalAgent.PushToExternal(filePath, self.BytesBinary.Bytes) end return self.BytesBinary ~= nil end function Loader:Ctor(path) self.TablePath = path self.LoadCount = 0 if UnityApplication.platform == UnityRuntimePlatform.Android or UnityApplication.platform == UnityRuntimePlatform.IPhonePlayer or XMain.IsWindowsEditor then if ExternalAgent.USE_EXTERNAL_FILE == 1 then local hasExternal, filePath = ExternalAgent.TryGetExternalFile(path) if hasExternal then return self:InitFromFile(filePath) else return self:InitFromBytes(filePath) end else return self:InitFromBytes() end else return self:InitFromBytes() end end function Loader:GetLen() if self.Type == LoaderType.Bundle then return self.BytesBinary:GetLen() else return self.FileBinary:GetLen() end end function Loader:ReadInt() if self.Type == LoaderType.Bundle then return self.BytesBinary:ReadInt() else return self.FileBinary:ReadInt() end end function Loader:GetReader(len, offset) if self.Type == LoaderType.Bundle then return self.BytesBinary:GetReader(len, offset) else return self.FileBinary:GetReader(len, offset) end end function Loader:Close() if self.Type == LoaderType.Bundle then return self.BytesBinary:Close() else return self.FileBinary:Close() end end return Loader;