Last active
May 2, 2022 09:11
-
-
Save Ryxali/33fa23ec833b2b64aae88e616e0f03bb to your computer and use it in GitHub Desktop.
Enforcing a specific transition configuration for all transitions in a RuntimeAnimationController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using System.Text.RegularExpressions; | |
using System.IO; | |
// Drop this in some Editor folder | |
public static class AnimatorControllerTool { | |
[MenuItem("CONTEXT/RuntimeAnimatorController/Enforce Transition Settings")] | |
public static void FixTransitions(MenuCommand command) | |
{ | |
var path = AssetDatabase.GetAssetPath(command.context); | |
path = Regex.Replace(path, "^Assets", Application.dataPath); | |
AssetDatabase.StartAssetEditing(); | |
try | |
{ | |
// We can't use serialization to read the properties, so we rely on editing the asset text file instead | |
// This naturally requires asset files to be serialized as text | |
// You can achieve this by Edit/Project Settings with Asset Serialization Mode set to Force Text | |
var txt = File.ReadAllText(path); | |
txt = Regex.Replace(txt, @"(?<param>m_HasExitTime:\s+)\d+", "${param}0"); | |
txt = Regex.Replace(txt, @"(?<param>m_HasFixedDuration:\s+)\d+", "${param}1"); | |
txt = Regex.Replace(txt, @"(?<param>m_TransitionDuration:\s+)[\.\d]+", "${param}0"); | |
txt = Regex.Replace(txt, @"(?<param>m_TransitionOffset:\s+)[\.\d]+", "${param}0"); | |
File.WriteAllText(path, txt); | |
} | |
catch(System.Exception e) { Debug.LogException(e); } | |
AssetDatabase.StopAssetEditing(); | |
AssetDatabase.Refresh(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
BEWARE that this operation can be really destructive as it manually overwrites parts of the asset data in a really hacky way. So backup your asset before attempting this!