Example #1
0
    public void ExecuteEvent(string eventId, object data)
    {
        if (!m_UseDataEventCallers.ContainsKey(eventId) &&
            !m_NotDataEventCallers.ContainsKey(eventId))
        {
#if UNITY_EDITOR || DEBUG
            AiukDebugUtility.LogWarning(string.Format("没有发现目标事件{0}", eventId));
#endif
            return;
        }

        if (m_UseDataEventCallers.ContainsKey(eventId))
        {
            var caller = m_UseDataEventCallers[eventId];
            caller.CallEventHanlder(data);
            TryCleanZero();
        }

        if (m_NotDataEventCallers.ContainsKey(eventId))
        {
            var caller = m_NotDataEventCallers[eventId];
            caller.CallEventHanlder();
            TryCleanZero();
        }
    }
Example #2
0
        /// <summary>
        /// 创建实例
        /// </summary>
        private void CreateInstance()
        {
            while (true)
            {
                if (m_CreateTotalCount == m_Types.Count)
                {
                    return;
                }
                if (m_CreateCount == m_EveryCount)
                {
                    m_CreateCount = 0;
                    return;
                }

                m_TypeIndex++;
                m_CreateCount++;
                m_CreateTotalCount++;
                if (m_ExplicitCreatedIndexs.Contains(m_TypeIndex))
                {
                    continue;
                }

                m_CurrentType = m_Types[m_TypeIndex];
                var instance = Activator.CreateInstance(m_CurrentType) as T;
#if UNITY_EDITOR || DEBUG
                AiukDebugUtility.Log(string.Format("加载器{0}成功创建了一个类型{1}的实例!", m_Name, m_CurrentType.Name));
#endif
                m_Instances.Add(instance);
            }
        }
        public void ExecuteEvent()
        {
            if (m_TaskQueue.Count == 0)
            {
                return;
            }

            var taskCount = m_TaskQueue.Count;

            for (int i = 0; i < taskCount; i++)
            {
                var task = m_TaskQueue.Dequeue();
                if (!m_EventHandleUnits.ContainsKey(task.EventCode.EventModuleType))
                {
#if UNITY_EDITOR || DEBUG
                    AiukDebugUtility.LogWarning(string.Format("尝试触发一个没有响应处理器的事件," +
                                                              "事件Id为{0}", task.EventCode.EventName));
#endif
                    continue;
                }
                else
                {
                    var unit = m_EventHandleUnits[task.EventCode.EventModuleType];
                    unit.ExecuteEvent(task.EventCode.EventName, task.EventData);
                }

                if (task.OnCompelted != null)
                {
                    task.OnCompelted();
                }

                AiukEventFactory.EventTaskPool.Restore(task);
            }
        }
        public void BuildAppModule()
        {
            CreateAppModuleCsDir();
            CrewateAssetDatabaseDir();
            CreateOriginalAssetDir();

            AiukDebugUtility.Log("更新成功",
                                 string.Format("应用模块{0}的文件结构及资源已更新。", m_AppModule.Name),
                                 "知道了");
        }
Example #5
0
        private void Update()
        {
            if (m_CreateTotalCount == m_Types.Count)
            {
                Destroy(this);
                AiukDebugUtility.Log(string.Format("帧实例加载器{0}已创建完所有实例,加载器将销毁!", m_Name));
                return;
            }

            CreateInstance();
        }
Example #6
0
        public IAiukViewActionDispatcher <T> ReplaceResponser(string token, IAiukViewActionResponser <T> responser)
        {
            if (!m_Responsers.ContainsKey(token))
            {
                AiukDebugUtility.LogError(string.Format("目标响应器{0}当前不存在,无法替换!", token));
                return(this);
            }

            m_Responsers[token] = responser;
            return(this);
        }
Example #7
0
        public void BindingAction(AiukButtonEventType type, Action action)
        {
            if (m_ButtonActions.ContainsKey(type))
            {
                AiukDebugUtility.LogError
                    (string.Format("目标行为处理委托{0}已存在,无法绑定!", type));
                return;
            }

            m_ButtonActions.Add(type, action);
        }
