示例#1
0
    public virtual void Init(int hp, int damage, ACTION_STATE initState, BasePlayer target)
    {
        AnimationStateData stateData = new AnimationStateData(_skeletonAnimation.state.Data.skeletonData);

        stateData.DefaultMix = 0.1f;
        stateData.SetMix(
            AnimationHelper.Instance.GetAnimDetailName(ANIM_ATTACK_BITE_ID),
            AnimationHelper.Instance.GetAnimDetailName(ANIM_MOVE_BACK_ID),
            0.8f);
        stateData.SetMix(
            AnimationHelper.Instance.GetAnimDetailName(ANIM_ATTACK_HORN_ID),
            AnimationHelper.Instance.GetAnimDetailName(ANIM_MOVE_BACK_ID),
            0.8f);

        Spine.AnimationState state = new Spine.AnimationState(stateData);

        _skeletonAnimation.state = state;
        DoAnimIdle();

        _skeletonAnimation.AnimationState.Event += OnEvent;
        _skeletonAnimation.AnimationState.Start += OnStartTrack;

        _maxHp       = hp;
        CurrentHp    = _maxHp;
        Damage       = damage;
        CurrentState = initState;
        _target      = target;

        _checkHit = true;
        _healthBar.Init(_maxHp);

        SetColliderState();
    }
示例#2
0
 public void Reset(ACTION_STATE state)
 {
     CurrentHp    = _maxHp;
     _checkHit    = true;
     CurrentState = state;
     _healthBar.Reset();
 }
示例#3
0
 public virtual void CopyValues(Action_GS copy)
 {
     _agent = copy._agent;
     _name  = copy._name;
     _cost  = copy._cost;
     _state = copy._state;
 }
示例#4
0
        //Loop Methods ================
        //Action awake is called once at the plan start
        public virtual bool ActionAwake()
        {
            //Set action state to start
            _state = ACTION_STATE.A_START;

            return(true);
        }
示例#5
0
    private bool CalcMoveCommond()
    {
        if (m_KeyRecordList.Count > 0)
        {
            Vector3          moveSpeed = Vector3.zero;
            CommondKeyRecord KeyRecord = m_KeyRecordList[m_KeyRecordList.Count - 1];
            if (KeyRecord.IsKeyDownOrHold(KeyCode.W))
            {
                moveSpeed += transform.forward * m_MoveForwardSpeed;
            }
            if (KeyRecord.IsKeyDownOrHold(KeyCode.S))
            {
                moveSpeed -= transform.forward * m_MoveBackSpeed;
            }
            if (KeyRecord.IsKeyDownOrHold(KeyCode.A))
            {
                moveSpeed -= transform.right * m_MoveLeftSpeed;
            }
            if (KeyRecord.IsKeyDownOrHold(KeyCode.D))
            {
                moveSpeed += transform.right * m_MoveBackSpeed;
            }

            m_ActionState             = ACTION_STATE.MOVE_NORMAL;
            m_NormalMoveCmd.moveSpeed = moveSpeed;
            return(true);
        }
        m_ActionState = ACTION_STATE.IDLE;
        return(false);
    }
示例#6
0
        private ACTION_STATE InitKI(ACTION_STATE stm)
        {
            RxInfo currRx = rx;

            SetDelays();
            currRx.var.iSrc = RunWnd.syscfg.GetCurrent(currRx.iIx, currRx.bSqrt); //0.1mA
            currRx.var.rRx  = currRx.dRxInput;
            currRx.var.iK   = RX_VAR.INIT_LOOP;
            currRx.var.iK   = currRx.var.calc_capture_nextk();

            if (currRx.iRRange == RNG_P1)   //P1 ohm
            {
                currRx.var.iK = 100;        //10:1
            }
            if (currRx.iRRange == RNG_P01)  //P01 ohm
            {
                currRx.var.iK = 10;         //100:1
            }
            if (currRx.iRRange == RNG_P001) //P001 ohm
            {
                currRx.var.iK = 1;          //1000:1
            }
            DeviceMgr.Action("turnk", Convert.ToUInt32(currRx.var.iK));
            if ((currRx.iRRange == RNG_P1) || (currRx.iRRange == RNG_P01) || (currRx.iRRange == RNG_P001))
            {
                return(ACTION_STATE.INIT_FOR_RS_KTTP);
            }
            else
            {
                return(ACTION_STATE.INIT_FOR_TRACKP);
            }
        }
示例#7
0
 protected override void ResetAction()
 {
     Debug.Log("复原");
     m_state = ACTION_STATE.STATE_ONE;
     CreatSlate();
     m_trigger.enabled = true;
     base.ResetAction();
 }
示例#8
0
 private ACTION_STATE InitNavRange(ACTION_STATE stm)
 {
     nav_range = "navto1v";
     DeviceMgr.Action(nav_range, 0);
     if (stm == ACTION_STATE.INIT_FOR_START)
     {
         return(ACTION_STATE.INIT_FOR_SEARCH);
     }
     else
     {
         return(stm);
     }
 }
示例#9
0
    // Function

    void Awake()
    {
        m_KeyCheckDuration = 0.2f;
        m_MaxRecordSize    = 200;      // 最多记录1000条按键记录 m_KeyCheckDuration * fps = 0.2f * 1000
        m_KeyRecordList    = new List <CommondKeyRecord>();
        m_ClickKeyList     = new List <KeyCode>();

        //m_MoveForwardSpeed = 2.0f;
        //m_MoveBackSpeed = 1.0f;
        //m_MoveLeftSpeed = 1.0f;
        //m_MoveRightSpeed = 1.0f;

        m_ActionState   = ACTION_STATE.IDLE;
        m_NormalMoveCmd = new NormalMoveCommond();
        m_DoubleMoveCmd = new DoubleMoveCommond();
        m_DoubleMoveCmd.durationTime = 0.15f;
        m_JumpMoveCmd = new JumpMoveCommond();

        m_LockHView = false;
    }
