From e846c64d6f927879cb8a095e62d773a8d7b3c9f4 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 15 Oct 2020 07:24:10 +0800 Subject: *ability system --- .../Plugins/AdvancedInspector/Attributes/Title.cs | 111 +++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 Assets/Plugins/AdvancedInspector/Attributes/Title.cs (limited to 'Assets/Plugins/AdvancedInspector/Attributes/Title.cs') diff --git a/Assets/Plugins/AdvancedInspector/Attributes/Title.cs b/Assets/Plugins/AdvancedInspector/Attributes/Title.cs new file mode 100644 index 00000000..2330db37 --- /dev/null +++ b/Assets/Plugins/AdvancedInspector/Attributes/Title.cs @@ -0,0 +1,111 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Linq; +using System.Text; + +using UnityEngine; + +namespace AdvancedInspector +{ + /// + /// Similar to Unity "Header" attribute, but can be place on any members and be set at runtime. + /// + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)] + public class TitleAttribute : Attribute, IRuntimeAttribute + { + public delegate TitleAttribute TitleDelegate(); + public delegate TitleAttribute TitleStaticDelegate(TitleAttribute title, object instance, object value); + + private string message; + + /// + /// The title message + /// + public string Message + { + get { return message; } + set { message = value; } + } + + private FontStyle style = FontStyle.Bold; + + /// + /// The font style. + /// + public FontStyle Style + { + get { return style; } + set { style = value; } + } + + #region IRuntime Implementation + private string methodName = ""; + + public string MethodName + { + get { return methodName; } + } + + public Type Template + { + get { return typeof(TitleDelegate); } + } + + public Type TemplateStatic + { + get { return typeof(TitleStaticDelegate); } + } + + private List delegates = new List(); + + public List Delegates + { + get { return delegates; } + set { delegates = value; } + } + + public TitleAttribute Invoke(int index, object instance, object value) + { + if (delegates.Count == 0 || index >= delegates.Count) + return this; + + try + { + if (delegates[index].Target == null) + { + return delegates[0].DynamicInvoke(this, instance, value) as TitleAttribute; + } + else + { + return delegates[0].DynamicInvoke() as TitleAttribute; + } + } + catch (Exception e) + { + if (e is TargetInvocationException) + e = ((TargetInvocationException)e).InnerException; + + Debug.LogError(string.Format("Invoking a method failed while trying to retrieve a Title attribute. The exception was \"{0}\".", e.Message)); + return null; + } + } + #endregion + + public TitleAttribute(string methodName) + { + this.methodName = methodName; + } + + public TitleAttribute(FontStyle style, string message) + { + this.style = style; + this.message = message; + } + + public TitleAttribute(Delegate method) + { + this.delegates.Add(method); + } + } +} -- cgit v1.1-26-g67d0