コード例 #1
0
ファイル: BuildManager.cs プロジェクト: KingJA/TowerKiller
 private void Update(){
     //鼠标被按下
     if (Input.GetMouseButtonDown(0)) {
         //UI没有被选中
         if (EventSystem.current.IsPointerOverGameObject() == false) {
             //MapCube上没有建过炮塔
             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);//Camera.main tag上标记MainCamera即可
             RaycastHit hit;
             bool isCollider = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("MapCube"));
             if (isCollider) {
                 MapCube mapCube = hit.collider.GetComponent<MapCube>(); //得到点击的mapCube
                 if (mapCube.turretGo == null) {
                     //建造
                     if (money >= selectedTurretData.cost) {
                         mapCube.BuildTurret(selectedTurretData.turretPrefab);
                         ChangeMoney(-selectedTurretData.cost);
                     }
                     else {
                         //提示钱不够
                         moneyAnimator.SetTrigger("Flicker");
                     }
                 }
                 else {
                     //升级
                     if (money >= selectedTurretData.costUpgraded) {
                         ChangeMoney(-selectedTurretData.costUpgraded);
                     }
                     else {
                         //提示钱不够
                     }
                 }
             }
         }
     }
 }
コード例 #2
0
    public void SelectNode(MapCube node)
    {
        selectedTurret = node;
        turrentToBuild = null;

        selectionUI.SetTarget(node);
    }
コード例 #3
0
    private MapCube FindClosestPlane(Vector3 pos)
    {
        MapCube ret = heat_matrix[0, 0].GetComponent <MapCube>();
        float   current_distance = (heat_matrix[0, 0].transform.position - pos).magnitude;

        for (int i = 0; i < size.x; i++)
        {
            for (int j = 0; j < size.y; j++)
            {
                if ((heat_matrix[i, j].transform.position - pos).magnitude < current_distance)
                {
                    ret = heat_matrix[i, j].GetComponent <MapCube>();
                    current_distance = (heat_matrix[i, j].transform.position - pos).magnitude;
                }
            }
        }
        if (current_distance < 10)
        {
            return(ret);
        }
        else
        {
            Debug.Log("WHOOPS");
            return(null);
        }
    }
コード例 #4
0
ファイル: MapManager.cs プロジェクト: lilice168/gameX
    // 計算路徑
    private bool SetMoveDirection()
    {
        // 暫時預設0,0為起點, 最後一點為終點
        MapCube startMap = m_Maps[0, 0];
        MapCube endMap   = m_Maps[m_MapMaxX - 1, m_MapMaxY - 1];

        startMap.m_State = MapCube.EMapState.eStart;
        endMap.m_State   = MapCube.EMapState.eEnd;

        // 開始計算
        MapCube moveMap = startMap;

        while (moveMap != endMap)
        {
            Debug.LogFormat("move map name: " + moveMap.name);
            for (MapCube.EDirection i = MapCube.EDirection.eUp; i < MapCube.EDirection.eMax; i++)
            {
                MapCube nextMapCube = CheckNext(moveMap, i);
                if (nextMapCube != null)
                {
                    moveMap.SetDirection(i, nextMapCube.transform);
                    moveMap = nextMapCube;
                    break;
                }
            }
        }

        return(true);
    }
コード例 #5
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         if (!EventSystem.current.IsPointerOverGameObject())
         {
             Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             RaycastHit hit;
             bool       isCollider = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("MapCube"));
             if (isCollider)
             {
                 MapCube mapCube = hit.collider.gameObject.GetComponent <MapCube>();
                 if (mapCube != null)
                 {
                     if (selectedTurretData != null && mapCube.turrentGo == null)
                     {
                         if (_money >= selectedTurretData.cost)
                         {
                             ChangeMoney(-selectedTurretData.cost);
                             mapCube.BuildTurret(selectedTurretData.turretPrefab);
                         }
                     }
                     else if (mapCube.turrentGo != null)
                     {
                     }
                 }
             }
         }
     }
 }
