upgrade CCK to v3.5
This commit is contained in:
parent
6fe98b333d
commit
3005cfc8aa
43 changed files with 1213 additions and 289 deletions
|
@ -1,11 +1,14 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using ABI.CCK.Components;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Random = System.Random;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
|
@ -13,8 +16,10 @@ namespace ABI.CCK.Scripts.Editor
|
|||
{
|
||||
public static PreAvatarBundleEvent PreAvatarBundleEvent = new PreAvatarBundleEvent();
|
||||
public static PrePropBundleEvent PrePropBundleEvent = new PrePropBundleEvent();
|
||||
|
||||
public static string upload_id = "";
|
||||
|
||||
public static void BuildAndUploadAvatar(GameObject avatarObject)
|
||||
public static async Task BuildAndUploadAvatar(GameObject avatarObject)
|
||||
{
|
||||
//GameObject avatarCopy = null;
|
||||
var origInfo = avatarObject.GetComponent<CVRAssetInfo>();
|
||||
|
@ -33,17 +38,35 @@ namespace ABI.CCK.Scripts.Editor
|
|||
//CVRAssetInfo info = avatarCopy.GetComponent<CVRAssetInfo>();
|
||||
if (string.IsNullOrEmpty(origInfo.objectId))
|
||||
{
|
||||
origInfo.objectId = Guid.NewGuid().ToString();
|
||||
//origInfo.guid = info.guid;
|
||||
try
|
||||
#if UNITY_EDITOR
|
||||
APIConnection.Initialize(EditorPrefs.GetString("m_ABI_Username"), EditorPrefs.GetString("m_ABI_Key"));
|
||||
#endif
|
||||
|
||||
APIConnection.BaseResponse<APIConnection.GenerateResponse> response = await APIConnection.MakeRequest<APIConnection.GenerateResponse>("cck/generate/avatar", put: true);
|
||||
|
||||
if (response != null && response.Data != null)
|
||||
{
|
||||
PrefabUtility.ApplyPrefabInstance(avatarObject, InteractionMode.UserAction);
|
||||
origInfo.objectId = response.Data.Id.ToString();
|
||||
}
|
||||
catch
|
||||
else
|
||||
{
|
||||
Debug.Log("[CCK:BuildUtility] Object is not a prefab. No need to Apply To Instance.");
|
||||
Debug.LogError($"[CCK:BuildUtility] New Guid could not be generated");
|
||||
}
|
||||
}
|
||||
|
||||
Random rnd = new Random();
|
||||
origInfo.randomNum = rnd.Next(11111111, 99999999).ToString();
|
||||
|
||||
EditorUtility.SetDirty(origInfo);
|
||||
|
||||
try
|
||||
{
|
||||
PrefabUtility.ApplyPrefabInstance(avatarObject, InteractionMode.UserAction);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.Log("[CCK:BuildUtility] Object is not a prefab. No need to Apply To Instance.");
|
||||
}
|
||||
|
||||
PreAvatarBundleEvent.Invoke(avatarObject);
|
||||
|
||||
|
@ -51,7 +74,10 @@ namespace ABI.CCK.Scripts.Editor
|
|||
|
||||
EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene());
|
||||
|
||||
PrefabUtility.SaveAsPrefabAsset(avatarObject, "Assets/ABI.CCK/Resources/Cache/_CVRAvatar.prefab");
|
||||
if (!Application.unityVersion.Contains("2021"))
|
||||
PrefabUtility.SaveAsPrefabAsset(avatarObject, "Assets/ABI.CCK/Resources/Cache/_CVRAvatar.prefab");
|
||||
else
|
||||
PrefabUtility.SaveAsPrefabAsset(avatarObject, $"Assets/ABI.CCK/Resources/Cache/CVRAvatar_{origInfo.objectId}_{origInfo.randomNum}.prefab");
|
||||
//GameObject.DestroyImmediate(avatarCopy);
|
||||
|
||||
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
|
||||
|
@ -59,11 +85,19 @@ namespace ABI.CCK.Scripts.Editor
|
|||
EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene());
|
||||
|
||||
AssetBundleBuild assetBundleBuild = new AssetBundleBuild();
|
||||
assetBundleBuild.assetNames = new[] {"Assets/ABI.CCK/Resources/Cache/_CVRAvatar.prefab"};
|
||||
assetBundleBuild.assetBundleName = "bundle.cvravatar";
|
||||
if (!Application.unityVersion.Contains("2021"))
|
||||
assetBundleBuild.assetNames = new[] {"Assets/ABI.CCK/Resources/Cache/_CVRAvatar.prefab"};
|
||||
else
|
||||
assetBundleBuild.assetNames = new[] {$"Assets/ABI.CCK/Resources/Cache/CVRAvatar_{origInfo.objectId}_{origInfo.randomNum}.prefab"};
|
||||
|
||||
upload_id = origInfo.objectId;
|
||||
EditorPrefs.SetString("m_ABI_uploadId", upload_id);
|
||||
EditorPrefs.SetString("m_ABI_uploadRand", origInfo.randomNum);
|
||||
|
||||
assetBundleBuild.assetBundleName = $"cvravatar_{origInfo.objectId}_{origInfo.randomNum}.cvravatar";
|
||||
|
||||
BuildPipeline.BuildAssetBundles(Application.persistentDataPath, new[] {assetBundleBuild},
|
||||
BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget);
|
||||
BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget);
|
||||
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
|
@ -71,13 +105,35 @@ namespace ABI.CCK.Scripts.Editor
|
|||
EditorApplication.isPlaying = true;
|
||||
}
|
||||
|
||||
public static void BuildAndUploadSpawnable(GameObject s)
|
||||
public static async Task BuildAndUploadSpawnable(GameObject s)
|
||||
{
|
||||
GameObject sCopy = null;
|
||||
var origInfo = s.GetComponent<CVRAssetInfo>();
|
||||
var spawnable = s.GetComponent<CVRSpawnable>();
|
||||
spawnable.spawnableType = CVRSpawnable.SpawnableType.StandaloneSpawnable;
|
||||
|
||||
if (string.IsNullOrEmpty(origInfo.objectId))
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
APIConnection.Initialize(EditorPrefs.GetString("m_ABI_Username"), EditorPrefs.GetString("m_ABI_Key"));
|
||||
#endif
|
||||
|
||||
APIConnection.BaseResponse<APIConnection.GenerateResponse> response = await APIConnection.MakeRequest<APIConnection.GenerateResponse>("cck/generate/spawnable", put: true);
|
||||
|
||||
if (response != null && response.Data != null)
|
||||
{
|
||||
origInfo.objectId = response.Data.Id.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"[CCK:BuildUtility] New Guid could not be generated");
|
||||
}
|
||||
}
|
||||
|
||||
Random rnd = new Random();
|
||||
origInfo.randomNum = rnd.Next(11111111, 99999999).ToString();
|
||||
EditorUtility.SetDirty(origInfo);
|
||||
|
||||
PrePropBundleEvent.Invoke(s);
|
||||
|
||||
try
|
||||
|
@ -92,25 +148,25 @@ namespace ABI.CCK.Scripts.Editor
|
|||
}
|
||||
|
||||
CVRAssetInfo info = sCopy.GetComponent<CVRAssetInfo>();
|
||||
if (string.IsNullOrEmpty(info.objectId))
|
||||
|
||||
try
|
||||
{
|
||||
info.objectId = Guid.NewGuid().ToString();
|
||||
origInfo.objectId = info.objectId;
|
||||
try
|
||||
{
|
||||
PrefabUtility.ApplyPrefabInstance(s, InteractionMode.UserAction);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.Log("[CCK:BuildUtility] Object is not a prefab. No need to Apply To Instance.");
|
||||
}
|
||||
PrefabUtility.ApplyPrefabInstance(s, InteractionMode.UserAction);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.Log("[CCK:BuildUtility] Object is not a prefab. No need to Apply To Instance.");
|
||||
}
|
||||
|
||||
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
|
||||
|
||||
EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene());
|
||||
|
||||
PrefabUtility.SaveAsPrefabAsset(sCopy, "Assets/ABI.CCK/Resources/Cache/_CVRSpawnable.prefab");
|
||||
if (!Application.unityVersion.Contains("2021"))
|
||||
PrefabUtility.SaveAsPrefabAsset(sCopy, "Assets/ABI.CCK/Resources/Cache/_CVRSpawnable.prefab");
|
||||
else
|
||||
PrefabUtility.SaveAsPrefabAsset(sCopy, $"Assets/ABI.CCK/Resources/Cache/CVRSpawnable_{origInfo.objectId}_{origInfo.randomNum}.prefab");
|
||||
|
||||
GameObject.DestroyImmediate(sCopy);
|
||||
|
||||
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
|
||||
|
@ -118,11 +174,20 @@ namespace ABI.CCK.Scripts.Editor
|
|||
EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene());
|
||||
|
||||
AssetBundleBuild assetBundleBuild = new AssetBundleBuild();
|
||||
assetBundleBuild.assetNames = new[] {"Assets/ABI.CCK/Resources/Cache/_CVRSpawnable.prefab"};
|
||||
assetBundleBuild.assetBundleName = "bundle.cvrprop";
|
||||
|
||||
if (!Application.unityVersion.Contains("2021"))
|
||||
assetBundleBuild.assetNames = new[] {"Assets/ABI.CCK/Resources/Cache/_CVRSpawnable.prefab"};
|
||||
else
|
||||
assetBundleBuild.assetNames = new[] {$"Assets/ABI.CCK/Resources/Cache/CVRSpawnable_{origInfo.objectId}_{origInfo.randomNum}.prefab"};
|
||||
|
||||
upload_id = origInfo.objectId;
|
||||
EditorPrefs.SetString("m_ABI_uploadId", upload_id);
|
||||
EditorPrefs.SetString("m_ABI_uploadRand", origInfo.randomNum);
|
||||
|
||||
assetBundleBuild.assetBundleName = $"cvrspawnable_{origInfo.objectId}_{origInfo.randomNum}.cvrprop";
|
||||
|
||||
BuildPipeline.BuildAssetBundles(Application.persistentDataPath, new[] {assetBundleBuild},
|
||||
BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget);
|
||||
BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget);
|
||||
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
|
@ -130,17 +195,35 @@ namespace ABI.CCK.Scripts.Editor
|
|||
EditorApplication.isPlaying = true;
|
||||
}
|
||||
|
||||
public static void BuildAndUploadMapAsset(Scene scene, GameObject descriptor)
|
||||
public static async Task BuildAndUploadMapAsset(Scene scene, GameObject descriptor)
|
||||
{
|
||||
SetupNetworkUUIDs();
|
||||
|
||||
CVRAssetInfo info = descriptor.GetComponent<CVRAssetInfo>();
|
||||
|
||||
if (string.IsNullOrEmpty(info.objectId))
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
APIConnection.Initialize(EditorPrefs.GetString("m_ABI_Username"), EditorPrefs.GetString("m_ABI_Key"));
|
||||
#endif
|
||||
|
||||
APIConnection.BaseResponse<APIConnection.GenerateResponse> response = await APIConnection.MakeRequest<APIConnection.GenerateResponse>("cck/generate/world", put: true);
|
||||
|
||||
if (response != null && response.Data != null)
|
||||
{
|
||||
info.objectId = response.Data.Id.ToString();
|
||||
EditorUtility.SetDirty(info);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"[CCK:BuildUtility] New Guid could not be generated");
|
||||
}
|
||||
}
|
||||
|
||||
EditorSceneManager.MarkSceneDirty(scene);
|
||||
|
||||
EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene());
|
||||
|
||||
CVRAssetInfo info = descriptor.GetComponent<CVRAssetInfo>();
|
||||
if (string.IsNullOrEmpty(info.objectId)) info.objectId = Guid.NewGuid().ToString();
|
||||
|
||||
|
||||
PrefabUtility.SaveAsPrefabAsset(descriptor, "Assets/ABI.CCK/Resources/Cache/_CVRWorld.prefab");
|
||||
|
||||
AssetBundleBuild assetBundleBuild = new AssetBundleBuild();
|
||||
|
@ -148,7 +231,7 @@ namespace ABI.CCK.Scripts.Editor
|
|||
assetBundleBuild.assetBundleName = "bundle.cvrworld";
|
||||
|
||||
BuildPipeline.BuildAssetBundles(Application.persistentDataPath, new[] {assetBundleBuild},
|
||||
BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget);
|
||||
BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget);
|
||||
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue