Addressables+CCD云端分发服务

家电修理 2023-07-16 17:23www.caominkang.com电器维修

1.账号登陆

使用Unity账号登陆CCD云服务控制台
CCD操作文档

2.账号绑定

CCD资源云加载服务后台对应腾讯云,需要进行腾讯账号绑定

3.开通云端服务


点击Cloud Content Delivery,选择组织机构,点击开通即可


点击Overvie,选择需要云端分发的项目并进入

依次点击Content Delivery——COS Key,记下右侧的COS key号码,后面要使用

4.插件导入

打开Unity工程,打开Package Manager窗口并搜索Addressables和Cloud Content Delivery插件导入

5.Cloud Content Delivery插件使用

在Windo菜单下打开Cloud Content Delivery插件界面

根据提示,前往ProjectSettings界面CloudContentDelivery项填写COS Key。
在bucket name输入bucket名称,点击Create Ne Bucket即可新建bucket。
点击List Bucket,刷新bucket列表,点击bucket下拉列表选择要上传到的bucket,
点击Set Release Url以设置当前的Addressable的远程加载地址为当前bucket地址(勾选latest则始终获取该bucket下最新的release)
打开Addressable打包界面


点击选择需要远程加载的资源包,设置资源的Labels标签,在右侧设置打包和加载地址分别为RemoteBuildPath和RemoteLoadPath
依次点击Build——Ne Build——Default Build Script,打包资源完成后反回CloudContentDelivery界面,点击SyncEntries,上传完成后可点击List Entries刷新资源查看。点击CreateRelease创建发布
至此,打包发布游戏即可。
资源更新当资源变更需要远程更新时,选择build下的update previousbuild打包新的bundle。打开CCD插件面板,点击SyncEntries,点击CreateRelease即可

注意在配合addressable使用release的promote功能时,务必使两个bucket对应的addressable的
Settings(Windo >> Asset Managment >> Addressables >> Settings)中Catlog选项下的Player
Version Override的值保持一致且不为空!

预加载示例代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.AddressableAssets.ResourceLocators;
using UnityEngine.UI;
using System;

public class TextureController : MonoBehaviour
{
 public Renderer m_ReferencedMaterial;

 public Slider progressBar;

 public Text progressText;

 AsyncOperationHandle donloadDependencies;

 public void PreloadTex()
 {
  StartCoroutine(StartPreload());
 }

 public IEnumerator StartPreload()
 {
  AsyncOperationHandle handle = Addressables.InitializeAsync();
  yield return handle;
  Debug.Log("InitializeAsync");
  //Clear all cached AssetBundles

  Caching.ClearCache();

  string key = "HD";
  AsyncOperationHandle getDonloadSize = Addressables.GetDonloadSizeAsync(key);
  yield return getDonloadSize;

  if (getDonloadSize.Result > 0)
  {
   donloadDependencies = Addressables.DonloadDependenciesAsync(key);
   progressBar.gameObject.SetActive(true);
   yield return donloadDependencies;
  }
 }

 private void Update()
 {
  if (donloadDependencies.IsValid())
  {
   if (donloadDependencies.GetDonloadStatus().Percent < 1)
   {
    UpdateProgressBar(donloadDependencies.GetDonloadStatus().Percent);
   }
   else if (donloadDependencies.IsDone)
   {
    Addressables.Release(donloadDependencies);
   }
  }
 }

 void UpdateProgressBar(float donloadPercent)
 {
  progressBar.value = donloadPercent;
  progressText.text = Mathf.CeilToInt(donloadPercent  100f) + "%";
 }

 public void SitchToHighDef()
 {
  LoadTexture("TEX_Archer_D", "HD");
 }

 void LoadTexture(string key, string label)
 {
  //Caching.ClearCache();

  Addressables
   .LoadAssetsAsync(ne List { key, label }, null, Addressables.MergeMode.Intersection)
   .Completed += TextureLoaded;
 }

 void TextureLoaded(AsyncOperationHandle> obj)
 {
  m_ReferencedMaterial.material.mainTexture = obj.Result[0];
 }
}
 
        
        
               
      
    
    

  

Copyright © 2016-2025 www.caominkang.com 曹敏电脑维修网 版权所有 Power by