Example #8
0
        public void RemoveAction(AiukButtonEventType type)
        {
            if (m_ButtonActions.ContainsKey(type))
            {
                AiukDebugUtility.LogError
                    (string.Format("目标行为处理委托{0}不存在,无法移除", type));
                return;
            }

            m_ButtonActions.Remove(type);
        }
        public static void DeleteApp(string appName)
        {
            if (!IsExist(appName))
            {
                AiukDebugUtility.LogError(string.Format("目标App{0}不存在,无法删除!", appName));
                return;
            }

            var app = GetApp(appName);

            Instance.AppSetings.Remove(app);
        }
        /// <summary>
        /// 添加一个新的应用模块。
        /// </summary>
        /// <param name="module">Module.</param>
        public void AddModule(AiukAppModuleSetting module)
        {
            if (IsExist(module.Name))
            {
                AiukDebugUtility.LogError(
                    string.Format("目标模块{0}已存在,添加失败!", module.Name));
                return;
            }

            AppModules.Add(module);
            CurrentModuleName = module.Name;
        }
        /// <summary>
        /// 目标编号协议是否可以被发送。
        /// </summary>
        /// <param name="messageId"></param>
        /// <returns></returns>
        public bool CanSend(int messageId)
        {
            if (!m_SendStates.ContainsKey(messageId))
            {
#if UNITY_EDITOR || DEBUG
                AiukDebugUtility.LogError(string.Format("没有对应的客户端消息编号{0}存在!", messageId));
#endif
                return(false);
            }

            var state = m_SendStates[messageId];
            return(state.CanSend);
        }
Example #12
0
        public IAiukViewActionDispatcher <T> InjectResponser(IAiukViewActionResponser <T> responser)
        {
            //  命名约定,视图行为处理器的类名一定和行为的令牌(Token)相同。
            var token = responser.GetType().Name;

            if (m_Responsers.ContainsKey(token))
            {
                AiukDebugUtility.LogError(string.Format("目标响应器{0}当前已存在,无法注入!", token));
                return(this);
            }

            m_Responsers.Add(token, responser);
            return(this);
        }
Example #13
0
        /// <summary>
        /// 获得目标资源的资源数据。
        /// </summary>
        /// <param name="assetName"></param>
        /// <returns></returns>
        public AiukAssetInfo GetAssetInfo(string assetName)
        {
            if (!m_AssetTypeMap.ContainsKey(assetName))
            {
                AiukDebugUtility.Log(string.Format("目标资源{0}没有资源数据!", assetName));
                return(null);
            }

            var type      = m_AssetTypeMap[assetName];
            var typeInfos = m_AssetInfos[type];
            var info      = typeInfos[assetName];

            return(info);
        }
Example #14
0
        /// <summary>
        /// 添加一个将要启动的应用模块。
        /// </summary>
        /// <returns>The app module.</returns>
        /// <param name="module">Module.</param>
        public AiukUnityApp SetAppModule(AiukAppModuleSetting module)
        {
            var exist = AppModules.Find(m => m.Token == module.Token);

            if (exist != null)
            {
                AiukDebugUtility.LogError(
                    string.Format("目标模块设置{0}当前已存在!", module.Token));
                return(this);
            }

            AppModules.Add(module);
            return(this);
        }