コード例 #6
0
 private void Update()
 {
     if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
     {
         Ray  ray     = Camera.main.ScreenPointToRay(Input.mousePosition);
         bool isExist = Physics.Raycast(ray, out RaycastHit raycastHit, 1000, LayerMask.GetMask("MapCube"));
         if (isExist)
         {
             m_currMapCube = raycastHit.collider.gameObject;
             if (m_currMapCube.GetComponent <MapCube>().m_isEmpty)
             {
                 //if(EntityManager.Instance.m_isBuild)
                 if (EditorManager.CurrES == EditState.ENTITYEDIT)
                 {
                     m_currMapCube.GetComponent <MapCube>().m_isEmpty = false;
                     MapCube mapCube = m_currMapCube.GetComponent <MapCube>();
                     EntityManager.Instance.CreateEntity(mapCube.m_position, mapCube.m_index);
                 }
                 //else if(PathManager.Instance.m_isEdit)
                 else if (EditorManager.CurrES == EditState.PATHEDIT)
                 {
                     PathManager.Instance.CreateKeyPoint(m_currMapCube.GetComponent <MapCube>().m_position);
                 }
             }
         }
     }
 }
コード例 #7
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         //开发炮台的建造
         if (EventSystem.current.IsPointerOverGameObject() == false)
         {
             Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             RaycastHit hit;
             bool       isCollider = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("MapCube"));
             if (isCollider)
             {
                 MapCube mapCube = hit.collider.GetComponent <MapCube>();//得到点击的mapCube
                 if (selectedTurretData != null && mapCube.turretGo == null)
                 {
                     //可以创建
                     if (money >= selectedTurretData.cost)
                     {
                         ChangeMoney(-selectedTurretData.cost);
                         mapCube.BuildTurret(selectedTurretData.turretPrefab);
                     }
                     else
                     {
                         //TODO 提示钱不够
                         moneyAnimator.SetTrigger("flicker");
                     }
                 }
                 else if (mapCube.turretGo != null)
                 {
                     //TODO 升级处理
                 }
             }
         }
     }
 }
コード例 #8
0
    void Update()
    {
        time += Time.deltaTime;
        if (time > 1.0)
        {
            ChangeMoney(1);
            time = 0f;
        }
        if (Input.GetMouseButtonDown(0))
        {
            if (EventSystem.current.IsPointerOverGameObject() == false)
            {
                //开发炮台的建造
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                bool       isCollider = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("MapCube"));
                if (isCollider)
                {
                    MapCube mapCube = hit.collider.GetComponent <MapCube>();
                    if (selectedTurretData != null && mapCube.turretGo == null)
                    {
                        //可以创建
                        if (money > selectedTurretData.cost)
                        {
                            ChangeMoney(-selectedTurretData.cost);
                            mapCube.BuildTurret(selectedTurretData);
                        }
                        else
                        {
                            //提示钱不够
                            moneyAnimator.SetTrigger("Flicker");
                        }
                    }
                    else if (mapCube.turretGo != null)
                    {
                        // 升级处理

                        //if (mapCube.isUpgraded)
                        //{
                        //    ShowUpgradeUI(mapCube.transform.position, true);
                        //}
                        //else
                        //{
                        //    ShowUpgradeUI(mapCube.transform.position, false);
                        //}
                        if (mapCube == selectedMapCube && upgradeCanvas.activeInHierarchy)
                        {
                            StartCoroutine(HideUpgradeUI());
                        }
                        else
                        {
                            ShowUpgradeUI(mapCube.transform.position, mapCube.isUpgraded);
                        }
                        selectedMapCube = mapCube;
                    }
                }
            }
        }
    }
コード例 #9
0
    public void BuildWrong(MapCube mapCube)
    {
        mapCube.DestroyFlag();
        GameObject selectedNumberData = (GameObject)Resources.Load("Mine");

        Instantiate(selectedNumberData, mapCube.transform.position, mapCube.transform.rotation);
        MineAudio.Play();
    }
コード例 #10
0
ファイル: Snake.cs プロジェクト: FeedFestival/SnakeBot
    public void Init(MapCube toMapCube)
    {
        SnakeHead.gameObject.SetActive(true);
        PlaceSnake(toMapCube);

        BodyParts[0].gameObject.SetActive(false);
        SnakeHeadIndex = 0;
        SnakeTail.gameObject.SetActive(false);
    }