示例#10
0
        //Used to iterate all the previous loop methods
        public ACTION_RESULT Execute()
        {
            //Action execution result
            Action_GS.ACTION_RESULT execution_result = Action_GS.ACTION_RESULT.A_ERROR;
            //Execute the current action
            switch (_state)
            {
            case Action_GS.ACTION_STATE.A_START:
            {
                execution_result = ActionStart();
            }
            break;

            case Action_GS.ACTION_STATE.A_UPDATE:
            {
                //Execute behaviour in action update
                execution_result = ActionUpdate();
            }
            break;

            case Action_GS.ACTION_STATE.A_COMPLETE:
            {
                execution_result = ActionEnd();
            }
            break;
            }
            //React with the action result
            if (execution_result == Action_GS.ACTION_RESULT.A_NEXT)
            {
                _state += 1;
            }
            else if (execution_result == Action_GS.ACTION_RESULT.A_ERROR)
            {
                ActionBreak();
            }

            return(execution_result);
        }
示例#11
0
 private ACTION_STATE InitNavRange(ACTION_STATE stm)
 {
     nav_range = "navto1v";
     DeviceMgr.Action(nav_range, 0);
     if (stm == ACTION_STATE.INIT_FOR_START)
         return ACTION_STATE.INIT_FOR_SEARCH;
     else
         return stm;
 }
示例#12
0
        public ACTION_STATE Do(ACTION_REQUEST action, ACTION_STATE stm)
        {
            laststm = stm;
            if (action == ACTION_REQUEST.INIT_NAV_RANGE)
            {
                return InitNavRange(stm);
            }
            if (action == ACTION_REQUEST.INITKI_FOR_SEARCH)
            {
                delay = 2;
                return InitKI(stm);
            }

            if (action == ACTION_REQUEST.SET_FOR_RS_KTTP)
            {
                DeviceMgr.Action("MEAS_RS|KTTP|" + DeviceMgr.ComposeAction(rx), 0);
                range_dir = 1;
                delay = delayKI;
                bInReading = true;
                return ACTION_STATE.INIT_FOR_RS_KTTN;
            }
            if (action == ACTION_REQUEST.SET_FOR_RS_KTTN)
            {
                DeviceMgr.Action("MEAS_RS|KTTN|" + DeviceMgr.ComposeAction(rx), 0);
                range_dir = 1;
                delay = delayKTT;
                bInReading = true;

                return ACTION_STATE.COMPLETE_ISRC;
            }
            /*
            if (action == ACTION_REQUEST.SET_FOR_RX_KTTP)
            {
                DeviceMgr.Action("MEAS_RX|KTTP|" + DeviceMgr.ComposeAction(rx), 0);
                range_dir = 1;
                delay = delayKI;
                bInReading = true;
                return ACTION_STATE.INIT_FOR_RX_KTTN;
            }
            if (action == ACTION_REQUEST.SET_FOR_RX_KTTN)
            {
                DeviceMgr.Action("MEAS_RX|KTTN|" + DeviceMgr.ComposeAction(rx), 0);
                range_dir = 1;
                delay = delayKTT;
                bInReading = true;
                return ACTION_STATE.INIT_FOR_TRACKP;
            }
             */
            if (action == ACTION_REQUEST.SET_FOR_TRACKP)
            {
                DeviceMgr.Action("MEAS_DELTA|KTTP|" + DeviceMgr.ComposeAction(rx), 0);
                delay = RunWnd.syscfg.iKTT; //adjust delay
                range_dir = 1;
                bInReading = true;
                return ACTION_STATE.INIT_FOR_TRACKN;
            }
            if (action == ACTION_REQUEST.SET_FOR_TRACKN)
            {
                if (RangeAdjustDown(Math.Abs(rx.var.vCrossP)))
                {
                    range_dir = 1;
                    delay = 2;
                    bInReading = false;
                    return ACTION_STATE.INIT_FOR_TRACKP;
                }

                DeviceMgr.Action("MEAS_DELTA|KTTN|" + DeviceMgr.ComposeAction(rx), 0);
                delay = RunWnd.syscfg.iKTT; //adjust delay
                range_dir = 1;
                bInReading = true;
                return ACTION_STATE.UPDATE_K_TRACK;
            }
            if (action == ACTION_REQUEST.SET_NEXT_K)
            {
                /*
                if (RangeAdjustDown(Math.Max(Math.Abs(rx.var.vCrossP), Math.Abs(rx.var.vCrossN))))
                {
                    range_dir = 1;
                    delay = 2;
                    bInReading = false;
                    return ACTION_STATE.INIT_FOR_TRACKP;
                }
                */
                if ((rx.iRRange == RNG_P1) || (rx.iRRange == RNG_P01) || (rx.iRRange == RNG_P001))  //P1 ohm, P01 ohm, P001 ohm
                {
                    rx.var.calc_track_nextk(rx.iRRange);
                    return ACTION_STATE.SHOW_NEW_VALUE;
                }
                int newN = rx.var.calc_track_nextk(rx.iRRange) - rx.var.iK;
                if (newN == 0)
                {
                    return ACTION_STATE.SHOW_NEW_VALUE;
                }
                if ((!history_newk.ContainsKey(rx.var.iK)) || (history_newk[rx.var.iK] != newN)) //a different decision
                {
                    history_newk[rx.var.iK] = newN;
                    rx.var.iK += newN;
                    DeviceMgr.Action("turnk", rx.var.iK);
                    return ACTION_STATE.INIT_FOR_TRACKP;
                }
                if (history_newk.ContainsKey(rx.var.iK + newN)) //it has an old decision
                {
                    int oldnewN = history_newk[rx.var.iK + newN];
                    if ((oldnewN + newN) == 0)   //just jump up and down
                    {
                        return ACTION_STATE.SHOW_NEW_VALUE;
                    }
                    rx.var.iK += newN;
                    DeviceMgr.Action("turnk", rx.var.iK);
                    return ACTION_STATE.INIT_FOR_TRACKP;
                }
                return ACTION_STATE.SHOW_NEW_VALUE;
            }
            return ACTION_STATE.IDLE;
        }