Example #15
0
            /// <summary>
            /// 移除一个Unity类型的事件处理器。
            /// </summary>
            /// <param name="type">Type.</param>
            /// <param name="action">Action.</param>
            public void RemoveUnityEvent(AiukUnityEventType type, Action action)
            {
                if (!m_EventCallers.ContainsKey(type))
                {
#if UNITY_EDITOR || DEBUG
                    AiukDebugUtility.LogWarning(
                        string.Format("尝试移除一个不存在的Unity事件类型,事件类型为{0}", type));
#endif
                    return;
                }

                var caller = m_EventCallers[type];
                caller.RemoveHandler(action);
            }
        /// <summary>
        /// 添加一个新的应用。
        /// </summary>
        /// <param name="app">App.</param>
        public static void AddApp(AiukAppSetting app)
        {
            if (IsExist(app.Name))
            {
                AiukDebugUtility.LogError(
                    string.Format("目标应用{0}已存在,添加失败!", app.Name));
                return;
            }

            Instance.AppSetings.Add(app);
            Debug.Log(Instance.AppSetings.Count);
            //  更新当前应用为新添加的应用。
            Instance.CurrentAppName = app.Name;
        }
        public void RemoveHandler(int handlerId)
        {
            var handler = m_Handlers.Find(h => h.Id == handlerId);

            if (handler == null)
            {
#if UNITY_EDITOR || DEBUG
                AiukDebugUtility.LogWarning(
                    string.Format("尝试移除不存在的事件处理器,事件Id为{0}!", handlerId));
#endif
                return;
            }

            m_Handlers.Remove(handler);
        }
        public void RemoveSpecifiedHandler(AiukEventCode eventCode, int handlerId)
        {
            if (!m_EventHandleUnits.ContainsKey(eventCode.EventModuleType))
            {
#if UNITY_EDITOR || DEBUG
                AiukDebugUtility.LogWarning(
                    string.Format("尝试移除一个当前不存在的事件处理器,事件Id为{0}。",
                                  eventCode.EventName));
#endif
                return;
            }

            var unit = m_EventHandleUnits[eventCode.EventModuleType];
            unit.RemoveSpecifiedHandler(eventCode.EventName, handlerId);
        }
Example #19
0
        public virtual IAiukView Component(params AiukAbsViewComponent[] components)
        {
            foreach (var viewComponent in components)
            {
                if (m_ViewComponents.ContainsKey(viewComponent.Name))
                {
                    AiukDebugUtility.LogError(string.Format("名为{0}的视图组件当前已存在!"
                                                            , viewComponent.Name));
                    continue;
                }

                m_ViewComponents.Add(viewComponent.Name, viewComponent);
            }

            return(this);
        }
Example #20
0
        /// <summary>
        /// 观察数据。
        /// </summary>
        /// <param name="onDataChanged"></param>
        public void Watch(Action <long> onDataChanged)
        {
            if (onDataChanged == null)
            {
                AiukDebugUtility.LogError("不能添加一个空的数据处理委托!");
                return;
            }

            if (m_DataChangeActions.Find(del => del == onDataChanged) != null)
            {
                AiukDebugUtility.LogError
                    (string.Format("不能重复添加数据处理委托,目标委托为{0}!", onDataChanged));
                return;
            }

            m_DataChangeActions.Add(onDataChanged);
        }
        /// <summary>
        /// 注入一个数据到数据管道。
        /// </summary>
        /// <param name="producer">消息生产者。</param>
        /// <param name="message">消息。</param>
        public void PushData(IAiukDataProducer <TMessage> producer, TMessage message)
        {
#if UNITY_EDITOR || DEBUG
            if (producer == null)
            {
                AiukDebugUtility.LogError("没有合法的数据提供者,不允许置入数据!");
                return;
            }
#endif

            if (m_Systems.Count == 0)
            {
                return;
            }

            //  调用第一个系统实例的消息处理方法,并由该系统启动可能存在的系统处理链。
            m_Systems[0].HandleMessage(message);
        }
Example #22
0
        /// <summary>
        /// 显式手动创建实例。
        /// </summary>
        /// <returns></returns>
        public T ExplicitCreate(string typeName)
        {
            var index = m_Types.FindIndex(t => t.Name == typeName);

            if (index == -1)
            {
                AiukDebugUtility.LogWarning(string.Format("没有找到所要创建的目标类型{0}!", typeName));
                return(null);
            }

            m_ExplicitCreatedIndexs.Add(index);
            var type     = m_Types[index];
            var instance = Activator.CreateInstance(type) as T;

            m_Instances.Add(instance);

            return(instance);
        }
