The Animation Layer contains a state machine that controls animations of a model or part of it.
private void UndoRedoPerformed() { AnimatorControllerLayer[] layers = this.m_Controller.layers; if (this.m_LayerIndex < layers.Length) { this.m_Layer = layers[this.m_LayerIndex]; base.Repaint(); } else { this.m_Layer = null; Undo.undoRedoPerformed = (Undo.UndoRedoCallback) Delegate.Remove(Undo.undoRedoPerformed, new Undo.UndoRedoCallback(this.UndoRedoPerformed)); base.Close(); } }
void Start() { if (LBoot.LBootApp.Running) { this.enabled = false; return; } this.animator = GetComponent <Animator>(); this.controller = this.animator.runtimeAnimatorController as UnityEditor.Animations.AnimatorController; this.clips = this.controller.animationClips; this.baseAnimLayer = this.controller.layers.ElementAt(0); overrideController = new AnimatorOverrideController(); overrideController.runtimeAnimatorController = this.animator.runtimeAnimatorController; if (effect != null) { effect.SetActive(false); } for (int i = 1; i <= 10; ++i) { var colGO = gameObject.transform.Find("AttackCollider_" + i.ToString()); colliderEnableList.Add(false); colliderList.Add(colGO.GetComponent <BoxCollider>()); } }
protected void OnRemoveLayer(int layerIndex) { int count = this.m_LayerList.list.Count; List <int> list = new List <int>(); for (int i = count - 1; i >= 0; i--) { UnityEditor.Animations.AnimatorControllerLayer animatorControllerLayer = this.m_LayerList.list[i] as UnityEditor.Animations.AnimatorControllerLayer; if (animatorControllerLayer.syncedLayerIndex == layerIndex || i == layerIndex) { list.Add(i); } } if (list.Count > 0) { if (list.Count == count) { if (list.Count == 1) { Debug.LogError("You cannot remove all layers from an AnimatorController."); } else if (list.Count > 1) { Debug.LogError("Deleting this layer will also delete all the layers that are synchronized on it. This operation cannot be performed because it would remove all the layers on this controller."); } } else if (list.Count == 1 || EditorUtility.DisplayDialog("Deleting synchronized layer", "Deleting this layer will also delete all the layers that are synchronized on it. Are you sure you want to delete it?", "Delete", "Cancel")) { this.m_Host.animatorController.RemoveLayers(list); this.ResetUI(); this.m_Host.ResetUI(); } } }
private static bool BuildStateMapImp(Animator animator, ref Hashtable statedic) { if (animator == null) { return(false); } UnityEditor.Animations.AnimatorController ac = (UnityEditor.Animations.AnimatorController)animator.runtimeAnimatorController; if (ac == null) { return(false); } int layerCount = ac.layers.Length; for (int k = 0; k < layerCount; k++) { UnityEditor.Animations.AnimatorControllerLayer layer = ac.layers[k]; if (layer == null) { continue; } UnityEditor.Animations.AnimatorStateMachine sm = layer.stateMachine; EnumStatesImp(animator, ref statedic, sm); } return(true); }
/// <summary> /// 添加动画状态机状态 /// </summary> /// <param name="path"></param> /// <param name="layer"></param> private static void AddStateTranstion(string path, AnimatorControllerLayer layer) { AnimatorStateMachine sm = layer.stateMachine; // 根据动画文件读取它的AnimationClip对象 var datas = AssetDatabase.LoadAllAssetsAtPath(path); if (datas.Length == 0) { Debug.Log(string.Format("Can't find clip in {0}", path)); return; } // 先添加一个默认的空状态 var emptyState = sm.AddState("empty"); sm.AddAnyStateTransition(emptyState); // 遍历模型中包含的动画片段,将其加入状态机中 foreach (var data in datas) { if (!(data is AnimationClip)) continue; var newClip = data as AnimationClip; if (newClip.name.StartsWith("__")) continue; // 取出动画名字,添加到state里面 var state = sm.AddState(newClip.name); state.motion = newClip; // 把State添加在Layer里面 sm.AddAnyStateTransition(state); } }
public void ValidateLayers(AnimatorController controller) { for (int i = 0; i < AvaCryptKeyNames.Length; ++i) { if (controller.layers.All(l => l.name != AvaCryptKeyNames[i])) { CreateLayer(i, controller); } else { Debug.Log($"Layer already existing: {AvaCryptKeyNames[i]}"); AnimatorControllerLayer layer = controller.layers.FirstOrDefault(l => l.name == AvaCryptKeyNames[i]); if (layer.stateMachine == null) { Debug.Log("Layer missing state machine."); // Try to delete blend tree and layers if by chance they still exist for some reason. DeleteObjectFromController(controller, string.Format(StateMachineName, i)); DeleteObjectFromController(controller, string.Format(BlendTreeName, i)); controller.RemoveLayer(controller.layers.ToList().IndexOf(layer)); CreateLayer(i, controller); } else { ValidateLayerBlendTree(i, layer, controller); } } } }
private void ValidateBitKeySwitch(int index, AnimatorControllerLayer layer, AnimatorController controller) { string trueSwitchName = string.Format(BitKeySwitchName, "True", index); string falseSwitchName = string.Format(BitKeySwitchName, "False", index); if (layer.stateMachine.states.All(s => s.state.name != trueSwitchName)) { Debug.Log($"Layer missing BitKeySwtich. {trueSwitchName}"); AddBitKeySwitch(index, layer, controller); } else { Debug.Log($"Layer BitKey Switch Validated {trueSwitchName}."); AssetDatabase.SaveAssets();; } if (layer.stateMachine.states.All(s => s.state.name != falseSwitchName)) { Debug.Log($"Layer missing BitKeySwtich. {falseSwitchName}"); AddBitKeySwitch(index, layer, controller); } else { Debug.Log($"Layer BitKey Switch Validated {falseSwitchName}."); AssetDatabase.SaveAssets();; } }
public void ValidateLayers(AnimatorController controller) { for (int i = 0; i < _avaCryptKeyNames.Length; ++i) { if (controller.layers.All(l => l.name != _avaCryptKeyNames[i])) { CreateLayer(i, controller); } else { Debug.Log($"Layer already existing: {_avaCryptKeyNames[i]}"); AnimatorControllerLayer layer = controller.layers.FirstOrDefault(l => l.name == _avaCryptKeyNames[i]); if (layer == null || layer.stateMachine == null) { Debug.Log("Layer missing state machine."); controller.RemoveLayer(controller.layers.ToList().IndexOf(layer)); CreateLayer(i, controller); } else { ValidateBitKeySwitch(i, layer, controller); } } } }
private void ValidateLayerBlendTree(int index, AnimatorControllerLayer layer, AnimatorController controller) { string blendTreeName = string.Format(BlendTreeName, index); if (layer.stateMachine.states.All(s => s.state.name != blendTreeName)) { Debug.Log($"Layer missing blend tree. {blendTreeName}"); DeleteObjectFromController(controller, blendTreeName); AddBlendTree(index, layer, controller); } else { Debug.Log($"Layer Blend Tree Validated {blendTreeName}."); BlendTree blendTree = layer.stateMachine.states.FirstOrDefault(s => s.state.name == blendTreeName).state.motion as BlendTree; // Just re-assign since ChildMotions aren't their own ScriptableObjects. ChildMotion childMotion0 = new ChildMotion { motion = _clips0[index], timeScale = 1 }; ChildMotion childMotion1 = new ChildMotion { motion = _clips100[index], timeScale = 1 }; blendTree.children = new ChildMotion[2] { childMotion0, childMotion1 }; AssetDatabase.SaveAssets();; } }
public void AddLayer(AnimatorControllerLayer layer) { this.undoHandler.DoUndo(this, "Layer added"); AnimatorControllerLayer[] layers = this.layers; ArrayUtility.Add <AnimatorControllerLayer>(ref layers, layer); this.layers = layers; }
public void AddLayer(AnimatorControllerLayer layer) { undoHandler.DoUndo(this, "Layer added"); AnimatorControllerLayer[] layerVector = layers; ArrayUtility.Add(ref layerVector, layer); layers = layerVector; }
void CreateAnimator() { //得到它的Layer, 默认layer为base 你可以去拓展 AnimatorControllerLayer layer = mAnimatorController.layers[0]; for (int i = 0; i < mAnimationClipList.Count; i++) { AddStateTransition(mAnimationClipList[i], layer); } }
internal AnimatorStateMachine FindEffectiveRootStateMachine(int layerIndex) { AnimatorControllerLayer animatorControllerLayer = this.layers[layerIndex]; while (animatorControllerLayer.syncedLayerIndex != -1) { animatorControllerLayer = this.layers[animatorControllerLayer.syncedLayerIndex]; } return(animatorControllerLayer.stateMachine); }
internal AnimatorStateMachine FindEffectiveRootStateMachine(int layerIndex) { AnimatorControllerLayer currentLayer = layers[layerIndex]; while (currentLayer.syncedLayerIndex != -1) { currentLayer = layers[currentLayer.syncedLayerIndex]; } return(currentLayer.stateMachine); }
void Start() { this.animator = GetComponent <Animator>(); this.controller = this.animator.runtimeAnimatorController as UnityEditor.Animations.AnimatorController; this.clips = this.controller.animationClips; this.baseAnimLayer = this.controller.layers.ElementAt(0); this.skin = transform.Find("skin"); this.skeleton = transform.Find("skeleton"); this.myBones = this.skeleton.GetComponentsInChildren <Transform>(true); this.bonename = this.controller.name.Split('_')[0]; if (effect != null) { effect.SetActive(false); } clothes = new List <GameObject>(); var files = Directory.GetFiles("Assets/Prefab/clothes/", "*.prefab", SearchOption.AllDirectories); foreach (var f in files) { Debug.Log(f); if (f.Contains(this.bonename)) { clothes.Add(AssetDatabase.LoadAssetAtPath <GameObject>(f)); } } foreach (var part in allParts) { foreach (var cloth in clothes) { if (cloth.name.Contains(part)) { List <GameObject> list = null; if (!clothesParts.TryGetValue(part, out list)) { list = new List <GameObject>(); clothesParts[part] = list; } list.Add(cloth); } } this.selectedParts[part] = false; } this.transform.position = new Vector3(0f, 1.3f, 0f); this.transform.localEulerAngles = new Vector3(0f, 180f, 0f); this.transform.localScale = Vector3.one; }
private static void AddStateTransition(AnimationClip clip, AnimatorControllerLayer layer) { AnimatorStateMachine sm = layer.stateMachine; //取出动画名子 添加到state里面 AnimatorState state = sm.AddState(clip.name); state.motion = clip; ////把state添加在layer里面 AnimatorStateTransition trans = sm.AddAnyStateTransition(state); ////把默认的时间条件删除 }
private static void AddStateTransition(AnimatorController ctrl, string path, AnimatorControllerLayer layer) { AnimatorStateMachine sm = layer.stateMachine; //根据动画文件读取它的AnimationClip对象 Object[] objs = AssetDatabase.LoadAllAssetsAtPath(path); List<AnimationClip> clips = new List<AnimationClip>(); for (int i = 0; i < objs.Length;i++ ) { AnimationClip clip = objs[i] as AnimationClip; if (clip != null && clip.name.IndexOf("__preview__") == -1) { clips.Add(clip); } } AnimatorState idleState = null; List<AnimatorState> otherStates = new List<AnimatorState>(); foreach (AnimationClip newClip in clips) { AnimatorState state = sm.AddState(newClip.name); state.motion = newClip; if (newClip.name == CreateAnimatorController.IdleName) { idleState = state; } else { string cond = string.Format("{0}_{1}",CreateAnimatorController.IdleName, newClip.name); ctrl.AddParameter(cond, AnimatorControllerParameterType.Bool); cond = string.Format("{1}_{0}", CreateAnimatorController.IdleName, newClip.name); ctrl.AddParameter(cond, AnimatorControllerParameterType.Bool); otherStates.Add(state); } } sm.defaultState = idleState; foreach (AnimatorState state in otherStates) { string cond = string.Format("{0}_{1}",CreateAnimatorController.IdleName, state.motion.name); AnimatorStateTransition tran = idleState.AddTransition(state); tran.AddCondition(AnimatorConditionMode.If, 0, cond); cond = string.Format("{1}_{0}", CreateAnimatorController.IdleName, state.motion.name); tran = state.AddTransition(idleState); tran.AddCondition(AnimatorConditionMode.If, 0, cond); } }
/// <summary> /// <para>Utility function to add a layer to the controller.</para> /// </summary> /// <param name="name">The name of the Layer.</param> /// <param name="layer">The layer to add.</param> public void AddLayer(string name) { AnimatorControllerLayer layer = new AnimatorControllerLayer(); layer.name = this.MakeUniqueLayerName(name); layer.stateMachine = new AnimatorStateMachine(); layer.stateMachine.name = layer.name; layer.stateMachine.hideFlags = HideFlags.HideInHierarchy; if (AssetDatabase.GetAssetPath((UnityEngine.Object) this) != string.Empty) { AssetDatabase.AddObjectToAsset((UnityEngine.Object)layer.stateMachine, AssetDatabase.GetAssetPath((UnityEngine.Object) this)); } this.AddLayer(layer); }
public void AddLayer(string name) { AnimatorControllerLayer animatorControllerLayer = new AnimatorControllerLayer(); animatorControllerLayer.name = this.MakeUniqueLayerName(name); animatorControllerLayer.stateMachine = new AnimatorStateMachine(); animatorControllerLayer.stateMachine.name = animatorControllerLayer.name; animatorControllerLayer.stateMachine.hideFlags = HideFlags.HideInHierarchy; if (AssetDatabase.GetAssetPath(this) != "") { AssetDatabase.AddObjectToAsset(animatorControllerLayer.stateMachine, AssetDatabase.GetAssetPath(this)); } this.AddLayer(animatorControllerLayer); }
static UnityEditor.Animations.AnimatorController BuildAnimationController(List <AnimationClip> clips, string name) { System.IO.Directory.CreateDirectory(animationControllerPath); UnityEditor.Animations.AnimatorController animatorController = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath(animationControllerPath + "/" + name + ".controller"); UnityEditor.Animations.AnimatorControllerLayer layer = animatorController.layers[0]; UnityEditor.Animations.AnimatorStateMachine sm = layer.stateMachine; foreach (AnimationClip newClip in clips) { UnityEditor.Animations.AnimatorState state = sm.AddState(newClip.name); state.motion = newClip; } AssetDatabase.SaveAssets(); return(animatorController); }
private void OnMouseUpLayer(ReorderableList list) { if ((this.m_HadKeyFocusAtMouseDown && (list.index == this.m_LastSelectedIndex)) && (Event.current.button == 0)) { UnityEditor.Animations.AnimatorControllerLayer layer = list.list[list.index] as UnityEditor.Animations.AnimatorControllerLayer; this.renameOverlay.BeginRename(layer.name, list.index, 0.1f); } else if ((AnimatorControllerTool.tool.stateMachineGraph.activeStateMachine != null) && !Selection.Contains(AnimatorControllerTool.tool.stateMachineGraph.activeStateMachine)) { Selection.objects = new List <UnityEngine.Object> { AnimatorControllerTool.tool.stateMachineGraph.activeStateMachine }.ToArray(); } this.m_LastSelectedIndex = list.index; }
private static void AddStateTransition(string path, UnityEditor.Animations.AnimatorControllerLayer layer, string motionName, Vector3 pos) { UnityEditor.Animations.AnimatorStateMachine sm = layer.stateMachine; Motion motion = AssetDatabase.LoadAssetAtPath(path, typeof(Motion)) as Motion; //根据动画文件读取它的Motion对象 UnityEditor.Animations.AnimatorState state = sm.AddState(motionName, pos); //motion.name state.motion = motion; //取出动画名子 添加到state里面 UnityEditor.Animations.AnimatorStateTransition trans = sm.AddAnyStateTransition(state); //把state添加在layer里面 trans.hasExitTime = false; //把默认的时间条件删除 //false //trans.exitTime = 1f; //0.9f trans.duration = 0f; //默认过渡时间 // 0.1f trans.canTransitionToSelf = true; //默认true }
void OnGUI() { if (LBoot.LBootApp.Running) { return; } scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, GUILayout.Width(size.x), GUILayout.Height(size.y)); EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.Label("preview skill effects"); if (baseAnimLayer == null) { baseAnimLayer = this.controller.layers.ElementAt(0); } for (int i = 0; i < baseAnimLayer.stateMachine.states.Length; i++) { var state = baseAnimLayer.stateMachine.states[i]; if (GUILayout.Button(state.state.name, EditorStyles.miniButtonMid)) { this.time = 0; animTimeVal = 0; preATV = 0; timer = 0; preState = state.state.name; this.animator.Play(state.state.name, 0, 0); this.animator.enabled = true; this.animator.speed = 1.0f; if (effect != null) { effect.SetActive(false); effect.SetActive(true); } } } EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.Label("play time: " + timer.ToString()); animTimeVal = GUILayout.HorizontalSlider(animTimeVal, 0.0f, 1.0f, GUILayout.Width(300)); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndScrollView(); }
public void AddLayer(string name) { AnimatorControllerLayer newLayer = new AnimatorControllerLayer(); newLayer.name = MakeUniqueLayerName(name); newLayer.stateMachine = new AnimatorStateMachine(); newLayer.stateMachine.name = newLayer.name; newLayer.stateMachine.hideFlags = HideFlags.HideInHierarchy; if (AssetDatabase.GetAssetPath(this) != "") { AssetDatabase.AddObjectToAsset(newLayer.stateMachine, AssetDatabase.GetAssetPath(this)); } undoHandler.DoUndoCreated(newLayer.stateMachine, "Layer added"); AddLayer(newLayer); }
static UnityEditor.Animations.AnimatorController BuildAnimationController(List <AnimationClip> clips, string name) { UnityEditor.Animations.AnimatorController animatorController = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath(AnimationControllerPath + "/" + name + ".controller"); UnityEditor.Animations.AnimatorControllerLayer layer = animatorController.layers[0]; AnimatorStateMachine sm = layer.stateMachine; foreach (AnimationClip newClip in clips) { AnimatorState state = sm.AddState(newClip.name); state.motion = newClip; // if(newClip.name == "idle") // { // sm.defaultState = state; // } } AssetDatabase.SaveAssets(); return(animatorController); }
private AnimationClip[] GetAnimClip(Animator animator) { List <AnimationClip> result = new List <AnimationClip>(); AnimatorController animatorController = animator.runtimeAnimatorController as AnimatorController; AnimatorControllerLayer animatorControllerLayer = animatorController.layers[0]; foreach (ChildAnimatorState child in animatorControllerLayer.stateMachine.states) { AnimationClip animClip = child.state.motion as AnimationClip; if (animClip != null) { result.Add(animClip); } } return(result.ToArray()); }
void test02() { AnimatorController controller = AnimatorController.CreateAnimatorControllerAtPath("Assets/animation.controller"); // Add parameters //controller.AddLayer("hahaha"); AnimatorState mstate = new AnimatorState(); mstate.name = "myState"; Motion mmotion = Resources.Load <AnimationClip>("animation/playerClip") as Motion; mmotion.name = "myMotion"; AnimatorControllerLayer myLayer = new AnimatorControllerLayer(); myLayer.name = "hahaha"; //myLayer.SetOverrideBehaviours(mstate,; myLayer.SetOverrideMotion(mstate, mmotion); controller.AddLayer(myLayer); }
void AddBitKeySwitch(int index, AnimatorControllerLayer layer, AnimatorController controller) { string trueSwitchName = string.Format(BitKeySwitchName, "True", index); string falseSwitchName = string.Format(BitKeySwitchName, "False", index); AnimatorState falseState = layer.stateMachine.AddState(falseSwitchName); falseState.motion = _clipsFalse[index]; falseState.speed = 1; AnimatorCondition falseCondition = new AnimatorCondition { mode = AnimatorConditionMode.IfNot, parameter = _avaCryptKeyNames[index], threshold = 0 }; AnimatorStateTransition falseTransition = layer.stateMachine.AddAnyStateTransition(falseState); falseTransition.canTransitionToSelf = false; falseTransition.duration = 0; falseTransition.conditions = new[] { falseCondition }; AnimatorState trueState = layer.stateMachine.AddState(trueSwitchName); trueState.motion = _clipsTrue[index]; trueState.speed = 1; AnimatorCondition trueCondition = new AnimatorCondition { mode = AnimatorConditionMode.If, parameter = _avaCryptKeyNames[index], }; AnimatorStateTransition trueTransition = layer.stateMachine.AddAnyStateTransition(trueState); trueTransition.canTransitionToSelf = false; trueTransition.duration = 0; trueTransition.conditions = new[] { trueCondition }; AssetDatabase.SaveAssets(); }
private void CreateLayer(int index, AnimatorController controller) { Debug.Log($"Creating layer: {AvaCryptKeyNames[index]}"); string controllerPath = AssetDatabase.GetAssetPath(controller); AnimatorControllerLayer layer = new AnimatorControllerLayer { name = AvaCryptKeyNames[index], defaultWeight = 1, stateMachine = new AnimatorStateMachine(), }; layer.stateMachine.name = string.Format(StateMachineName, index); controller.AddLayer(layer); AssetDatabase.AddObjectToAsset(layer.stateMachine, controllerPath); AssetDatabase.SaveAssets(); AddBlendTree(index, layer, controller); }
private bool IsLayerUsingHumanoid(UnityEditor.Animations.AnimatorControllerLayer layer) { ChildAnimatorState[] states = layer.stateMachine.states; for (int i = 0; i < states.Length; i++) { AnimatorState state = states[i].state; if (state.motion is AnimationClip) { AnimationClip motion = state.motion as AnimationClip; if (motion.humanMotion) { return(true); } } else if ((state.motion is UnityEditor.Animations.BlendTree) && this.IsBlendTreeUsingHumanoid(state.motion as UnityEditor.Animations.BlendTree)) { return(true); } } return(false); }
void ShowAnimatorControllerLayer(UnityEditor.Animations.AnimatorControllerLayer layer) { #if UNITY_4_6 StateMachine stateMachine = layer.stateMachine; for (int pos = 0; pos < stateMachine.stateCount; pos++) { Motion motion = stateMachine.GetState(pos).GetMotion(); if (null != motion) { EditorGUILayout.BeginHorizontal(); CreateLabel(stateMachine.GetState(pos).name); CreateLabel(motion.averageDuration.ToString()); CreateLabel(motion.isLooping.ToString()); EditorGUILayout.EndHorizontal(); } } #endif AnimatorStateMachine stateMachine = layer.stateMachine; ChildAnimatorState[] states = layer.stateMachine.states; for (int pos = 0; pos < states.Length; pos++) { var animaState = states[pos].state; Motion motion = states[pos].state.motion; if (motion is UnityEditor.Animations.BlendTree) { var blendTree = (motion as UnityEditor.Animations.BlendTree); var childMotion = blendTree.children; for (int i = 0; i < childMotion.Length; i++) { } } else { } } }
private void RenameEnd() { if (this.renameOverlay.userAcceptedRename) { string text = (!string.IsNullOrEmpty(this.renameOverlay.name)) ? this.renameOverlay.name : this.renameOverlay.originalName; if (text != this.renameOverlay.originalName) { int userData = this.renameOverlay.userData; UnityEditor.Animations.AnimatorControllerLayer animatorControllerLayer = this.m_LayerList.list[userData] as UnityEditor.Animations.AnimatorControllerLayer; AnimatorStateMachine stateMachine = animatorControllerLayer.stateMachine; text = this.m_Host.animatorController.MakeUniqueLayerName(text); if (stateMachine != null) { ObjectNames.SetNameSmart(stateMachine, text); } Undo.RegisterCompleteObjectUndo(this.m_Host.animatorController, "Layer renamed"); animatorControllerLayer.name = text; this.m_Host.animatorController.layers = (this.m_LayerList.list as UnityEditor.Animations.AnimatorControllerLayer[]); } } this.m_LayerList.GrabKeyboardFocus(); this.renameOverlay.Clear(); }
void ShowAnimatorControllerLayer(UnityEditor.Animations.AnimatorControllerLayer layer) { #if UNITY_4_6 StateMachine stateMachine = layer.stateMachine; for (int pos = 0; pos < stateMachine.stateCount; pos++) { Motion motion = stateMachine.GetState(pos).GetMotion(); if (null != motion) { EditorGUILayout.BeginHorizontal(); CreateLabel(stateMachine.GetState(pos).name); CreateLabel(motion.averageDuration.ToString()); CreateLabel(motion.isLooping.ToString()); EditorGUILayout.EndHorizontal(); } } #elif UNITY_5 AnimatorStateMachine stateMachine = layer.stateMachine; ChildAnimatorState[] states = layer.stateMachine.states; for (int pos = 0; pos < states.Length; pos++) { Motion motion = states[pos].state.motion; if (null != motion) { EditorGUILayout.BeginHorizontal(); CreateLabel(motion.name); CreateLabel(motion.averageDuration.ToString()); CreateLabel(motion.isLooping.ToString()); EditorGUILayout.EndHorizontal(); } } #endif }
public void SetTransition(AnimatorStateTransition transition, AnimatorState sourceState, AnimatorState destinationState, AnimatorControllerLayer srcLayer, Animator previewObject) { this.m_RefSrcState = sourceState; this.m_RefDstState = destinationState; TransitionInfo info = new TransitionInfo(); info.Set(transition, sourceState, destinationState); if (this.MustResample(info)) { this.ResampleTransition(transition, srcLayer.avatarMask, info, previewObject); } }
internal void OnGUI() { if (s_Styles == null) { s_Styles = new Styles(); } if (this.m_Layer != null) { bool flag = false; GUI.Box(new Rect(0f, 0f, base.position.width, base.position.height), GUIContent.none, new GUIStyle("grey_border")); AnimatorControllerLayer[] layers = this.m_Controller.layers; EditorGUIUtility.labelWidth = 100f; using (new EditorGUI.DisabledScope(this.m_LayerIndex == 0)) { if (AnimatorControllerTool.tool.liveLink) { float num = (this.m_LayerIndex != 0) ? AnimatorControllerTool.tool.previewAnimator.GetLayerWeight(this.m_LayerIndex) : 1f; AnimatorControllerTool.tool.previewAnimator.SetLayerWeight(this.m_LayerIndex, EditorGUILayout.Slider(s_Styles.weight, num, 0f, 1f, new GUILayoutOption[0])); } else { EditorGUI.BeginChangeCheck(); float num2 = (this.m_LayerIndex != 0) ? this.m_Layer.defaultWeight : 1f; num2 = EditorGUILayout.Slider(s_Styles.weight, num2, 0f, 1f, new GUILayoutOption[0]); if (EditorGUI.EndChangeCheck() && (this.m_LayerIndex != 0)) { this.m_Layer.defaultWeight = num2; flag = true; } } } EditorGUI.BeginChangeCheck(); this.m_Layer.avatarMask = EditorGUILayout.ObjectField(s_Styles.mask, this.m_Layer.avatarMask, typeof(AvatarMask), false, new GUILayoutOption[0]) as AvatarMask; this.m_Layer.blendingMode = (AnimatorLayerBlendingMode) EditorGUILayout.EnumPopup(s_Styles.blending, this.m_Layer.blendingMode, new GUILayoutOption[0]); if (EditorGUI.EndChangeCheck()) { flag = true; } int selectedIndex = 0; List<GUIContent> list = new List<GUIContent>(); List<int> list2 = new List<int>(); for (int i = 0; i < layers.Length; i++) { AnimatorControllerLayer layer = layers[i]; if ((this.m_LayerIndex != i) && (layer.syncedLayerIndex == -1)) { list.Add(new GUIContent(layer.name)); list2.Add(i); if (i == this.m_Layer.syncedLayerIndex) { selectedIndex = list.Count - 1; } } } using (new EditorGUI.DisabledScope(list.Count == 0)) { GUILayout.BeginHorizontal(new GUILayoutOption[0]); bool flag2 = EditorGUILayout.Toggle(s_Styles.sync, this.m_Layer.syncedLayerIndex > -1, new GUILayoutOption[0]); GUILayout.Space(10f); GUI.enabled = flag2 && (this.m_Layer.blendingMode == AnimatorLayerBlendingMode.Override); EditorGUI.BeginChangeCheck(); this.m_Layer.syncedLayerAffectsTiming = EditorGUILayout.Toggle(s_Styles.timing, this.m_Layer.syncedLayerAffectsTiming, new GUILayoutOption[0]); if (EditorGUI.EndChangeCheck()) { flag = true; } GUI.enabled = true; GUILayout.EndHorizontal(); if (flag2) { int num5 = EditorGUILayout.Popup(s_Styles.sourceLayer, selectedIndex, list.ToArray(), new GUILayoutOption[0]); if ((num5 < list2.Count) && (list2[num5] != this.m_Layer.syncedLayerIndex)) { this.m_Layer.syncedLayerIndex = list2[num5]; flag = true; } } else if (this.m_Layer.syncedLayerIndex != -1) { this.m_Layer.syncedLayerIndex = -1; flag = true; } } EditorGUI.BeginChangeCheck(); this.m_Layer.iKPass = EditorGUILayout.Toggle(s_Styles.ik, this.m_Layer.iKPass, new GUILayoutOption[0]); if (EditorGUI.EndChangeCheck()) { flag = true; } if (flag) { Undo.RegisterCompleteObjectUndo(this.m_Controller, "Layer settings Changed"); layers[this.m_LayerIndex] = this.m_Layer; this.m_Controller.layers = layers; this.m_Layer = this.m_Controller.layers[this.m_LayerIndex]; AnimatorControllerTool.tool.ResetUI(); } } }
AnimatorControllerLayer CreateLayer(AnimatorController controller, string name, AvatarMask mask, float weight = 1f) { AnimatorControllerLayer layer = new AnimatorControllerLayer(); layer.avatarMask = mask; layer.name = name; layer.stateMachine = new AnimatorStateMachine(); layer.defaultWeight = weight; layer.stateMachine.name = layer.name; layer.stateMachine.hideFlags = HideFlags.HideInHierarchy; if (AssetDatabase.GetAssetPath(controller) != "") AssetDatabase.AddObjectToAsset(layer.stateMachine, AssetDatabase.GetAssetPath(controller)); return layer; }
internal static bool ShowAtPosition(Rect buttonRect, AnimatorControllerLayer layer, int layerIndex, AnimatorController controller) { long num = DateTime.Now.Ticks / 0x2710L; if (num >= (s_LastClosedTime + 50L)) { Event.current.Use(); if (s_LayerSettingsWindow == null) { s_LayerSettingsWindow = ScriptableObject.CreateInstance<LayerSettingsWindow>(); } s_LayerSettingsWindow.m_Layer = layer; s_LayerSettingsWindow.m_LayerIndex = layerIndex; s_LayerSettingsWindow.m_Controller = controller; s_LayerSettingsWindow.Init(buttonRect); return true; } return false; }
public void clear() { m_stateMachineList.Clear(); m_xmlStateMachineTransitionList.Clear(); m_animatorControllerLayer = null; }