コード例 #11
0
    void Update()
    {
        moneyText.text = "$" + money;
        if (getmoney != 0)
        {
            ChangeMoney(getmoney);
            getmoney = 0;
        }
        if (Input.GetMouseButtonDown(0))
        {
            if (EventSystem.current.IsPointerOverGameObject() == false)
            {
                //开发炮台的建造
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                bool       isCollider = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("MapCube"));
                //Debug.DrawRay(ray,Vector3.up,Color.red);
                if (isCollider)
                {
                    MapCube mapCube = hit.collider.GetComponent <MapCube>();

                    if (mapCube.turretGo == null && selectedTurretData != null)
                    {
                        //可以创建
                        if (money > selectedTurretData.cost)
                        {
                            ChangeMoney(-selectedTurretData.cost);
                            mapCube.BuildTurret(selectedTurretData);
                        }
                        else
                        {
                            moneyAnimator.SetTrigger("Flick");
                            //todo 提示钱不够
                        }
                    }
                    else if (mapCube.turretGo != null)
                    {
                        ShowUpgradedUI(mapCube.transform.position, mapCube.isUpgraded);
                        //if (mapCube.isUpgraded)
                        //{
                        //ShowUpgradedUI(mapCube.transform.position, true);
                        //}
                        //else
                        //{
                        // ShowUpgradedUI(mapCube.transform.position, false);
                        //}
                        if (mapCube.turretGo == selectedMapCube && upgradeCanvas.activeInHierarchy)
                        {
                            StartCoroutine(HideUpgradeUI());
                        }
                        selectedMapCube = mapCube;
                        //todo 升级处理
                    }
                }
            }
        }
    }
コード例 #12
0
ファイル: MapManager.cs プロジェクト: lilice168/gameX
    private MapCube CheckNext(MapCube _mapCube, MapCube.EDirection _direction)
    {
        int xIndex = _mapCube.m_X;
        int yIndex = _mapCube.m_Y;

        MapCube nextMapCube = null;

        MapCube.EDirection checkDirection = MapCube.EDirection.eUp;
        if (_direction == MapCube.EDirection.eUp)
        {
            yIndex = yIndex - 1;
            if (yIndex < 0)
            {
                return(null);
            }
            nextMapCube    = m_Maps[xIndex, yIndex];
            checkDirection = MapCube.EDirection.eDown;
        }
        else if (_direction == MapCube.EDirection.eDown)
        {
            yIndex = yIndex + 1;
            if (yIndex >= m_MapMaxY)
            {
                return(null);
            }
            nextMapCube    = m_Maps[xIndex, yIndex];
            checkDirection = MapCube.EDirection.eUp;
        }
        else if (_direction == MapCube.EDirection.eLeft)
        {
            xIndex = xIndex - 1;
            if (xIndex < 0)
            {
                return(null);
            }
            nextMapCube    = m_Maps[xIndex, yIndex];
            checkDirection = MapCube.EDirection.eRight;
        }
        else if (_direction == MapCube.EDirection.eRight)
        {
            xIndex = xIndex + 1;
            if (xIndex >= m_MapMaxX)
            {
                return(null);
            }
            nextMapCube    = m_Maps[xIndex, yIndex];
            checkDirection = MapCube.EDirection.eLeft;
        }

        if (nextMapCube.CheckNextMove(checkDirection, _mapCube.m_Cost) == false)
        {
            nextMapCube = null;
        }

        return(nextMapCube);
    }
コード例 #13
0
ファイル: BuildManager.cs プロジェクト: chidehang/CubeTD
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (!EventSystem.current.IsPointerOverGameObject())
            {
                //鼠标坐标不在UI上
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("Map")))
                {
                    //获取鼠标点击到的方块
                    GameObject cube    = hit.collider.gameObject;
                    MapCube    mapCube = cube.GetComponent <MapCube>();
                    if (mapCube.turret == null)
                    {
                        //建造炮塔
                        if (selectedTurret != null)
                        {
                            if (money >= selectedTurret.cost)
                            {
                                ChangeMoney(-selectedTurret.cost);
                                mapCube.BuildTurret(selectedTurret);
                            }
                            else
                            {
                                //金额不足
                                moneyAnim.SetTrigger("Flicker");
                            }
                        }
                    }
                    else
                    {
                        //升级炮塔
                        if (readyUpgradeMapCube != mapCube)
                        {
                            //未选中该炮塔
                            ShowUpgradeUI(new Vector3(mapCube.transform.position.x, mapCube.transform.position.y + 6, mapCube.transform.position.z + 4),
                                          (mapCube.isLevelTop || money < mapCube.turretData.upgradedCost));
                            readyUpgradeMapCube = mapCube;
                        }
                        else
                        {
                            HideUpgradeUI();
                        }
                    }
                }
            }
        }

        if (readyUpgradeMapCube != null)
        {
            upgradeBtn.interactable = money >= readyUpgradeMapCube.turretData.upgradedCost && !readyUpgradeMapCube.isLevelTop;
        }
    }