示例#13
0
        public void Step()
        {
            if (DeviceMgr.IsInAction()) //communication action is going on
                return;

            if (currRx.i_State == RUN_STATE.STOPPING)   //user choose to stop
            {
                DeviceMgr.Reset();
                act_mgr.Reset();
                bPaused = false;
                bRunning = false;
                currRx.i_State = RUN_STATE.IDLE;
            }
            if (bPaused || !bRunning || act_mgr.IsBusy)
                return;

            Debug.WriteLine("Step:" + stm.ToString());
            if (stm == ACTION_STATE.INIT_FOR_START)//search the next valid channel
            {
                currRx.i_State = RUN_STATE.SEARCHING;
                StatusChanged(this, "search");
                stm = act_mgr.Do(ACTION_REQUEST.INIT_NAV_RANGE,stm);
                return;
            }
            if (stm == ACTION_STATE.INIT_FOR_SEARCH) //prepare the capture with 1:1 mode
            {
                currRx.i_State = RUN_STATE.SEARCHING;
                StatusChanged(this, "search");
                stm = act_mgr.Do(ACTION_REQUEST.INITKI_FOR_SEARCH,stm);
                return;
            }
            if (stm == ACTION_STATE.INIT_FOR_RS_KTTP) //capture once //set to KTTP mode and delay 1s
            {
                currRx.i_State = RUN_STATE.SEARCHING;
                StatusChanged(this, "search");
                stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_RS_KTTP, stm);
                return;
            }
            if (stm == ACTION_STATE.INIT_FOR_RS_KTTN) 
            {
                currRx.i_State = RUN_STATE.SEARCHING;
                StatusChanged(this, "search");

                double val = act_mgr.dStableReading;
                if (val < -999)
                {
                    currRx.i_State = RUN_STATE.STOPPING;
                    StatusChanged(this, "stopping");
                    return;
                } 
                currRx.var.vRs = val;
                stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_RS_KTTN, stm);
                return;
            }
            if (stm == ACTION_STATE.COMPLETE_ISRC) //capture once //set to KTTP mode 
            {
                currRx.i_State = RUN_STATE.SEARCHING;
                StatusChanged(this, "search");
                double val = act_mgr.dStableReading;
                if (val < -999)
                {
                    currRx.i_State = RUN_STATE.STOPPING;
                    StatusChanged(this, "stopping");
                    return;
                }
                currRx.var.vRs = Math.Abs(currRx.var.vRs - val) / 2.0;
                currRx.var.iSrc = currRx.var.vRs / currRx.var.rRs;
                currRx.var.iSrc = currRx.var.iSrc * RX_VAR.INIT_LOOP / (double)currRx.var.iK;
                double stdcurr = RunWnd.syscfg.GetStdCurrent(currRx.iIx,currRx.bSqrt);
                if (currRx.var.iSrc < 0 || (Math.Abs(stdcurr - currRx.var.iSrc) > stdcurr * 0.5))
                {
                    if (retry == 0)
                    {
                        retry++;
                        stm = ACTION_STATE.INIT_FOR_SEARCH;
                        DeviceMgr.SysLog(String.Format("Incorrect current {0} vs std:{1}, bSqrt is {2}, iIx is {3}",
                            currRx.var.iSrc.ToString(), stdcurr.ToString(), currRx.bSqrt.ToString(), currRx.iIx.ToString())); 
                    }
                    else
                    {
                        currRx.i_State = RUN_STATE.STOPPING;
                        StatusChanged(this, "stopping");
                        return;
                    }
                }
                else
                {
                    stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_TRACKP, stm);
                }
                return;
            }
            #region  no use 
            /*
            if (stm == ACTION_STATE.INIT_FOR_RX_KTTP) //capture once //set to KTTP mode 
            {
                currRx.i_State = RUN_STATE.SEARCHING;
                StatusChanged(this, "search");
                double val = act_mgr.dStableReading;
                if (val < -999)
                {
                    currRx.i_State = RUN_STATE.STOPPING;
                    StatusChanged(this, "stopping");
                    return;
                }

                currRx.var.vRs = Math.Abs(currRx.var.vRs - val) / 2.0;
                currRx.var.iSrc = currRx.var.vRs / currRx.var.rRs;
                stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_RX_KTTP, stm);
                return;
            }
            if (stm == ACTION_STATE.INIT_FOR_RX_KTTN)
            {
                currRx.i_State = RUN_STATE.SEARCHING;
                StatusChanged(this, "search");
                double val = act_mgr.dStableReading;
                if (val < -999)
                {
                    currRx.i_State = RUN_STATE.STOPPING;
                    StatusChanged(this, "stopping");
                    return;
                }
                currRx.var.vRx = val;
                stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_RX_KTTN, stm);
                return;
            }
            if (stm == ACTION_STATE.INIT_K_ADJUST) //adjust K
            {
                double val = act_mgr.dStableReading;
                if (val < -999)
                {
                    currRx.i_State = RUN_STATE.STOPPING;
                    StatusChanged(this, "stopping");
                    return;
                }

                currRx.var.vRx = Math.Abs(currRx.var.vRx - val)/ 2;
                currRx.var.rRx = currRx.var.vRx / currRx.var.iSrc;

                currRx.var.iK = currRx.var.calc_capture_nextk();
                DeviceMgr.Action("turnk", Convert.ToUInt32(currRx.var.iK));
                stm = ACTION_STATE.INIT_FOR_TRACKP;
            }
*/
            #endregion
            if (stm == ACTION_STATE.INIT_FOR_TRACKP) //capture once //set to KTTP mode 
            {
                currRx.i_State = RUN_STATE.TRACKING;
                StatusChanged(this, "tracking");
                
                stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_TRACKP, stm);
                return;
            }
            if (stm == ACTION_STATE.INIT_FOR_TRACKN)
            {
                currRx.i_State = RUN_STATE.TRACKING;
                StatusChanged(this, "tracking");
                double val = act_mgr.dStableReading;
                if (val < -999)
                {
                    currRx.i_State = RUN_STATE.STOPPING;
                    StatusChanged(this, "stopping");
                    return;
                }
                currRx.var.vCrossP = val;
                stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_TRACKN, stm);
                return;
            }
            if (stm == ACTION_STATE.UPDATE_K_TRACK)
            {
                currRx.i_State = RUN_STATE.TRACKING;
                StatusChanged(this, "tracking");

                double val = act_mgr.dStableReading;
                if (val < -999)
                {
                    currRx.i_State = RUN_STATE.STOPPING;
                    StatusChanged(this, "stopping");
                    return;
                }
                currRx.var.vCrossN = val;
                               
                stm = act_mgr.Do(ACTION_REQUEST.SET_NEXT_K,stm);
                if (stm == ACTION_STATE.SHOW_NEW_VALUE)
                    currRx.var.log_start(currRx.iRRange);
                return;
            }
            if (stm == ACTION_STATE.SHOW_NEW_VALUE)
            {
                if (data_mgr.AddNewValue(ref currRx.var.rRx))
                {
                     StatusChanged(this, "newvalue");
                }
                if (data_mgr.iMeasCnt == RunWnd.syscfg.iMeasTimes)
                    stm = ACTION_STATE.COMPLETE;
                else
                    stm = ACTION_STATE.INIT_FOR_TRACKP;
                return;
            }
          
            if (stm == ACTION_STATE.COMPLETE) //update the display and try the next channel
            {
                currRx.i_State = RUN_STATE.IDLE;
                bRunning = false;
                StatusChanged(this, "complete");
                act_mgr.Do(ACTION_REQUEST.INIT_NAV_RANGE,stm);
                DeviceMgr.Reset();
                while (DeviceMgr.IsInAction())
                    ;
                stm = ACTION_STATE.IDLE;
            }
        }
