/// <summary> /// 取得過程文字 /// </summary> public void SetProcessText() { //設定目標文字 string targetStr = ""; switch (Target) { case EventCheckTarget.All: targetStr = "全隊"; break; case EventCheckTarget.Single: targetStr = "有隊員"; break; default: Debug.LogWarning("讀意外事件表時有錯誤的目標類型"); break; } Process = Process.Replace("@@", targetStr); //設定屬性文字 string AttrStr = ""; AttrStr = GameDictionary.String_AttributeDic[RequireAttribute.ToString()].ZH_TW; Process = Process.Replace("##", AttrStr); //設定運算元文字 string operatorStr = ""; switch (OperatorType) { case Operator.GreaterThanOrEqualTo: operatorStr = "大於"; break; case Operator.LessThanOrEqualTo: operatorStr = "小於"; break; default: Debug.LogWarning("讀意外事件表時有錯誤的運算元類型"); break; } Process = Process.Replace("%%", operatorStr); //設定數值文字 Process = Process.Replace("&&", Value.ToString()); }
private void Awake() { FieldInfo[] fields = GetType().GetFields(_bindingFlags); PropertyInfo[] properties = GetType().GetProperties(_bindingFlags); List <MemberInfo> members = new List <MemberInfo>(); members.AddRange(fields); members.AddRange(properties); foreach (MemberInfo member in members) { RequireAttribute requireAttribute = member.GetCustomAttribute <RequireAttribute>(); RequireChildAttribute requireChildAttribute = member.GetCustomAttribute <RequireChildAttribute>(); if (requireAttribute != null) { switch (member) { case FieldInfo field: field.SetValue(this, GetComponent(field.FieldType)); continue; case PropertyInfo property: property.SetValue(this, GetComponent(property.PropertyType)); continue; } } else if (requireChildAttribute != null) { Transform child; if (string.IsNullOrEmpty(requireChildAttribute.Name)) { // index child = transform.GetChild(requireChildAttribute.ChildIndex); } else { // name child = transform.Find(requireChildAttribute.Name); } switch (member) { case FieldInfo field: { Type type = field.FieldType; if (type == typeof(GameObject)) { field.SetValue(this, child.gameObject); continue; } field.SetValue(this, child.GetComponent(requireChildAttribute.Type == null ? type : requireChildAttribute.Type)); continue; } case PropertyInfo property: { Type type = property.PropertyType; if (type == typeof(GameObject)) { property.SetValue(this, child.gameObject); continue; } property.SetValue(this, child.GetComponent(requireChildAttribute.Type == null ? type : requireChildAttribute.Type)); continue; } } } } }