diff --git a/Unity/Demos/Assets/DragonBones/Editor/UnityArmatureEditor.cs b/Unity/Demos/Assets/DragonBones/Editor/UnityArmatureEditor.cs index 5852053..4ed78fe 100644 --- a/Unity/Demos/Assets/DragonBones/Editor/UnityArmatureEditor.cs +++ b/Unity/Demos/Assets/DragonBones/Editor/UnityArmatureEditor.cs @@ -20,6 +20,7 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +using System; using System.Collections.Generic; using UnityEngine; using UnityEditor; @@ -36,11 +37,13 @@ public class UnityArmatureEditor : Editor private float _frameRate = 1.0f / 24.0f; private int _armatureIndex = -1; + private int _armatureBaseIndex = 0; private int _animationIndex = -1; private int _sortingModeIndex = -1; private int _sortingLayerIndex = -1; private List _armatureNames = null; + private List _armatureBaseNames = null; private List _animationNames = null; private List _sortingLayerNames = null; @@ -57,11 +60,13 @@ public class UnityArmatureEditor : Editor void ClearUp() { this._armatureIndex = -1; + this._armatureBaseIndex = 0; this._animationIndex = -1; // this._sortingModeIndex = -1; // this._sortingLayerIndex = -1; this._armatureNames = null; + this._armatureBaseNames = null; this._animationNames = null; // this._sortingLayerNames = null; } @@ -217,6 +222,9 @@ public override void OnInspectorGUI() var armatureName = _armatureNames[_armatureIndex]; UnityEditor.ChangeArmatureData(_armatureComponent, armatureName, dragonBonesData.name); + UpdateBaseAnimation(); + UpdateAnimation(); + _UpdateParameters(); _armatureComponent.gameObject.name = armatureName; @@ -225,6 +233,33 @@ public override void OnInspectorGUI() } } + // Armature Base Animation + if (UnityFactory.factory.GetAllDragonBonesData().ContainsValue(dragonBonesData) && _armatureNames != null && _armatureBaseNames != null) + { + var armatureIndex = EditorGUILayout.Popup("Base animation", _armatureBaseIndex, _armatureBaseNames.ToArray()); + if (_armatureBaseIndex != armatureIndex && _armatureIndex != -1) + { + _armatureBaseIndex = armatureIndex; + + if (_armatureBaseIndex == 0) + { + var armatureName = _armatureNames[_armatureIndex]; + UnityEditor.ChangeArmatureData(_armatureComponent, armatureName, dragonBonesData.name); + _armatureComponent.gameObject.name = armatureName; + UnityEditor.ReplaceAnimation(_armatureComponent, null); + } + else + { + UpdateBaseAnimation(); + } + UpdateAnimation(); + + _UpdateParameters(); + + MarkSceneDirty(); + } + } + // Animation if (_animationNames != null && _animationNames.Count > 0) { @@ -235,19 +270,7 @@ public override void OnInspectorGUI() if (animationIndex != _animationIndex) { _animationIndex = animationIndex; - if (animationIndex >= 0) - { - _armatureComponent.animationName = _animationNames[animationIndex]; - var animationData = _armatureComponent.animation.animations[_armatureComponent.animationName]; - _armatureComponent.animation.Play(_armatureComponent.animationName, _playTimesPro.intValue); - _UpdateParameters(); - } - else - { - _armatureComponent.animationName = null; - _playTimesPro.intValue = 0; - _armatureComponent.animation.Stop(); - } + UpdateAnimation(); MarkSceneDirty(); } @@ -397,6 +420,31 @@ public override void OnInspectorGUI() } } + private void UpdateBaseAnimation() + { + if (_armatureBaseIndex > 0) + { + var baseArmatureName = _armatureBaseNames[_armatureBaseIndex]; + UnityEditor.ReplaceAnimation(_armatureComponent, baseArmatureName); + } + } + + private void UpdateAnimation() + { + if (_animationIndex >= 0 && _animationIndex < _animationNames.Count) + { + _armatureComponent.animationName = _animationNames[_animationIndex]; + _armatureComponent.animation.Play(_armatureComponent.animationName, _playTimesPro.intValue); + _UpdateParameters(); + } + else + { + _armatureComponent.animationName = null; + _playTimesPro.intValue = 0; + _armatureComponent.animation.Stop(); + } + } + void OnSceneGUI() { if (!EditorApplication.isPlayingOrWillChangePlaymode && _armatureComponent.armature != null) @@ -429,8 +477,15 @@ private void _UpdateParameters() if (_armatureComponent.armature.armatureData.parent != null) { _armatureNames = _armatureComponent.armature.armatureData.parent.armatureNames; - _animationNames = _armatureComponent.animation.animationNames; _armatureIndex = _armatureNames.IndexOf(_armatureComponent.armature.name); + + _armatureBaseNames = new List(_armatureComponent.armature.armatureData.parent.armatureNames); + _armatureBaseNames.Insert(0, "Default"); + _armatureBaseIndex = Math.Max(0, _armatureBaseNames.IndexOf(_armatureComponent.armatureBaseName)); + UpdateBaseAnimation(); + + _animationNames = _armatureComponent.animation.animationNames; + // if (!string.IsNullOrEmpty(_armatureComponent.animationName)) { @@ -440,16 +495,20 @@ private void _UpdateParameters() else { _armatureNames = null; + _armatureBaseNames = null; _animationNames = null; _armatureIndex = -1; + _armatureBaseIndex = 0; _animationIndex = -1; } } else { _armatureNames = null; + _armatureBaseNames = null; _animationNames = null; _armatureIndex = -1; + _armatureBaseIndex = 0; _animationIndex = -1; } } diff --git a/Unity/Demos/Assets/DragonBones/Editor/UnityEditor.cs b/Unity/Demos/Assets/DragonBones/Editor/UnityEditor.cs index 3d9c196..481c7da 100644 --- a/Unity/Demos/Assets/DragonBones/Editor/UnityEditor.cs +++ b/Unity/Demos/Assets/DragonBones/Editor/UnityEditor.cs @@ -247,6 +247,18 @@ public static void ChangeArmatureData(UnityArmatureComponent _armatureComponent, _armatureComponent.sortingOrder = _armatureComponent.sortingOrder; } + public static void ReplaceAnimation(UnityArmatureComponent _armatureComponent, string armatureName) + { + _armatureComponent.armatureBaseName = armatureName; + + if (!string.IsNullOrEmpty(armatureName)) + { + string dragonBonesName = _armatureComponent.unityData.dataName; + ArmatureData baseDiceArmature = UnityFactory.factory.GetArmatureData(armatureName, dragonBonesName); + UnityFactory.factory.ReplaceAnimation(_armatureComponent.armature, baseDiceArmature); + } + } + public static UnityEngine.Transform GetSelectionParentTransform() { var parent = Selection.activeObject as GameObject; diff --git a/Unity/Demos/Assets/DragonBones/Scripts/animation/AnimationState.cs b/Unity/Demos/Assets/DragonBones/Scripts/animation/AnimationState.cs index 9fa7314..0147f57 100644 --- a/Unity/Demos/Assets/DragonBones/Scripts/animation/AnimationState.cs +++ b/Unity/Demos/Assets/DragonBones/Scripts/animation/AnimationState.cs @@ -262,11 +262,6 @@ protected override void _OnClear() timeline.ReturnToPool(); } - foreach(var timeline in this._poseTimelines) - { - timeline.ReturnToPool(); - } - foreach (var bonePose in this._bonePoses.Values) { bonePose.ReturnToPool(); @@ -311,7 +306,6 @@ protected override void _OnClear() this._boneTimelines.Clear(); this._slotTimelines.Clear(); this._constraintTimelines.Clear(); - this._poseTimelines.Clear(); this._bonePoses.Clear(); this._animationData = null; // this._armature = null; // @@ -954,17 +948,20 @@ internal void AdvanceTime(float passedTime, float cacheFrameRate) for (int i = 0, l = this._slotTimelines.Count; i < l; ++i) { var timeline = this._slotTimelines[i]; - var displayController = timeline.slot.displayController; - - if ( - displayController == null || - displayController == this.name || - displayController == this.group - ) + if (timeline.slot != null) { - if (timeline.playState <= 0) + var displayController = timeline.slot.displayController; + + if ( + displayController == null || + displayController == this.name || + displayController == this.group + ) { - timeline.Update(time); + if (timeline.playState <= 0) + { + timeline.Update(time); + } } } } diff --git a/Unity/Demos/Assets/DragonBones/Scripts/unity/UnityArmatureComponent.cs b/Unity/Demos/Assets/DragonBones/Scripts/unity/UnityArmatureComponent.cs index e865df2..b01cb76 100644 --- a/Unity/Demos/Assets/DragonBones/Scripts/unity/UnityArmatureComponent.cs +++ b/Unity/Demos/Assets/DragonBones/Scripts/unity/UnityArmatureComponent.cs @@ -76,6 +76,8 @@ public class UnityArmatureComponent : DragonBoneEventDispatcher, IArmatureProxy public UnityDragonBonesData unityData = null; /// public string armatureName = null; + /// + public string armatureBaseName = null; /// /// Is it the UGUI model? /// @@ -677,6 +679,11 @@ void Awake() if (dragonBonesData != null && !string.IsNullOrEmpty(armatureName)) { UnityFactory.factory.BuildArmatureComponent(armatureName, unityData.dataName, null, null, gameObject, isUGUI); + if (!string.IsNullOrEmpty(armatureBaseName)) + { + ArmatureData baseData = UnityFactory.factory.GetArmatureData(armatureBaseName, unityData.dataName); + UnityFactory.factory.ReplaceAnimation(armature, baseData); + } } }