Esempio n. 1
0
 protected virtual void OnSetTargetUnit(RTSGameUnit unit)
 {
     if (unit == null)
     {
         return;
     }
     targetGameUnit = unit;
 }
Esempio n. 2
0
    //public static void addSelectionReleaseListener(RTSGameUnit unit)
    //{
    //    if (unit == null)
    //    {
    //        return;
    //    }
    //    UnitsSelected.Add(unit);
    //}

    //public static void removeSelectionReleaseListener(RTSGameUnit unit)
    //{
    //    if (unit == null)
    //    {
    //        return;
    //    }
    //    if (UnitsSelected.Contains(unit))
    //    {
    //        UnitsSelected.Remove(unit);
    //    }
    //}
    //
    //private static void selectionReleaseEventInvoke()
    //{
    //    if (selectionReleaseEvent != null)
    //    {
    //        selectionReleaseEvent.Invoke();
    //    }
    //}
    //
    private void singleSelectionEventInvoke()
    {
        // Debug.Log("singleSelectionEventInvoke");
        if (RTSCameraController.RTSCamera)
        {
            Ray        ray     = RTSCameraController.RTSCamera.ScreenPointToRay(InputManager.ShareInstance.MousePosition);
            RaycastHit hitInfo = new RaycastHit();
            //
            // Debug.DrawLine(ray.origin, ray.origin+1000f*ray.direction, Color.red);
            // Debug.Log("RTSLayerManager.ShareInstance.LayerMaskRayCastMouse0 = "+RTSLayerManager.ShareInstance.LayerMaskRayCastMouse0);
            //
            if (Physics.Raycast(ray.origin, ray.direction, out hitInfo, 2000f, RTSLayerManager.ShareInstance.LayerMaskRayCastMouse0, QueryTriggerInteraction.Ignore))
            {
                GameObject hitObj = hitInfo.collider.gameObject;
                // Debug.Log("hit");
                // Debug.DrawLine(ray.origin, hitInfo.point, Color.red);
                //if (hitObj.layer == RTSLayerManager.ShareInstance.LayerNumberUI) {
                //    Debug.LogError("hit UI");
                //    return;
                //}else {
                //
                //Debug.LogError("hit => " + hitObj.name);
                //
                //selectionRelease();
                // RTSGameUnit gameUnit = hitObj.GetComponent<RTSGameUnit>();
                RTSGameUnit gameUnit = (RTSGameUnit)hitObj.GetComponent("RTSGameUnit");
                //
                //
                if (gameUnit)
                {
                    if (gameUnit.IsAllowSingleSelection)
                    {
                        gameUnit.IsSelected = true;
                        singleSelectedUnit  = gameUnit;
                        //lock (UnitsSelected)
                        //{
                        //    UnitsSelected.Add(gameUnit);
                        //}
                    }
                }
                // if (hitObj.layer == RTSLayerManager.ShareInstance.LayerNumberPlayerGameUnit)
                // {
                //     //Debug.LogError("hit ground");
                // }
                // else if (hitObj.layer == RTSLayerManager.ShareInstance.LayerNumberEnemyGameUnit)
                // {
                // }else if (hitObj.layer == RTSLayerManager.ShareInstance.LayerNumberFriendlyGameUnit) {
                // }
                //}
            }
        }
    }
Esempio n. 3
0
    private void setTeam(KeyCode key)
    {
        Debug.Log("setting team");
        List <RTSGameUnit> sl = RTSGameUnitManager.ShareInstance.SelectedUnits;

        if (sl == null || sl.Count <= 0)
        {
            return;
        }
        RTSGameUnit[] copy = new RTSGameUnit[sl.Count];
        sl.CopyTo(copy);
        TeamDict[key] = copy;
    }