Example #23
0
        public void Close()
        {
            if (!m_RunToggle)
            {
                return;
            }

#if UNITY_EDITOR || DEBUG
            var runAtStopTime = (DateTime.Now - m_StarTime).TotalSeconds;
            AiukDebugUtility.Log(string.Format("编号为{0}的计时器总共运行{1}秒,已停止!"
                                               , Id, runAtStopTime));
#endif

            m_RunToggle = false;
            m_CloseTime = DateTime.Now;
            if (m_OnClose != null)
            {
                m_OnClose(this);
            }
        }
Example #24
0
        private AiukAssetBundleRef SyncGetAssetBundle(AiukAssetInfo assetInfo)
        {
            var assetName = assetInfo.AssetName;
            var appModule = m_ModuleMap[assetInfo.LocModule];

            if (AiukAppModuleHelper.GetMainfest(appModule) == null)
            {
                AiukDebugUtility.LogError
                    ("Ab主描述文件为空,请确认执行了AssetBundle打包操作!");
                return(null);
            }

            var manifest = AiukAppModuleHelper.GetMainfest(appModule);
            var depends  = manifest.GetAllDependencies(assetName + ".assetbundle");

            foreach (var item in depends)
            {
                var bundleName = item.Replace(".assetbundle", "");
                if (m_CoreAssetBundleRefs.ContainsKey(bundleName))
                {
                    var bundleRef = m_CoreAssetBundleRefs[bundleName];
                    bundleRef.Use();
                }
                else
                {
                    var tempInfo  = GetAssetInfo(bundleName);
                    var tempAb    = AssetBundle.LoadFromFile(tempInfo.ImporterPath);
                    var bundleRef = new AiukAssetBundleRef(tempAb);
                    bundleRef.Use();
                    m_CoreAssetBundleRefs.Add(bundleName, bundleRef);
                    return(bundleRef);
                }
            }

            var assetBundle = AssetBundle.LoadFromFile(assetInfo.ImporterPath);
            var newAbRef    = new AiukAssetBundleRef(assetBundle);

            newAbRef.Use();
            m_NormalAssetBundleRefs.Add(assetInfo.BundleName, newAbRef);
            return(newAbRef);
        }
Example #25
0
    private void RemoveSpecifiedHandlerAtUseData(string eventName, int handlerId)
    {
        if (!m_UseDataEventCallers.ContainsKey(eventName))
        {
#if UNITY_EDITOR || DEBUG
            AiukDebugUtility.LogWarning(
                string.Format("尝试移除不存在的有数据事件处理器,事件名为{0}", eventName));
#endif

            return;
        }
        else
        {
            var caller = m_UseDataEventCallers[eventName];
            caller.RemoveHandler(handlerId);
            if (caller.EventHanlderCount == 0)
            {
                m_UseDataEventCallers.Remove(eventName);
            }
        }
    }
Example #26
0
        private void AsyncGetAssetBundle(AiukAssetInfo assetInfo, Action <AiukAssetBundleRef> callback)
        {
            var bundleRef = TryGetAssetBundleRefFromCache(assetInfo);

            if (bundleRef != null)
            {
                callback(bundleRef);
                return;
            }

            var assetName = assetInfo.AssetName;
            var appModule = m_ModuleMap[assetInfo.LocModule];

            if (AiukAppModuleHelper.GetMainfest(appModule) == null)
            {
                AiukDebugUtility.LogError
                    ("Ab主描述文件为空,请确认执行了AssetBundle打包操作!");
                return;
            }

            var manifest = AiukAppModuleHelper.GetMainfest(appModule);
            var depends  = manifest.GetAllDependencies(assetName + ".assetbundle");
        }
        /// <summary>
        /// 结束一次执行周期。
        /// </summary>
        public virtual void FinishExecute()
        {
#if UNITY_EDITOR || DEBUG
            AiukDebugUtility.Log(GetType().Name + "_FinishExecute!");
#endif
        }
 public override void HandleMessage(AiukButtonMessage message)
 {
     AiukDebugUtility.Log("AiukButtonSystem: HandleMessage, this action name is " + message.EventTypeStr);
 }