/// <summary> /// Creates a new plugin of the given type and stores it inside the given converterController asset /// </summary> /// <returns>Returns the created asset</returns> private static DynamicDNAPlugin CreatePlugin(System.Type pluginType, DynamicDNAConverterController converter) { //Checks and warnings if (pluginType == null) { Debug.LogWarning("Could not create plugin because the plugin type was null"); return(null); } if (converter == null) { Debug.LogWarning("Could not create plugin because no converterController was provided to add it to"); return(null); } if (!DynamicDNAPlugin.IsValidPluginType(pluginType)) { Debug.LogWarning("Could not create plugin because it did not descend from DynamicDNAPlugin"); return(null); } DynamicDNAPlugin asset = ScriptableObject.CreateInstance(pluginType) as DynamicDNAPlugin; asset.name = converter.GetUniquePluginName(pluginType.Name.Replace("Plugin", "") + "s"); #if UNITY_EDITOR Debug.Log(pluginType + " created successfully! Its asset '" + asset.name + "' has been stored in " + converter.name); AssetDatabase.AddObjectToAsset(asset, converter); #endif return(asset); }
//UMA 2.8 FixDNAPrefabs: Swaps the legacy converter (DnaConverterBehaviour Prefab) for the new DNAConverterController /// <summary> /// Replaces a legacy DnaConverterBehaviour Prefab with a new DynamicDNAConverterController /// </summary> /// <returns>returns true if any converters were replaced.</returns> public bool UpgradeFromLegacy(DnaConverterBehaviour oldConverter, DynamicDNAConverterController newConverter) { if (_slotDNA.Value as Object == oldConverter) //Not sure why I am being told by visualStudio to cast the left side to Object here... { _slotDNA.Value = newConverter; return(true); } return(false); }
//UMA 2.8 FixDNAPrefabs: Swaps the legacy converter (DnaConverterBehaviour Prefab) for the new DNAConverterController /// <summary> /// Replaces a legacy DnaConverterBehaviour Prefab with a new DynamicDNAConverterController /// </summary> /// <returns>returns true if any converters were replaced.</returns> public bool UpgradeFromLegacy(DnaConverterBehaviour oldConverter, DynamicDNAConverterController newConverter) { if (_dnaConverterList.Contains(oldConverter)) { if (_dnaConverterList.Replace(oldConverter, newConverter)) { return(true); } } return(false); }
private void CreatePoseSet(string fileName) { SlotDataAsset sda = CustomAssetUtility.CreateAsset <SlotDataAsset>("", false, fileName + "_Slot", false); sda.slotName = sda.name; sda.nameHash = UMAUtils.StringToHash(sda.slotName); DynamicDNAConverterController ddcc = UMA.CustomAssetUtility.CreateAsset <DynamicDNAConverterController>("", false, fileName + "_Controller", false); sda.slotDNA = ddcc; DynamicUMADnaAsset duda = UMA.CustomAssetUtility.CreateAsset <DynamicUMADnaAsset>("", false, fileName + "_DNAAsset", false); ddcc.DNAAsset = duda; UMABonePose bp = UMA.CustomAssetUtility.CreateAsset <UMABonePose>("", true, fileName + "_Pose", false); BonePoseDNAConverterPlugin bpdcp = (BonePoseDNAConverterPlugin)ddcc.AddPlugin(typeof(BonePoseDNAConverterPlugin)); bpdcp.poseDNAConverters.Add(new BonePoseDNAConverterPlugin.BonePoseDNAConverter()); bpdcp.poseDNAConverters[0].poseToApply = bp; bpdcp.poseDNAConverters[0].startingPoseWeight = 1.0f; EditorUtility.SetDirty(sda); EditorUtility.SetDirty(ddcc); EditorUtility.SetDirty(duda); EditorUtility.SetDirty(bp); EditorUtility.SetDirty(bpdcp); if (addToLibrary) { UMAAssetIndexer.Instance.EvilAddAsset(typeof(SlotDataAsset), sda); UMAAssetIndexer.Instance.EvilAddAsset(typeof(DynamicUMADnaAsset), duda); EditorUtility.SetDirty(UMAAssetIndexer.Instance); } if (createWardrobeRecipe) { string path = CustomAssetUtility.GetAssetPathAndName <UMAWardrobeRecipe>(fileName, false); UMAWardrobeRecipe uwr = UMAEditorUtilities.CreateRecipe(path, sda, null, fileName, addToLibrary); uwr.compatibleRaces = new List <string>(); uwr.wardrobeSlot = "Physique"; uwr.compatibleRaces.Add(raceNames[selectedRace]); EditorUtility.SetDirty(uwr); } AssetDatabase.SaveAssets(); }
//UMA 2.8 FixDNAPrefabs: Swaps the legacy converter (DnaConverterBehaviour Prefab) for the new DNAConverterController /// <summary> /// Replaces a legacy DnaConverterBehaviour Prefab with a new DynamicDNAConverterController /// </summary> /// <returns>returns true if any converters were replaced.</returns> public bool UpgradeFromLegacy(DnaConverterBehaviour oldConverter, DynamicDNAConverterController newConverter, bool saveChanges = false) { if (_dnaConverter.Value as Object == oldConverter) //Not sure why I am being told by visualStudio to cast the left side to Object here... { _dnaConverter.Value = newConverter; //we need to update means/spreads/deviations here too- keeping existing data if we can var matchingIndexes = GetMatchingIndexes(oldConverter, newConverter); var newMeans = new float[EntryCount]; var newDeviations = new float[EntryCount]; var newSpreads = new float[EntryCount]; for (int i = 0; i < EntryCount; i++) { if (matchingIndexes.ContainsKey(i)) { newMeans[i] = means[matchingIndexes[i]]; newDeviations[i] = deviations[matchingIndexes[i]]; newSpreads[i] = spreads[matchingIndexes[i]]; } else { newMeans[i] = 0.5f; newDeviations[i] = 0.16f; newSpreads[i] = 0.5f; } } means = newMeans; deviations = newDeviations; spreads = newSpreads; #if UNITY_EDITOR if (saveChanges) { UnityEditor.EditorUtility.SetDirty(this); UnityEditor.AssetDatabase.SaveAssets(); } #endif return(true); } return(false); }