private void UpdatePos( UnitSensorSystem _sensorSys )
 {
     Dictionary<string,NamedObjectPair>.Enumerator eInMinimap = m_MiniMapUnits.GetEnumerator() ;
     while( eInMinimap.MoveNext() )
     {
         // string unitName = eInMinimap.Current.Key ;
         GameObject unitObject = eInMinimap.Current.Value.UnitObj.GetObj() ;
         GameObject minimapObject = eInMinimap.Current.Value.MiniMapObj.GetObj() ;
         if( null != unitObject &&
             null != minimapObject )
         {
             minimapObject.transform.position = new Vector3(
                 unitObject.transform.position.x ,
                 minimapObject.transform.position.y ,
                 unitObject.transform.position.z
                  ) ;
         }
     }
 }
    private void CheckMinimapSize( UnitSensorSystem _sensorSys )
    {
        float minimapCameraViewportSize = _sensorSys.m_SensorDistance ;

        // 超過就露餡了
        if( minimapCameraViewportSize > 200 )
            minimapCameraViewportSize = 200 ;
        else if( minimapCameraViewportSize < 1 )
            minimapCameraViewportSize = 1 ;

        GameObject miniMapCameraObj = GlobalSingleton.GetMiniMapCameraObj() ;
        if( null == miniMapCameraObj )
        {
            return ;
        }
        miniMapCameraObj.camera.orthographicSize = minimapCameraViewportSize ;
    }
    private void UpdateMiniMap( UnitSensorSystem _sensorSys )
    {
        CheckMinimapSize( _sensorSys ) ;

        CheckForRemove( _sensorSys ) ;

        RemoveUnitInMinimap() ;

        CheckForAdd( _sensorSys ) ;

        UpdatePos( _sensorSys ) ;
    }
 private void CheckForRemove( UnitSensorSystem _sensorSys )
 {
     // 先檢查有沒有已經消失需要移除的船隻
     Dictionary<string, NamedObjectPair>.Enumerator eInMinimap = m_MiniMapUnits.GetEnumerator() ;
     m_RemoveList.Clear() ;
     while( eInMinimap.MoveNext() )
     {
         string unitInMinimapName = eInMinimap.Current.Key ;
         bool found = false ;
         foreach( NamedObject eUnitInSensor in _sensorSys.m_SensorUnitList )
         {
             if( eUnitInSensor.Name == unitInMinimapName )
             {
                 found = true ;
                 break ;
             }
         }
         if( found == false )
         {
             // the unit should be remove from mini map
             m_RemoveList.Add( unitInMinimapName ) ;
         }
     }
 }
    private List<string> m_RemoveList = new List<string>() ; // 準備移除的清單

    #endregion Fields

    #region Methods

    private void CheckForAdd( UnitSensorSystem _sensorSys )
    {
        // check for add
        // 檢查新增.
        foreach( NamedObject eUnitInSensor in _sensorSys.m_SensorUnitList )
        {
            bool found = false ;
            string unitNameInSensor = eUnitInSensor.Name ;
            Dictionary<string, NamedObjectPair>.Enumerator eInMinimap = m_MiniMapUnits.GetEnumerator() ;
            while( eInMinimap.MoveNext() )
            {
                string unitNameInMiniMap = eInMinimap.Current.Key ;
                if( unitNameInSensor == unitNameInMiniMap )
                {
                    found = true ;
                    break ;// break while
                }
            }

            if( false == found )
            {
                GameObject anewObj = CreateAMiniMapObj( eUnitInSensor.Obj ) ;
                if( null != anewObj )
                {
                    // Debug.Log( "anewObj = CreateAMiniMapObj" ) ;
                    m_MiniMapUnits.Add( unitNameInSensor ,
                        new NamedObjectPair(
                        eUnitInSensor ,
                        new NamedObject( anewObj ) ) );
                }
            }
        }
    }
    private List<NamedObject> RetrievePossibleUnitInOrder( UnitSensorSystem _SensorSys )
    {
        List<NamedObject> allEnemyUnits = new List<NamedObject>() ;
        List<NamedObject> ret = new List<NamedObject>() ;

        // 剔除友軍
        foreach( NamedObject unit in _SensorSys.m_SensorUnitList )
        {
            if( -1 != unit.Name.IndexOf( "Enemy_" ) )
            {
                allEnemyUnits.Add( unit ) ;
            }
        }

        while( allEnemyUnits.Count > 0 )
        {
            float maxRange = -1 ;
            NamedObject maxRangeUnit = null ;

            foreach( NamedObject unit in allEnemyUnits )
            {
                Vector3 toUnit = unit.Obj.transform.position - this.gameObject.transform.position ;
                if( toUnit.magnitude > maxRange )
                {
                    maxRange = toUnit.magnitude ;
                    maxRangeUnit = unit ;
                }
            }

            if( null == maxRangeUnit )// error
                break ;

            ret.Add( maxRangeUnit ) ;
            allEnemyUnits.Remove( maxRangeUnit ) ;

        }

        return ret ;
    }
    /*
     * @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 ) ;
        }
    }
    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 ;
    }