update CCK to 3.10, fixing unity 2021 crash :)

This commit is contained in:
Crispy 2024-08-03 22:24:42 +02:00
parent 48a978fa2a
commit d11e0fb3a9
492 changed files with 2165204 additions and 437687 deletions

View file

@ -2,18 +2,14 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Xml.Linq;
using System.Xml.XPath;
using ABI.CCK.Components;
using ABI.CCK.Scripts;
using Abi.Newtonsoft.Json;
using UnityEditor;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Rendering;
namespace ABI.CCK.Scripts.Runtime
{
[AddComponentMenu("")]
public class CCK_RuntimeUploaderMaster : MonoBehaviour
{
public OnGuiUpdater updater;
@ -24,6 +20,11 @@ namespace ABI.CCK.Scripts.Runtime
public float progress = 0f;
public string encryption;
private void Start()
{
Application.targetFrameRate = 60; // we don't need to cook
}
public void StartUpload()
{
@ -32,8 +33,17 @@ namespace ABI.CCK.Scripts.Runtime
var sfwLevel = string.Empty;
var overwritePic = string.Empty;
if (!File.Exists($"{Application.persistentDataPath}/bundle.png")) gameObject.GetComponent<CCK_TexImageCreation>().SaveTexture(updater.camObj.GetComponent<Camera>(), updater.tex);
StartCoroutine(UploadAssetAndSendInformation(updater.asset.objectId, type.ToString(), sfwLevel, updater.assetName.text, updater.assetDesc.text, updater.dontOverridePicture.isOn, updater.asset.randomNum));
// Fallback?
if (!File.Exists($"{Application.persistentDataPath}/bundle.png"))
{
//Debug.LogWarning("[CCK:RuntimeUploader] Content image is missing! Taking scene image as fallback.");
// I am unsure why we always upload an image, even if dontOverridePicture is off...
updater.CaptureInSceneImage();
}
StartCoroutine(UploadAssetAndSendInformation(updater.asset.objectId, type.ToString(), sfwLevel,
updater.assetName.text, updater.assetDesc.text, updater.dontOverridePicture.isOn,
updater.asset.randomNum));
}
private IEnumerator UploadAssetAndSendInformation(string contentId, string type, string sfwLevel, string assetName, string assetDesc, bool overwritePic, string randomNum)

View file

@ -9,6 +9,7 @@ using UnityEngine;
namespace ABI.CCK.Scripts.Runtime
{
[AddComponentMenu("")]
public class CCK_RuntimeVariableStream : MonoBehaviour
{
private void Start()
@ -23,7 +24,7 @@ namespace ABI.CCK.Scripts.Runtime
string uploadRegion = "0";
#if UNITY_EDITOR
APIConnection.Initialize(EditorPrefs.GetString("m_ABI_Username"), EditorPrefs.GetString("m_ABI_Key"));
EditorPrefs.GetInt("ABI_PREF_UPLOAD_REGION").ToString();
uploadRegion = EditorPrefs.GetInt("ABI_PREF_UPLOAD_REGION").ToString();
#endif
Task<APIConnection.BaseResponse<APIConnection.ContentInfoResponse>> task = Task.Run(() => APIConnection.MakeRequest<APIConnection.ContentInfoResponse>(

View file

@ -0,0 +1,42 @@
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
namespace ABI.CCK.Scripts.Runtime
{
[AddComponentMenu("")]
public class CCK_TamperCheck : MonoBehaviour
{
private bool _hasErrorOccured;
public void DummyTargetMethod()
{
// ignored
}
private void FixedUpdate()
{
if (_hasErrorOccured)
return;
Button button = GetComponent<Button>();
if (button == null)
return;
UnityEvent onClickEvent = button.onClick;
if (onClickEvent == null || onClickEvent.GetPersistentEventCount() != 0)
return;
_hasErrorOccured = true;
Debug.LogError(
"[CCK:TamperCheck] No OnClick events detected on dummy button. A third-party script may have removed them on entering playmode!");
#if UNITY_EDITOR
Debug.LogError("[CCK:TamperCheck] Exiting playmode & canceling upload. The CCK is unusable in this state.");
if (UnityEditor.EditorUtility.DisplayDialog("CCK :: TamperCheck",
"An error has occured which has rendered the CCK unusable. Please check console for errors.", "Okay"))
UnityEditor.EditorApplication.ExitPlaymode();
#endif
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d61a45e574932314f9e6c61fca8171e2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -2,18 +2,17 @@
using System.Collections.Generic;
using UnityEngine;
[AddComponentMenu("")]
public class CCK_TexImageCreation : MonoBehaviour
{
public void SaveTexture (Camera cam, RenderTexture renderTexture,int resWidth = 512, int resHeight = 512) {
public void SaveTexture(RenderTexture renderTexture, int resWidth = 512, int resHeight = 512)
{
Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false);
cam.Render();
RenderTexture.active = renderTexture;
screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0);
screenShot.Apply();
cam.targetTexture = null;
RenderTexture.active = null;
byte[] bytes = screenShot.EncodeToPNG();
System.IO.File.WriteAllBytes(Application.persistentDataPath + "/bundle.png", bytes);
}
}

View file

@ -2,6 +2,7 @@
namespace ABI.CCK.Scripts.Runtime
{
[AddComponentMenu("")]
public class LinkOpener : MonoBehaviour
{
public void OpenLink(string url)

View file

@ -1,14 +1,13 @@
using System;
using System.Collections;
using System.IO;
using ABI.CCK.Components;
using UnityEditor;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UI;
namespace ABI.CCK.Scripts.Runtime
{
[AddComponentMenu("")]
public class OnGuiUpdater : MonoBehaviour
{
[Space] [Header("Object details")] [Space]
@ -75,86 +74,48 @@ namespace ABI.CCK.Scripts.Runtime
public Text assetFileManifestSizeText;
public Text assetFilePano1SizeText;
public Text assetFilePano4SizeText;
public Text cckVersion;
[HideInInspector] public string UploadLocation;
public CCK_RuntimeUploaderMaster uploader;
public void ToggleObject(GameObject obj)
{
obj.SetActive(!obj.activeInHierarchy);
}
public static string ToFileSizeString(long fileSize)
{
string[] sizes = { "B", "KB", "MB", "GB", "TB" };
int order = 0;
while (fileSize >= 1024 && order < sizes.Length - 1) {
order++;
fileSize = fileSize/1024;
}
return $"{fileSize:0.##} {sizes[order]}";
}
void Start()
private void Start()
{
SwitchPage(0);
CVRAssetInfo.AssetType type = asset.GetComponent<CVRAssetInfo>().type;
if (type == CVRAssetInfo.AssetType.World)
{
Scripts.Editor.CCK_WorldPreviewCapture.CreatePanoImages();
}
tex = new RenderTexture(512,512,1, RenderTextureFormat.ARGB32);
tex.Create();
CVRAssetInfo.AssetType type = asset.GetComponent<CVRAssetInfo>().type;
string basePath = Application.persistentDataPath;
string content_id = asset.objectId;
string commonPath = $"{basePath}/cvr{type.ToString().ToLower()}_{content_id}_{asset.randomNum}.cvr";
camObj = new GameObject();
camObj.name = "ShotCam for CVR CCK";
camObj.transform.rotation = new Quaternion(0,180,0,0);
CVRAvatar avatar = asset.GetComponent<CVRAvatar>();
if (avatar != null && asset.type == CVRAssetInfo.AssetType.Avatar) camObj.transform.position = new Vector3(avatar.viewPosition.x, avatar.viewPosition.y, avatar.viewPosition.z *= 5f);
var cam = camObj.AddComponent<Camera>();
cam.aspect = 1f;
cam.nearClipPlane = 0.01f;
cam.targetTexture = tex;
if (type == CVRAssetInfo.AssetType.Avatar || type == CVRAssetInfo.AssetType.World)
commonPath += type.ToString().ToLower();
else if (type == CVRAssetInfo.AssetType.Spawnable) commonPath += "prop";
SetupCCKShotCam();
texView.texture = tex;
texViewBig.texture = tex;
#if UNITY_EDITOR
#endif
string content_id = asset.objectId;
if (type == CVRAssetInfo.AssetType.Avatar)
{
assetFileSizeText.text = ToFileSizeString(new FileInfo(Application.persistentDataPath + $"/cvravatar_{content_id}_{asset.randomNum}.cvravatar").Length);
assetImageFileSizeText.text = "N/A";
assetFileManifestSizeText.text = ToFileSizeString(new FileInfo(Application.persistentDataPath + $"/cvravatar_{content_id}_{asset.randomNum}.cvravatar.manifest").Length);
assetFilePano1SizeText.text = "N/A";
assetFilePano4SizeText.text = "N/A";
}
if (type == CVRAssetInfo.AssetType.Spawnable)
{
assetFileSizeText.text = ToFileSizeString(new FileInfo(Application.persistentDataPath + $"/cvrspawnable_{content_id}_{asset.randomNum}.cvrprop").Length);
assetImageFileSizeText.text = "";
assetFileManifestSizeText.text = ToFileSizeString(new FileInfo(Application.persistentDataPath + $"/cvrspawnable_{content_id}_{asset.randomNum}.cvrprop.manifest").Length);
assetFilePano1SizeText.text = "N/A";
assetFilePano4SizeText.text = "N/A";
}
if (type == CVRAssetInfo.AssetType.World)
{
assetFileSizeText.text = ToFileSizeString(new FileInfo(Application.persistentDataPath + "/bundle.cvrworld").Length);
Editor.CCK_WorldPreviewCapture.CreatePanoImages();
assetFileSizeText.text = ToFileSizeString(new FileInfo($"{basePath}/bundle.cvrworld").Length);
assetImageFileSizeText.text = "N/A";
assetFileManifestSizeText.text = ToFileSizeString(new FileInfo(Application.persistentDataPath + "/bundle.cvrworld.manifest").Length);
assetFilePano1SizeText.text = ToFileSizeString(new FileInfo(Application.persistentDataPath + "/bundle_pano_1024.png").Length);
assetFilePano4SizeText.text = ToFileSizeString(new FileInfo(Application.persistentDataPath + "/bundle_pano_4096.png").Length);
assetFileManifestSizeText.text = ToFileSizeString(new FileInfo($"{basePath}/bundle.cvrworld.manifest").Length);
assetFilePano1SizeText.text = ToFileSizeString(new FileInfo($"{basePath}/bundle_pano_1024.png").Length);
assetFilePano4SizeText.text = ToFileSizeString(new FileInfo($"{basePath}/bundle_pano_4096.png").Length);
}
else
{
assetImageFileSizeText.text = type == CVRAssetInfo.AssetType.Avatar ? "N/A" : "";
assetFilePano1SizeText.text = "N/A";
assetFilePano4SizeText.text = "N/A";
assetFileSizeText.text = ToFileSizeString(new FileInfo($"{commonPath}").Length);
assetFileManifestSizeText.text = ToFileSizeString(new FileInfo($"{commonPath}.manifest").Length);
}
cckVersion.text = "ABI Platform Content Creation Kit v" + CVRCommon.CCK_VERSION;
}
public void SwitchPage(int index)
@ -249,21 +210,115 @@ namespace ABI.CCK.Scripts.Runtime
break;
}
}
public void ToggleObject(GameObject obj) => obj.SetActive(!obj.activeInHierarchy);
public void MakePhotoAndDisableCamera()
#region Private Methods
private static string ToFileSizeString(long fileSize)
{
string[] sizes = { "B", "KB", "MB", "GB", "TB" };
int order = 0;
while (fileSize >= 1024 && order < sizes.Length - 1) {
order++;
fileSize = fileSize/1024;
}
return $"{fileSize:0.##} {sizes[order]}";
}
#endregion
#region Camera Handling
public void CaptureInSceneImage()
{
Camera c = GetOrEnableCamera();
c.Render();
c.targetTexture = tex;
RenderTexture.active = tex;
SaveAndDisplayTexture();
}
public void CaptureImageFromFile()
{
if (TryLoadImageFromFile())
SaveAndDisplayTexture();
}
public void ClearTakenImage()
{
Texture2D clearTexture = new Texture2D(2, 2);
clearTexture.SetPixels(new Color[] { Color.white, Color.white, Color.white, Color.white });
clearTexture.Apply();
Graphics.Blit(clearTexture, tex);
}
private Camera GetOrEnableCamera()
{
Camera c = camObj.GetComponent<Camera>();
if (!c.enabled)
{
c.targetTexture = tex;
c.enabled = true;
}
gameObject.GetComponent<CCK_TexImageCreation>().SaveTexture(c, tex);
assetImageFileSizeText.text = ToFileSizeString(new FileInfo(Application.persistentDataPath + "/bundle.png").Length);
c.enabled = false;
//
//StartCoroutine(MakePhotoAndDisableCamera__Internal());
return c;
}
private bool TryLoadImageFromFile()
{
string path = OpenFileBrowserAndGetFilePathInEditor();
if (string.IsNullOrEmpty(path))
return false;
byte[] imageBytes = File.ReadAllBytes(path);
Texture2D loadedImage = new Texture2D(2, 2);
if (!loadedImage.LoadImage(imageBytes)) return false;
Graphics.Blit(loadedImage, tex);
return true;
}
private void SaveAndDisplayTexture()
{
gameObject.GetComponent<CCK_TexImageCreation>().SaveTexture(tex);
assetImageFileSizeText.text = ToFileSizeString(new FileInfo(Application.persistentDataPath + "/bundle.png").Length);
camObj.GetComponent<Camera>().enabled = false;
}
private string OpenFileBrowserAndGetFilePathInEditor()
{
#if UNITY_EDITOR
return EditorUtility.OpenFilePanel("Select an Image", "", "png,jpg,jpeg");
#else
return null;
#endif
}
private void SetupCCKShotCam()
{
tex = new RenderTexture(512, 512, 1, RenderTextureFormat.ARGB32);
tex.Create();
camObj = new GameObject
{
name = "ShotCam for CVR CCK",
transform =
{
rotation = new Quaternion(0, 180, 0, 0)
}
};
CVRAvatar avatar = asset.GetComponent<CVRAvatar>();
if (avatar != null && asset.type == CVRAssetInfo.AssetType.Avatar)
camObj.transform.position = new Vector3(avatar.viewPosition.x, avatar.viewPosition.y, avatar.viewPosition.z *= 5f);
Camera cam = camObj.AddComponent<Camera>();
cam.aspect = 1f;
cam.nearClipPlane = 0.01f;
cam.targetTexture = tex;
}
#endregion
}
}