2025-06-04 05:02:57 +08:00

359 lines
11 KiB
Plaintext

Game = class("Game")
Game.GameObjectType = {
Camera = 1,
Light = 2,
RoomHideObject = 3,
SceneObjectFinder = 4,
SceneAnimation = 5,
LocalNPC = 6,
DynamicObject = 7,
CullingObject = 8,
SceneSeat = 9,
ScenePhotoFrame = 10,
SceneGuildFlag = 11,
WeddingPhotoFrame = 12,
}
Game.EState = {
Running = 1,
Finished = 2,
}
autoImport ("DataStructureManager")
autoImport ("FunctionSystemManager")
autoImport ("GUISystemManager")
autoImport ("GCSystemManager")
autoImport ("GOManager_Camera")
autoImport ("GOManager_Light")
autoImport ("GOManager_Room")
autoImport ("GOManager_SceneObject")
autoImport ("GOManager_LocalNPC")
autoImport ("GOManager_DynamicObject")
autoImport ("GOManager_CullingObject")
autoImport ("GOManager_SceneSeat")
autoImport ("GOManager_ScenePhotoFrame")
autoImport ("GOManager_SceneGuildFlag")
autoImport ("GOManager_WeddingPhotoFrame")
-- GameFunctions begin
autoImport ("PreprocessHelper")
autoImport ("Preprocess_Table")
autoImport ("Preprocess_SceneInfo")
autoImport ("Preprocess_EnviromentInfo")
autoImport ("Game_Interface_ForCSharp")
-- GameFunctions end
autoImport ("OverSeaFunc")
local ResolutionPool = {2160,1440,1080,720,540}
local ResolutionTextPool = {"4K","2K","1080p","720p","540p"}
local RefreshRatePool = { 60, 90, 120 }
local RefreshRateTextPool = { "60 Hz", "90 Hz", "120 Hz" }
local ResolutionGap = 100
Game.SwitchRoleScene = "SwitchRoleLoader"
Game.Param_SwitchRole = "Param_SwitchRole"
function Game.Me(param)
if nil == Game.me then
Game.me = Game.new(param)
end
return Game.me
end
function Game.GetResolutionNames()
return Game.ScreenResolutionTexts
end
function Game.GetRefreshRateNames()
return Game.ScreenRefreshRateTexts
end
function Game.SetResolution(index)
if nil == Game.ScreenResolutions or 0 >= #Game.ScreenResolutions then
return
end
index = RandomUtil.Clamp( index, 1, #Game.ScreenResolutions )
if 1 > index then
index = 1
end
local resolution = Game.ScreenResolutions[index]
Screen.SetResolution(resolution[1], resolution[2], true)
end
function Game.InitAppIsInReview()
local inAppStoreReview = false
local verStr = VersionUpdateManager.serverResJsonString
if(verStr~=nil and verStr~='')then
local result = StringUtil.Json2Lua(verStr)
if(result and result["data"])then
local data = result["data"]
local res = data["inAppStoreReview"]
if(res) then
if(type(res)=="string") then
if(res=="true") then
inAppStoreReview = true
end
elseif(type(res)=="boolean")then
inAppStoreReview = res
end
end
end
end
Game.inAppStoreReview = inAppStoreReview
end
function Game.SetRefreshRate(index)
local refreshRate = Game.ScreenRefreshRates[index]
UnityEngine.Application.targetFrameRate = refreshRate[1]
end
function Game:ctor(param)
Game.State = Game.EState.Running
-- 0. game config
local screenWidth = LuaLuancher.originalScreenWidth
local screenHeight = LuaLuancher.originalScreenHeight
Game.ScreenResolutions = {
{screenWidth, screenHeight}
}
Game.ScreenResolutionTexts = {
ZhString.OriginalResolution
}
Game.ScreenRefreshRates = {}
Game.ScreenRefreshRateTexts = {}
for i=1, #ResolutionPool do
-- if ResolutionPool[i]+ResolutionGap < screenHeight then
TableUtility.ArrayPushBack(
Game.ScreenResolutions,
{
math.ceil(ResolutionPool[i]*screenWidth/screenHeight),
ResolutionPool[i]
})
TableUtility.ArrayPushBack(
Game.ScreenResolutionTexts,
ResolutionTextPool[i])
-- end
end
for i = 1, #RefreshRatePool do
TableUtility.ArrayPushBack(
Game.ScreenRefreshRates,
{
RefreshRatePool[i]
})
TableUtility.ArrayPushBack(
Game.ScreenRefreshRateTexts,
RefreshRateTextPool[i])
end
LogUtility.SetEnable(ROLogger.enable)
LogUtility.SetTraceEnable(ROLogger.enable)
local luaLuancher = LuaLuancher.Instance
self.prefabs = luaLuancher.prefabs
self.objects = luaLuancher.objects
UnityEngine.Application.targetFrameRate = 60
UnityEngine.Screen.sleepTimeout = -1;
LeanTween.init( 1000 )
Game.InitAppIsInReview()
-- 1. preprocess config and table
Game.Preprocess_Table()
-- Game.Preprocess_SceneInfo() -- preprocess when switching map
-- Game.Preprocess_EnviromentInfo() -- preprocess when setting enviroment
-- 2. create managers
self.dataStructureManager = DataStructureManager.new()
self.functionSystemManager = FunctionSystemManager.new()
self.guiSystemManager = GUISystemManager.new()
self.gcSystemManager = GCSystemManager.new()
-- 3. register GameObject managers
local gameObjectManagers = {}
gameObjectManagers[Game.GameObjectType.Camera] = GOManager_Camera.new()
gameObjectManagers[Game.GameObjectType.Light] = GOManager_Light.new()
gameObjectManagers[Game.GameObjectType.RoomHideObject] = GOManager_Room.new()
local sceneObjectManager = GOManager_SceneObject.new()
gameObjectManagers[Game.GameObjectType.SceneObjectFinder] = sceneObjectManager
gameObjectManagers[Game.GameObjectType.SceneAnimation] = sceneObjectManager
gameObjectManagers[Game.GameObjectType.LocalNPC] = GOManager_LocalNPC.new()
gameObjectManagers[Game.GameObjectType.DynamicObject] = GOManager_DynamicObject.new()
gameObjectManagers[Game.GameObjectType.CullingObject] = GOManager_CullingObject.new()
gameObjectManagers[Game.GameObjectType.SceneSeat] = GOManager_SceneSeat.new()
gameObjectManagers[Game.GameObjectType.ScenePhotoFrame] = GOManager_ScenePhotoFrame.new()
gameObjectManagers[Game.GameObjectType.SceneGuildFlag] = GOManager_SceneGuildFlag.new()
gameObjectManagers[Game.GameObjectType.WeddingPhotoFrame] = GOManager_WeddingPhotoFrame.new()
self.gameObjectManagers = gameObjectManagers
-- 4. set global objects
Game.Instance = self
Game.Prefab_RoleComplete = self.prefabs[1]:GetComponent(RoleComplete)
Game.Prefab_SceneSeat = self.prefabs[2]:GetComponent(LuaGameObjectClickable)
Game.Prefab_ScenePhoto = self.prefabs[3]:GetComponent(Renderer)
Game.Prefab_SceneGuildIcon = self.prefabs[4]:GetComponent(Renderer)
Game.Object_Rect = self.objects[1]
Game.Object_GameObjectMap = self.objects[2]
Game.Object_AudioSource2D = self.objects[3]
-- c#
Game.ShaderManager = ShaderManager.Instance
Game.RolePartMaterialManager = RolePartMaterialManager.Instance
Game.RoleFollowManager = RoleFollowManager.Instance
Game.TransformFollowManager = TransformFollowManager.Instance
Game.InputManager = InputManager.Instance
Game.CameraPointManager = CameraPointManager.Instance
-- Game.RoomPointManager = RoomPointManager.Instance
Game.BusManager = BusManager.Instance
Game.Map2DManager = Map2DManager.Instance
Game.ResourceManager = ResourceManager.Instance
Game.NetConnectionManager = NetConnectionManager.Instance
Game.NetConnectionManager.EnableLog = false
-- Game.FunctionLoginMono = FunctionLoginMono.Instance
Game.InternetUtil = InternetUtil.Ins
Game.NetIngFileTaskManager = NetIngFileTaskManager.Ins
Game.HttpWWWRequest = HttpWWWRequest.Instance
Game.FarmlandManager = FarmlandManager.Ins
Game.GameObjectManagers = self.gameObjectManagers
Game.DataStructureManager = self.dataStructureManager
Game.FunctionSystemManager = self.functionSystemManager
Game.GUISystemManager = self.guiSystemManager
Game.GCSystemManager = self.gcSystemManager
-- 5. preload
Game.AssetManager_Role:PreloadComplete(200)
-- 6. game real start
NetConnectionManager.Instance:Restart()
GameFacade.Instance:registerCommand(StartEvent.StartUp, StartUpCommand)
-- ProtocolStatistics.Instance():Start()
GameFacade.Instance:sendNotification(StartEvent.StartUp)
FunctionInteractionGrass.Ins():Open()
--<RB>purchase from app store
if not BackwardCompatibilityUtil.CompatibilityMode_V19 then
AppStorePurchase.Ins():AddListener()
end
--<RE>purchase from app store
if(param == nil) then
SceneProxy.Instance:SyncLoad('CharacterChoose')
GameFacade.Instance:sendNotification(UIEvent.ShowUI,{viewname = "StartGamePanel"})
elseif(Game.Param_SwitchRole == param) then
GameFacade.Instance:sendNotification(UIEvent.ShowUI,{viewname = "SwitchRolePanel"})
end
DiskFileHandler.Ins():EnterRoot()
DiskFileHandler.Ins():EnterExtension()
DiskFileHandler.Ins():EnterPublicPicRoot()
DiskFileHandler.Ins():EnterActivityPicture()
DiskFileHandler.Ins():EnterLotteryPicture()
FunctionsCallerInMainThread.Ins:Call(nil)
CloudFile.CloudFileManager.Ins:Open()
Game.MapManager:SetInputDisable(true)
math.randomseed(tostring(os.time()):reverse():sub(1, 6))
end
function Game:End(toScene,keepResManager)
local list = LuaUtils.CreateStringList()
if ApplicationInfo.IsRunOnEditor() then
else
ROPush.SetTags(os.time(), list)
end
toScene = toScene or "Launch"
Game.State = Game.EState.Finished
Game.isSecurityDevice = false
local netError = FunctionNetError.Me()
netError:DisConnect()
NetManager.GameClose()
UpYunNetIngFileTaskManager.Ins:Close();
CloudFile.CloudFileManager.Ins:Close()
DiskFileManager.Instance:Reset()
FrameRateSpeedUpChecker.Instance():Close()
if not BackwardCompatibilityUtil.CompatibilityMode_V19 then
AppStorePurchase.Ins():ClearCallbackAppStorePurchase()
end
netError:Clear()
if(Game.Myself) then
Game.Myself:Destroy()
Game.Myself = nil
end
UIModelUtil.Instance:Reset()
UIMultiModelUtil.Instance:Reset()
FunctionAppStateMonitor.Me():Reset()
HttpWWWRequest.Instance:Clear()
local independentTestGo = GameObject.Find("IndependentTest (delete)")
if(independentTestGo~=nil) then
GameObject.Destroy(independentTestGo)
end
FunctionPreload.Me():Reset()
if(LuaLuancher.Instance) then
GameObject.Destroy(LuaLuancher.Instance.monoGameObject)
end
if(not keepResManager) then
self:_DisposeResManager()
end
local shaderManager = GameObject.Find("ShaderManager(Clone)")
if (shaderManager) then
GameObject.Destroy(shaderManager)
end
local ImageCrop = GameObject.Find("ImageCrop")
if (ImageCrop) then
GameObject.Destroy(ImageCrop)
end
LeanTween.CancelAll()
LuaTimer.DeleteAll()
FunctionGetIpStrategy.Me():GameEnd()
SceneUtil.SyncLoad(toScene)
-- if (IndependentTest.Me != null) {
-- GameObject.Destroy (IndependentTest.Me.gameObject);
-- }
-- if (MyLuaSrv.Instance != null) {
-- MyLuaSrv.Instance.Dispose ();
-- }
-- if (SkillManager.Me != null) {
-- SkillManager.Me.Reset ();
-- }
-- Player.Reset ();
-- RoleControllerLua.ResetFactory ();
end
function Game:_DisposeResManager()
ResourceManager.Instance:DestroySelf()
GameObject.Destroy(ResourceManager.Instance.monoGameObject)
end
function Game:BackToSwitchRole()
if(CameraController.Instance ~= nil and CameraController.Instance.monoGameObject ~= nil) then
CameraController.Instance.monoGameObject:SetActive(false)
end
EventManager.Me():DispatchEvent(AppStateEvent.BackToLogo)
if(ApplicationHelper.AssetBundleLoadMode) then
ResourceManager.Instance:SLoadScene(Game.SwitchRoleScene)
end
self:End(Game.SwitchRoleScene,true)
self:_DisposeResManager()
end
function Game:BackToLogo()
-- helplog("Game:BackToLogo")
EventManager.Me():DispatchEvent(AppStateEvent.BackToLogo)
self:End()
end
function Game:BackToLogin()
-- helplog("Game:BackToLogin")
UpYunNetIngFileTaskManager.Ins:Close();
FrameRateSpeedUpChecker.Instance():Close()
GameFacade.Instance:sendNotification(FunctionNetError.BackToLogin)
FunctionSelectCharacter.Me():Shutdown()
GameFacade.Instance:sendNotification(UIEvent.ShowUI,{viewname = "StartGamePanel"})
end