private static void GetResources() { List <StrInt> _totals = new List <StrInt>(); List <ItemDrop.ItemData> Items = new List <ItemDrop.ItemData>(); List <string> Names = new List <string>(); foreach (Container c in containers) { foreach (ItemDrop.ItemData item in c.GetInventory().GetAllItems()) { Items.Add(item); string cleanName = item.m_shared.m_name.Replace("$item_", ""); if (!Names.Contains(cleanName)) { Names.Add(cleanName); } } } foreach (Piece p in pieces) { ItemDrop.ItemData item = p.m_resources[0].m_resItem.m_itemData; string cleanName = item.m_shared.m_name.Replace("$item_", ""); if (!Names.Contains(cleanName)) { Names.Add(cleanName); } } Names.Sort(); foreach (string name in Names) { StrInt total = new StrInt(); total.name = name; foreach (Piece p in pieces) { if (p.name.Split('_')[0] == name) { total.amount += 50; } } foreach (ItemDrop.ItemData item in Items) { string cleanName = item.m_shared.m_name.Replace("$item_", ""); if (cleanName == name) { total.amount += item.m_stack; } } _totals.Add(total); } foreach (StrInt total in _totals) { string _output = total.name + " : " + total.amount; Debug.Log(_output); } }
/// <summary> /// 判断是否是Decimal类型 /// </summary> /// <param name="TBstr0">判断数据字符</param> /// <returns>true是false否</returns> public static bool IsDecimal(string TBstr0) { bool IsBool = false; string Intstr0 = "1234567890"; string IntSign0, StrInt, StrDecimal; int IntIndex0, IntSubstr, IndexInt; int decimalbool = 0; int db = 0; bool Bf, Bl; if (TBstr0.Length > 2) { IntIndex0 = TBstr0.IndexOf("."); if (IntIndex0 != -1) { string StrArr = "."; char[] CharArr = StrArr.ToCharArray(); string[] NumArr = TBstr0.Split(CharArr); IndexInt = NumArr.GetUpperBound(0); if (IndexInt > 1) { decimalbool = 1; } else { StrInt = NumArr[0].ToString(); StrDecimal = NumArr[1].ToString(); //--- 整数部分----- if (StrInt.Length > 0) { if (StrInt.Length == 1) { IntSubstr = Intstr0.IndexOf(StrInt); if (IntSubstr != -1) { Bf = true; } else { Bf = false; } } else { for (int i = 0; i <= StrInt.Length - 1; i++) { IntSign0 = StrInt.Substring(i, 1).ToString(); IntSubstr = Intstr0.IndexOf(IntSign0); if (IntSubstr != -1) { db = db + 0; } else { db = i + 1; break; } } if (db == 0) { Bf = true; } else { Bf = false; } } } else { Bf = true; } //----小数部分---- if (StrDecimal.Length > 0) { for (int j = 0; j <= StrDecimal.Length - 1; j++) { IntSign0 = StrDecimal.Substring(j, 1).ToString(); IntSubstr = Intstr0.IndexOf(IntSign0); if (IntSubstr != -1) { db = db + 0; } else { db = j + 1; break; } } if (db == 0) { Bl = true; } else { Bl = false; } } else { Bl = false; } if ((Bf && Bl) == true) { decimalbool = 0; } else { decimalbool = 1; } } } else { decimalbool = 1; } } else { decimalbool = 1; } if (decimalbool == 0) { IsBool = true; } else { IsBool = false; } return(IsBool); }
static void Method(string description, string str, int num, StrInt meth) { Console.Write(description + ": "); Console.WriteLine(meth(str, num)); }