コード例 #14
0
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (EventSystem.current.IsPointerOverGameObject() == false)//检测鼠标是否按在UI上
            {
                //炮台的建造
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                bool       isCollider = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("MapCube"));//距离1000,获取碰撞的层
                if (isCollider)
                {
                    MapCube mapcube = hit.collider.GetComponent <MapCube>();//得到点击的mapcube
                    if (selectedTurretData != null && mapcube.turretGo == null)
                    {
                        //可以创建
                        if (money > selectedTurretData.cost)
                        {
                            ChangeMoney(-selectedTurretData.cost);
                            mapcube.BuildTurret(selectedTurretData);
                        }
                        else
                        {
                            //金钱不足
                            moneyAnimator.SetTrigger("Flicker");
                        }
                    }
                    else if (mapcube.turretGo != null)
                    {
                        //升级创建

                        /*1.方法1
                         * if(mapcube.isUpgraded)
                         * {
                         *  ShowUpgradeUI(mapcube.transform.position,true);
                         * }
                         * else
                         * {
                         *  ShowUpgradeUI(mapcube.transform.position, false);
                         * }*/
                        //2.方法2
                        if (mapcube == selectedMapCube && upgradeCanvas.activeInHierarchy)//点击同一个炮台
                        {
                            StartCoroutine(HideUpgradeUI());
                        }
                        else
                        {
                            ShowUpgradeUI(mapcube.transform.position, mapcube.isUpgraded);
                        }
                        selectedMapCube = mapcube;
                    }
                }
            }
        }
    }
コード例 #15
0
ファイル: BuildManager.cs プロジェクト: Rzzil/ARProject
    void Update()
    {
        //if (Input.GetMouseButtonDown(0) && isShowBuildUI == false && isShowUpgradeUI == false && isShowDestroyUI == false)
        if (Input.GetMouseButtonDown(0) && isShowBuildUI == false && isShowUpgradeUI == false && isShowDestroyUI == false)
        {
            if (EventSystem.current.IsPointerOverGameObject() == false)
            {
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, 1000.0f, LayerMask.GetMask("MapCube")))
                {
                    mapCube = hit.collider.GetComponent <MapCube>();
                    if (mapCube.currentTurret == null)
                    {
                        //can build turret
                        TDSoundManager.instance.playButtonSound();
                        showBuildOperationUI();
                        hideUpgradeOperationUI();
                        hideDestroyOperationUI();
                    }
                    else if (mapCube.currentTurret != null && mapCube.TurrentLevel != 5 && mapCube.TurrentLevel != 10 && mapCube.TurrentLevel != 15 && mapCube.TurrentLevel != 20)
                    {
                        //need upgrade turret
                        TDSoundManager.instance.playButtonSound();
                        showUpgradeOperationUI();
                        HideBuildOperationUI();
                        hideDestroyOperationUI();
                    }
                    else
                    {
                        //the max upgrade situation, need to show shut destroy turret ui
                        TDSoundManager.instance.playButtonSound();
                        showDestroyOperationUI();
                        HideBuildOperationUI();
                        hideUpgradeOperationUI();
                    }
                }
            }
        }
        if (Input.GetMouseButtonDown(1))
        {
            HideBuildOperationUI();
            hideUpgradeOperationUI();
            isShowBuildUI     = false;
            isShowUpgradeUI   = false;
            isEqualOpen       = false;
            trueCompare       = -1;
            updateTrueCompare = -1;
            isUpdateEqualson  = false;

            hideDestroyOperationUI();
            isShowDestroyUI = false;
        }
    }
