public DNAEvaluator(string dnaName, DNAEvaluationGraph evaluator = null, float multiplier = 1f, CalcOption calcOption = CalcOption.Add) { _calcOption = calcOption; _dnaName = dnaName; _dnaNameHash = UMAUtils.StringToHash(_dnaName); _evaluator = evaluator == null ? DNAEvaluationGraph.Default : new DNAEvaluationGraph(evaluator); _multiplier = multiplier; _initialized = true; }
public DNAEvaluator(DNAEvaluator other) { _calcOption = other.calcOption; _dnaName = other.dnaName; _dnaNameHash = UMAUtils.StringToHash(_dnaName); _evaluator = other.evaluator == null ? DNAEvaluationGraph.Default : new DNAEvaluationGraph(other.evaluator); _multiplier = other.multiplier; _initialized = true; }
//I'd really like this if its inspected at runtime to show the actual DNA value thats chosen being evaluated //but for that I'd need some kind of context thing like UMABonePose has //I'll get to it...TODO protected float EvalauateValue(float value, SerializedProperty evaluatorProp) { //maybe I can get the active dna off the plugin using property.serializedObject.targetObject like dnaEvalutaor does? var multiplierProp = evaluatorProp.FindPropertyRelative("_multiplier"); var graphProp = evaluatorProp.FindPropertyRelative("_evaluator"); var graphNameProp = graphProp.FindPropertyRelative("_name"); var graphCurveProp = graphProp.FindPropertyRelative("_graph"); dummyEvaluator = new DNAEvaluationGraph(graphNameProp.stringValue, graphCurveProp.animationCurveValue); return(dummyEvaluator.Evaluate(value) * multiplierProp.floatValue); }
/// <summary> /// Deletes any customPresets using the given graph from all preset libraries in the project /// </summary> public static void DeleteCustomPreset(DNAEvaluationGraph graphToDelete) { var presetLibs = GetAllInstances(); int indexToDel = -1; for (int i = 0; i < presetLibs.Length; i++) { if (presetLibs[i]._customGraphPresets.Count > 0) { for (int ci = 0; ci < presetLibs[i]._customGraphPresets.Count; ci++) { if (presetLibs[i]._customGraphPresets[ci] == graphToDelete) { Debug.Log("Found Delete Target " + graphToDelete.name + " in " + presetLibs[i].name); indexToDel = ci; break; } } if (indexToDel > -1) { Debug.Log(graphToDelete.name + " Deleted from list in " + presetLibs[i].name); presetLibs[i]._customGraphPresets.RemoveAt(indexToDel); try { presetLibs[i]._customGraphTooltips.RemoveAt(indexToDel); } catch { } } } if (indexToDel > -1) { //force the global caches to refresh _cachedGlobalList.Clear(); _cachedGlobalTooltips.Clear(); EditorUtility.SetDirty(presetLibs[i]); AssetDatabase.SaveAssets(); break; } } }
/// <summary> /// Attempts to find the tooltip for the given evaluation graph from all the graph presets in the project (Default and Custom) /// </summary> public static string GetTooltipFor(DNAEvaluationGraph graph) { var ret = graph.name; foreach (KeyValuePair <DNAEvaluationGraph, string> kp in DNAEvaluationGraph.Defaults) { if (kp.Key.GraphMatches(graph)) { return(kp.Value); } } var _allCustomPresets = AllCustomGraphPresets; for (int i = 0; i < _allCustomPresets.Count; i++) { if (_allCustomPresets[i].GraphMatches(graph)) { return(AllCustomGraphTooltips[i]); } } return(ret); }
public MasterWeight(MasterWeightType masterWeightType = MasterWeightType.UseGlobalValue, float defaultWeight = 1f, string dnaForWeightName = "", DNAEvaluationGraph dnaForWeightGraph = null, float dnaForWeightMultiplier = 1f) { _masterWeightType = masterWeightType; _globalWeight = defaultWeight; if (!string.IsNullOrEmpty(dnaForWeightName)) { _DNAForWeight = new DNAEvaluator(dnaForWeightName, dnaForWeightGraph, dnaForWeightMultiplier); } else { _DNAForWeight = new DNAEvaluator("", DNAEvaluationGraph.Raw, 1); } }
public EditorHelper(DNAEvaluationGraph dnaEasingCurve) { _evaluationGraph = new DNAEvaluationGraph(dnaEasingCurve); }
public EditorHelper(AnimationCurve graph, string name, string description) { _evaluationGraph = new DNAEvaluationGraph(name, graph); }
public EditorHelper() { _evaluationGraph = new DNAEvaluationGraph(); }
/// <summary> /// Add a new preset to this assets DNAEvaluatorPresets list /// </summary> /// <returns>Returns true if the preset was added. False if another preset already existed with the same name or graph</returns> public bool AddNewPreset(string name, string tooltip, AnimationCurve graph, ref string nameError, ref string graphError, DNAEvaluationGraph existingGraph = null) { nameError = ""; graphError = ""; bool added = true; if (graph == null) { graphError = "No graph Provided"; Debug.LogWarning(graphError); return(false); } if (string.IsNullOrEmpty(name)) { nameError = "No name provided"; Debug.LogWarning(nameError); return(false); } if (graph.keys.Length < 2) { graphError = "The new graph must have at least two keys"; Debug.LogWarning(graphError); return(false); } //if we are not updating an existing one if (existingGraph == null) { //make sure there is not already an existing one if (!CheckForExistingPreset(name, graph, ref nameError, ref graphError)) { Debug.LogWarning("Graph could not be added"); if (!string.IsNullOrEmpty(nameError)) { Debug.LogWarning(nameError); } if (!string.IsNullOrEmpty(graphError)) { Debug.LogWarning(graphError); } return(false); } _customGraphPresets.Add(new DNAEvaluationGraph(name, graph)); _customGraphTooltips.Add(tooltip); } else { //get the existing one (which might reside in another asset) and update that var presetLibs = GetAllInstances(); int foundIndex = -1; for (int i = 0; i < presetLibs.Length; i++) { foundIndex = -1; for (int ci = 0; ci < presetLibs[i]._customGraphPresets.Count; ci++) { if (presetLibs[i]._customGraphPresets[ci] == existingGraph) { foundIndex = ci; break; } } if (foundIndex >= 0) { presetLibs[i]._customGraphPresets[foundIndex] = new DNAEvaluationGraph(name, graph); presetLibs[i]._customGraphTooltips[foundIndex] = tooltip; added = true; EditorUtility.SetDirty(presetLibs[i]); //AssetDatabase.SaveAssets(); break; } } if (!added) { nameError = graphError = "Could not find existsing graph to update"; } } if (added) { //force the global caches to refresh _cachedGlobalList.Clear(); _cachedGlobalTooltips.Clear(); } return(added); }