/// <summary> /// 启动 /// </summary> public static void setup(GameObject root, Action exitRun = null) { if (_inited) { return; } _inited = true; _root = root; GameObject.DontDestroyOnLoad(_root); _exitRun = exitRun; _rootBehavious = _root.AddComponent <ShineBehavious>(); SystemControl.init(); ThreadControl.init(); DateControl.init(); NetControl.init(); BytesControl.init(); //显示部分 if (ShineSetting.isWholeClient) { SKeyboardControl.init(); STouchControl.init(); UIControl.init(); CameraControl.init(); Tween.init(); LoadControl.init(); ResourceInfoControl.init(); AssetPoolControl.init(); } else { //gm指令所需 if (ShineSetting.needGMCommandUI) { SKeyboardControl.init(); STouchControl.init(); UIControl.init(); } ShineSetting.debugJumpResourceVersion = true; ResourceInfoControl.initBase(); } }
public static void setupForEditor() { SystemControl.init(); DateControl.init(); BytesControl.init(); if (ShineSetting.isWholeClient) { ResourceInfoControl.init(); } else { ResourceInfoControl.initBase(); } }
/** io出错(1:wwwError,2:超时,3:不完整) */ private void toIoError(int type) { //把www停了 if (_www != null) { _www.Dispose(); _www = null; } Ctrl.print("io出错:" + type, _url); //本地缓存资源被删除了 if (_loadMethod == LoadMethodType.Resource && _currentSaveData != null && _currentSaveData.state == ResourceSaveStateType.Downloaded) { //改成cdn下载 _currentSaveData.state = ResourceSaveStateType.None; ResourceInfoControl.versionModified(); _useURL = ResourceInfoControl.getCDNResourcePath(_url, _currentSaveData.version); _needCache = true; toReload(); } else { if (_tryForever) { //等2秒 _tryWaitTime = _ioErrorWaitTime; } else { unload(); if (_ioErrorCall != null) { _ioErrorCall(); } } } }
/** 缓存到持久化目录 */ private void resourceCache() { if (ShineSetting.debugJumpResourceVersion) { return; } if (_www != null) { //缓存 FileUtils.writeFileForBytes(ResourceInfoControl.getPersistentPath(_url, false), _www.bytes); _currentSaveData.state = ResourceSaveStateType.Downloaded; ResourceInfoControl.versionModified(); } else if (_webRequest != null) { // _webRequest. } else { Ctrl.errorLog("ShineLoader,resourceCache时,没有可用对象"); } }
/** 执行加载 */ private void toLoad() { _needSize = 0; switch (_loadMethod) { case LoadMethodType.Resource: { if (ShineSetting.debugJumpResourceVersion || ShineSetting.localLoadWithOutBundle) { _needSize = 0; _useURL = ResourceInfoControl.getStreamingAssetsPath(_url, true); _resourceType = ResourceType.Unknown; } else { if ((_currentSaveData = ResourceInfoControl.getResourceSaveData(_url)) == null) { Ctrl.throwError("不该找不到资源数据", _url); return; } _resourceType = _currentSaveData.getType(); bool isBundle = _resourceType == ResourceType.Bundle; _needSize = _currentSaveData.size; //从steamingAsset中加载 if (_currentSaveData.state == ResourceSaveStateType.StreamingAssetsReady) { _useURL = ResourceInfoControl.getStreamingAssetsPath(_url, !isBundle); } //从持久化中加载 else if (_currentSaveData.state == ResourceSaveStateType.Downloaded) { _useURL = ResourceInfoControl.getPersistentPath(_url, !isBundle); } //需要加载 else { _useURL = ResourceInfoControl.getCDNResourcePath(_url, _currentSaveData.version); _needCache = true; } } } break; case LoadMethodType.StreamingAssets: { _useURL = ResourceInfoControl.getStreamingAssetsPath(_url, true); _resourceType = ResourceType.Unknown; } break; default: { _useURL = _url; _resourceType = ResourceType.Unknown; } break; } _reloadTimes = 0; //标记开始加载 _loadState = LoadState_Loading; resetTimeOut(); toDoLoad(); }