コード例 #16
0
    public void DestroyTurret()
    {
        MapCube mapCube = TowerManager.Instance.isSameMapCube;

        if (mapCube != null)
        {
            Destroy(mapCube.transform.GetChild(0).gameObject);
            mapCube.turret        = null;
            mapCube.currentTurret = null;
        }
    }
コード例 #17
0
 void Update()
 {
     // 鼠标左键按下
     if (Input.GetMouseButtonDown(0))
     {
         // 鼠标是否点击到UI上 - 如果是手机上,则需要判断触摸
         if (EventSystem.current.IsPointerOverGameObject() == false)
         {
             // 发射射线
             Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             RaycastHit hit;
             // 射线检测,参数:射线、碰撞信息、最大距离、检测的层。返回是否碰撞到
             bool isCollider = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("MapCube"));
             if (isCollider)
             {
                 // 获取到点击的Cube
                 MapCube mapCube = hit.collider.gameObject.GetComponent <MapCube>();
                 // 已经选择了一个默认的炮塔类型,并且点击的位置的炮塔还没有创建
                 if (selectedTurretData != null && mapCube.turretGo == null)
                 {
                     // 如果点击的cube下没有炮塔,则可以创建
                     if (money >= selectedTurretData.cost)
                     {
                         // 金钱数量变化
                         ChangeMoney(-selectedTurretData.cost);
                         // 创建炮塔
                         mapCube.BuildTurret(selectedTurretData);
                     }
                     else
                     {
                         // TODO钱不够,给一个提示
                         moneyAnimator.SetTrigger("Flicker");
                     }
                 }
                 else if (mapCube.turretGo != null)
                 {
                     if (mapCube == selectedMapCube && upgradeCanvas.activeInHierarchy)
                     {
                         // 选择的是同一个炮塔,并且炮塔上已经显示了升级UI
                         StartCoroutine(HideUpgradeUI());
                     }
                     else
                     {
                         // 已经有了炮塔,传递炮塔位置和是否已经升级
                         ShowUpgradeUI(mapCube.transform.position, mapCube.isUpgraded);
                     }
                     // 记录当前选择的炮塔
                     selectedMapCube = mapCube;
                 }
             }
         }
     }
 }
コード例 #18
0
 void UpgradeTurretUI(MapCube mapCube)
 {
     if (selectMapcube == mapCube && canvasTurretUpgrade.activeInHierarchy)
     {
         HideTurretUpgradeCanvas();
     }
     else
     {
         ShowTurretUpgradeCanvas(mapCube.turretGo.transform.position, mapCube.isUpgrade);
     }
     selectMapcube = mapCube;
 }
コード例 #19
0
 void Update()
 {
     //当点击鼠标左键时
     if (Input.GetMouseButtonDown(0))
     {
         //当点击的不是ui时
         if (EventSystem.current.IsPointerOverGameObject() == false)
         {
             //炮台建造
             //射线碰撞检测
             Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             RaycastHit hit;
             bool       isCollider = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("MapCube"));
             if (isCollider)
             {
                 //得到点击的mapCube
                 //GameObject mapCube = hit.collider.gameObject;
                 MapCube mapcube = hit.collider.GetComponent <MapCube>();
                 //Debug.Log(mapcube.name);
                 //mapcube上没有炮台
                 if (selectedTurretData != null && mapcube.turretGo == null)
                 {
                     //金钱足够建造
                     if (money > selectedTurretData.cost)
                     {
                         ChangeMoney(-selectedTurretData.cost);
                         mapcube.BuildTurret(selectedTurretData);
                     }
                     else
                     {
                         //提示钱不够
                         moneyAnimator.SetTrigger("Flicker");
                     }
                 }
                 else if (mapcube.turretGo != null)
                 {
                     //升级炮台
                     if (mapcube == selectedMapcube && upgradeCanvas.activeInHierarchy)
                     {
                         StartCoroutine(HideUpgradeUI());
                         //HideUpgradeUI();
                     }
                     else
                     {
                         ShowUpgradeUI(mapcube.transform.position, mapcube.isUpgraded);
                     }
                     selectedMapcube = mapcube;
                 }
             }
         }
     }
 }