示例#14
0
    /**
    // 並列でステータスが変更されると動きが変になるので補正する。
    */
    void changeStatus(ACTION_STATE statusName)
    {
        // statusName ←へ 変更しようとしている
        // characterStatus 現在のステータス

        Debug.Log("  characterStatus" + characterStatus + "  statusName:" + statusName  );

        if (statusName == ACTION_STATE.CHARACTER_ATTACKED) {
            if (isAcceptDamage == true){
                return;
            }
        }

        if(characterStatus == ACTION_STATE.CHARACTER_ATTACKED){
            if( statusName != ACTION_STATE.CHARACTER_ATTACKED_2 && statusName != ACTION_STATE.CHARACTER_DEAD){
                return;
            }
            if (isAcceptDamage == false){
                isAcceptDamage = true;
                StartCoroutine(damageState());
            }
        }
        else if( characterStatus == ACTION_STATE.CHARACTER_ATTACKED_2){
            if( statusName != ACTION_STATE.CHARACTER_ATTACKED_3){
                return;
            }
        }
        else if( characterStatus == ACTION_STATE.CHARACTER_ATTACKED_3){
            if( statusName != ACTION_STATE.CHARACTER_MOVE_START){
                return;
            }
        }
        else if( characterStatus == ACTION_STATE.CHARACTER_DEAD){
            if( statusName != ACTION_STATE.CHARACTER_DEAD_2){
                return;
            }
        }
        else if( characterStatus == ACTION_STATE.CHARACTER_DEAD_2){
            return;
        }

        // ステータスを変更する。
        characterStatus = statusName;
    }
示例#15
0
    private void ChangeActionState()
    {
        IsKeysClicked(KeyCode.A);

        ACTION_STATE lastActionState = m_ActionState;

        if (m_ActionState == ACTION_STATE.MOVE_DOUBLE)
        {
            if (Time.time > m_DoubleMoveCmd.timeStamp + m_DoubleMoveCmd.durationTime)
            {
                m_ActionState = ACTION_STATE.IDLE;
                m_LockHView   = false;
                m_KeyRecordList.Clear();                 // 清空 KeyRecords
                return;
            }
            else
            {
                return;
            }
        }

        if (m_KeyRecordList.Count > 0)
        {
            if (IsKeysClicked(KeyCode.A, KeyCode.W))
            {
                Debug.Log("A-W: BOOM");
            }

            if (lastActionState != ACTION_STATE.MOVE_DOUBLE)
            {
                if (IsKeysClicked(KeyCode.A, KeyCode.A))
                {
                    m_ActionState             = ACTION_STATE.MOVE_DOUBLE;
                    m_DoubleMoveCmd.timeStamp = Time.time;
                    m_DoubleMoveCmd.moveSpeed = -transform.right * m_DoubleMoveSpeed;
                    m_LockHView = true;
                }
                else if (IsKeysClicked(KeyCode.S, KeyCode.S))
                {
                    m_ActionState             = ACTION_STATE.MOVE_DOUBLE;
                    m_DoubleMoveCmd.timeStamp = Time.time;
                    m_DoubleMoveCmd.moveSpeed = -transform.forward * m_DoubleMoveSpeed;
                    m_LockHView = true;
                }
                else if (IsKeysClicked(KeyCode.D, KeyCode.D))
                {
                    m_ActionState             = ACTION_STATE.MOVE_DOUBLE;
                    m_DoubleMoveCmd.timeStamp = Time.time;
                    m_DoubleMoveCmd.moveSpeed = transform.right * m_DoubleMoveSpeed;
                    m_LockHView = true;
                }
                else if (IsKeysClicked(KeyCode.W, KeyCode.W))
                {
                    m_ActionState             = ACTION_STATE.MOVE_DOUBLE;
                    m_DoubleMoveCmd.timeStamp = Time.time;
                    m_DoubleMoveCmd.moveSpeed = transform.forward * m_DoubleMoveSpeed;
                    m_LockHView = true;
                }
                else
                {
                    // 最后处理移动
                    CalcMoveCommond();
                }
            }
        }
    }