Esempio n. 4
0
 //private float rayCastingWaitTime = 0.05f;
 //
 private IEnumerator buildingLocating()
 {
     //
     while (rayCastingLocatingStarted && RTSCameraController.RTSCamera && buildingTempUnit != null)
     {
         Ray        ray     = RTSCameraController.RTSCamera.ScreenPointToRay(InputManager.ShareInstance.MousePosition);
         RaycastHit hitInfo = new RaycastHit();
         //
         if (Physics.Raycast(ray.origin, ray.direction, out hitInfo, 1000f, RTSLayerManager.ShareInstance.LayerMaskRayCastMouse1, QueryTriggerInteraction.Ignore))
         {
             //
             GameObject hitObj = hitInfo.collider.gameObject;
             //
             if (hitObj != null)
             {
                 //
                 //Debug.LogError("hit obj");
                 //
                 if (hitObj.layer == RTSLayerManager.ShareInstance.LayerNumberEnvironmentGround)
                 {
                     //Debug.LogError("hit Ground");
                     //
                     buildingTempUnit.transform.position = hitInfo.point;
                     //
                 }
                 else if (hitObj.layer == RTSLayerManager.ShareInstance.LayerNumberEnemyGameUnit)
                 {
                     //Debug.LogError("hit EnemyGameUnit");
                     //
                     RTSGameUnit gameUnit = (RTSGameUnit)hitObj.GetComponent("RTSGameUnit");
                     //
                     if (gameUnit)
                     {
                         //
                     }
                 }
                 else if (hitObj.layer == RTSLayerManager.ShareInstance.LayerNumberEnvironmentObstacle)
                 {
                     //Debug.LogError("hit Obstacle");
                 }
             }
         }
         //
         //yield return new WaitForSeconds(rayCastingWaitTime);
         yield return(null);
         //
     }
     //
 }
Esempio n. 5
0
 protected override void OnSetTargetUnit(RTSGameUnit unit)
 {
     base.OnSetTargetUnit(unit);
     //
     if (isWorking)
     {
         stopWork();
     }
     //
     if (unit is RTSResource)
     {
         //
         if (IsMiningHarvestedFull)
         {
             startReturning();
             //
         }
         else
         {
             goMine();
         }
         //
     }
     else if (unit is RTSBuilding)
     {
         RTSBuilding building = (RTSBuilding)unit;
         //
         if (miningAchievement > 0 && homeBuilding != null && building == homeBuilding)
         {
             startReturning();
         }
         else
         {
             //
             if (building.IsNeedRepair)
             {
                 goRepair();
             }
             else
             {
                 goMine();
             }
             //
         }
     }
     //
     move(unit.transform.position);
 }
Esempio n. 6
0
 //
 public bool unitUnRegister(RTSGameUnit unit)
 {
     if (unit == null || GameUnitsDic == null)
     {
         return(false);
     }
     if (GameUnitsDic.ContainsKey(unit.gameUnitBelongSide))
     {
         List <RTSGameUnit> unitsList = GameUnitsDic[unit.gameUnitBelongSide];
         lock (unitsList)
         {
             unitsList.Remove(unit);
         }
     }
     return(true);
 }
Esempio n. 7
0
    //
    public bool unitRegister(RTSGameUnit unit)
    {
        if (unit == null || GameUnitsDic == null)
        {
            return(false);
        }
        if (!GameUnitsDic.ContainsKey(unit.gameUnitBelongSide))
        {
            GameUnitsDic.Add(unit.gameUnitBelongSide, new List <RTSGameUnit>());
        }
        List <RTSGameUnit> unitsList = GameUnitsDic[unit.gameUnitBelongSide];

        lock (unitsList)
        {
            unitsList.Add(unit);
        }
        return(true);
    }
Esempio n. 8
0
    public void FindAttackTarget(KeyCode k)
    {
        //TODO
        //得到鼠标点击到的对象

        //将鼠标左击事件改回选取单位
        // InputManager.ShareInstance.InputEventHandlerRegister_GetKeyDown (KeyCode.Mouse0, RTSOperations.PointSelect);

        InputManager.ShareInstance.InputEventHandlerUnRegister_GetKeyDown(KeyCode.Mouse0, FindAttackTarget);
        //
        //
        //

        Vector3 mousePos = Input.mousePosition;

        Ray        ray = Camera.main.ScreenPointToRay(mousePos);
        RaycastHit hit;

        if (!Physics.Raycast(ray, out hit))
        {
            return;
        }

        RTSGameUnit targetinfo = hit.transform.GetComponent <RTSGameUnit> ();

        if (targetinfo == null)
        {
            return;
        }

        //
        // if (targetinfo.gameUnitBelongSide == RTSGameUnitBelongSide.Player) {
        // }
        //TODO
        //攻击方法
        Debug.Log(gameObject.GetComponent <RTSGameUnit>().playerInfo.name + "攻击" + targetinfo.playerInfo.name);
        //
        InputManager.ShareInstance.InputEventHandlerRegister_GetKeyUp(KeyCode.Mouse0, activateSelection);
        //
    }