コード例 #20
0
ファイル: BuildManager.cs プロジェクト: GrapeWang/U3D_learn
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (EventSystem.current.IsPointerOverGameObject() == false)
            {
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hitinfo, 1000f, LayerMask.GetMask("MapCube")))
                {
                    currentMap = hitinfo.collider.gameObject.GetComponent <MapCube>();
                    if (SelectedTurretData != null && currentMap.TurretOn == null)
                    {
                        //create turret
                        if (DataManager.money >= SelectedTurretData.Cost)
                        {
                            MoneyChange(-SelectedTurretData.Cost);
                            currentMap.BuildTurret(SelectedTurretData);
                        }
                        else
                        {
                            MoneyAnimator.SetTrigger("Flicker");
                        }
                    }
                    else if (currentMap.TurretOn != null)
                    {
                        //upgrade turret

                        if (SelectedTurret == currentMap.TurretOn && isUpgradeUIHide == false)
                        {
                            HideUpgradeUI();
                        }
                        else
                        {
                            if (currentMap.isUpgraded == false)
                            {
                                UpgradeCost.text  = "-" + currentMap.turretData.UpgradeCost + "¥";
                                DestroyValue.text = "+" + currentMap.turretData.Value + "¥";
                                ShowUpgradeUI(currentMap.transform.position, currentMap.isUpgraded);
                            }
                            else
                            {
                                UpgradeCost.text  = null;
                                DestroyValue.text = "+" + currentMap.turretData.UpgradeValue + "¥";
                                ShowUpgradeUI(currentMap.transform.position + offset, currentMap.isUpgraded);
                            }
                        }
                        SelectedTurret = currentMap.TurretOn;
                    }
                }
            }
        }
    }
コード例 #21
0
ファイル: MapMaker.cs プロジェクト: FeedFestival/SnakeBot
    public void CreateStartingCube()
    {
        GameObject go = Instantiate(PrefabBank._.GreenCube, new Vector3(0, 0, 0), Quaternion.identity);

        go.transform.SetParent(transform);
        go.transform.localPosition = new Vector3(_startAtX, 0, -1);
        MapCubeStart = go.GetComponent <MapCube>();
        // MapCubeStart.Init(_startAtX, -1, _debugThis);
        MapCubeStart.Init(new Vector2Int(_startAtX, -1), _debugThis);
        go = Instantiate(PrefabBank._.TreeLog, new Vector3(0, 0, 0), Quaternion.identity);
        go.transform.SetParent(MapCubeStart.transform);
        go.transform.localPosition = Vector3.zero;
    }
コード例 #22
0
    public void SelectNode(MapCube node)
    {
        if (selectedTurret == node)
        {
            DeselectNode();
            return;
        }

        selectedTurret = node;
        turrentToBuild = null;

        selectionUI.SetTarget(node);
    }
コード例 #23
0
    private void Update()
    {
        if (!selectLaserTurret && !selectMissileTurret && !selectStandardTurret)
        {
            selectedTurretData = null;
        }

        if (Input.GetMouseButtonDown(0))
        {
            if (!EventSystem.current.IsPointerOverGameObject())
            {
                //点击左键  并且没有点击UI
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                bool       isCollider = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("MapCube"));
                if (isCollider)
                {
                    MapCube mapCube = hit.collider.GetComponent <MapCube>();
                    if (mapCube.turretGo == null)
                    {
                        if (selectedTurretData != null && money < selectedTurretData.cost)
                        {
                            moneyAnimator.SetTrigger("Flicker");
                        }

                        //可以创建炮台
                        if (selectedTurretData != null && money >= selectedTurretData.cost)
                        {
                            StartCoroutine("HideUpgradeUI");
                            ChangeMoney(-selectedTurretData.cost);
                            mapCube.BuildTurret(selectedTurretData);
                            //selectedTurretData = null;
                        }
                    }
                    else
                    {
                        //升级炮台
                        if (mapCube == selectedMapCube && upgradeCanvas.activeInHierarchy)
                        {
                            StartCoroutine("HideUpgradeUI");
                        }
                        else
                        {
                            ShowUpgradeUI(mapCube.transform.position, mapCube.isUpgraded);
                        }
                        selectedMapCube = mapCube;
                    }
                }
            }
        }
    }
