Esempio n. 1
0
        public void UnregisterNotice(NoticeType childType, NoticeType parentType = NoticeType.NONE)
        {
            BaseNotice child = null;

            if (!noticeDic.TryGetValue(childType, out child))
            {
                if (child == null)
                {
                    child = new BaseNotice(childType);
                    noticeDic[childType] = child;
                }
            }

            if (parentType != NoticeType.NONE)
            {
                BaseNotice parent = null;
                if (!noticeDic.TryGetValue(parentType, out parent))
                {
                    if (parent == null)
                    {
                        parent = new BaseNotice(parentType);
                        noticeDic[parentType] = parent;
                    }
                }
                parent.RemoveChild(child);

                if (child.parent == parent)
                {
                    child.SetParent(null);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 递归检查设置父级notice
        /// </summary>
        /// <param name="notice"></param>
        private void checkNotice(BaseNotice notice)
        {
            if (notice != null)
            {
                //Debug.LogErrorFormat("checkNotice:: NoticeType = {0} isAlive = {1}", notice.noticeType, notice.isAlive);
                bool isAlive = false;
                if (notice.childs != null)
                {
                    for (int i = 0; i < notice.childs.Count; i++)
                    {
                        if (notice.childs[i].isAlive)
                        {
                            isAlive = true;
                            break;
                        }
                    }
                }
                if (isAlive != notice.isAlive)
                {
                    notice.Notify(notice, isAlive);
                    //Debug.LogErrorFormat("checkNotice:: NoticeType = {0} isAlive = {1} Notify", notice.noticeType, notice.isAlive);
                }

                if (notice.parent != null)
                {
                    checkNotice(notice.parent);
                }
            }
        }
Esempio n. 3
0
 internal virtual void Notify(BaseNotice notice, bool isAlive)
 {
     this.isAlive = isAlive;
     if (notifyCallBacks != null)
     {
         for (int i = 0; i < notifyCallBacks.Count; i++)
         {
             notifyCallBacks[i].Invoke();
         }
     }
 }
Esempio n. 4
0
 internal virtual void RemoveChild(BaseNotice child)
 {
     if (child != null)
     {
         if (childs != null)
         {
             if (childs.Contains(child))
             {
                 childs.Remove(child);
             }
         }
     }
 }
Esempio n. 5
0
        internal virtual void AddChild(BaseNotice child)
        {
            if (child != null)
            {
                if (childs == null)
                {
                    childs = new List <BaseNotice>();
                }

                if (!childs.Contains(child))
                {
                    childs.Add(child);
                }
            }
        }
Esempio n. 6
0
        private void setChild(BaseNotice notice, string path)
        {
            GameObject obj = new GameObject(notice.noticeType.ToString());

            obj.AddComponent <WatchMonoAction>().noticeActions = notice.notifyCallBacks;
            Transform parent = transform.Find(path);

            if (parent == null)
            {
                parent = transform;
            }

            obj.transform.SetParent(parent);

            path = string.IsNullOrEmpty(path) ? obj.name : path + "/" + obj.name;
            if (notice.childs != null && notice.childs.Count > 0)
            {
                for (int i = 0; i < notice.childs.Count; i++)
                {
                    setChild(notice.childs[i], path);
                }
            }
        }
Esempio n. 7
0
 internal virtual void SetParent(BaseNotice parent)
 {
     this.parent = parent;
 }
Esempio n. 8
0
 internal void SetOwn(BaseNotice ownNotice)
 {
     this.ownNotice = ownNotice;
 }