示例#16
0
 /*
  * Called when the action process ends with errors
  * When an action ends with errors the agent dont look for the next action connected with this
  * The actions path is recalculed from the start action node
  */
 public virtual void ActionBreak()
 {
     _state = ACTION_STATE.A_COMPLETE;
 }
示例#17
0
        private ACTION_STATE InitKI(ACTION_STATE stm)
        {
            RxInfo currRx = rx;
            SetDelays();
            currRx.var.iSrc = RunWnd.syscfg.GetCurrent(currRx.iIx,currRx.bSqrt); //0.1mA
            currRx.var.rRx = currRx.dRxInput;
            currRx.var.iK = RX_VAR.INIT_LOOP;
            currRx.var.iK = currRx.var.calc_capture_nextk();

            if (currRx.iRRange == RNG_P1) //P1 ohm
                currRx.var.iK = 100; //10:1
            if (currRx.iRRange == RNG_P01) //P01 ohm
                currRx.var.iK = 10;  //100:1
            if (currRx.iRRange == RNG_P001) //P001 ohm
                currRx.var.iK = 1;   //1000:1
            
            DeviceMgr.Action("turnk", Convert.ToUInt32(currRx.var.iK));
            if ((currRx.iRRange == RNG_P1) || (currRx.iRRange == RNG_P01) || (currRx.iRRange == RNG_P001))
                return ACTION_STATE.INIT_FOR_RS_KTTP;
            else
                return ACTION_STATE.INIT_FOR_TRACKP;
        }
示例#18
0
        public ACTION_STATE Do(ACTION_REQUEST action, ACTION_STATE stm)
        {
            laststm = stm;
            if (action == ACTION_REQUEST.INIT_NAV_RANGE)
            {
                return(InitNavRange(stm));
            }
            if (action == ACTION_REQUEST.INITKI_FOR_SEARCH)
            {
                delay = 2;
                return(InitKI(stm));
            }

            if (action == ACTION_REQUEST.SET_FOR_RS_KTTP)
            {
                DeviceMgr.Action("MEAS_RS|KTTP|" + DeviceMgr.ComposeAction(rx), 0);
                range_dir  = 1;
                delay      = delayKI;
                bInReading = true;
                return(ACTION_STATE.INIT_FOR_RS_KTTN);
            }
            if (action == ACTION_REQUEST.SET_FOR_RS_KTTN)
            {
                DeviceMgr.Action("MEAS_RS|KTTN|" + DeviceMgr.ComposeAction(rx), 0);
                range_dir  = 1;
                delay      = delayKTT;
                bInReading = true;

                return(ACTION_STATE.COMPLETE_ISRC);
            }

            /*
             * if (action == ACTION_REQUEST.SET_FOR_RX_KTTP)
             * {
             *  DeviceMgr.Action("MEAS_RX|KTTP|" + DeviceMgr.ComposeAction(rx), 0);
             *  range_dir = 1;
             *  delay = delayKI;
             *  bInReading = true;
             *  return ACTION_STATE.INIT_FOR_RX_KTTN;
             * }
             * if (action == ACTION_REQUEST.SET_FOR_RX_KTTN)
             * {
             *  DeviceMgr.Action("MEAS_RX|KTTN|" + DeviceMgr.ComposeAction(rx), 0);
             *  range_dir = 1;
             *  delay = delayKTT;
             *  bInReading = true;
             *  return ACTION_STATE.INIT_FOR_TRACKP;
             * }
             */
            if (action == ACTION_REQUEST.SET_FOR_TRACKP)
            {
                DeviceMgr.Action("MEAS_DELTA|KTTP|" + DeviceMgr.ComposeAction(rx), 0);
                delay      = RunWnd.syscfg.iKTT; //adjust delay
                range_dir  = 1;
                bInReading = true;
                return(ACTION_STATE.INIT_FOR_TRACKN);
            }
            if (action == ACTION_REQUEST.SET_FOR_TRACKN)
            {
                if (RangeAdjustDown(Math.Abs(rx.var.vCrossP)))
                {
                    range_dir  = 1;
                    delay      = 2;
                    bInReading = false;
                    return(ACTION_STATE.INIT_FOR_TRACKP);
                }

                DeviceMgr.Action("MEAS_DELTA|KTTN|" + DeviceMgr.ComposeAction(rx), 0);
                delay      = RunWnd.syscfg.iKTT; //adjust delay
                range_dir  = 1;
                bInReading = true;
                return(ACTION_STATE.UPDATE_K_TRACK);
            }
            if (action == ACTION_REQUEST.SET_NEXT_K)
            {
                /*
                 * if (RangeAdjustDown(Math.Max(Math.Abs(rx.var.vCrossP), Math.Abs(rx.var.vCrossN))))
                 * {
                 *  range_dir = 1;
                 *  delay = 2;
                 *  bInReading = false;
                 *  return ACTION_STATE.INIT_FOR_TRACKP;
                 * }
                 */
                if ((rx.iRRange == RNG_P1) || (rx.iRRange == RNG_P01) || (rx.iRRange == RNG_P001))  //P1 ohm, P01 ohm, P001 ohm
                {
                    rx.var.calc_track_nextk(rx.iRRange);
                    return(ACTION_STATE.SHOW_NEW_VALUE);
                }
                int newN = rx.var.calc_track_nextk(rx.iRRange) - rx.var.iK;
                if (newN == 0)
                {
                    return(ACTION_STATE.SHOW_NEW_VALUE);
                }
                if ((!history_newk.ContainsKey(rx.var.iK)) || (history_newk[rx.var.iK] != newN)) //a different decision
                {
                    history_newk[rx.var.iK] = newN;
                    rx.var.iK += newN;
                    DeviceMgr.Action("turnk", rx.var.iK);
                    return(ACTION_STATE.INIT_FOR_TRACKP);
                }
                if (history_newk.ContainsKey(rx.var.iK + newN)) //it has an old decision
                {
                    int oldnewN = history_newk[rx.var.iK + newN];
                    if ((oldnewN + newN) == 0)   //just jump up and down
                    {
                        return(ACTION_STATE.SHOW_NEW_VALUE);
                    }
                    rx.var.iK += newN;
                    DeviceMgr.Action("turnk", rx.var.iK);
                    return(ACTION_STATE.INIT_FOR_TRACKP);
                }
                return(ACTION_STATE.SHOW_NEW_VALUE);
            }
            return(ACTION_STATE.IDLE);
        }
