Пример #1
0
        /// <summary>
        /// 创建一个新的或者复用存在的UITask
        /// </summary>
        /// <param name="uiTaskRegisterItem"></param>
        /// <returns></returns>
        private UITask CreateOrGetUITaskInstance(UITaskRegisterItem uiTaskRegisterItem)
        {
            UITask instance = null;

            if (uiTaskRegisterItem.AllowMultipleInstance)
            {
                //AllowMultipleInstance总是会创建出新的实例
                instance = ClassLoader.CreateInstance(uiTaskRegisterItem.TypeFullName, uiTaskRegisterItem.Name) as UITask;
                int instanceId = GetInstanceID(uiTaskRegisterItem.Name);
                instance.SetInstanceID(instanceId);
            }
            else
            {
                //复用之前的UITask
                List <UITask> uiTasks;
                m_uiTaskDic.TryGetValue(uiTaskRegisterItem.Name, out uiTasks);
                if (uiTasks != null && uiTasks.Count != 0)
                {
                    instance = uiTasks[0];
                }
                else
                {
                    //如果不存在,创建一个新的
                    instance = ClassLoader.CreateInstance(uiTaskRegisterItem.TypeFullName, uiTaskRegisterItem.Name) as UITask;
                }
            }
            return(instance);
        }
Пример #2
0
 private void OnUITaskStart(UITask uiTask)
 {
     //加入栈
     m_uiTaskStack.Add(uiTask);
     if (!m_uiTaskDic.ContainsKey(uiTask.Name))
     {
         m_uiTaskDic.Add(uiTask.Name, new List <UITask>());
     }
     //加入字典
     m_uiTaskDic[uiTask.Name].Add(uiTask);
 }
Пример #3
0
 /// <summary>
 /// 当UITask销毁
 /// </summary>
 /// <param name="uiTask"></param>
 private void OnUITaskStop(UITask uiTask)
 {
     //从字典中移除
     m_uiTaskDic[uiTask.Name].Remove(uiTask);
     if (m_uiTaskDic[uiTask.Name].Count == 0)
     {
         //重置最大ID
         ResetInstanceID(uiTask.Name);
     }
     //从栈中移除
     m_uiTaskStack.Remove(uiTask);
 }
Пример #4
0
 /// <summary>
 /// 开启UITask
 /// </summary>
 /// <param name="uiTask"></param>
 /// <param name="intent"></param>
 /// <param name="onPrepareEnd"></param>
 private void StartUITaskInternal(UITask uiTask, UIIntent intent, Action <bool> onPrepareEnd = null)
 {
     uiTask.PrapareDataForStart((res) => {
         if (onPrepareEnd != null)
         {
             onPrepareEnd(res);
         }
         if (res)
         {
             StartOrResumeUITask(uiTask, intent);
         }
         else
         {
             Debug.LogError(string.Format("PrapareDataForStart Failed UITask Name:", uiTask.Name));
         }
     });
 }
Пример #5
0
        private void StartOrResumeUITask(UITask uiTask, UIIntent intent)
        {
            switch (uiTask.State)
            {
            case TaskState.Init:
                uiTask.UpdateCtx.m_isInit = true;
                uiTask.EventOnStop       += () => { OnUITaskStop(uiTask); };
                uiTask.EventOnStart      += () => { OnUITaskStart(uiTask); };
                uiTask.Start(intent);
                break;

            case TaskState.Paused:
                uiTask.UpdateCtx.m_isResume = true;
                uiTask.Resume(intent);
                break;

            case TaskState.Runing:
                uiTask.OnNewIntent(intent);
                break;
            }
        }