예제 #1
0
 /// <summary>
 /// 移除UI红点
 /// </summary>
 /// <param name="self"></param>
 /// <param name="target"></param>
 /// <param name="uiRedDotComponent"></param>
 public static void RemoveUIRedDotComponent(this RedDotComponent self, string target, out Entity uiRedDotComponent)
 {
     if (self.RedDotMonoViewDict.TryGetValue(target, out uiRedDotComponent))
     {
         self.RedDotMonoViewDict.Remove(target);
     }
 }
예제 #2
0
        /// <summary>
        /// 创建树————添加节点
        /// </summary>
        /// <param name="self"></param>
        /// <param name="parent"></param>
        /// <param name="target"></param>
        public static void AddRodDotNode(this RedDotComponent self, string parent, string target)
        {
            if (string.IsNullOrEmpty(target))
            {
                Log.Error($"target is null");
                return;
            }

            if (string.IsNullOrEmpty(parent))
            {
                Log.Error($"parent is null");
                return;
            }

            if (self.ToParentDict.ContainsKey(target))
            {
                Log.Error($"{target} is already exist!");
                return;
            }

            self.ToParentDict.Add(target, parent);

            if (!self.RetainViewCount.ContainsKey(target))
            {
                self.RetainViewCount.Add(target, 0);
            }

            if (self.RedDotNodeParentsDict.TryGetValue(parent, out ListComponent <string> list))
            {
                list.Add(target);
                return;
            }

            var listComponent = ListComponent <string> .Create();

            listComponent.Add(target);
            self.RedDotNodeParentsDict.Add(parent, listComponent);
        }
예제 #3
0
        /// <summary>
        /// 刷新红点数量
        /// </summary>
        /// <param name="self"></param>
        /// <param name="target"></param>
        /// <param name="Count"></param>
        public static void RefreshRedDotViewCount(this RedDotComponent self, string target, int Count)
        {
            if (!self.IsLeafNode(target))
            {
                Log.Error("can not refresh parent node view count");
                return;
            }

            self.RedDotMonoViewDict.TryGetValue(target, out Entity uiRedDotComponent);

            self.RetainViewCount[target] = Count;

            if (uiRedDotComponent != null)
            {
                UIEventSystem.Instance.OnChangeRedDotActive(uiRedDotComponent, self.RetainViewCount[target]);
            }

            bool isParentExist = self.ToParentDict.TryGetValue(target, out string parent);

            while (isParentExist)
            {
                var viewCount = 0;

                foreach (var childNode in self.RedDotNodeParentsDict[parent])
                {
                    viewCount += self.RetainViewCount[childNode];
                }

                self.RetainViewCount[parent] = viewCount;

                if (self.RedDotMonoViewDict.TryGetValue(parent, out uiRedDotComponent))
                {
                    UIEventSystem.Instance.OnChangeRedDotActive(uiRedDotComponent, viewCount);
                }

                isParentExist = self.ToParentDict.TryGetValue(parent, out parent);
            }
        }
예제 #4
0
        /// <summary>
        /// 创建树————移除节点
        /// </summary>
        /// <param name="self"></param>
        /// <param name="target"></param>
        public static void RemoveRedDotNode(this RedDotComponent self, string target)
        {
            if (!self.ToParentDict.TryGetValue(target, out string parent))
            {
                return;
            }

            if (!self.IsLeafNode(target))
            {
                Log.Error("can not remove parent node!");
                return;
            }

            self.ToParentDict.Remove(target);
            if (!string.IsNullOrEmpty(parent))
            {
                self.RedDotNodeParentsDict[parent].Remove(target);
                if (self.RedDotNodeParentsDict[parent].Count <= 0)
                {
                    self.RedDotNodeParentsDict[parent].Dispose();
                    self.RedDotNodeParentsDict.Remove(parent);
                }
            }
        }
예제 #5
0
 /// <summary>
 /// 是否是子节点
 /// </summary>
 /// <param name="self"></param>
 /// <param name="target"></param>
 /// <returns></returns>
 public static bool IsLeafNode(this RedDotComponent self, string target)
 {
     return(!self.RedDotNodeParentsDict.ContainsKey(target));
 }
예제 #6
0
 /// <summary>
 /// 添加UI红点
 /// </summary>
 /// <param name="self"></param>
 /// <param name="target"></param>
 /// <param name="uiRedDotComponent"></param>
 public static void AddUIRedDotComponent(this RedDotComponent self, string target, Entity uiRedDotComponent)
 {
     self.RedDotMonoViewDict[target] = uiRedDotComponent;
 }