void UpdatePlacementSprite()
    {
        string canPlaceText = CanPlaceAtPos(placePos);

        if (canPlaceText.Length == 0)
        {
            placementMaterial.color      = Color.green;
            rangeIndicatorMaterial.color = Color.green;
            HoverContext.ChangeText("");
        }
        else
        {
            placementMaterial.color      = Color.black;
            rangeIndicatorMaterial.color = Color.red;
            HoverContext.ChangeText(canPlaceText);
        }

        placementParent.position = placePos;
        placementParent.rotation = placeRot;

        if (hitModule)
        {
            placementParent.position += Vector3.forward * (hitModule.transform.position.z - 1);
        }
        else
        {
            placementParent.position -= Vector3.forward * placementParent.position.z;
        }
    }
Exemple #2
0
    void Update()
    {
        HoverContext.StaticUpdate();

        if (isPaused)
        {
            mainAudioSource.volume = SettingsMenu.musicVolume;
        }
    }
 void Start()
 {
     cur = this;
     gameObject.SetActive(false);
 }
    // Update is called once per frame
    void Update()
    {
        // Grap mouse position, and round it.
        worldMousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        pos           = RoundPos(worldMousePos, pModule ? pModule.moduleClass : 1);

        if (rangeIndicator)
        {
            rangeIndicator.GetRange(0f);
        }

        if (Input.GetButtonDown("Cancel"))
        {
            bool isPaused  = Game.isPaused;
            bool anyActive = Game.AnyActiveAboveOverlay();

            if (isPaused)
            {
                Game.game.TogglePause();
            }

            if (!CancelAll())
            {
                CloseAllWindows();
                if (!anyActive && !isPaused)
                {
                    Game.game.TogglePause();
                }
            }
        }

        if (isPlacing && !isEditingWalls && Game.currentScene != Scene.BattlefieldEditor)
        {
            rangeIndicator.transform.position = placementParent.position;

            if (!isRotting)
            {
                placePos = new Vector3(pos.x, pos.y, 0f);
                placeRot = Quaternion.Euler(0, 0, 90f);
            }

            UpdatePlacementSprite();
            GetHitModule();

            indicatorRange = 0f;
            RangeIndicator.ForceRequestRange(activePurchaseCopy, gameObject);

            if (hitModule)
            {
                placeRot = hitModule.transform.rotation;

                if (hitModule.moduleType == Module.Type.Weapon || hitModule.moduleType == Module.Type.Independent)
                {
                    rangeIndicator.GetRange(0f);
                }
                else if (pModule.moduleType == Module.Type.Weapon)
                {
                    if (hitModule.parentBase)
                    {
                        rangeIndicator.GetRange(indicatorRange * hitModule.parentBase.GetRange());
                    }
                    else
                    {
                        rangeIndicator.GetRange(indicatorRange * WeaponModule.indieRange);
                    }
                }
                else
                {
                    rangeIndicator.GetRange(indicatorRange);
                }
            }
            else
            {
                RangeIndicator.ForceRequestRange(pModule.gameObject, rangeIndicator.gameObject);
            }

            if (isRotting)
            {
                ang = Mathf.RoundToInt(Angle.CalculateAngle(placePos, pos) / 90f) * 90;
                if (Input.GetButton("LCtrl"))
                {
                    placeRot = Quaternion.Euler(0, 0, ang);
                }
            }
            else
            {
                ang = placeRot.eulerAngles.z;
            }

            if (Input.GetMouseButtonDown(1))
            {
                CancelPurchase();
            }

            if (!purchaseMenu.isOpen)
            {
                if (Input.GetMouseButtonUp(0))
                {
                    PlaceModule();
                }

                if (Input.GetMouseButtonDown(0))
                {
                    isRotting = true;
                }
            }
        }

        if (!EnemyManager.waveStarted)
        {
            if (!isPlacing && isEditingWalls)
            {
                wallGraphicStart = wallDragGraphic.transform.position + wallDragGraphic.transform.localScale / 2f;
                wallGraphicEnd   = wallDragGraphic.transform.position - wallDragGraphic.transform.localScale / 2f;

                if ((Input.GetMouseButtonDown(1) && wallDragStatus == WallDragStatus.Adding) || (Input.GetMouseButtonDown(0) && wallDragStatus == WallDragStatus.Removing))
                {
                    wallDragStatus = WallDragStatus.Inactive;
                }

                if (Input.GetMouseButtonDown(0) && wallDragStatus == WallDragStatus.Inactive && !(HoverContext.hoveringButton && HoverContext.hoveringButton.tag == "DarkOverlay"))
                {
                    wallDragStatus = WallDragStatus.Adding;
                    wallDragStart  = pos;
                    wallDragStart  = MovePosInsideBattlefield(pos, 0.5f);
                    wallDragGraphic.sharedMaterial.color = Color.green;
                }

                if (Input.GetMouseButtonUp(0) && wallDragStatus == WallDragStatus.Adding)
                {
                    wallDragStatus = WallDragStatus.Inactive;
                    Game.ChangeWalls(new Rect(wallGraphicStart.x, wallGraphicStart.y, wallGraphicEnd.x, wallGraphicEnd.y), Game.WallType.Player);
                    wallDragGraphic.sharedMaterial.color = Color.white;
                    HoverContext.ChangeText("");
                    Game.PlaySFXAudio(placementAudio);
                }


                if (Input.GetMouseButtonDown(1) && wallDragStatus == WallDragStatus.Inactive && !(HoverContext.hoveringButton && HoverContext.hoveringButton.tag == "DarkOverlay"))
                {
                    wallDragStatus = WallDragStatus.Removing;
                    wallDragStart  = MovePosInsideBattlefield(pos, 0.5f);
                    wallDragGraphic.sharedMaterial.color = Color.red;
                }

                if (Input.GetMouseButtonUp(1) && wallDragStatus == WallDragStatus.Removing)
                {
                    wallDragStatus = WallDragStatus.Inactive;
                    Game.ChangeWalls(new Rect(wallGraphicStart.x, wallGraphicStart.y, wallGraphicEnd.x, wallGraphicEnd.y), Game.WallType.None);
                    wallDragGraphic.sharedMaterial.color = Color.white;
                    HoverContext.ChangeText("");
                    Game.PlaySFXAudio(placementAudio);
                }

                if (wallDragStatus != WallDragStatus.Inactive)
                {
                    Vector3 locPos = MovePosInsideBattlefield(pos, 0.5f);

                    wallDragGraphic.transform.localScale            = new Vector3(Mathf.Abs(locPos.x - wallDragStart.x), Mathf.Abs(locPos.y - wallDragStart.y)) + Vector3.one;
                    wallDragGraphic.transform.position              = new Vector3(wallDragStart.x + (locPos.x - wallDragStart.x) / 2f, wallDragStart.y + (locPos.y - wallDragStart.y) / 2f);
                    wallDragGraphic.sharedMaterial.mainTextureScale = new Vector2(wallDragGraphic.transform.localScale.x, wallDragGraphic.transform.localScale.y);

                    //Vector3 absStart = new Vector3(Mathf.Abs(wallDragStart.x), Mathf.Abs(wallDragStart.y));
                    //Vector3 absPos = new Vector3(Mathf.Abs(pos.x), Mathf.Abs(pos.y));



                    Rect rect = Game.PositivizeRect(new Rect(wallGraphicStart.x, wallGraphicStart.y, wallGraphicEnd.x, wallGraphicEnd.y));

                    int rectX = Mathf.RoundToInt(rect.x);
                    int rectY = Mathf.RoundToInt(rect.y);
                    int rectW = Mathf.RoundToInt(rect.width);
                    int rectH = Mathf.RoundToInt(rect.height);

                    if (wallDragStatus == WallDragStatus.Adding)
                    {
                        HoverContext.ChangeText("Cost: " + Game.GetWallingCost(rectX, rectY, rectW, rectH, Game.WallType.Player));
                    }
                    else
                    {
                        HoverContext.ChangeText("Cost: " + Game.GetWallingCost(rectX, rectY, rectW, rectH, Game.WallType.None));
                    }
                }
                else
                {
                    wallDragGraphic.transform.position              = MovePosInsideBattlefield(pos, 0.5f) + Vector3.forward;
                    wallDragGraphic.transform.localScale            = Vector3.one;
                    wallDragGraphic.sharedMaterial.mainTextureScale = new Vector2(wallDragGraphic.transform.localScale.x, wallDragGraphic.transform.localScale.y);
                    HoverContext.ChangeText("");
                }
            }
        }

        if (!isPlacing && !isEditingWalls && Game.currentScene != Scene.BattlefieldEditor)
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, -camDepth * 2f, turretLayer))
            {
                Module mod = hit.collider.GetComponent <Module> ();

                if (HoverContext.cur.IsReachable(mod.transform))
                {
                    hoverMarker.transform.position   = hit.collider.transform.position + Vector3.forward * (camDepth + 1);
                    hoverMarker.transform.localScale = Vector3.one * mod.moduleClass;
                }

                if (isUpgrading)
                {
                    upgradingMarker.transform.position = hit.collider.transform.position + Vector3.right * mod.moduleClass * 2f;
                    if (mod.GetUpgradeCost((int)mod.moduleType) > Game.credits || !mod.IsAssemblyUpgradeable(-1))
                    {
                        upgradingMarker.color = Color.red;
                    }
                    else
                    {
                        upgradingMarker.color = Color.green;
                    }
                }
            }
            else if (contextMenu && !contextMenu.gameObject.activeSelf)
            {
                hoverMarker.transform.position     = Vector3.right * 10000f;
                upgradingMarker.transform.position = (Vector3)(Vector2)(Camera.main.ScreenToWorldPoint(Input.mousePosition) + Vector3.right * 2f) + Vector3.forward * (camDepth + 1f);
                upgradingMarker.color = Color.white;
            }
        }

        if (isUpgrading)
        {
            if (Input.GetMouseButtonDown(1))
            {
                CancelAll();
            }
        }
    }
Exemple #5
0
 void Start()
 {
     cur = this;
     gameObject.SetActive (false);
 }
 void OnMouseEnterElement()
 {
     HoverContext.ChangeText(text);
 }
 void OnMouseExitElement()
 {
     HoverContext.ChangeText("");
 }