| guids | GUIDs of assets to be uploaded to CacheServer. |
| uploadAll | Full assets source data will be uploaded if true(false by default). |
| force | Force of uploading source data to the CacheServer, even if the upload option in CacheServer setting is not enabled. |
Upload source info to cache server with given GUID of the asset.
Collect the source info of specified assets, including asset path, guid and other related data. And upload these data to the CacheServer so that they can be retrieved in other non-Editor situations. Make use of CacheServer.UploadSources and CacheServer.UploadReference, the artifact cache of assets and their dependencies can be retrieved during runtime, even if these assets were not packaged into the player during the build process. *Must be used in conjunction with the latest version of the Tuanjie Accelerator, and requires the cache server host and namespace to be properly configured.
using UnityEditor; using UnityEngine; using System.Linq;
public class RemoteSourceUpload : MonoBehaviour { [MenuItem("Source/UploadSource", false, 1)] private static void UploadSource() { for ( int i = 0; i < Selection.objects.Length; i++) { string path = AssetDatabase.GetAssetPath(Selection.objects[i]); if (string.IsNullOrEmpty(path)) { Debug.LogWarning($"Selected object {Selection.objects[i].name} does not have a valid path."); continue; }
string fileID = GetFileID(path); GUID[] guids = { new GUID(fileID) };
CacheServer.UploadSources(guids, false, false); CacheServer.UploadReference(guids); } }
[MenuItem("Source/UploadAll", false, 2)] private static void ClearRemoteSourceAndUploadAll() { // CacheServer.ClearRemoteSource(); CacheServer.UploadSources(new GUID[] { }, true, false); CacheServer.UploadReference(GetAllGuidsInAssetsOnly()); }
private static string GetFileID(string path) { return AssetDatabase.AssetPathToGUID(path); }
public static GUID[] GetAllGuidsInAssetsOnly() { return AssetDatabase.FindAssets("", new[] { "Assets" }) .Select(s => new GUID(s)) .Where(g => !string.IsNullOrEmpty(AssetDatabase.GUIDToAssetPath(g.ToString())) && !AssetDatabase.GUIDToAssetPath(g.ToString()).EndsWith(".meta")) .ToArray(); } }
Upload source info of the selected assets, or just upload all assets' source infos. It is recommanded to invoke CacheServer.UploadReference after uploading the source data, so that the cache server can retain complete asset source and dependency information.