cvr-props/Assets/ABI.CCK/Scripts/Runtime/CCK_RuntimeVariableStream.cs

97 lines
4.1 KiB
C#
Raw Permalink Normal View History

2023-01-22 16:38:23 +01:00
using System;
using System.Collections;
using System.Net.Http;
using System.Text;
2023-07-30 01:20:46 +02:00
using System.Threading.Tasks;
2023-01-22 16:38:23 +01:00
using Abi.Newtonsoft.Json;
using UnityEditor;
using UnityEngine;
namespace ABI.CCK.Scripts.Runtime
{
[AddComponentMenu("")]
2023-01-22 16:38:23 +01:00
public class CCK_RuntimeVariableStream : MonoBehaviour
{
private void Start()
{
StartCoroutine(StreamVars());
}
private IEnumerator StreamVars()
{
OnGuiUpdater updater = gameObject.GetComponent<OnGuiUpdater>();
string type = updater.asset.type.ToString();
2023-07-30 01:20:46 +02:00
string uploadRegion = "0";
2023-01-22 16:38:23 +01:00
#if UNITY_EDITOR
2023-07-30 01:20:46 +02:00
APIConnection.Initialize(EditorPrefs.GetString("m_ABI_Username"), EditorPrefs.GetString("m_ABI_Key"));
uploadRegion = EditorPrefs.GetInt("ABI_PREF_UPLOAD_REGION").ToString();
2023-01-22 16:38:23 +01:00
#endif
2023-07-30 01:20:46 +02:00
Task<APIConnection.BaseResponse<APIConnection.ContentInfoResponse>> task = Task.Run(() => APIConnection.MakeRequest<APIConnection.ContentInfoResponse>(
$"cck/contentInfo/{type}/{updater.asset.objectId}?platform=pc_standalone&region={uploadRegion}"));
while (!task.IsCompleted) yield return null;
2023-01-22 16:38:23 +01:00
2023-07-30 01:20:46 +02:00
APIConnection.BaseResponse<APIConnection.ContentInfoResponse> response = task.Result;
2023-01-22 16:38:23 +01:00
2023-07-30 01:20:46 +02:00
if (response != null)
{
if (response.Data != null)
{
updater.UploadLocation = response.Data.UploadLocation;
2023-01-22 16:38:23 +01:00
2023-07-30 01:20:46 +02:00
Debug.Log($"Upload Location: {updater.UploadLocation}");
2023-01-22 16:38:23 +01:00
2023-07-30 01:20:46 +02:00
updater.assetName.text = response.Data.ContentData.Name;
updater.assetDesc.text = response.Data.ContentData.Description;
2023-01-22 16:38:23 +01:00
2023-07-30 01:20:46 +02:00
updater.LoudAudio.isOn = response.Data.ContentData.Tags.LoudAudio;
updater.LongRangeAudio.isOn = response.Data.ContentData.Tags.LongRangeAudio;
updater.SpawnAudio.isOn = response.Data.ContentData.Tags.SpawnAudio;
updater.ContainsMusic.isOn = response.Data.ContentData.Tags.ContainsMusic;
2023-01-22 16:38:23 +01:00
2023-07-30 01:20:46 +02:00
updater.ScreenEffects.isOn = response.Data.ContentData.Tags.ScreenEffects;
updater.FlashingColors.isOn = response.Data.ContentData.Tags.FlashingColors;
updater.FlashingLights.isOn = response.Data.ContentData.Tags.FlashingLights;
updater.ExtremelyBright.isOn = response.Data.ContentData.Tags.ExtremelyBright;
updater.ParticleSystems.isOn = response.Data.ContentData.Tags.ParticleSystems;
2023-01-22 16:38:23 +01:00
2023-07-30 01:20:46 +02:00
updater.Violence.isOn = response.Data.ContentData.Tags.Violence;
updater.Gore.isOn = response.Data.ContentData.Tags.Gore;
updater.Horror.isOn = response.Data.ContentData.Tags.Horror;
updater.Jumpscare.isOn = response.Data.ContentData.Tags.Jumpscare;
2023-01-22 16:38:23 +01:00
2023-07-30 01:20:46 +02:00
updater.ExcessivelySmall.isOn = response.Data.ContentData.Tags.ExtremelySmall;
updater.ExcessivelyHuge.isOn = response.Data.ContentData.Tags.ExtremelyHuge;
2023-01-22 16:38:23 +01:00
2023-07-30 01:20:46 +02:00
updater.Suggestive.isOn = response.Data.ContentData.Tags.Suggestive;
updater.Nudity.isOn = response.Data.ContentData.Tags.Nudity;
}
else
{
#if UNITY_EDITOR
EditorUtility.ClearProgressBar();
if (UnityEditor.EditorUtility.DisplayDialog("Alpha Blend Interactive CCK",
response.Message, "Okay"))
{
EditorApplication.isPlaying = false;
}
#endif
yield break;
2023-01-22 16:38:23 +01:00
}
}
2023-07-30 01:20:46 +02:00
else
{
#if UNITY_EDITOR
EditorUtility.ClearProgressBar();
if (UnityEditor.EditorUtility.DisplayDialog("Alpha Blend Interactive CCK",
"An Error occured while uploading. Please try again later.", "Okay"))
{
EditorApplication.isPlaying = false;
}
#endif
yield break;
}
2023-01-22 16:38:23 +01:00
}
}
}