/// <summary> /// Load the UMA Avatar. /// </summary> public void Load() { //Load UMA-string from local text file string fileName = "Avatar.txt"; StreamReader stream = File.OpenText(fileName); SaveString = stream.ReadLine(); stream.Close(); UMATextRecipe recipe = ScriptableObject.CreateInstance <UMATextRecipe> (); recipe.recipeString = SaveString; umaDynamicAvatar.Load(recipe); Destroy(recipe); }
void LoadText() { //Save string to text file string fileName = "Assets/UMASavedTextFile.txt"; StreamReader stream = File.OpenText(fileName); myCustomUMA.SaveString = stream.ReadLine(); stream.Close(); //Generate UMA String UMATextRecipe recipe = ScriptableObject.CreateInstance <UMATextRecipe>(); recipe.recipeString = myCustomUMA.SaveString; umaDynamicAvatar.Load(recipe); Destroy(recipe); }
void RpcCreateChar(string savedPlayer, uint id) { //Give it a unique name gameObject.name = "Player|" + netId; ///Setup the UMA basics thisUMA = new GameObject("Player"); UMADynamicAvatar dynamicAvatar = thisUMA.AddComponent <UMADynamicAvatar>(); dynamicAvatar.Initialize(); //IMPORTANT to set this up before loading! dynamicAvatar.animationController = animController; //Load our UMA based on the string we sent var asset = ScriptableObject.CreateInstance <UMATextRecipe>(); asset.recipeString = savedPlayer; dynamicAvatar.Load(asset); //Set upp correct transforms and parent the UMA to our player object. thisUMA.transform.position = Vector3.zero; thisUMA.transform.rotation = transform.rotation; thisUMA.transform.SetParent(transform); //Set up callback to be called when creation is done thisUMA.GetComponent <UMAData>().OnCharacterCreated += UMAFinished; }
/** * Given an AssetLoaderController in input,a UMA avator's name and a UMADynamicAvator * create and spawn a new uma avator. It is possible to pass also a callback * that it's executed after the uma avator is created. * */ public static GameObject createUMAAvator(AssetLoaderController assetLoaderController, string umaAvatorName, UMADynamicAvatar umaDynamicAvator, Action <UMAData> onCharacterCreatedCallback = null) { GameObject thisUma = null; if (assetLoaderController != null && umaAvatorName != null && umaDynamicAvator != null) { //Set/spawn a UMA Avator thisUma = umaDynamicAvator.gameObject; UMADynamicAvatar thisUmaDynamicAvator = thisUma.GetComponent <UMADynamicAvatar>(); thisUmaDynamicAvator.context = assetLoaderController.context; thisUmaDynamicAvator.umaGenerator = assetLoaderController.generator; thisUmaDynamicAvator.loadOnStart = false; thisUmaDynamicAvator.Initialize(); thisUmaDynamicAvator.animationController = assetLoaderController.thirdPersonController; UMATextRecipe recipe = assetLoaderController.umaCharactersTemplates[umaAvatorName]; thisUmaDynamicAvator.Load(recipe); if (onCharacterCreatedCallback != null) { thisUma.GetComponent <UMAData>().OnCharacterCreated += onCharacterCreatedCallback; } } else { string partOfTheError = "given in input is null"; if (assetLoaderController == null) { throw new System.ArgumentException("AssetLoader " + partOfTheError); } else if (umaAvatorName == null) { throw new System.ArgumentException("UMA's avator name " + partOfTheError); } else if (umaDynamicAvator == null) { throw new System.ArgumentException("DyanamicAvator " + partOfTheError); } } return(thisUma); }
/// <summary> /// Simple Asset Loader /// </summary> public void LoadAsset() { UMARecipeBase recipe = Resources.Load(AssetName) as UMARecipeBase; umaDynamicAvatar.Load(recipe); }