using System; using System.Collections; using System.Collections.Generic; using Common.Utility.CombatEvent; using Fort23.Core; using GameLogic.Bag; using UnityEngine; using Utility; public class DBManager : Singleton { public DBManager() { EventManager.Instance.AddEventListener(CustomEventType.ItemUpdate, ItemUpdate); EventManager.Instance.AddEventListener(CustomEventType.ItemCost, ItemCost); } public string Source = ""; protected override void ProDispose() { EventManager.Instance.RemoveEventListener(CustomEventType.ItemUpdate, ItemUpdate); EventManager.Instance.RemoveEventListener(CustomEventType.ItemCost, ItemCost); } private void ItemCost(IEventData e) { ItemUpdateData data = e as ItemUpdateData; // if (data != null) RecordCostItems(Source, data.ItemInfo); } private void ItemUpdate(IEventData e) { ItemUpdateData data = e as ItemUpdateData; // if (data != null) RecordGetItems(Source, data.ItemInfo); } /// /// 自定义打点 /// /// /// public void CustomEvent(string key, Dictionary properties) { } /// /// 更新用户属性 /// /// public void UpdateUserProperty(Dictionary properties) { } private void ProcessSource(Dictionary properties, string s) { if (string.IsNullOrEmpty(s)) { properties.Add("#source", Source); } else { properties.Add("#source", s); } } /// /// 获取道具记录 /// /// 来源 /// 道具 public void RecordGetItems(string source, List items) { Dictionary properties = new Dictionary(); foreach (ItemInfo itemInfo in items) { int id = itemInfo.itemID; long count = itemInfo.count.Value; properties.Add(id.ToString(), count); } ProcessSource(properties, source); // properties.Add("#source", source); CustomEvent("#get_items", properties); Source = ""; } /// /// 获取道具记录 /// /// /// public void RecordGetItems(string source, ItemInfo itemInfo) { Dictionary properties = new Dictionary(); int id = itemInfo.itemID; long count = itemInfo.count.Value; properties.Add(id.ToString(), count); // properties.Add("#source", source); ProcessSource(properties, source); CustomEvent("#get_items", properties); } /// /// 消耗道具记录 /// /// /// public void RecordCostItems(string source, List items) { Dictionary properties = new Dictionary(); // properties.Add("#source", source); ProcessSource(properties, source); foreach (ItemInfo itemInfo in items) { int id = itemInfo.itemID; long count = itemInfo.count.Value; properties.Add(id.ToString(), count); } CustomEvent("#cost_items", properties); } /// /// 消耗道具记录 /// /// /// public void RecordCostItems(string source, ItemInfo itemInfo) { Dictionary properties = new Dictionary(); // properties.Add("#source", source); ProcessSource(properties, source); int id = itemInfo.itemID; long count = itemInfo.count.Value; properties.Add(id.ToString(), count); CustomEvent("#cost_items", properties); } }