private void Rebuild() { Clear(); if (_Asset != null) { _SkinMeshData = _Asset.Load(); } if (_SkinMeshData.Animations != null) { for (int i = 0; i < _SkinMeshData.Animations.Length; i++) { AnimationClipData anim = _SkinMeshData.Animations[i]; AnimationClipListItem item = new AnimationClipListItem(anim) { Text = anim.Name, UserData = anim }; _AnimationList.Items.Add(item); } } if (_SkinMeshData.Root != null) { CreateTree(_SkinMeshData.Root, _TransformTree); } }
/// <summary> /// Load SkinMesh data from XmlElement /// </summary> /// <param name="e">XmlElement to load from</param> public void Load(XmlElement e) { this.Name = e.GetAttributeValueAsString("Name", this.Name); XmlElement bones = e["Bones"]; if (bones != null) { XmlElement root = bones["Bone"]; if (root != null) { this.Root = new BoneData(); this.Root.Load(root); } } XmlElement animations = e["Animations"]; if (animations != null) { int count = animations.GetAttributeValueAsInt("Count", 0); Animations = new AnimationClipData[count]; int i = 0; foreach (var element in animations) { AnimationClipData clip = new AnimationClipData(); clip.Load(element); Animations[i++] = clip; } } }
private void Optimize(AnimationClipData anim) { _MixingTransforms.Clear(); _MixList.Clear(); if (anim.MixingTransforms != null) { foreach (var ms in anim.MixingTransforms) { _MixingTransforms.Add(ms.TransformPath, ms); } CheckForRecursive(_Root); anim.MixingTransforms = _MixList.ToArray(); } }
void Bone_Changed(object sender, System.EventArgs e) { if (_AnimationList.SelectedItem == null || _IgnoreChanges) { return; } AnimationClipData data = ((AnimationClipListItem)_AnimationList.SelectedItem).Data; if (data != null) { Skill.Editor.UI.ToggleButton item = (Skill.Editor.UI.ToggleButton)sender; if (item.IsChecked) { if (item.UserData == item.Parent.UserData) { AddMixingTransformRecursive(item.Parent as BaseControl); } else { AddMixingTransform(item); } } else { if (item.UserData == item.Parent.UserData) { RemoveMixingTransformRecursive(item.Parent as BaseControl); } else { RemoveMixingTransform(item); } } data.MixingTransforms = new MixingTransformData[_MixingTransforms.Count]; _MixingTransforms.Values.CopyTo(data.MixingTransforms, 0); RefreshToggles(); } }
private void RefreshTree() { _MixingTransforms.Clear(); if (_AnimationList.SelectedItem != null) { AnimationClipData data = _AnimationList.SelectedItem.UserData as AnimationClipData; if (data != null && data.MixingTransforms != null) { foreach (var ms in data.MixingTransforms) { if (ms.Recursive) { BaseControl c; if (_TreeMap.TryGetValue(ms.TransformPath, out c)) { AddMixingTransformRecursive(c); } } else { AddMixingTransform(ms); } } RefreshToggles(); } else { UncheckTree(); } } else { UncheckTree(); } Repaint(); }
private void CopyAnimations() { if (_RootBone.Object == null) { Debug.LogError("Set valid Root"); } else if (_Animations.Object == null) { Debug.LogError("Set valid Animation"); } else { if (_Animations.Object != null) { XmlDocument document = new XmlDocument(); XmlElement animationsElement = new XmlElement("Animations"); List <string> animNames = new List <string>(); foreach (AnimationState state in _Animations.Object) { if (animNames.Contains(state.name)) { continue; } animNames.Add(state.name); Skill.Editor.Animation.AnimationClipData clip = new Animation.AnimationClipData() { Name = state.name, WrapMode = (UnityEngine.WrapMode)state.wrapMode, Length = state.length }; EditorCurveBinding binding = new EditorCurveBinding() { path = _RootBone.Object.name, type = typeof(Transform) }; binding.propertyName = "m_LocalPosition.x"; var xCurve = AnimationUtility.GetEditorCurve(state.clip, binding); binding.propertyName = "m_LocalPosition.y"; var yCurve = AnimationUtility.GetEditorCurve(state.clip, binding); binding.propertyName = "m_LocalPosition.z"; var zCurve = AnimationUtility.GetEditorCurve(state.clip, binding); AddKeys(xCurve, clip.RootMotion.XKeys); AddKeys(yCurve, clip.RootMotion.YKeys); AddKeys(zCurve, clip.RootMotion.ZKeys); binding.propertyName = "m_LocalRotation.x"; var rxCurve = AnimationUtility.GetEditorCurve(state.clip, binding); binding.propertyName = "m_LocalRotation.y"; var ryCurve = AnimationUtility.GetEditorCurve(state.clip, binding); binding.propertyName = "m_LocalRotation.z"; var rzCurve = AnimationUtility.GetEditorCurve(state.clip, binding); AddKeys(rxCurve, clip.RootMotion.RXKeys); AddKeys(ryCurve, clip.RootMotion.RYKeys); AddKeys(rzCurve, clip.RootMotion.RZKeys); animationsElement.AppendChild(clip.ToXmlElement()); } if (animNames.Count > 0) { document.AppendChild(animationsElement); CopyToClipboard(document); Debug.Log("AnimationClips copied to clipboard"); } else { Debug.LogWarning("can not find any AnimationClip"); } } } }
public AnimationClipListItem(AnimationClipData data) { this.Data = data; }
private void UpdateAnimations() { if (_AnimationField.Object == null) { Debug.LogError("Set valid Animation"); } else { if (_AnimationField.Object != null) { SkinMeshData skin = _Data.Load(); if (skin.Root == null) { Debug.LogError("First build skeleton"); return; } List <AnimationClipData> anims = new List <AnimationClipData>(); if (skin.Animations != null && skin.Animations.Length > 0) { foreach (var a in skin.Animations) { if (_AnimationField.Object[a.Name] != null) { anims.Add(a); } } } foreach (AnimationState state in _AnimationField.Object) { if (state == null || state.clip == null) { continue; } Skill.Editor.Animation.AnimationClipData clip = Find(state.name, anims); if (clip == null) { clip = new Animation.AnimationClipData() { Name = state.name, WrapMode = (UnityEngine.WrapMode)state.wrapMode, }; anims.Add(clip); } clip.Length = state.length; AnimationState rootState = state; if (_RootMotionAnimationField.Object != null) { var s = _RootMotionAnimationField.Object[state.name]; if (s != null) { rootState = s; } } EditorCurveBinding binding = new EditorCurveBinding() { path = skin.Root.Name, type = typeof(Transform) }; binding.propertyName = "m_LocalPosition.x"; var xCurve = AnimationUtility.GetEditorCurve(rootState.clip, binding); binding.propertyName = "m_LocalPosition.y"; var yCurve = AnimationUtility.GetEditorCurve(rootState.clip, binding); binding.propertyName = "m_LocalPosition.z"; var zCurve = AnimationUtility.GetEditorCurve(rootState.clip, binding); AddKeys(xCurve, clip.RootMotion.XKeys); AddKeys(yCurve, clip.RootMotion.YKeys); AddKeys(zCurve, clip.RootMotion.ZKeys); binding.propertyName = "m_LocalRotation.x"; var rxCurve = AnimationUtility.GetEditorCurve(rootState.clip, binding); binding.propertyName = "m_LocalRotation.y"; var ryCurve = AnimationUtility.GetEditorCurve(rootState.clip, binding); binding.propertyName = "m_LocalRotation.z"; var rzCurve = AnimationUtility.GetEditorCurve(rootState.clip, binding); AddKeys(rxCurve, clip.RootMotion.RXKeys); AddKeys(ryCurve, clip.RootMotion.RYKeys); AddKeys(rzCurve, clip.RootMotion.RZKeys); } if (anims.Count > 0) { skin.Animations = anims.ToArray(); _Data.Save(skin); } else { Debug.LogWarning("can not find any AnimationClip"); } } } }