Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class AnimatorParameter : ScriptableObject
  5. {
  6. [SerializeField]
  7. RuntimeAnimatorController animatorController;
  8.  
  9. public AnimatorParameterInfo[] parameterInfos;
  10.  
  11. [System.Serializable]
  12. public struct AnimatorParameterInfo
  13. {
  14. public ParameterType type;
  15. public int hashName;
  16. public string name;
  17. public enum ParameterType
  18. {
  19. NONE,
  20. BOOL,
  21. FLOAT,
  22. INT,
  23. TRIGGER
  24. }
  25. }
  26. #if UNITY_EDITOR
  27. [ContextMenu("Setup")]
  28. void Setup()
  29. {
  30. var controller = animatorController as UnityEditorInternal.AnimatorController;
  31. parameterInfos = new AnimatorParameterInfo[controller.parameterCount];
  32.  
  33.  
  34. UnityEditor.AssetDatabase.RenameAsset(UnityEditor.AssetDatabase.GetAssetPath(this), animatorController.name);
  35. name = animatorController.name;
  36.  
  37. for (int i=0; i<controller.parameterCount; i++) {
  38. var param = controller.GetParameter (i);
  39. parameterInfos [i].hashName = Animator.StringToHash (param.name);
  40. parameterInfos[i].name = param.name;
  41. if (param.type == UnityEditorInternal.AnimatorControllerParameterType.Bool) {
  42. parameterInfos [i].type = AnimatorParameterInfo.ParameterType.BOOL;
  43. } else if (param.type == UnityEditorInternal.AnimatorControllerParameterType.Float) {
  44. parameterInfos [i].type = AnimatorParameterInfo.ParameterType.FLOAT;
  45. } else if (param.type == UnityEditorInternal.AnimatorControllerParameterType.Int) {
  46. parameterInfos [i].type = AnimatorParameterInfo.ParameterType.INT;
  47. } else if (param.type == UnityEditorInternal.AnimatorControllerParameterType.Trigger) {
  48. parameterInfos [i].type = AnimatorParameterInfo.ParameterType.TRIGGER;
  49. }
  50. }
  51.  
  52. UnityEditor.EditorUtility.SetDirty(this);
  53. }
  54.  
  55. [UnityEditor.CustomEditor(typeof(AnimatorParameter)), UnityEditor.CanEditMultipleObjects]
  56. class AnimatorParameterEditor : UnityEditor.Editor
  57. {
  58. public override void OnInspectorGUI ()
  59. {
  60. base.OnInspectorGUI ();
  61.  
  62.  
  63. UnityEditor.EditorGUILayout.Space();
  64. if( GUILayout.Button("Setup") ){
  65. foreach( var obj in targets )
  66. {
  67. var animparameter = obj as AnimatorParameter;
  68. animparameter.Setup();
  69. }
  70. }
  71. }
  72. }
  73.  
  74. #endif
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement