using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
{
public class GettingStarted : MonoBehaviour
{
public Helpers.ProgressBar ProgressBar;
private GameObject _rootGO;
private AvatarItem _avatarItem;
private List<CatalogEntry> _avatarList = null;
private List<CatalogEntry> _lastAssetSearch = null;
private int _assetIndex = 0;
private int _avatarIndex = 0;
private string _assetSearchType;
void Start()
{
}
#region event management
{
}
private void HandleButtonInitialize()
{
StartCoroutine(InitializeCoroutine());
}
private IEnumerator InitializeCoroutine()
{
AstraManager.StartupAstra();
yield return AstraManager.WaitForInit();
Configuration.ProjectConfigError error = Configuration.ProjectConfigError.Success;
yield
return Configuration.Initialize(
AppConfig).AsCoroutine(
null,
null, e => error = e);
if (error == Configuration.ProjectConfigError.Success)
{
}
else
{
}
}
private void HandleButtonSearchAvatars()
{
StartCoroutine(Catalog.GetAvatars().AsCoroutine(CallbackProgress,
(avatarList) =>
{
_avatarList = avatarList;
Astra.Logger.Log("Found: " + avatarList.Count);
AvatarText.text = avatarList.Count + " Avatars";
},
CallbackCatalogError));
}
private void HandleButtonSearchFigures()
{
_assetSearchType = "Figure";
StartCoroutine(Catalog.SearchForFigures(_avatarItem).AsCoroutine(CallbackProgress, CallbackAssetListLoaded, CallbackCatalogError));
}
private void HandleButtonSearchCloth()
{
_assetSearchType = "Clothing";
StartCoroutine(Catalog.SearchForClothing(_avatarItem, null).AsCoroutine(CallbackProgress, CallbackAssetListLoaded, CallbackCatalogError));
}
private void HandleButtonSearchDecals()
{
_assetSearchType = "Decal";
StartCoroutine(Catalog.SearchForDecals(_avatarItem, null).AsCoroutine(CallbackProgress, CallbackAssetListLoaded, CallbackCatalogError));
}
private void HandleButtonSearchMorphables()
{
_assetSearchType = "Morph";
StartCoroutine(Catalog.SearchForMorphables(_avatarItem).AsCoroutine(CallbackProgress, CallbackAssetListLoaded, CallbackCatalogError));
}
private void HandleButtonLoadNextAsset()
{
if (_lastAssetSearch == null || _lastAssetSearch.Count <= 0)
{
return;
}
if (_assetIndex >= _lastAssetSearch.Count)
{
_assetIndex = 0;
}
var catalogEntry = _lastAssetSearch[_assetIndex];
StartCoroutine(_avatarItem.ApplyAsset(catalogEntry).AsCoroutine(CallbackProgress,
() =>
{
LoadNextAssetText.text = "Loaded: " + catalogEntry.Name;
ButtonLoadNextAsset.enabled = true;
},
() => { Astra.Logger.LogError("Failed to load asset: " + catalogEntry.Name); }));
_assetIndex++;
}
private void HandleButtonLoadNextAvatar()
{
if (_avatarList == null || _avatarList.Count <= 0)
{
}
if (_avatarIndex >= _avatarList.Count)
{
_avatarIndex = 0;
}
var guid = _avatarList[_avatarIndex].Guid;
StartCoroutine(Loader.LoadAvatar(guid).AsCoroutine(CallbackProgress,
(avatarItem) => {
Astra.Logger.Log("Avatar loaded");
AvatarLoadText.text = "Loaded: " + guid;
_avatarItem = avatarItem;
if (_rootGO != null)
{
GameObject.Destroy(_rootGO);
}
_rootGO = _avatarItem.gameObject;
},
_avatarIndex++;
}
private void HandleButtonClearItems()
{
if (_avatarItem == null)
{
return;
}
_avatarItem.RemoveAllItems();
}
#endregion
#region callbacks
private void CallbackProgress(float progress)
{
ProgressBar.UpdatePercent(progress);
}
private void CallbackCatalogError(Catalog.CatalogError catalogError)
{
}
private void CallbackAssetListLoaded(List<CatalogEntry> assetList)
{
_lastAssetSearch = assetList;
var logMessage = "Found: " + assetList.Count + " " + _assetSearchType + " assets";
LastSearchAssetsText.text = logMessage;
}
#endregion
}
}
Text LastSearchAssetsText
Used when displaying info about searching figures
Definition: GettingStarted.cs:64
Button ButtonLoadNextAsset
Loads the next asset from the search results
Definition: GettingStarted.cs:69
void BindEvents()
Helper to link various ui elements to their actions
Definition: GettingStarted.cs:128
Text AvatarText
Used to display the avatar info
Definition: GettingStarted.cs:34
Button ButtonSearchCloth
Finds cloth items compatible with the current figure
Definition: GettingStarted.cs:49
Text InitializeText
Used to show when the Astra system has been initialized
Definition: GettingStarted.cs:29
Button ButtonInitialize
Clicking this button will create our base astra gameobject, we need this in all scenes You can skip t...
Definition: GettingStarted.cs:24
TextAsset AppConfig
Drag your config file into this slot (or load in code)
Definition: GettingStarted.cs:95
Button ButtonSearchMorphable
Finds compatible morphables
Definition: GettingStarted.cs:59
Text LoadNextAssetText
Displays info when loading an asset from a search
Definition: GettingStarted.cs:74
Button ButtonSearchAvatars
Finds avatars and prints list
Definition: GettingStarted.cs:39
Button ButtonLoadNextAvatar
Loads a complete avatar
Definition: GettingStarted.cs:79
Button ButtonSearchDecals
Finds decals compatible with the current figure
Definition: GettingStarted.cs:54
Button ButtonClearItems
Removes items on the avatar except the figure
Definition: GettingStarted.cs:90
Text AvatarLoadText
Info about the loading avatar
Definition: GettingStarted.cs:84
Button ButtonSearchFigures
Finds figures and prints list
Definition: GettingStarted.cs:44
Handles Astra logging messages in C# allowing filtering and redirection
Definition: Logger.cs:15
static void LogError(object message)
A one-to-one with UnityEngine.Debug.LogError, records as Info level
Definition: Logger.cs:115
static void LogWarning(object message)
A one-to-one with UnityEngine.Debug.LogWarning, records as Info level
Definition: Logger.cs:107
static void Log(object message)
A one-to-one with UnityEngine.Debug.Log, records as Info level
Definition: Logger.cs:99
Definition: AnimationManager.cs:10
Definition: AnimatingAnAvatar.cs:9
Definition: AnimationManager.cs:10