/* * @brief 自動選擇最近的單位 * * 向感測系統取得最近的單位 * 通知選擇系統點選 */ private void TrySelectClosestUnit( UnitSensorSystem _Sensor , UnitSelectionSystem _Select ) { if( null == _Sensor || null == _Select ) return ; GameObject closest = _Sensor.GetClosestObj() ; if( null != closest ) { _Select.ClickOnUnit( closest.name ) ; } }
// retrieve selection information from selection system. private bool RetrieveSelectionInfo( UnitSelectionSystem _SelectSys , out SelectInformation _SelectionInfo ) { _SelectionInfo = _SelectSys.GetPrimarySelectInfo() ; if( null == _SelectionInfo || false == _SelectionInfo.isValid ) return false ; return true ; }
private bool TryFireWeaponInMultiAttackMode( UnitData _unitData , UnitSensorSystem _sensorSys , UnitWeaponSystem _weaponSys , UnitSelectionSystem _selectSys , ref Dictionary<string , SelectInformation > _fireList ) { bool ret = false ; // 取得最大可能的瞄準框 int maxSelectionNum = _selectSys.m_MaxSelectionNum ; int selectionIndexNow = 0 ; string [] selectionKeyArray = new string[ _selectSys.m_Selections.Count ] ; _selectSys.m_Selections.Keys.CopyTo( selectionKeyArray , 0 ) ; // 取得最大的武器清單,並依照距離來排序 List<string> possibleWeaponList = RetrievePossibleWeaponListInOrder( _unitData , _weaponSys ) ; // 取得所有的可能敵人,並依照距離來排序 List<NamedObject> possibleUnits = RetrievePossibleUnitInOrder( _sensorSys ); // 目標是讓所有的武器都分別對上不同的敵人.然後設定好所有的瞄準框.最後全部開火. foreach( NamedObject possibleUnit in possibleUnits ) { // Debug.Log( "possibleUnit=" + possibleUnit.Name ) ; // 假如瞄準框已經用盡,離開 if( selectionIndexNow == maxSelectionNum - 1 ) break ; // 每一個單位,找到可以發射的武器,而且最接近中線的武器 string weaponComponentName = FindMostCloestWeaponComponent( _unitData , _weaponSys , possibleUnit , possibleWeaponList , ref _fireList ) ; // Debug.Log( "weaponComponentName=" + weaponComponentName ) ; if( 0 == weaponComponentName.Length ) continue ; // 指定瞄準框的資訊 string key = selectionKeyArray[ selectionIndexNow ] ; _selectSys.m_Selections[ key ].TargetUnitName = possibleUnit.Name ; _selectSys.m_Selections[ key ].TargetUnitObject = possibleUnit.Obj ; // Debug.Log( "_selectSys.m_Selections " + key + " " + possibleUnit.Name ) ; _fireList[ weaponComponentName ] = _selectSys.m_Selections[ key ] ; ++selectionIndexNow ; ret = true ; } // 針對每個瞄準框,發射指定的武器 return ret ; }