public string GetFormatBundleName(string formatPath, string assetPath) { if (!string.IsNullOrEmpty(formatPath)) { string assetRootPath = Path.GetDirectoryName(assetPath); string assetEx = Path.GetExtension(assetPath); string assetName = Path.GetFileName(assetPath); string assetNameNotEx = Path.GetFileNameWithoutExtension(assetPath); string assetFlatPath = GetFlatPath(assetPath); string assetKey = XStringTools.SplitPathKey(assetPath); string nameFormat = formatPath; nameFormat = nameFormat.Replace("{assetRootPath}", assetRootPath); nameFormat = nameFormat.Replace("{assetEx}", assetEx); nameFormat = nameFormat.Replace("{assetNameNotEx}", assetNameNotEx); nameFormat = nameFormat.Replace("{assetName}", assetName); nameFormat = nameFormat.Replace("{assetKey}", assetKey); nameFormat = nameFormat.Replace("{assetFlatPath}", assetFlatPath); if (isRidofSpecialChar) { nameFormat = AssetPathUtil.TrimInvalidCharacter(nameFormat); } return(nameFormat); } return(null); }
public void Awake() { _instance = this; Debuger.EnableLog = false; Application.targetFrameRate = 50; isOpenMicrophone = true; Screen.sleepTimeout = SleepTimeout.NeverSleep; //保留主程序 GameObject.DontDestroyOnLoad(gameObject); VersionManager.localVersion = Application.version; //Bugly、友盟等对接 SDKManager.SetupBugly(); // LayerManager.Setup(); AssetPathUtil.Setup(); LoaderManager.Setup(); AlertUI.Setup(); PopManager.Setup(); /** * _loadingView = GameObject.Find("UI_Loading").AddComponent<SceneLoadingPanel>(); * m_NOTICEUI = LayerManager.topUILayer.Find("NoticeUI").gameObject.AddComponent<NoticeUI>(); * m_NOTICEUI.Online(); * _loadingView.SetTitle("正在检查游戏版本..."); */ }
private static void StartLoad(LoadTask task) { string abName = task.abName; //先加载依赖AB string[] dependenciesAB = _manifest.GetAllDependencies(abName); foreach (string dpdAB in dependenciesAB) { if (_abDic.ContainsKey(dpdAB)) { continue; } task.dependencies.Add(dpdAB); if (_loadingABCountDic.ContainsKey(dpdAB)) { _loadingABCountDic[dpdAB]++; continue; } _loadingABCountDic.Add(dpdAB, 1); string relativePath = AssetPathUtil.PlatformString + "/" + dpdAB; string dpdUrl; if (VersionManager.HasCache(relativePath)) { dpdUrl = VersionManager.GetPath(relativePath); } else { dpdUrl = AssetPathUtil.GetAssetBundlePath(dpdAB); } LoaderManager.Load(dpdUrl, EnumResouceType.ASSETBUNDLE, OnABLoadComplete); } if (task.IsDependenciesLoadComplete()) { if (!_loadingABCountDic.ContainsKey(abName)) { _loadingABCountDic.Add(abName, 1); string relativePath = AssetPathUtil.PlatformString + "/" + abName; string abUrl; if (VersionManager.HasCache(relativePath)) { abUrl = VersionManager.GetPath(relativePath); } else { abUrl = AssetPathUtil.GetAssetBundlePath(abName); } LoaderManager.Load(abUrl, EnumResouceType.ASSETBUNDLE, OnABLoadComplete); } else { _loadingABCountDic[task.abName]++; } } }
private static void UnloadLoadingAB(string abName) { if (_loadingABCountDic.ContainsKey(abName)) { _loadingABCountDic[abName]--; if (_loadingABCountDic[abName] == 0) { _loadingABCountDic.Remove(abName); LoaderManager.Unload(AssetPathUtil.GetAssetBundlePath(abName), OnABLoadComplete); } } }
public void Show(object obj = null) { _showData = obj; if (_module != null) { _module.Show(obj); } else { _path = AssetPathUtil.GetUI(_name); ResourceManager.GetResource(_path, OnGetAppModule); } }
/// <summary> /// 创建一条路径 /// </summary> public bool CreateRoute() { pointList.Clear(); pointIndex = 1; currentIndex = 0; pointList.Add(Player.transform.localPosition); // Vector3 axis = new Vector3(0, 0, 1); int dir = Random.Range(0, 2) == 0 ? 1 : -1; Vector3 ov = this.player.Direction * moveDis; Vector3 v1 = ov; Vector3 v3 = Quaternion.AngleAxis(90 * dir, axis) * v1; Vector3 v2 = v1 + v3; pointList.Add(Player.transform.localPosition + v1); pointList.Add(Player.transform.localPosition + v2); pointList.Add(Player.transform.localPosition + v3); GameObject go = Resources.Load <GameObject>(AssetPathUtil.GetPlayerPath(0)); for (int i = 1; i < pointList.Count; i++) { //GameObject o = GameObject.Instantiate<GameObject>(go); //o.transform.localPosition = pointList[i]; //o.transform.SetParent(LayerManager.mapLayer, false); } isRandomDir = false; foreach (var item in pointList) { if (MapManager.GetGridByPos(item) == null || MapManager.IsNearSideByPos(item)) { return(false); } } _isCreateRoute = true; return(true); }
public static void SwitchProjectToURP() { #if URP_PACKAGE_IS_INSTALLED // Create default URP render pipeline asset (if it doesn't already exist). // // The #if/#else is needed here because Unity renamed `ForwardRendererData` // to `UniversalRendererData` in Unity 2021.2. #if UNITY_2021_2_OR_NEWER UniversalRendererData rendererData = null; if (!AssetPathUtil.Exists(URP_RENDERER_ASSET_PATH)) { rendererData = ScriptableObject.CreateInstance <UniversalRendererData>(); AssetDatabase.CreateAsset(rendererData, URP_RENDERER_ASSET_PATH); // reload asset so that object reference is "backed" by asset file rendererData = AssetDatabase.LoadAssetAtPath <UniversalRendererData>(URP_RENDERER_ASSET_PATH); } #else ForwardRendererData rendererData = null; if (!AssetPathUtil.Exists(URP_RENDERER_ASSET_PATH)) { rendererData = ScriptableObject.CreateInstance <ForwardRendererData>(); AssetDatabase.CreateAsset(rendererData, URP_RENDERER_ASSET_PATH); // reload asset so that object reference is "backed" by asset file rendererData = AssetDatabase.LoadAssetAtPath <ForwardRendererData>(URP_RENDERER_ASSET_PATH); } #endif RenderPipelineAsset renderPipeline = null; if (!AssetPathUtil.Exists(URP_PIPELINE_ASSET_PATH)) { renderPipeline = UniversalRenderPipelineAsset.Create(rendererData); AssetDatabase.CreateAsset(renderPipeline, URP_PIPELINE_ASSET_PATH); } // reload asset so that object reference is "backed" by asset file renderPipeline = AssetDatabase.LoadAssetAtPath <RenderPipelineAsset>(URP_PIPELINE_ASSET_PATH); GraphicsSettings.renderPipelineAsset = renderPipeline; // Set color space to linear to match Unity's // default setting for new URP projects. PlayerSettings.colorSpace = ColorSpace.Linear; #endif }
/// <summary> /// 开始预加载assetbundle /// </summary> /// <param name="abName"></param> /// <param name="OnLoadComplete">参数为AssetBundle</param> private static void PreloadAssetBundle(string abName) { if (_abDic.ContainsKey(abName)) { PreloadNext(); return; } string relativePath = AssetPathUtil.PlatformString + "/" + abName; if (VersionManager.HasCache(relativePath)) { LoaderManager.Load(VersionManager.GetPath(relativePath), EnumResouceType.ASSETBUNDLE, OnPreloadOne); } else { LoaderManager.Load(AssetPathUtil.GetAssetBundlePath(abName), EnumResouceType.ASSETBUNDLE, OnPreloadOne); } }
public Player() { tree = AIManager.GetTree(this); mineList = new List <MapGrid>(); GameObject go = Resources.Load <GameObject>(AssetPathUtil.GetPlayerPath(0)); obj = GameObject.Instantiate <GameObject>(go); spRender = obj.GetComponent <SpriteRenderer>(); spRender.sortingLayerName = LayerUtil.SORTING_LAYER_PLAYER; Color = new Color(156 / 255F, 255 / 255f, 137 / 255f); checkGrid = new CheckGrid(this); //_direction = new Vector3(-0.3f, -1, 0).normalized; }
/// <summary> /// 打开界面 /// </summary> /// <param name="windowEnum"></param> /// <param name="userData"></param> public void OpenWindow(WindowEnum windowEnum, object userData = null) { WindowConfig config = WindowConfigList.Instance.GetConfig((int)windowEnum); WindowGroupComponent windowGroupComponent = m_WindowGroupComponents[config.WindowGroup]; if (config.Singleton) { WindowBaseView windowBase = GetWindow(windowEnum); if (windowBase != null) { return; } } windowModel.AddOpenWindowData(windowEnum, userData); string assetPath = AssetPathUtil.GetWindowAssetPath(config.AssetName); Addressables.InstantiateAsync(assetPath, windowGroupComponent.transform, false).Completed += (aoh) => { Debug.LogWarning("111"); WindowBaseView baseWindow = aoh.Result.GetOrAddComponent <WindowBaseView>(); baseWindow.config = config; if (config.PauseCovered) { LinkedList <WindowBaseView> allWindows = windowGroupComponent.GetAllWindows(); foreach (WindowBaseView window in allWindows) { if (window.isActiveAndEnabled) { window.gameObject.SetActive(false); } } } windowGroupComponent.AddWindow(baseWindow); MobiusMediator mobiusMediator = aoh.Result.GetComponent <MobiusMediator>(); mobiusMediator.windowEnum = windowEnum; Debug.LogWarning("222"); }; }
public static string GetAbAssetRoot() { return(s_abAssetRootWithPlatform ?? Path.Combine(AB_ASSET_ROOT, AssetPathUtil.GetCurPlatformName()).ToLower()); }
private static void OnABLoadComplete(object content) { AssetBundle ab = (AssetBundle)content; _abDic.Add(ab.name, ab); _loadingABCountDic.Remove(ab.name); foreach (LoadTask task in _taskDic.Values) { if (task.IsDependenciesLoadComplete() && ab.name == task.abName) { _loadedTask.Add(task); } else if (task.dependencies.Contains(ab.name)) { task.dependencies.Remove(ab.name); if (task.IsDependenciesLoadComplete()) { if (!_loadingABCountDic.ContainsKey(task.abName)) { _loadingABCountDic.Add(task.abName, 1); string relativePath = AssetPathUtil.PlatformString + "/" + task.abName; string abUrl; if (VersionManager.HasCache(relativePath)) { abUrl = VersionManager.GetPath(relativePath); } else { abUrl = AssetPathUtil.GetAssetBundlePath(task.abName); } LoaderManager.Load(abUrl, EnumResouceType.ASSETBUNDLE, OnABLoadComplete); } else { _loadingABCountDic[task.abName]++; } } } } foreach (LoadTask task in _loadedTask) { _taskDic.Remove(task.resCallback); object obj;// = ab.LoadAsset(StringUtil.GetFileName(task.resPath)); if (!_assetDic.ContainsKey(task.resPath)) { obj = ab.LoadAsset(Path.GetFileNameWithoutExtension(task.resPath)); _assetDic.Add(task.resPath, obj); if (task.isFinishUnload) { string[] names = ab.GetAllAssetNames(); foreach (string assName in names) { string resPath = FileUtil.GetRelativeResourcePath(assName); if (_assetDic.ContainsKey(resPath)) { continue; } _assetDic.Add(resPath, ab.LoadAsset(Path.GetFileNameWithoutExtension(resPath))); } _abDic.Remove(ab.name); ab.Unload(false); } } else { obj = _assetDic[task.resPath]; } task.resCallback.Invoke(obj); task.Dispose(); obj = null; } _loadedTask.Clear(); ab = null; }
public void Init() { ResourceManager.GetResource(AssetPathUtil.GetUI("BattleUI"), OnGetMainUI); }
public void PlayMusic(uint id) { ResourceManager.GetResource(AssetPathUtil.GetPrefab("Music/" + id), OnMusicLoaded); }
public static void CreateMap(int w, int h, Transform parent) { Map = parent; maxXindex = w - 1; maxYindex = h - 1; if (dict == null) { dict = new Dictionary <int, MapGrid>(); allList = new List <MapGrid>(); } dict.Clear(); allList.Clear(); GameObject obj = Resources.Load <GameObject>(AssetPathUtil.GetMapPath(0)); GameObject borderY = Resources.Load <GameObject>(AssetPathUtil.GetMapPath(1001)); GameObject borderX = Resources.Load <GameObject>(AssetPathUtil.GetMapPath(1000)); MapWidth = (w - 1) * GridConst.Radius * 1.5f; MapHeight = (h - 1) * GridConst.Height * 2; for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { GameObject go = GameObject.Instantiate <GameObject>(obj); //go.AddComponent<SpriteRenderer>().sprite = sp; ; go.name = i.ToString(); go.transform.SetParent(parent, false); int xIndex = i; int yIndex = j; //Debug.Log(xIndex + "_" + yIndex); float x = xIndex * GridConst.Radius * 1.5f; float y = yIndex * 2 * GridConst.Height - GridConst.Height * (i % 2); go.transform.localPosition = new Vector3(x, y, 0); MapGrid grid = go.AddComponent <MapGrid>(); grid.xIndex = xIndex; grid.yIndex = yIndex; grid.Center = new Vector2(x, y); dict.Add(xIndex * N + yIndex, grid); allList.Add(grid); } } // float H = (h * GridConst.Height * 2); float W = (w * GridConst.Radius * 1.5f); GameObject b = GameObject.Instantiate <GameObject>(borderY); b.transform.localScale = new Vector3(1, H, 1); b.transform.localPosition = new Vector3(-GridConst.Radius * 1.5f, H / 2 - GridConst.Height, -1); b.transform.SetParent(parent, false); b = GameObject.Instantiate <GameObject>(borderY); b.transform.localScale = new Vector3(1, H + GridConst.Height * 2, 1); b.transform.localPosition = new Vector3(W, H / 2 - GridConst.Height, -1); b.transform.SetParent(parent, false); b = GameObject.Instantiate <GameObject>(borderX); b.transform.localScale = new Vector3(W + GridConst.Radius * 2, 1, 1); b.transform.localPosition = new Vector3(W / 2 - GridConst.Radius * 1.5f, -GridConst.Height, -1); b.transform.SetParent(parent, false); b = GameObject.Instantiate <GameObject>(borderX); b.transform.localScale = new Vector3(W + GridConst.Radius * 2, 1, 1); b.transform.localPosition = new Vector3(W / 2 - GridConst.Radius * 1.5f, H - GridConst.Height, -1); b.transform.SetParent(parent, false); }