示例#19
0
    // Update is called once per frame
    void Update()
    {
        //if(GameObject.FindGameObjectsWithTag("ship")!=null){
        if(bow!=null){

            // bow の向き
            if (Input.GetMouseButtonDown(0)){ //マウスクリック
                startPoint = Input.mousePosition;
                bowStartPoint = bow.transform.position;
            }
            else if (Input.GetMouseButton(0))  // マウスドラッグ
            {

                currentPoint = Input.mousePosition;

                Vector3 tmp = bow.transform.position;
                tmp.x = bowStartPoint.x + (currentPoint.x - startPoint.x)/MOVE_RATE;

                if( tmp.x < -38.0F ){
                    tmp.x = -38.0F;
                }else if( tmp.x > 36.65F ){
                    tmp.x = 36.65F;
                }

                bow.transform.position = tmp;

                int diff = 0;
                Camera mainCamera = Camera.mainCamera;
                Vector3 pos = mainCamera.transform.position;
                if( pos.x < bow.transform.position.x - diff ){
                    pos.x = bow.transform.position.x - diff;
                }else if( pos.x > bow.transform.position.x + diff ){
                    pos.x = bow.transform.position.x + diff;
                }
                mainCamera.transform.position = pos;

            }
            else if (Input.GetMouseButtonUp(0)) //マウスボタン離した
            {

            }

            //if(Input.GetKey(KeyCode.Space)){

                if(playerAlive){
                    if(canShoot){

                        canShoot = false;
                        shootTime = 0;

                        ball = (GameObject)Instantiate(ballPrefab,transform.position,transform.rotation);

                 		Vector3 ballVelocity_1 = new Vector3( 0 , 0 , BALL_SPEED );
                        ballController ballConScript = ((ballController)ball.GetComponent("ballController"));
                        ballConScript.ballVelocity = ballVelocity_1;

                        Vector3 ballPosition = bow.transform.position;
                        ballConScript.ballPosition = ballPosition;

                    }
                }
            //}

            if(!canShoot){
                shootTime += Time.deltaTime;
                float nextShootTime = 1.0F;
                if(powerup){
                    nextShootTime = 0.5F;
                }
                if(shootTime > nextShootTime){
                    canShoot = true;
                    //shootTime = 0;
                }
            }

        }

        // alian ミサイル
        int tmpRange;
        GameObject[] allAlianObj = GameObject.FindGameObjectsWithTag("alian");
        int alianCount = allAlianObj.Length;
        if(alianCount > 40 ){
            tmpRange = 100;
        }else if(alianCount > 30 ){
            tmpRange = 80;
        }else if(alianCount > 20 ){
            tmpRange = 70;
        }else if(alianCount > 15 ){
            tmpRange = 60;
        }else if(alianCount > 10 ){
            tmpRange = 50;
        }else if(alianCount > 8 ){
            tmpRange = 50;
        }else if(alianCount > 5 ){
            tmpRange = 40;
        }else if(alianCount > 2 ){
            tmpRange = 30;
        }else if(alianCount > 1 ){
            tmpRange = 20;
        }else{
            tmpRange = 20;
        }

        if(Random.Range(0,tmpRange) < 2+StageNumber*0.5 ){

            int alianLength = allAlianObj.Length;
            if(alianLength > 0){
            //if(false){
                int rnd = Random.Range(0, allAlianObj.Length);
                Vector3 misPos = allAlianObj[rnd].transform.position;
                GameObject missilePrefab = (GameObject)Resources.Load("missilePrefab");
                Quaternion tmpQu = Quaternion.AngleAxis(90,Vector3.left);
                GameObject missile = (GameObject)Instantiate(missilePrefab,misPos, tmpQu);
                //GameObject missile = (GameObject)Instantiate( missilePrefab , new Vector3(0,0,10) , missilePrefab.rigidbody.rotation);
                missile.rigidbody.velocity = new Vector3(0,0,-20);
            }
        }

        // 敵が陣地まで到達したら Player死ぬ。ミサイルをわざとあてて死ぬようにする。
        foreach(GameObject tmp in allAlianObj){
            float alianPositionZ = tmp.transform.position.z;
            if(alianPositionZ < -14.0){
                GameObject missilePrefab = (GameObject)Resources.Load("missilePrefab");
                Quaternion tmpQu = Quaternion.AngleAxis(90,Vector3.left);
                GameObject missile = (GameObject)Instantiate(missilePrefab,bow.transform.position, tmpQu);
            }
        }

        // 敵を全部倒したら ステージシーンに戻る
        if(actionState == ACTION_STATE.STATE_START){
            if(alianCount<1){
                timer = 0;
                actionState = ACTION_STATE.STATE_END;
            }
        }else if(actionState == ACTION_STATE.STATE_END){
            timer += Time.deltaTime;
            if(timer>3.0F){
                actionState = ACTION_STATE.STATE_END2;
            }

        }else if(actionState == ACTION_STATE.STATE_END2){
            StageNumber++;
            Debug.Log("StageNumber"+ StageNumber);
            PlayerPrefs.SetInt("StageNumber", StageNumber);

            int MaxStageNumber = PlayerPrefs.GetInt("MaxStageNumber");
            if( StageNumber > MaxStageNumber ){
                MaxStageNumber = StageNumber;
                PlayerPrefs.SetInt("MaxStageNumber", MaxStageNumber );
            }

            Application.LoadLevel("stage");

        }
    }
