Ejemplo n.º 1
0
        protected override void OnAdd(GUnit unit)
        {
            var unitData           = unit.GetData <UnitData>();
            var controlStateData   = unit.GetData <ObjectControlStateData>();
            var controlProcessData = unit.GetData <ObjectKeyboardControlProcessData>();
            var stateProcessData   = unit.GetData <ObjectStateProcessData>();

            controlStateData.stateType.Subscribe(controlStateType =>
            {
                if (controlStateType == ObjectControlStateType.Start)
                {
                    controlProcessData.checkDispose = GameSystem.ObserveEveryUpdate().Subscribe(_ =>
                    {
                        foreach (var controlData in controlProcessData.controlDataList)
                        {
                            if (Input.GetKeyDown(controlData.key))
                            {
                                ObjectControlStateTypeDict.Set(unit, controlData.controlType, KeyStateType.Down);
                                ObjectControlState.CheckAllControl(unit, controlData.controlType, controlStateData,
                                                                   stateProcessData);
                            }
                            else if (Input.GetKeyUp(controlData.key))
                            {
                                ObjectControlStateTypeDict.Set(unit, controlData.controlType, KeyStateType.Up);
                                ObjectControlState.CheckAllControl(unit, controlData.controlType, controlStateData,
                                                                   stateProcessData);
                                ObjectControlStateTypeDict.Set(unit, controlData.controlType, KeyStateType.None);
                            }
                        }
                    });
                }
                else if (controlStateType == ObjectControlStateType.Finish)
                {
                    controlProcessData.checkDispose?.Dispose();
                }
            }).AddTo(unitData.disposable);
        }
Ejemplo n.º 2
0
        protected override void OnAdd(GUnit unit)
        {
            var unitData           = unit.GetData <UnitData>();
            var controlStateData   = unit.GetData <ObjectControlStateData>();
            var controlProcessData = unit.GetData <ObjectUIControlProcessData>();
            var stateProcessData   = unit.GetData <ObjectStateProcessData>();

            controlStateData.stateType.Subscribe(controlStateType =>
            {
                if (controlStateType == ObjectControlStateType.Start)
                {
                    controlProcessData.checkDispose = new CompositeDisposable();
                    foreach (var controlData in controlProcessData.controlDataList)
                    {
                        controlData.controlHelper.ObservePointerDown().Subscribe(_ =>
                        {
                            ObjectControlStateTypeDict.Set(unit, controlData.controlType, KeyStateType.Down);
                            ObjectControlState.CheckAllControl(unit, controlData.controlType, controlStateData,
                                                               stateProcessData);
                        }).AddTo(controlProcessData.checkDispose);

                        controlData.controlHelper.ObservePointerUp().Subscribe(_ =>
                        {
                            ObjectControlStateTypeDict.Set(unit, controlData.controlType, KeyStateType.Up);
                            ObjectControlState.CheckAllControl(unit, controlData.controlType, controlStateData,
                                                               stateProcessData);
                            ObjectControlStateTypeDict.Set(unit, controlData.controlType, KeyStateType.None);
                        }).AddTo(controlProcessData.checkDispose);
                    }
                }
                else if (controlStateType == ObjectControlStateType.Finish)
                {
                    controlProcessData.checkDispose?.Dispose();
                }
            }).AddTo(unitData.disposable);
        }