Esempio n. 9
0
    void UnitDie()
    {
        //TODO
        //在对象池中隐藏
//		UnitInfo unitinfo = gameObject.GetComponent<UnitInfo>();
        RTSGameUnit unitinfo = gameObject.GetComponent <RTSGameUnit>();

        // if (unitinfo is Building) {
        if (unitinfo is RTSBuilding)
        {
            UnitManager.ShareInstance.Buildings [unitinfo.playerInfo].Remove(gameObject);
        }
//		if (unitinfo is Building) {
        if (unitinfo is RTSBuilding)
        {
            UnitManager.ShareInstance.Armys [unitinfo.playerInfo].Remove(gameObject);
        }
        else
        {
            return;
        }
    }
Esempio n. 10
0
    //
    #region event register&unregister
    //
    //public static void eventRegister(DGameUnitMultipleSelectionValidUnitsListGeneration eventHandler)
    //{
    //    if (multipleSelectionValidListGenerationEvent == null)
    //    {
    //        multipleSelectionValidListGenerationEvent = new DGameUnitMultipleSelectionValidUnitsListGeneration(eventHandler);
    //    }
    //    else
    //    {
    //        multipleSelectionValidListGenerationEvent += eventHandler;
    //    }
    //}
    ////
    //public static void eventUnRegister(DGameUnitMultipleSelectionValidUnitsListGeneration eventHandler)
    //{
    //    if (multipleSelectionValidListGenerationEvent == null)
    //    {
    //        return;
    //    }
    //    else
    //    {
    //        multipleSelectionValidListGenerationEvent -= eventHandler;
    //    }
    //}
    ////
    ////
    //public static void eventRegister(DGameUnitMultipleSelectionSelectedUnitsNotification eventHandler)
    //{
    //    if (multipleSelectionValidListGenerationEvent == null)
    //    {
    //        multipleSelectionSelectedDoneNotificationEvent = new DGameUnitMultipleSelectionSelectedUnitsNotification(eventHandler);
    //    }
    //    else
    //    {
    //        multipleSelectionSelectedDoneNotificationEvent += eventHandler;
    //    }
    //}
    ////
    //public static void eventUnRegister(DGameUnitMultipleSelectionSelectedUnitsNotification eventHandler)
    //{
    //    if (multipleSelectionSelectedDoneNotificationEvent == null)
    //    {
    //        return;
    //    }
    //    else
    //    {
    //        multipleSelectionSelectedDoneNotificationEvent -= eventHandler;
    //    }
    //}
    //
    //public static void eventRegister(DGameUnitSelectionRelease eventHandler)
    //{
    //    if (selectionReleaseEvent == null)
    //    {
    //        selectionReleaseEvent = new DGameUnitSelectionRelease(eventHandler);
    //    }
    //    else
    //    {
    //        selectionReleaseEvent += eventHandler;
    //    }
    //}
    ////
    //public static void eventUnRegister(DGameUnitSelectionRelease eventHandler)
    //{
    //    if (selectionReleaseEvent == null)
    //    {
    //        return;
    //    }
    //    else
    //    {
    //        selectionReleaseEvent -= eventHandler;
    //    }
    //}

    //public static void eventRegister(DGameUnitSingleSelectionSelected eventHandler)
    //{
    //    if (singleSelectionSelectedEvent == null)
    //    {
    //        singleSelectionSelectedEvent = new DGameUnitSingleSelectionSelected(eventHandler);
    //    }
    //    else
    //    {
    //        singleSelectionSelectedEvent += eventHandler;
    //    }
    //}
    ////
    //public static void eventUnRegister(DGameUnitSingleSelectionSelected eventHandler)
    //{
    //    if (singleSelectionSelectedEvent == null)
    //    {
    //        return;
    //    }
    //    else
    //    {
    //        singleSelectionSelectedEvent -= eventHandler;
    //    }
    //}
    //
    #endregion
    //
    //public static void addSelectionListener(RTSGameUnit unit)
    //{
    //    if (unit == null)
    //    {
    //        return;
    //    }
    //    if (!unit.IsAllowMultipleSelection)
    //    {
    //        return;
    //    }
    //    lock (UnitsSelectionAvailable)
    //    {
    //        UnitsSelectionAvailable.Add(unit);
    //    }
    //}
    ////
    //public static void removeSelectionListener(RTSGameUnit unit)
    //{
    //    if (unit == null)
    //    {
    //        return;
    //    }
    //    lock (UnitsSelectionAvailable)
    //    {
    //        if (UnitsSelectionAvailable.Contains(unit))
    //        {
    //            UnitsSelectionAvailable.Remove(unit);
    //        }
    //    }
    //}
    //
    public static void selectionRelease()
    {
        if (singleSelectedUnit != null)
        {
            singleSelectedUnit.IsSelected = false;
            singleSelectedUnit            = null;
        }
        //
        List <RTSGameUnit> selectedUnits = RTSGameUnitManager.ShareInstance.SelectedUnits;

        if (selectedUnits == null || selectedUnits.Count <= 0)
        {
            return;
        }
        for (int i = 0; i < selectedUnits.Count; i++)
        {
            RTSGameUnit unit = selectedUnits[i];
            if (unit != null)
            {
                unit.IsSelected = false;
            }
        }
        selectedUnits.Clear();
    }
    //
    private IEnumerator mouseRightKeyRayCast()
    {
        isMouseRightKeyRayCasting = true;
        //
        if (RTSCameraController.RTSCamera && (TargetUnitEventNeedInvoke || TargetPositionEventNeedInvoke))
        {
            Ray        ray     = RTSCameraController.RTSCamera.ScreenPointToRay(InputManager.ShareInstance.MousePosition);
            RaycastHit hitInfo = new RaycastHit();
            //
            if (Physics.Raycast(ray.origin, ray.direction, out hitInfo, 1000f, RTSLayerManager.ShareInstance.LayerMaskRayCastMouse1, QueryTriggerInteraction.Ignore))
            {
                //
                GameObject hitObj = hitInfo.collider.gameObject;
                //
                if (hitObj != null)
                {
                    //
                    //Debug.LogError("hit obj");
                    //
                    if (hitObj.layer == RTSLayerManager.ShareInstance.LayerNumberUI)
                    {
                        Debug.LogError("hit UI");
                    }
                    else if (hitObj.layer == RTSLayerManager.ShareInstance.LayerNumberEnvironmentGround)
                    {
                        //Debug.LogError("hit Ground");
                        //
                        if (TargetPositionEventNeedInvoke)
                        {
                            RTSGameUnitActionCursorController.ShareInstance.showMove(hitInfo.point);
                            //
                            targetPositionEvent.Invoke(hitInfo.point);
                        }
                    }
                    else if (hitObj.layer == RTSLayerManager.ShareInstance.LayerNumberEnemyGameUnit)
                    {
                        //Debug.LogError("hit EnemyGameUnit");
                        //
                        RTSGameUnit gameUnit = (RTSGameUnit)hitObj.GetComponent("RTSGameUnit");
                        //
                        if (gameUnit)
                        {
                            if (TargetUnitEventNeedInvoke)
                            {
                                RTSGameUnitActionCursorController.ShareInstance.showAttack();
                                //
                                targetUnitEvent.Invoke(gameUnit);
                            }
                        }
                    }
                    else if (hitObj.layer == RTSLayerManager.ShareInstance.LayerNumberEnvironmentObstacle)
                    {
                        Debug.LogError("hit Obstacle");
                    }
                    else if (hitObj.layer == RTSLayerManager.ShareInstance.LayerNumberEnvironmentResource)
                    {
                        Debug.LogError("hit Resource");
                        //
                        RTSGameUnit gameUnit = (RTSGameUnit)hitObj.GetComponent("RTSGameUnit");
                        //
                        if (gameUnit)
                        {
                            if (TargetUnitEventNeedInvoke)
                            {
                                //RTSGameUnitActionCursorController.ShareInstance.showAttack();
                                //
                                targetUnitEvent.Invoke(gameUnit);
                            }
                        }
                    }
                    else if (hitObj.layer == RTSLayerManager.ShareInstance.LayerNumberPlayerBuildingUnit)
                    {
                        Debug.LogError("hit Building");
                        //
                        RTSGameUnit gameUnit = (RTSGameUnit)hitObj.GetComponent("RTSGameUnit");
                        //
                        if (gameUnit)
                        {
                            if (TargetUnitEventNeedInvoke)
                            {
                                //RTSGameUnitActionCursorController.ShareInstance.showAttack();
                                //
                                targetUnitEvent.Invoke(gameUnit);
                            }
                        }
                    }
                }
            }
        }
        //
        yield return(new WaitForSeconds(mouseRightKeyRayCastingWaitTime));

        //
        isMouseRightKeyRayCasting = false;
    }
