generated from RageAgainstThePixel/upm-template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
com.rest.blockadelabs 1.0.0-preview.1 (#1)
- Loading branch information
1 parent
5efb747
commit b9a100f
Showing
96 changed files
with
4,595 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "BlockadeLabs.Demo", | ||
"rootNamespace": "BlockadeLabs.Demo", | ||
"references": [ | ||
"GUID:0e64303a4898a4d4ba94306e88e6c025", | ||
"GUID:a6609af893242c7438d701ddd4cce46a", | ||
"GUID:6ab1da3c58a70364e92dc36aaec78f43", | ||
"GUID:7958db66189566541a6363568aee1575", | ||
"GUID:6055be8ebefd69e48b49212b09b47b2f" | ||
], | ||
"includePlatforms": [], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
using BlockadeLabs.Skyboxes; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using TMPro; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
using Utilities.Extensions; | ||
|
||
namespace BlockadeLabs.Demo | ||
{ | ||
public class SkyboxDemo : MonoBehaviour | ||
{ | ||
[SerializeField] | ||
private TMP_InputField promptInputField; | ||
|
||
[SerializeField] | ||
private TMP_Dropdown skyboxStyleDropdown; | ||
|
||
[SerializeField] | ||
private Button generateButton; | ||
|
||
[SerializeField] | ||
private Material skyboxMaterial; | ||
|
||
private BlockadeLabsClient api; | ||
|
||
private CancellationTokenSource lifetimeCancellationTokenSource; | ||
|
||
private IReadOnlyList<SkyboxStyle> skyboxOptions; | ||
|
||
private void OnValidate() | ||
{ | ||
promptInputField.Validate(); | ||
skyboxStyleDropdown.Validate(); | ||
generateButton.Validate(); | ||
} | ||
|
||
private void Awake() | ||
{ | ||
OnValidate(); | ||
lifetimeCancellationTokenSource = new CancellationTokenSource(); | ||
|
||
try | ||
{ | ||
api = new BlockadeLabsClient(); | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.LogError($"Failed to create {nameof(BlockadeLabsClient)}!\n{e}"); | ||
enabled = false; | ||
return; | ||
} | ||
|
||
GetSkyboxStyles(); | ||
generateButton.onClick.AddListener(GenerateSkybox); | ||
promptInputField.onSubmit.AddListener(GenerateSkybox); | ||
promptInputField.onValueChanged.AddListener(ValidateInput); | ||
} | ||
|
||
private void ValidateInput(string input) | ||
{ | ||
generateButton.interactable = !string.IsNullOrWhiteSpace(input); | ||
} | ||
|
||
private void GenerateSkybox() => GenerateSkybox(promptInputField.text); | ||
|
||
private async void GenerateSkybox(string prompt) | ||
{ | ||
if (string.IsNullOrWhiteSpace(prompt)) | ||
{ | ||
Debug.LogWarning("No prompt given!"); | ||
return; | ||
} | ||
|
||
try | ||
{ | ||
generateButton.interactable = false; | ||
promptInputField.interactable = false; | ||
var request = new SkyboxRequest(prompt, skyboxStyleId: skyboxOptions[skyboxStyleDropdown.value].Id); | ||
var skyboxInfo = await api.SkyboxEndpoint.GenerateSkyboxAsync(request, lifetimeCancellationTokenSource.Token).ConfigureAwait(true); | ||
skyboxMaterial.mainTexture = skyboxInfo.MainTexture; | ||
Debug.Log($"Successfully created skybox: {skyboxInfo.Id}"); | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.LogError(e); | ||
} | ||
finally | ||
{ | ||
generateButton.interactable = true; | ||
promptInputField.interactable = true; | ||
} | ||
} | ||
|
||
private void OnDestroy() | ||
{ | ||
lifetimeCancellationTokenSource.Cancel(); | ||
} | ||
|
||
private async void GetSkyboxStyles() | ||
{ | ||
try | ||
{ | ||
skyboxOptions = await api.SkyboxEndpoint.GetSkyboxStylesAsync(lifetimeCancellationTokenSource.Token).ConfigureAwait(true); | ||
var dropdownOptions = new List<TMP_Dropdown.OptionData>(skyboxOptions.Count); | ||
dropdownOptions.AddRange(skyboxOptions.Select(skyboxStyle => new TMP_Dropdown.OptionData(skyboxStyle.Name))); | ||
skyboxStyleDropdown.options = dropdownOptions; | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.LogError(e); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.