示例#20
0
    // Use this for initialization
    void Start()
    {
        actionState = ACTION_STATE.STATE_START;

        alianSpeed = 1;

        GameObject cntObj = (GameObject)Resources.Load("cntObj");
        Instantiate( cntObj , cntObj.transform.position , cntObj.transform.rotation );

        //GameObject PointObj = GameObject.FindWithTag("point");
        //PointObj.transform.position = new Vector3( 0.9F , 0.1F , 0.0F );
        //PointObj.transform.position = new Vector3( -1.0F , 0.1F , 0.0F );

        ballPrefab = (GameObject)Resources.Load("ballPrefab");
        ballPrefab.AddComponent<Rigidbody>();
        ballPrefab.rigidbody.useGravity = false;

        alianPrefab = (GameObject)Resources.Load("alien_01_mobile");
        alianPrefab.AddComponent<Rigidbody>();
        alianPrefab.rigidbody.useGravity = false;

        alian = new GameObject[20,20];

        for(int x=1;x<12;x++){ //12
            for(int z=0;z<5;z++){ //5
                string alianObjName;

                if( z == 1){
                    alianObjName = "alien_04_mobile";
                }else if( z == 2 ){
                    alianObjName = "alien_01_mobile";
                }else if( z == 3 ){
                    alianObjName = "alien_02_mobile";
                }else{
                    alianObjName = "alien_03_mobile";
                }

                /*
                if(StageNumber<4){
                    alianObjName = "alien_01_mobile";
                }else if(StageNumber<7){
                    alianObjName = "alien_02_mobile";
                }else if(StageNumber<13){
                    alianObjName = "alien_03_mobile";
                }else if(StageNumber<20){
                    alianObjName = "alien_04_mobile";
                }else{
                    alianObjName = "alien_04_mobile";
                }
                */

                alianPrefab = (GameObject)Resources.Load(alianObjName);

                Vector3 tmpVec = new Vector3( (float)(x-5)*4 , (float)2.0F , (float)z*4+10 );
                Quaternion tmpQu = Quaternion.AngleAxis(180,Vector3.up);
                alian[x,z] = (GameObject)Instantiate(alianPrefab,tmpVec,tmpQu);

                alianController alianScript = (alianController)alian[x,z].GetComponent("alianController");

            }
        }
        alianSpeedChange("");

        // block(防御壁作成)
        GameObject blockPrefab = (GameObject)Resources.Load("blockPrefab");
        for(int c=0;c<4;c++){
            for(int i=0;i<12;i++){ // 12
                for(int j=0;j<5;j++){ // 5
                    float blockX = (float)(-24+(float)i*0.5 ) + c * 14 ;
                    float blockZ = (float)(-12+(float)j*0.5 );
                    Vector3 blockPos = new Vector3( blockX , 2.0F , blockZ );
                    Instantiate(blockPrefab,blockPos,transform.rotation);
                }
            }
        }

        waitingTime = 500;
        canShoot = true;
    }
