Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated demos with latest fixes. #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 73 additions & 14 deletions Unity/Demos/Assets/DragonBones/Editor/UnityArmatureEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<string> _armatureNames = null;
private List<string> _armatureBaseNames = null;
private List<string> _animationNames = null;
private List<string> _sortingLayerNames = null;

Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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)
{
Expand All @@ -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();
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<string>(_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))
{
Expand All @@ -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;
}
}
Expand Down
12 changes: 12 additions & 0 deletions Unity/Demos/Assets/DragonBones/Editor/UnityEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 12 additions & 15 deletions Unity/Demos/Assets/DragonBones/Scripts/animation/AnimationState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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; //
Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public class UnityArmatureComponent : DragonBoneEventDispatcher, IArmatureProxy
public UnityDragonBonesData unityData = null;
/// <private/>
public string armatureName = null;
/// <private/>
public string armatureBaseName = null;
/// <summary>
/// Is it the UGUI model?
/// </summary>
Expand Down Expand Up @@ -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);
}
}
}

Expand Down