コード例 #24
0
    private void Update()
    {
        ray = Camera.main.ScreenPointToRay(Input.mousePosition);



        if (Input.GetMouseButtonDown(0))                                //鼠标左键按下
        {
            if (EventSystem.current.IsPointerOverGameObject() == false) //这里的Gameobject是UI上的游戏物体,意为当前碰到的不是UI上的游戏物体
            {
                //满足以上2种条件才可建造炮台

                bool iscolliion = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("SpaceCube"));//只检测这个图层下的游戏物体
                if (iscolliion)
                {
                    //碰撞到的那个方块,获取上面的Mapcube组件
                    mapcube = hit.collider.gameObject.GetComponent <MapCube>();

                    Mapcube = mapcube;//之前一直不知道怎么在下面的方法中得到选中的小方块,想不到这么简单!!!!!!!!
                    //直接在上面public一个mapcube然后把这个值赋给它就可以在下面调用了

                    if (CurrentTurrent.Turrent != null && mapcube.TurrentOn == null)
                    {
                        //上面没有炮台//当前炮台游戏物体不为空的前提下
                        if (CurrentMoney > CurrentTurrent.Moneycost)
                        {
                            OnMoneyChanged(CurrentTurrent.Moneycost);
                            mapcube.BulidPrefabs(CurrentTurrent);
                            CanvasHide();
                        }
                        else
                        {
                            //提示钱不够
                        }
                    }
                    else if (mapcube.TurrentOn != null)
                    {
                        //mapcube.BuildUpdateButton();
                        CanvasOn(mapcube.transform.position + new Vector3(0, 10, 0), mapcube.isUpdate); //获取点击小方块的坐标,如果生成了炮台isuodate为true,按钮可以点击

                        if (mapcube.TurrentOn == SelecedTurrent && UpdateCanvas.activeInHierarchy)      //此按钮在层级列表中是否激活
                        {
                            CanvasHide();
                        }
                        SelecedTurrent = mapcube.TurrentOn;//保存下来的炮台,通过mapcube生成的游戏物体赋值
                        CurrentTurrent = mapcube.Turrentdata;
                    }
                }
            }
        }
    }
コード例 #25
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (EventSystem.current.IsPointerOverGameObject() == false)
            {
                //开始炮塔的创造
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                bool       isCollider = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("MapCube"));
                if (isCollider)
                {
                    //得到mapcube
                    //GameObject mapcube = hit.collider.gameObject;
                    MapCube mapCube = hit.collider.GetComponent <MapCube>();
                    if (mapCube.turretGo == null)   //mapcube上没有炮塔
                    {
                        if (money > selectedTurret.cost)
                        {
                            ChangeMoney(-selectedTurret.cost);

                            if (selectedTurret.turretPrefab == null)
                            {
                                return;
                            }
                            mapCube.BuildTurret(selectedTurret);
                        }
                        else
                        {
                            //提示资金不够
                            moneyAnim.SetTrigger("flicker");
                        }
                    }
                    else
                    {
                        //TODO 升级炮塔
                        ShowUpgradeUI(mapCube.transform.position, mapCube.isUpgraded);
                        if (mapCube.turretGo == selectedMapcube && upgradeCanvas.activeInHierarchy)
                        {
                            HideUpgradeUI();
                        }
                        else
                        {
                            ShowUpgradeUI(mapCube.transform.position, mapCube.isUpgraded);
                        }
                        selectedMapcube = mapCube;
                    }
                }
            }
        }
    }
コード例 #26
0
 private void Update()
 {
     // 建炮台
     if (Input.GetMouseButtonDown(0))
     {
         // 是否点击到了UI,false => 没有点击到UI
         if (EventSystem.current.IsPointerOverGameObject() == false)
         {
             Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             RaycastHit hit;
             bool       bIsCollider = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("MapCube"));
             if (bIsCollider)
             {
                 MapCube mapCube = hit.collider.GetComponent <MapCube>();
                 // 此mapCube上没有炮台 => 新建炮台
                 if (mapCube.m_goTurret == null)
                 {
                     // 有钱
                     if (GameManager.Instance.m_iMoney >= m_SelectedTurret.m_iCost)
                     {
                         // 花钱
                         GameManager.Instance.ChangeMoney(-m_SelectedTurret.m_iCost);
                         // 组装炮台
                         mapCube.BuildTurret(m_SelectedTurret);
                     }
                     // 穷人
                     else
                     {
                         // 钱闪一下,提示你是个穷人
                         m_animMoneyFlicker.SetTrigger("Flicker");
                     }
                 }
                 // 此mapCube上有炮台 => 显示升级炮台面板
                 else
                 {
                     // 点击的是同一个MapCube,隐藏升级面板
                     if (m_CurMapCube == mapCube && m_goCanvasUpgrade.activeInHierarchy)
                     {
                         StartCoroutine(HideUpgradePanel());
                     }
                     else
                     {
                         ShowUpgradePanel(mapCube.transform.position, mapCube.m_bIsUpgraded);
                     }
                     // 保存此次点击的炮台
                     m_CurMapCube = mapCube;
                 }
             }
         }
     }
 }