示例#21
0
        public void Step()
        {
            if (DeviceMgr.IsInAction()) //communication action is going on
            {
                return;
            }

            if (currRx.i_State == RUN_STATE.STOPPING)   //user choose to stop
            {
                DeviceMgr.Reset();
                act_mgr.Reset();
                bPaused        = false;
                bRunning       = false;
                currRx.i_State = RUN_STATE.IDLE;
            }
            if (bPaused || !bRunning || act_mgr.IsBusy)
            {
                return;
            }


            if (stm == ACTION_STATE.INIT_FOR_START)//search the next valid channel
            {
                currRx.i_State = RUN_STATE.SEARCHING;
                StatusChanged(this, "search");
                stm = act_mgr.Do(ACTION_REQUEST.INIT_NAV_RANGE, stm);
                return;
            }
            if (stm == ACTION_STATE.INIT_FOR_SEARCH) //prepare the capture with 1:1 mode
            {
                currRx.i_State = RUN_STATE.SEARCHING;
                StatusChanged(this, "search");
                stm = act_mgr.Do(ACTION_REQUEST.INITKI_FOR_SEARCH, stm);
                return;
            }
            if (stm == ACTION_STATE.INIT_FOR_RS_KTTP) //capture once //set to KTTP mode and delay 1s
            {
                currRx.i_State = RUN_STATE.SEARCHING;
                StatusChanged(this, "search");
                stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_RS_KTTP, stm);
                return;
            }
            if (stm == ACTION_STATE.INIT_FOR_RS_KTTN)
            {
                currRx.i_State = RUN_STATE.SEARCHING;
                StatusChanged(this, "search");

                double val = act_mgr.dStableReading;
                if (val < -999)
                {
                    currRx.i_State = RUN_STATE.STOPPING;
                    StatusChanged(this, "stopping");
                    return;
                }
                currRx.var.vRs = val;
                stm            = act_mgr.Do(ACTION_REQUEST.SET_FOR_RS_KTTN, stm);
                return;
            }
            if (stm == ACTION_STATE.COMPLETE_ISRC) //capture once //set to KTTP mode
            {
                currRx.i_State = RUN_STATE.SEARCHING;
                StatusChanged(this, "search");
                double val = act_mgr.dStableReading;
                if (val < -999)
                {
                    currRx.i_State = RUN_STATE.STOPPING;
                    StatusChanged(this, "stopping");
                    return;
                }
                currRx.var.vRs  = Math.Abs(currRx.var.vRs - val) / 2.0;
                currRx.var.iSrc = currRx.var.vRs / currRx.var.rRs;
                currRx.var.iSrc = currRx.var.iSrc * RX_VAR.INIT_LOOP / (double)currRx.var.iK;
                double stdcurr = RunWnd.syscfg.GetStdCurrent(currRx.iIx, currRx.bSqrt);
                if (currRx.var.iSrc < 0 || (Math.Abs(stdcurr - currRx.var.iSrc) > stdcurr * 0.5))
                {
                    if (retry == 0)
                    {
                        retry++;
                        stm = ACTION_STATE.INIT_FOR_SEARCH;
                        DeviceMgr.SysLog(String.Format("Incorrect current {0} vs std:{1}, bSqrt is {2}, iIx is {3}",
                                                       currRx.var.iSrc.ToString(), stdcurr.ToString(), currRx.bSqrt.ToString(), currRx.iIx.ToString()));
                    }
                    else
                    {
                        currRx.i_State = RUN_STATE.STOPPING;
                        StatusChanged(this, "stopping");
                        return;
                    }
                }
                else
                {
                    stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_TRACKP, stm);
                }
                return;
            }
            #region  no use

            /*
             * if (stm == ACTION_STATE.INIT_FOR_RX_KTTP) //capture once //set to KTTP mode
             * {
             *  currRx.i_State = RUN_STATE.SEARCHING;
             *  StatusChanged(this, "search");
             *  double val = act_mgr.dStableReading;
             *  if (val < -999)
             *  {
             *      currRx.i_State = RUN_STATE.STOPPING;
             *      StatusChanged(this, "stopping");
             *      return;
             *  }
             *
             *  currRx.var.vRs = Math.Abs(currRx.var.vRs - val) / 2.0;
             *  currRx.var.iSrc = currRx.var.vRs / currRx.var.rRs;
             *  stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_RX_KTTP, stm);
             *  return;
             * }
             * if (stm == ACTION_STATE.INIT_FOR_RX_KTTN)
             * {
             *  currRx.i_State = RUN_STATE.SEARCHING;
             *  StatusChanged(this, "search");
             *  double val = act_mgr.dStableReading;
             *  if (val < -999)
             *  {
             *      currRx.i_State = RUN_STATE.STOPPING;
             *      StatusChanged(this, "stopping");
             *      return;
             *  }
             *  currRx.var.vRx = val;
             *  stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_RX_KTTN, stm);
             *  return;
             * }
             * if (stm == ACTION_STATE.INIT_K_ADJUST) //adjust K
             * {
             *  double val = act_mgr.dStableReading;
             *  if (val < -999)
             *  {
             *      currRx.i_State = RUN_STATE.STOPPING;
             *      StatusChanged(this, "stopping");
             *      return;
             *  }
             *
             *  currRx.var.vRx = Math.Abs(currRx.var.vRx - val)/ 2;
             *  currRx.var.rRx = currRx.var.vRx / currRx.var.iSrc;
             *
             *  currRx.var.iK = currRx.var.calc_capture_nextk();
             *  DeviceMgr.Action("turnk", Convert.ToUInt32(currRx.var.iK));
             *  stm = ACTION_STATE.INIT_FOR_TRACKP;
             * }
             */
            #endregion
            if (stm == ACTION_STATE.INIT_FOR_TRACKP) //capture once //set to KTTP mode
            {
                currRx.i_State = RUN_STATE.TRACKING;
                StatusChanged(this, "tracking");

                stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_TRACKP, stm);
                return;
            }
            if (stm == ACTION_STATE.INIT_FOR_TRACKN)
            {
                currRx.i_State = RUN_STATE.TRACKING;
                StatusChanged(this, "tracking");
                double val = act_mgr.dStableReading;
                if (val < -999)
                {
                    currRx.i_State = RUN_STATE.STOPPING;
                    StatusChanged(this, "stopping");
                    return;
                }
                currRx.var.vCrossP = val;
                stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_TRACKN, stm);
                return;
            }
            if (stm == ACTION_STATE.UPDATE_K_TRACK)
            {
                currRx.i_State = RUN_STATE.TRACKING;
                StatusChanged(this, "tracking");

                double val = act_mgr.dStableReading;
                if (val < -999)
                {
                    currRx.i_State = RUN_STATE.STOPPING;
                    StatusChanged(this, "stopping");
                    return;
                }
                currRx.var.vCrossN = val;

                stm = act_mgr.Do(ACTION_REQUEST.SET_NEXT_K, stm);
                if (stm == ACTION_STATE.SHOW_NEW_VALUE)
                {
                    currRx.var.log_start(currRx.iRRange);
                }
                return;
            }
            if (stm == ACTION_STATE.SHOW_NEW_VALUE)
            {
                if (data_mgr.AddNewValue(ref currRx.var.rRx))
                {
                    StatusChanged(this, "newvalue");
                }
                if (data_mgr.iMeasCnt == RunWnd.syscfg.iMeasTimes)
                {
                    stm = ACTION_STATE.COMPLETE;
                }
                else
                {
                    stm = ACTION_STATE.INIT_FOR_TRACKP;
                }
                return;
            }

            if (stm == ACTION_STATE.COMPLETE) //update the display and try the next channel
            {
                currRx.i_State = RUN_STATE.IDLE;
                bRunning       = false;
                StatusChanged(this, "complete");
                act_mgr.Do(ACTION_REQUEST.INIT_NAV_RANGE, stm);
                DeviceMgr.Reset();
                while (DeviceMgr.IsInAction())
                {
                    ;
                }
                stm = ACTION_STATE.IDLE;
            }
        }
示例#22
0
 protected override void Init()
 {
     m_state = ACTION_STATE.STATE_ONE;
     CreatSlate();
 }