From d7eb9f807ce8fe63259642cd3745558d50b6765f Mon Sep 17 00:00:00 2001 From: yhh <359807859@qq.com> Date: Thu, 1 Aug 2019 15:58:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EOnFinalFrameEnd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CLEditor/windows/PropertyBox.xaml.cs | 19 +- Engine/CLEngine.Core/PropertyLabel.cs | 219 +++++++++--------- .../gameObjects/AnimationObject.cs | 23 +- 3 files changed, 134 insertions(+), 127 deletions(-) diff --git a/CLEditor/windows/PropertyBox.xaml.cs b/CLEditor/windows/PropertyBox.xaml.cs index ed38c3c..f2c1f3a 100644 --- a/CLEditor/windows/PropertyBox.xaml.cs +++ b/CLEditor/windows/PropertyBox.xaml.cs @@ -20,21 +20,14 @@ namespace CLEngine.Editor.windows get { return PropertyGrid.SelectedObject; } set { - Dispatcher.Invoke((Action)(() => + Dispatcher.Invoke(delegate { - selected = value; - PropertyGrid.SelectedObject = value; - Title.Content = CHelper.SplitCamelCase(value.ToString()); + selected = value; + PropertyGrid.SelectedObject = value; + Title.Content = CHelper.SplitCamelCase(value.ToString()); - if (value is ObjectComponent) - { - SettingsBtn.Visibility = System.Windows.Visibility.Visible; - } - else - { - SettingsBtn.Visibility = System.Windows.Visibility.Hidden; - } - })); + SettingsBtn.Visibility = value is ObjectComponent ? System.Windows.Visibility.Visible : System.Windows.Visibility.Hidden; + }); } } diff --git a/Engine/CLEngine.Core/PropertyLabel.cs b/Engine/CLEngine.Core/PropertyLabel.cs index ef5acc9..3ca1034 100644 --- a/Engine/CLEngine.Core/PropertyLabel.cs +++ b/Engine/CLEngine.Core/PropertyLabel.cs @@ -1,133 +1,134 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Serialization; namespace CLEngine.Core { - /// - /// - /// + /// + /// + /// #if WIN - [Serializable] + [Serializable] #endif - [DataContract] - public class PropertyLabel - { - #region Equality members + [DataContract] + [SuppressMessage("ReSharper", "PossibleNullReferenceException")] + public class PropertyLabel + { + #region Equality members - /// 确定指定的对象是否等于当前对象。 - /// 要与当前对象进行比较的对象。 - /// - /// 如果指定的对象等于当前对象,则为 ,否则为 。 - /// - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != GetType()) return false; - return Equals((PropertyLabel) obj); - } + /// 确定指定的对象是否等于当前对象。 + /// 要与当前对象进行比较的对象。 + /// + /// 如果指定的对象等于当前对象,则为 ,否则为 。 + /// + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((PropertyLabel)obj); + } - #endregion + #endregion - /// - /// - /// + /// + /// + /// #if WIN - [Serializable] + [Serializable] #endif - [DataContract] - public class EqualityComparer : IEqualityComparer - { - /// - /// - /// - /// - /// - /// - public bool Equals(PropertyLabel x, PropertyLabel y) - { - return x != null && x.Equals(y); - } + [DataContract] + public class EqualityComparer : IEqualityComparer + { + /// + /// + /// + /// + /// + /// + public bool Equals(PropertyLabel x, PropertyLabel y) + { + return x.Equals(y); + } - /// - /// - /// - /// - /// - public int GetHashCode(PropertyLabel obj) - { - return base.GetHashCode(); - } - } + /// + /// + /// + /// + /// + public int GetHashCode(PropertyLabel obj) + { + return base.GetHashCode(); + } + } - [DataMember] - private string typeName; + [DataMember] + private string typeName; - [DataMember] - private string name; + [DataMember] + private string name; - /// - /// - /// - /// - /// - public PropertyLabel(string typeName, string name) - { - this.typeName = typeName; - this.name = name; - } + /// + /// + /// + /// + /// + public PropertyLabel(string typeName, string name) + { + this.typeName = typeName; + this.name = name; + } - /// - /// - /// - /// - /// - public bool Equals(PropertyLabel other) - { - return (typeName.Equals(other.typeName) && name.Equals(other.name)); - } + /// + /// + /// + /// + /// + public bool Equals(PropertyLabel other) + { + return (typeName.Equals(other.typeName) && name.Equals(other.name)); + } - /// - /// - /// - /// - /// - /// - public static bool operator ==(PropertyLabel p1, PropertyLabel p2) - { - return p1 != null && p1.Equals(p2); - } + /// + /// + /// + /// + /// + /// + public static bool operator ==(PropertyLabel p1, PropertyLabel p2) + { + return p1.Equals(p2); + } - /// - /// - /// - /// - /// - /// - public static bool operator !=(PropertyLabel p1, PropertyLabel p2) - { - return p1 != null && !p1.Equals(p2); - } + /// + /// + /// + /// + /// + /// + public static bool operator !=(PropertyLabel p1, PropertyLabel p2) + { + return !p1.Equals(p2); + } - /// - /// - /// - /// - public override string ToString() - { - return name + ", " + typeName; - } + /// + /// + /// + /// + public override string ToString() + { + return name + ", " + typeName; + } - /// - /// - /// - /// - public override int GetHashCode() - { - // ReSharper disable once BaseObjectGetHashCodeCallInGetHashCode - return base.GetHashCode(); - } - } + /// + /// + /// + /// + public override int GetHashCode() + { + // ReSharper disable once BaseObjectGetHashCodeCallInGetHashCode + return base.GetHashCode(); + } + } } \ No newline at end of file diff --git a/Engine/CLEngine.Core/gameObjects/AnimationObject.cs b/Engine/CLEngine.Core/gameObjects/AnimationObject.cs index 057e95e..9942ef8 100644 --- a/Engine/CLEngine.Core/gameObjects/AnimationObject.cs +++ b/Engine/CLEngine.Core/gameObjects/AnimationObject.cs @@ -346,7 +346,7 @@ namespace CLEngine.Core PingPong ? (frameCount * 2 - 2) * frameDuration : frameCount * frameDuration; /// - /// 动画是否逆转播放 + /// /// #if WIN [NonSerialized] @@ -398,6 +398,12 @@ namespace CLEngine.Core [Browsable(false)] public EventHandler OnCompeleted { get; set; } + /// + /// 最后一帧结束 + /// + [Browsable(false)] + public EventHandler OnFinalFrameEnd { get; set; } + /// /// /// @@ -432,7 +438,7 @@ namespace CLEngine.Core if (PingPong) { - frameIndex = frameIndex % (frameCount * 2 - 2); + frameIndex %= (frameCount * 2 - 2); if (frameIndex >= frameCount) frameIndex = frameCount - 2 - (frameIndex - frameCount); @@ -442,12 +448,12 @@ namespace CLEngine.Core { if (IsReversed) { - frameIndex = frameIndex % frameCount; + frameIndex %= frameCount; frameIndex = frameCount - frameIndex - 1; } else { - frameIndex = frameIndex % frameCount; + frameIndex %= frameCount; } } else @@ -455,6 +461,13 @@ namespace CLEngine.Core ? Math.Max(frameCount - frameIndex - 1, 0) : Math.Min(frameCount - 1, frameIndex); + // 不考虑逆序情况 + // 如果当前帧大于下一阵序号说明已经播放至最后一帧 + if (!IsReversed && CurrentFrameIndex > frameIndex) + { + OnFinalFrameEnd?.Invoke(this, EventArgs.Empty); + } + CurrentFrameIndex = frameIndex; var region = _textures[_sheetSlots[CurrentFrameIndex].path].region; @@ -654,7 +667,7 @@ namespace CLEngine.Core /// 对象名称 public override string ToString() { - return this.Name; + return Name; } } } \ No newline at end of file -- Gitee