コード例 #27
0
ファイル: BuildManager.cs プロジェクト: q361567564/Test1
    public void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            //当UI和Cube不重合时,进行建造
            if (EventSystem.current.IsPointerOverGameObject() == false)
            {
                //开发炮台的建造
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                bool       isCollider = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("MapCube"));
                if (isCollider)
                {
                    MapCube mapCube = hit.collider.GetComponent <MapCube>();
                    //判断cube身上有没有炮台
                    if (selectedPaoTai != null && mapCube.PaoTai == null)
                    {
                        //可以创建
                        if (money >= selectedPaoTai.cost)
                        {
                            ChangeMoney(-selectedPaoTai.cost);
                            mapCube.BuildPaoTai(selectedPaoTai);
                        }
                        else //提示钱不够
                        {
                            moneyAnimator.SetTrigger("ShanShuo");
                        }
                    }
                    //升级处理
                    else if (mapCube.PaoTai != null)
                    {
                        //show(mapCube.transform.position, mapCube.isUpgraded);

                        //表示升级UI是否显示出来
                        if (mapCube == selectedMapCube && SJCanvas.activeInHierarchy)
                        {
                            Hide();
                        }
                        else
                        {
                            show(mapCube.transform.position, mapCube.isUpgraded);
                        }
                        selectedMapCube = mapCube;
                    }
                    //GameObject mapCube = hit.collider.gameObject;//得到点击的Cube
                    //if()
                }
            }
        }
    }
コード例 #28
0
    void Update()
    {
        //如果按下
        if (Input.GetMouseButtonDown(0))
        {
            //并且不在ui
            if (EventSystem.current.IsPointerOverGameObject() == false)
            {
                //射线碰撞
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                bool       isCollider = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("MapCube"));
                if (isCollider)
                {
                    //GameObject gameObject = hit.collider.gameObject;
                    MapCube mapCube = hit.collider.GetComponent <MapCube>();
                    if (selectedTurretData != null && mapCube.turretGo == null)
                    {
                        //可以建造
                        if (money > selectedTurretData.cost)
                        {
                            ChangeMoney(-selectedTurretData.cost);
                            mapCube.BuildTurret(selectedTurretData);
                        }
                        else
                        {
                            moneyFlicker.SetTrigger("Flicker");
                        }
                    }
                    else
                    {
                        //升级
                        if (mapCube.turretGo != null)
                        {
                            if (mapCube == selectedMapCube && upgradeCanvers.activeInHierarchy)
                            {
                                StartCoroutine(HideUpgradeUI());
                            }
                            else
                            {
                                ShowUpgradeUI(mapCube.transform.position, mapCube.isUpgraed);
                            }

                            selectedMapCube = mapCube;
                        }
                    }
                }
            }
        }
    }
コード例 #29
0
    public void BuildTurretOn(MapCube mapCube)
    {
        if (PlayerStats.Money < turretToBuild.cost)
        {
            Debug.Log("No money");
            return;
        }

        PlayerStats.Money -= turretToBuild.cost;

        GameObject turret = (GameObject)Instantiate(turretToBuild.prefab, mapCube.GetBuildPosition(), Quaternion.identity);

        mapCube.turret = turret;
    }
コード例 #30
0
 void CreateTurret(MapCube mapCube)
 {
     if (selectTurret == null)
     {
         return;
     }
     if (money < selectTurret.cost)
     {
         // 钱不够
         moneyAnimator.SetTrigger("Flicker");
         return;
     }
     ChangeMoney(-selectTurret.cost);
     mapCube.BuildTurret(selectTurret);
 }