/// <summary> /// Gets the asset hash and name for the given object /// </summary> private void GetEvilAssetNameAndHash(System.Type type, Object o, ref string assetName, int assetHash) { if (o is SlotDataAsset) { SlotDataAsset sd = o as SlotDataAsset; assetName = sd.slotName; assetHash = sd.nameHash; } else if (o is OverlayDataAsset) { OverlayDataAsset od = o as OverlayDataAsset; assetName = od.overlayName; assetHash = od.nameHash; } else if (o is RaceData) { RaceData rd = o as RaceData; assetName = rd.raceName; assetHash = UMAUtils.StringToHash(assetName); } else { assetName = o.name; assetHash = UMAUtils.StringToHash(assetName); } }
public static string GetEvilName(Object o) { if (!o) { return("<Not Found!>"); } if (o is SlotDataAsset) { SlotDataAsset sd = o as SlotDataAsset; if (!string.IsNullOrEmpty(sd.slotName)) { return(sd.slotName); } } if (o is OverlayDataAsset) { OverlayDataAsset od = o as OverlayDataAsset; if (!string.IsNullOrEmpty(od.overlayName)) { return(od.overlayName); } } if (o is RaceData) { RaceData rd = o as RaceData; if (!string.IsNullOrEmpty(rd.raceName)) { return(rd.raceName); } } return(o.name); }
private List <RandomColors> GetColorListForRace(RaceData rc) { UMATextRecipe utr = rc.baseRaceRecipe as UMATextRecipe; UMAPackedRecipeBase.UMAPackRecipe upr = utr.PackedLoad(); List <string> cols = new List <string>(); foreach (UMAPackedRecipeBase.PackedOverlayColorDataV3 pcd in upr.fColors) { if (pcd.name.Trim() != "-") { cols.Add(pcd.name); } } List <RandomColors> newColors = new List <RandomColors>(); foreach (string s in cols) { RandomColors rcs = new RandomColors(s, null); newColors.Add(rcs); } return(newColors); }
/// <summary> /// Add a race to the context. /// </summary> /// <param name="race">New race.</param> public override void AddRace(RaceData race) { raceLibrary.AddRace(race); raceLibrary.UpdateDictionary(); if (dynamicCharacterSystem != null) { dynamicCharacterSystem.RefreshRaceKeys(); } }
/// <summary> /// Add a race to the context. /// </summary> /// <param name="race">New race.</param> public override void AddRace(RaceData race) { AssetItem ai = new AssetItem(typeof(RaceData), race); UMAAssetIndexer.Instance.AddAsset(typeof(RaceData), race.raceName, "", race); //if (dynamicCharacterSystem != null) //{ // dynamicCharacterSystem.RefreshRaceKeys(); //} }
public void UpdateNewRace() { umaRace = umaData.umaRecipe.raceData; if (animationController != null) { umaData.animationController = animationController; // umaData.animator.runtimeAnimatorController = animationController; } umaData.umaGenerator = umaGenerator; umaData.Dirty(true, true, true); }
void SendRaceToUMA() { if (Gender == "Male") { _RaceData = raceLibrary.GetRace("HumanMale"); } else if (Gender == "Female") { _RaceData = raceLibrary.GetRace("HumanFemale"); } Debug.Log(_RaceData.raceName); // DefaultUMA.GetComponent<UMA.UMAData>().umaRecipe.SetRace(_RaceData); }
public RandomAvatar(RaceData race) { raceData = race; RaceName = race.raceName; SharedColors = new List <RandomColors>(); RandomWardrobeSlots = new List <RandomWardrobeSlot>(); RandomDna = new List <RandomDNA>(); SharedColors = GetColorListForRace(race); #if UNITY_EDITOR GuiFoldout = true; Delete = false; SetupDNA(race); #endif }
static void BonePoseUtilitiesWindow() { BonePoseUtilities window = ScriptableObject.CreateInstance(typeof(BonePoseUtilities)) as BonePoseUtilities; // Load races for lookup. List <string> RaceNames = new List <string>(); string[] foundRacesStrings = AssetDatabase.FindAssets("t:RaceData"); for (int i = 0; i < foundRacesStrings.Length; i++) { RaceData thisFoundRace = AssetDatabase.LoadAssetAtPath <RaceData>(AssetDatabase.GUIDToAssetPath(foundRacesStrings[i])); RaceNames.Add(thisFoundRace.raceName); } raceNames = RaceNames.ToArray(); window.ShowUtility(); }
public void UpdateNewRace() { #if SUPER_LOGGING Debug.Log("UpdateNewRace on DynamicCharacterAvatar: " + gameObject.name); #endif umaRace = umaData.umaRecipe.raceData; if (animationController != null) { umaData.animationController = animationController; } umaData.umaGenerator = umaGenerator; umaData.Dirty(true, true, true); }
/// <summary> /// Hide the avatar and clean up its components. /// </summary> public virtual void Hide() { if (umaData != null) { umaData.CleanTextures(); umaData.CleanMesh(true); umaData.CleanAvatar(); Destroy(umaData.umaRoot); umaData.umaRoot = null; umaData.SetRenderers(null); umaData.animator = null; umaData.firstBake = true; umaData.skeleton = null; } umaRace = null; }
public static void UpdateRace(RaceData race) { UMAAssetIndexer.Instance.ReleaseReference(race); List <DynamicCharacterAvatar> Avatars = GetSceneEditTimeAvatars(); foreach (DynamicCharacterAvatar dca in Avatars) { if (dca.activeRace.data != null) { RaceData rc = dca.activeRace.data; if (rc == race) { dca.GenerateSingleUMA(); } } } }
public static void UpdateRecipe(UMATextRecipe recipe) { UMAAssetIndexer.Instance.ReleaseReference(recipe); List <DynamicCharacterAvatar> Avatars = GetSceneEditTimeAvatars(); if (recipe is UMAWardrobeRecipe) { foreach (DynamicCharacterAvatar dca in Avatars) { var items = dca.preloadWardrobeRecipes.recipes; foreach (var wi in items) { if (wi == null) { continue; } var rcp = wi._recipe; if (rcp.name == recipe.name) { dca.GenerateSingleUMA(); break; } } } UMAAssetIndexer.Instance.ReleaseReference(recipe); return; } if (recipe is UMATextRecipe) { foreach (DynamicCharacterAvatar dca in Avatars) { if (dca.activeRace.data != null) { RaceData rc = dca.activeRace.data; if (recipe == rc.baseRaceRecipe) { dca.GenerateSingleUMA(); } } } } }
/// <summary> /// Hide the avatar and clean up its components. /// </summary> public virtual void Hide(bool DestroyRoot = true) { if (umaData != null) { umaData.CleanTextures(); umaData.CleanMesh(true); umaData.CleanAvatar(); if (DestroyRoot) { UMAUtils.DestroySceneObject(umaData.umaRoot); umaData.umaRoot = null; umaData.skeleton = null; } umaData.SetRenderers(null); umaData.animator = null; umaData.firstBake = true; } umaRace = null; }
override public void AddRace(RaceData race) { if (race == null) { return; } ValidateDictionary(); for (int i = 0; i < raceElementList.Length; i++) { if (raceElementList[i].raceName == race.raceName) { raceElementList[i] = race; return; } } var list = new RaceData[raceElementList.Length + 1]; Array.Copy(raceElementList, list, raceElementList.Length); list[raceElementList.Length] = race; raceElementList = list; raceDictionary.Add(race.raceName, race); }
public void SetupDNA(RaceData rc) { List <string> DNAList = new List <string>(); foreach (IDNAConverter cvt in rc.dnaConverterList) { if (cvt.DNAType == typeof(DynamicUMADna)) { DNAList.AddRange(((IDynamicDNAConverter)cvt).dnaAsset.Names); } else { if (cvt is DnaConverterBehaviour) { var legacyDNA = (cvt as DnaConverterBehaviour).DNAType.GetConstructor(System.Type.EmptyTypes).Invoke(null) as UMADnaBase; if (legacyDNA != null) { DNAList.AddRange(legacyDNA.Names); } } } } PossibleDNA = DNAList.ToArray(); }
/// <summary> /// Add a race to the context. /// </summary> /// <param name="race">New race.</param> public void AddRace(RaceData race) { raceLibrary.AddRace(race); }
public void GenerateAddressables() { try { //********************************************************************************************** //* Clear out the old data //********************************************************************************************** SlotTracker = new Dictionary <int, List <UMATextRecipe> >(); OverlayTracker = new Dictionary <int, List <UMATextRecipe> >(); TextureTracker = new Dictionary <int, List <UMATextRecipe> >(); GroupTracker = new Dictionary <int, AddressableAssetGroup>(); ClearAddressableFlags(typeof(SlotDataAsset)); ClearAddressableFlags(typeof(OverlayDataAsset)); // Will generate an editor context if needed. UMAContextBase context = UMAAssetIndexer.Instance.GetContext(); // Create the shared group that has each item packed separately. AddressableAssetGroup sharedGroup = AddressableUtility.AddressableSettings.CreateGroup(SharedGroupName, false, false, true, AddressableUtility.AddressableSettings.DefaultGroup.Schemas); sharedGroup.GetSchema <BundledAssetGroupSchema>().BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackSeparately; List <UMATextRecipe> theRecipes = new List <UMATextRecipe>(); //********************************************************************************************** //* Add Races //********************************************************************************************** System.Type theType = UMAAssetIndexer.Instance.GetIndexedType(typeof(RaceData)); var races = UMAAssetIndexer.Instance.GetAssetDictionary(theType).Values; foreach (AssetItem ai in races) { RaceData race = ai.Item as RaceData; if (race == null) { Debug.Log("Invalid race found!"); continue; } if (race.baseRaceRecipe as UMATextRecipe == null) { Debug.Log("Invalid base race recipe on race: " + race.raceName); } theRecipes.Add(race.baseRaceRecipe as UMATextRecipe); if (ai.IsAlwaysLoaded) { AssetItem recipe = UMAAssetIndexer.Instance.GetAssetItem <UMATextRecipe>(race.baseRaceRecipe.name); recipe.IsAlwaysLoaded = true; List <AssetItem> recipeItems = UMAAssetIndexer.Instance.GetAssetItems(race.baseRaceRecipe as UMAPackedRecipeBase, true); foreach (AssetItem recipeitem in recipeItems) { recipeitem.IsAlwaysLoaded = true; } } } var theRecipeItems = GetAddressableRecipes(); GenerateCollectionLabels(); GenerateLookups(context, theRecipeItems); float pos = 0.0f; float inc = 1.0f / theRecipes.Count; const string tprefix = "UTR_"; const string wprefix = "UWR_"; // Create the Addressable groups foreach (AssetItem recipeItem in theRecipeItems) { UMATextRecipe uwr = recipeItem.Item as UMATextRecipe; int iPos = Mathf.CeilToInt(pos); EditorUtility.DisplayProgressBar("Generating", "Creating Group: " + uwr.name, iPos); Debug.Log("Generating group: " + uwr.name); string groupName; if (uwr is UMAWardrobeRecipe) { groupName = wprefix + uwr.name; } else { groupName = tprefix + uwr.name; } AddressableAssetGroup recipeGroup = AddressableUtility.AddressableSettings.CreateGroup(groupName, false, false, true, AddressableUtility.AddressableSettings.DefaultGroup.Schemas); recipeGroup.GetSchema <BundledAssetGroupSchema>().BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackTogether; if (GroupTracker.ContainsKey(uwr.GetInstanceID())) { Debug.Log("Group already exists????? " + uwr.name); continue; } GroupTracker.Add(uwr.GetInstanceID(), recipeGroup); pos += inc; } AddAddressableAssets(SlotTracker, sharedGroup); AddAddressableAssets(OverlayTracker, sharedGroup); AddAddressableAssets(TextureTracker, sharedGroup); AssignAddressableInformation(); ReleaseReferences(UMAAssetIndexer.Instance.GetIndexedType(typeof(SlotDataAsset))); ReleaseReferences(UMAAssetIndexer.Instance.GetIndexedType(typeof(OverlayDataAsset))); CleanupAddressables(true); } finally { EditorUtility.ClearProgressBar(); UMAAssetIndexer.Instance.DestroyEditorUMAContextBase(); UMAAssetIndexer.Instance.ForceSave(); } }
/// <summary> /// Removes a list of downloadingAssetItems from the downloadingItems List. /// </summary> /// <param name="assetName"></param> public IEnumerator RemoveDownload(List <DownloadingAssetItem> itemsToRemove) { //Not used any more UMAs check the status of stuff they asked for themselves //Dictionary<UMAAvatarBase, List<string>> updatedUMAs = new Dictionary<UMAAvatarBase, List<string>>(); foreach (DownloadingAssetItem item in itemsToRemove) { item.isBeingRemoved = true; } foreach (DownloadingAssetItem item in itemsToRemove) { string error = ""; //we need to check everyitem in this batch belongs to an asset bundle that has actually been loaded LoadedAssetBundle loadedBundleTest = AssetBundleManager.GetLoadedAssetBundle(item.containingBundle, out error); AssetBundle loadedBundleABTest = loadedBundleTest.m_AssetBundle; if (loadedBundleABTest == null && (String.IsNullOrEmpty(error))) { while (loadedBundleTest.m_AssetBundle == null) { //could say we are unpacking here yield return(null); } } if (!String.IsNullOrEmpty(error)) { Debug.LogError(error); yield break; } } //Now every item in the batch should be in a loaded bundle that is ready to use. foreach (DownloadingAssetItem item in itemsToRemove) { if (item != null) { string error = ""; var loadedBundle = AssetBundleManager.GetLoadedAssetBundle(item.containingBundle, out error); var loadedBundleAB = loadedBundle.m_AssetBundle; if (!String.IsNullOrEmpty(error)) { Debug.LogError(error); yield break; } var itemFilename = AssetBundleManager.AssetBundleIndexObject.GetFilenameFromAssetName(item.containingBundle, item.requiredAssetName, item.tempAsset.GetType().ToString()); if (item.tempAsset.GetType() == typeof(RaceData)) { RaceData actualRace = loadedBundleAB.LoadAsset <RaceData>(itemFilename); UMAContext.Instance.raceLibrary.AddRace(actualRace); UMAContext.Instance.raceLibrary.UpdateDictionary(); } else if (item.tempAsset.GetType() == typeof(SlotDataAsset)) { SlotDataAsset thisSlot = null; thisSlot = loadedBundleAB.LoadAsset <SlotDataAsset>(itemFilename); if (thisSlot != null) { UMAContext.Instance.slotLibrary.AddSlotAsset(thisSlot); } else { Debug.LogWarning("[DynamicAssetLoader] could not add downloaded slot" + item.requiredAssetName); } } else if (item.tempAsset.GetType() == typeof(OverlayDataAsset)) { OverlayDataAsset thisOverlay = null; thisOverlay = loadedBundleAB.LoadAsset <OverlayDataAsset>(itemFilename); if (thisOverlay != null) { UMAContext.Instance.overlayLibrary.AddOverlayAsset(thisOverlay); } else { Debug.LogWarning("[DynamicAssetLoader] could not add downloaded overlay" + item.requiredAssetName + " from assetbundle " + item.containingBundle); } } else if (item.tempAsset.GetType() == typeof(UMATextRecipe)) { UMATextRecipe downloadedRecipe = loadedBundleAB.LoadAsset <UMATextRecipe>(itemFilename); (UMAContext.Instance.dynamicCharacterSystem as UMACharacterSystem.DynamicCharacterSystem).AddRecipe(downloadedRecipe); } else if (item.tempAsset.GetType() == typeof(UMAWardrobeRecipe)) { UMAWardrobeRecipe downloadedRecipe = loadedBundleAB.LoadAsset <UMAWardrobeRecipe>(itemFilename); (UMAContext.Instance.dynamicCharacterSystem as UMACharacterSystem.DynamicCharacterSystem).AddRecipe(downloadedRecipe); } else if (item.dynamicCallback.Count > 0) { //get the asset as whatever the type of the tempAsset is //send this as an array to the dynamicCallback var downloadedAsset = loadedBundleAB.LoadAsset(itemFilename, item.tempAsset.GetType()); var downloadedAssetArray = Array.CreateInstance(item.tempAsset.GetType(), 1); downloadedAssetArray.SetValue(downloadedAsset, 0); for (int i = 0; i < item.dynamicCallback.Count; i++) { item.dynamicCallback[i].DynamicInvoke(downloadedAssetArray); } } if (!String.IsNullOrEmpty(error)) { Debug.LogError(error); } } downloadingItems.Remove(item); } if (downloadingItems.Count == 0) { areDownloadedItemsReady = true; //AssetBundleManager.UnloadAllAssetBundles();//we cant do this yet } //yield break; }
/// <summary> /// Given a raceNames returns whether this race has been set to be 'cross compatible' with that race. /// </summary> public bool IsCrossCompatibleWith(RaceData compatibleRace) { return(GetCrossCompatibleRaces().Contains(compatibleRace.raceName)); }
public abstract void AddRace(RaceData race);
public static bool RaceIsValid(RaceData raceData) { return(raceData != null && !string.IsNullOrEmpty(raceData.raceName)); }
/// <summary> /// Removes a list of downloadingAssetItems from the downloadingItems List. /// </summary> /// <param name="assetName"></param> public IEnumerator RemoveDownload(List <DownloadingAssetItem> itemsToRemove) { //Not used any more UMAs check the status of stuff they asked for themselves //Dictionary<UMAAvatarBase, List<string>> updatedUMAs = new Dictionary<UMAAvatarBase, List<string>>(); foreach (DownloadingAssetItem item in itemsToRemove) { item.isBeingRemoved = true; } foreach (DownloadingAssetItem item in itemsToRemove) { string error = ""; //we need to check everyitem in this batch belongs to an asset bundle that has actually been loaded LoadedAssetBundle loadedBundleTest = AssetBundleManager.GetLoadedAssetBundle(item.containingBundle, out error); AssetBundle loadedBundleABTest = loadedBundleTest.m_AssetBundle; if (loadedBundleABTest == null && (String.IsNullOrEmpty(error))) { while (loadedBundleTest.m_AssetBundle == null) { //could say we are unpacking here yield return(null); } } if (!String.IsNullOrEmpty(error)) { Debug.LogError(error); yield break; } } //Now every item in the batch should be in a loaded bundle that is ready to use. foreach (DownloadingAssetItem item in itemsToRemove) { if (item != null) { string error = ""; var loadedBundle = AssetBundleManager.GetLoadedAssetBundle(item.containingBundle, out error); var loadedBundleAB = loadedBundle.m_AssetBundle; if (!String.IsNullOrEmpty(error)) { Debug.LogError(error); yield break; } var assetType = item.tempAsset.GetType(); //deal with RuntimeAnimatorController funkiness //the actual type of an instantiated clone of a RuntimeAnimatorController in the editor is UnityEditor.Animations.AnimatorController if (assetType.ToString().IndexOf("AnimatorController") > -1) { assetType = typeof(RuntimeAnimatorController); } var itemFilename = AssetBundleManager.AssetBundleIndexObject.GetFilenameFromAssetName(item.containingBundle, item.requiredAssetName, assetType.ToString()); if (assetType == typeof(RaceData)) { //HACK TO FIX RACEDATA DYNAMICDNACONVERTERS DYNAMICDNA ASSETS CAUSING LOAD FAILURES in UNITY 5.5+ //As of Unity 5.5 a bug has reappeared when loading some types of assets that reference assets in other bundles. //AssetBundleManager successfully ensures these required bundles are loaded first, but even so Unity fils to load //the required asset from them in some cases, notably it seems when the required asset is set in the field of a Prefab (like our DNAAssets are) //To fix this generally we could 'LoadAllAssets' from any dependent bundles, but this could incur significant memory overhead //So for now we will just fix this for UMA and hope a patch is forthcoming in a subsequent version of Unity if (AssetBundleManager.AssetBundleIndexObject.GetAllDependencies(item.containingBundle).Length > 0) { var allDeps = AssetBundleManager.AssetBundleIndexObject.GetAllDependencies(item.containingBundle); for (int i = 0; i < allDeps.Length; i++) { string depsError = ""; LoadedAssetBundle depsBundle = AssetBundleManager.GetLoadedAssetBundle(allDeps[i], out depsError); if (String.IsNullOrEmpty(depsError) && depsBundle != null) { depsBundle.m_AssetBundle.LoadAllAssets <DynamicUMADnaAsset>(); } } } RaceData actualRace = loadedBundleAB.LoadAsset <RaceData>(itemFilename); UMAContext.Instance.raceLibrary.AddRace(actualRace); UMAContext.Instance.raceLibrary.UpdateDictionary(); } else if (assetType == typeof(SlotDataAsset)) { SlotDataAsset thisSlot = null; thisSlot = loadedBundleAB.LoadAsset <SlotDataAsset>(itemFilename); if (thisSlot != null) { UMAContext.Instance.slotLibrary.AddSlotAsset(thisSlot); } else { Debug.LogWarning("[DynamicAssetLoader] could not add downloaded slot" + item.requiredAssetName); } } else if (assetType == typeof(OverlayDataAsset)) { OverlayDataAsset thisOverlay = null; thisOverlay = loadedBundleAB.LoadAsset <OverlayDataAsset>(itemFilename); if (thisOverlay != null) { UMAContext.Instance.overlayLibrary.AddOverlayAsset(thisOverlay); } else { Debug.LogWarning("[DynamicAssetLoader] could not add downloaded overlay" + item.requiredAssetName + " from assetbundle " + item.containingBundle); } } else if (assetType == typeof(UMATextRecipe)) { UMATextRecipe downloadedRecipe = loadedBundleAB.LoadAsset <UMATextRecipe>(itemFilename); (UMAContext.Instance.dynamicCharacterSystem as UMACharacterSystem.DynamicCharacterSystem).AddRecipe(downloadedRecipe); } else if (assetType == typeof(UMAWardrobeRecipe)) { UMAWardrobeRecipe downloadedRecipe = loadedBundleAB.LoadAsset <UMAWardrobeRecipe>(itemFilename); (UMAContext.Instance.dynamicCharacterSystem as UMACharacterSystem.DynamicCharacterSystem).AddRecipe(downloadedRecipe); } else if (item.dynamicCallback.Count > 0) { //get the asset as whatever the type of the tempAsset is //send this as an array to the dynamicCallback var downloadedAsset = loadedBundleAB.LoadAsset(itemFilename, assetType); var downloadedAssetArray = Array.CreateInstance(assetType, 1); downloadedAssetArray.SetValue(downloadedAsset, 0); for (int i = 0; i < item.dynamicCallback.Count; i++) { item.dynamicCallback[i].DynamicInvoke(downloadedAssetArray); } } if (!String.IsNullOrEmpty(error)) { Debug.LogError(error); } } downloadingItems.Remove(item); } if (downloadingItems.Count == 0) { areDownloadedItemsReady = true; //AssetBundleManager.UnloadAllAssetBundles();//we cant do this yet } //yield break; }
public void OnEnable() { race = target as RaceData; }
#pragma warning restore 618 public void SetRace(RaceData raceData) { this.raceData = raceData; ClearDNAConverters(); }