Esempio n. 12
0
 void Start()
 {
     RTSGameUnit = gameObject.GetComponent <RTSGameUnit> ();
     showPanel   = ObjectInfoShow.Current;
     isShow      = false;
 }
Esempio n. 13
0
    //
    private void multipleSelectionEventInvoke()
    {
        if (!RTSCameraController.RTSCamera)
        {
            return;
        }
        //
        //if (multipleSelectionValidListGenerationEvent == null)
        //{
        //    return;
        //}
        if (mousePositionStartPos.x == mousePositionEndPos.x || mousePositionStartPos.y == mousePositionEndPos.y)
        {
            //not a rect
            return;
        }
        //
        float xMin = 0f;
        float xMax = 0f;
        float yMin = 0f;
        float yMax = 0f;

        //
        if (mousePositionStartPos.x > mousePositionEndPos.x)
        {
            xMax = mousePositionStartPos.x;
            xMin = mousePositionEndPos.x;
        }
        else
        {
            xMax = mousePositionEndPos.x;
            xMin = mousePositionStartPos.x;
        }
        //
        if (mousePositionStartPos.y > mousePositionEndPos.y)
        {
            yMax = mousePositionStartPos.y;
            yMin = mousePositionEndPos.y;
        }
        else
        {
            yMax = mousePositionEndPos.y;
            yMin = mousePositionStartPos.y;
        }
        ////
        //
        List <RTSGameUnit> UnitsSelectionAvailable = RTSGameUnitManager.ShareInstance.PlayerUnits;

        if (UnitsSelectionAvailable == null)
        {
            return;
        }
        for (int i = 0; i < UnitsSelectionAvailable.Count; i++)
        {
            RTSGameUnit unit = UnitsSelectionAvailable[i];
            //
            if (unit != null && unit.IsAllowMultipleSelection && unit.IsVisible)
            {
                //
                Vector3 screenPos = RTSCameraController.RTSCamera.WorldToScreenPoint(unit.transform.position);
                //
                if (screenPos.x >= xMin && screenPos.x <= xMax && screenPos.y >= yMin && screenPos.y <= yMax)
                {
                    //inside the rect
                    unit.IsSelected = true;
                    //lock (UnitsSelected)
                    //{
                    //    UnitsSelected.Add(unit);
                    //}
                }
                else
                {
                    //outside the rect
                    unit.IsSelected = false;
                }
            }
        }
        //
        //RTSGameUnit[] temp = multipleSelectionValidListGenerationEvent.Invoke();
        //if (temp == null)
        //{
        //    return;
        //}
        //List<RTSGameUnit> selectedUnits = new List<RTSGameUnit>();
        //for (int i = 0; i < temp.Length; i++)
        //{
        //    RTSGameUnit unit = temp[i];
        //    //
        //    if (unit != null && unit.IsAllowMultipleSelection && unit.IsVisible)
        //    {
        //        //
        //        Vector3 screenPos = RTSCameraController.RTSCamera.WorldToScreenPoint(unit.transform.position);
        //        //
        //        if (screenPos.x >= xMin && screenPos.x <= xMax && screenPos.y >= yMin && screenPos.y <= yMax)
        //        {
        //            //inside the rect
        //            unit.IsSelected = true;
        //        }
        //        else
        //        {
        //            //outside the rect
        //            unit.IsSelected = false;
        //        }
        //    }
        //}
        ////
        //if (selectedUnits != null && multipleSelectionSelectedDoneNotificationEvent != null && selectedUnits.Count > 0)
        //{
        //    RTSGameUnit[] copy = new RTSGameUnit[selectedUnits.Count];
        //    selectedUnits.CopyTo(copy);
        //    multipleSelectionSelectedDoneNotificationEvent.Invoke(copy);
        //}
    }
Esempio n. 14
0
 void Start()
 {
     //info = gameObject.GetComponent<UnitInfo> ();
     info = gameObject.GetComponent <RTSGameUnit> ();
 }
Esempio n. 15
0
 public void SetMaster(RTSGameUnit m)
 {
     master = m;
 }
Esempio n. 16
0
 public virtual void RemoveTarget(RTSGameUnit t)
 {
 }