コード例 #1
0
    // 檢查武器並移動 , 會檢查是在範圍內 還是不能發射
    protected override bool CheckWeaponAndMoveToTarget( UnitData _unitData , 
													   UnitWeaponSystem _weaponSys ,
													   Vector3 _TargetPosition )
    {
        string weaponInRange = "" ;
        Vector3 vecToTarget = Vector3.zero ;
        Vector3 norVecToTarget = Vector3.zero ;
        float angleOfTarget = 0.0f ;
        float dotOfUp = 0.0f ;
        string IMPLUSE_ENGINE_RATIO = ConstName.UnitDataComponentImpulseEngineRatio ;

        // 剛轉換過來不要檢查武器
        if( m_State.ElapsedFromLast() > 0.5f )
        {
            // check fire phaser weapon is available
            weaponInRange = _weaponSys.FindAbleToShootTargetWeaponComponent( RandomAWeaponKeyword() ,
                                                                  m_TargetNow.Obj ) ;
            // Debug.Log( "weaponInRange=" + weaponInRange) ;
            if( 0 != weaponInRange.Length )
            {
                this.SetState( AI_Fire_State.StopAndFireToTarget ) ;
                return true ;
            }
        }

        // move to target
        if( true == MathmaticFunc.FindTargetRelation( this.gameObject ,
                                                     _TargetPosition ,
                                                     ref vecToTarget ,
                                                     ref norVecToTarget ,
                                                     ref angleOfTarget ,
                                                     ref dotOfUp ) )
        {
            if( true == _unitData.standardParameters.ContainsKey( IMPLUSE_ENGINE_RATIO ) )
            {
                // speed to maximum
                if( vecToTarget.sqrMagnitude > m_MaximumWeaponRange * m_MaximumWeaponRange )
                    _unitData.standardParameters[ IMPLUSE_ENGINE_RATIO ].ToMax() ;
                else
                    _unitData.standardParameters[ IMPLUSE_ENGINE_RATIO ].Clear() ;
            }

            // angular speed
            _unitData.AngularRatioHeadTo( angleOfTarget ,
                                          dotOfUp ,
                                          0.1f ) ;
        }

        return false ;
    }
コード例 #2
0
    protected override void FireWeapon( UnitWeaponSystem _weaponSys ,
							  			NamedObject _TargetUnit )
    {
        if( true == GlobalSingleton.GetGlobalSingletonObj().GetComponent<AutoPlayMachine>().m_Active )
            return ;

        string weaponComponent = "" ;
        string specifiedWeapon = RandomAWeaponKeyword() ;
        // 距離太遠
        string weaponInRange = _weaponSys.FindAbleToShootTargetWeaponComponent( specifiedWeapon , _TargetUnit.Obj ) ;
        // Debug.Log( "weaponInRange=" + weaponInRange ) ;
        if( 0 == weaponInRange.Length )
        {
            // no available weapon
            this.SetState( AI_Fire_State.MoveToTarget ) ;
            return ;
        }

        string weaponReady = _weaponSys.FindAbleToFireWeaponComponent( specifiedWeapon ) ;
        #if DEBUG
        Debug.Log( "FireWeapon() weaponReady=" + weaponReady ) ;
        #endif
        if( 0 == weaponReady.Length )
        {
            // no available weapon
            this.SetState( AI_Fire_State.WaitForReload ) ;
            return ;
        }

        // 檢查正在reload
        weaponComponent = _weaponSys.FindAbleWeaponComponent( specifiedWeapon , _TargetUnit.Obj ) ;
        // Debug.Log( "weaponReady=" + weaponComponent ) ;
        if( 0 == weaponComponent.Length )
        {
            // no available weapon
            this.SetState( AI_Fire_State.WaitForReload ) ;
            return ;
        }

        // Debug.Log( "_weaponSys.ActiveWeapon" ) ;
        // fire
        if( true == _weaponSys.ActiveWeapon( weaponComponent ,
                                            _TargetUnit ,
                                            ConstName.UnitDataComponentUnitIntagraty ) )
        {
            this.SetState( AI_Fire_State.WaitForReload ) ;
        }
    }