Beispiel #1
0
    void OnGUI()
    {
        if (Time.time != 0 && Time.timeScale != 0)
        {
            if (player != null)
            {
                if (GameApp.GetInstance().GetGameScene().PlayingState == PlayingState.GamePlaying && player.InputController.EnableShootingInput)
                {
                    Weapon weapon = player.GetWeapon();
                    if (weapon != null)
                    {
                        if (weapon.GetWeaponType() == WeaponType.Sniper)
                        {
                            GUI.DrawTexture(new Rect((Sniper.lockAreaRect.xMin - AutoRect.AutoValue(leftTopReticle.width / 2)), (Sniper.lockAreaRect.yMin - AutoRect.AutoValue(leftTopReticle.height / 2)), AutoRect.AutoValue(leftTopReticle.width), AutoRect.AutoValue(leftTopReticle.height)), leftTopReticle);
                            GUI.DrawTexture(new Rect((Sniper.lockAreaRect.xMax - AutoRect.AutoValue(rightTopReticle.width / 2)), (Sniper.lockAreaRect.yMin - AutoRect.AutoValue(rightTopReticle.height / 2)), AutoRect.AutoValue(rightTopReticle.width), AutoRect.AutoValue(rightTopReticle.height)), rightTopReticle);
                            GUI.DrawTexture(new Rect((Sniper.lockAreaRect.xMin - AutoRect.AutoValue(leftBottomReticle.width / 2)), (Sniper.lockAreaRect.yMax - AutoRect.AutoValue(leftBottomReticle.height / 2)), AutoRect.AutoValue(leftBottomReticle.width), AutoRect.AutoValue(leftBottomReticle.height)), leftBottomReticle);
                            GUI.DrawTexture(new Rect((Sniper.lockAreaRect.xMax - AutoRect.AutoValue(rightBottomReticle.width / 2)), (Sniper.lockAreaRect.yMax - AutoRect.AutoValue(rightBottomReticle.height / 2)), AutoRect.AutoValue(rightBottomReticle.width), AutoRect.AutoValue(rightBottomReticle.height)), rightBottomReticle);


                            Sniper sniper = (Sniper)weapon;
                            List <NearestEnemyInfo> neis = sniper.GetNearestEnemyInfoList();
                            foreach (NearestEnemyInfo info in neis)
                            {
                                GUI.DrawTexture(new Rect(info.currentScreenPos.x - AutoRect.AutoValue((reticle.width * 0.5f)), info.currentScreenPos.y - AutoRect.AutoValue((reticle.height * 0.5f)), AutoRect.AutoValue(reticle.width), AutoRect.AutoValue(reticle.height)), reticle);
                            }
                        }
                        else
                        {
                            //Debug.Log(reticlePosition.x);
                            GUI.DrawTexture(new Rect(reticlePosition.x - AutoRect.AutoValue(reticle.width * 0.5f * mutipleSizeReticle), reticlePosition.y - AutoRect.AutoValue((reticle.height * 0.5f * mutipleSizeReticle)), AutoRect.AutoValue(reticle.width * mutipleSizeReticle), AutoRect.AutoValue(reticle.height * mutipleSizeReticle)), reticle);
                        }
                    }
                }
            }
        }
    }
Beispiel #2
0
        public void Init()
        {
            thumbCenter.x = AutoRect.AutoX(110);
            thumbCenter.y = AutoRect.AutoY(530);
            thumbRadius   = AutoRect.AutoValue(85);


            shootThumbCenter.x = AutoRect.AutoX(852);
            shootThumbCenter.y = AutoRect.AutoY(530);

            if (AutoRect.GetPlatform() == Platform.IPad)
            {
                thumbCenter.x      = AutoRect.AutoX(66);
                shootThumbCenter.x = AutoRect.AutoX(896);
                thumbCenter.y      = AutoRect.AutoY(500);
                shootThumbCenter.y = AutoRect.AutoY(500);
            }



            thumbCenterToScreen      = new Vector2(thumbCenter.x, Screen.height - thumbCenter.y);
            shootThumbCenterToScreen = new Vector2(shootThumbCenter.x, Screen.height - shootThumbCenter.y);

            lastShootTouch = shootThumbCenterToScreen;
            for (int i = 0; i < 2; i++)
            {
                lastTouch[i] = new Touch();
            }

            gameScene = GameApp.GetInstance().GetGameScene();
            player    = gameScene.GetPlayer();

            EnableMoveInput     = true;
            EnableShootingInput = true;
            EnableTurningAround = true;
        }
Beispiel #3
0
    public void HandleEvent(UIControl control, int command, float wparam, float lparam)
    {
        if (control == m_UIMove)
        {
            if (command == (int)(UIMove.Command.Move))
            {
                if (m_LongPressSelectionIndex == -1)
                {
                    m_lastBeginPressTime      = -1;
                    m_LongPressSelectionIndex = -1;

                    if (m_Dir == ScrollerDir.Horizontal)
                    {
                        m_ScrollerPos += wparam;
                    }
                    else if (m_Dir == ScrollerDir.Vertical)
                    {
                        m_ScrollerPos += lparam;
                    }
                    m_LastMove = new Vector2((wparam), lparam);
                    m_fingerOn = true;
                }
                else
                {
                }
            }
            else if (command == (int)(UIMove.Command.MovePos))
            {
                if (m_LongPressSelectionIndex != -1)
                {
                    m_Parent.SendEvent(this, (int)Command.DragMove, wparam, lparam);
                }
                else
                {
                    if (m_EnableLongPress)
                    {
                        float   x          = (int)(m_ClipRect.x + 0.5f * (m_ClipRect.width - m_IconWidth));
                        float   y          = m_CenterPos;
                        Rect    centerRect = new Rect(x, y, m_IconWidth, m_IconHeight);
                        Vector2 diffPos    = m_BeginPos - new Vector2(wparam, lparam);
                        if (diffPos.sqrMagnitude > AutoRect.AutoValue(10) * AutoRect.AutoValue(10))
                        {
                            if (Mathf.Abs(diffPos.x) > Mathf.Abs(diffPos.y))
                            {
                                m_LongPressSelectionIndex = m_SelectionIndex;
                                m_Parent.SendEvent(this, (int)Command.PressSelect, m_SelectionIndex, 0);
                            }
                            else
                            {
                                m_bMoveNotDrag = true;
                            }
                        }
                    }
                }
            }
            else if (command == (int)(UIMove.Command.End))
            {
                float x = Mathf.Clamp(m_LastMove.x, -30, 30);
                float y = Mathf.Clamp(m_LastMove.y, -30, 30);
                m_Velocity = new Vector2(x, y);
                m_fingerOn = false;
                m_LastMove = Vector2.zero;

                if (m_EnableLongPress)
                {
                    m_lastBeginPressTime      = -1;
                    m_LongPressSelectionIndex = -1;
                    m_Parent.SendEvent(this, (int)Command.PressEnd, wparam, lparam);
                }
            }
            else if (command == (int)(UIMove.Command.Begin))
            {
                if (m_EnableLongPress)
                {
                    m_BeginPos = new Vector2(wparam, lparam);
                    float x          = (int)(m_ClipRect.x + 0.5f * (m_ClipRect.width - m_IconWidth));
                    float y          = m_CenterPos;
                    Rect  centerRect = new Rect(x, y, m_IconWidth, m_IconHeight);
                    if (centerRect.Contains(new Vector2(wparam, lparam)))
                    {
                        if (m_lastBeginPressTime == -1)
                        {
                            m_lastBeginPressTime = Time.time;
                        }
                    }
                }
            }
        }
    }
Beispiel #4
0
    // Update is called once per frame
    void Update()
    {
        timeLeft -= Time.deltaTime;

        accum += Time.timeScale / Time.deltaTime;
        frames++;

        if (timeLeft <= 0)
        {
            fpsStr   = "FPS:" + (accum / frames).ToString();
            frames   = 0;
            accum    = 0;
            timeLeft = updateInterval;
        }

        if (uiInited)
        {
            fpsText.SetText(fpsStr);
            dayInfoPanel.UpdateAnimation();
            panels[GameUIName.GAME_OVER].UpdateLogic();

            if (FadeAnimationScript.GetInstance().FadeOutComplete())
            {
                foreach (UITouchInner touch in iPhoneInputMgr.MockTouches())
                {
                    if (m_UIManager.HandleInput(touch))
                    {
                        continue;
                    }
                }
            }


            if (gameScene.PlayingState == PlayingState.GameWin)
            {
                dayclear.Visible = true;
            }

            if (!GameApp.GetInstance().GetGameScene().GetPlayer().InputController.EnableShootingInput)
            {
                semiMask.Visible = true;
            }
            else
            {
                semiMask.Visible = false;
            }
        }

        if (Time.time - lastUpdateTime < 0.03f || !uiInited)
        {
            return;
        }

        lastUpdateTime = Time.time;


        if (player != null)
        {
            InputController inputController = player.InputController;

            float guihp      = player.GetGuiHp();
            float guihpWidth = uiPos.HPImage.width * guihp / player.GetMaxHp();


            int g = (int)guihpWidth;
            if (g % 2 != 0)
            {
                g += 1;
            }
            if (hpImage != null)
            {
                hpImage.Rect = AutoRect.AutoPos(new Rect(uiPos.HPImage.xMin, uiPos.HPImage.yMin, g, uiPos.HPImage.height));
                hpImage.SetTexture(gameuiMaterial, GameUITexturePosition.GetHPTextureRect(g), AutoRect.AutoSize(GameUITexturePosition.GetHPTextureRect(g)));
            }

            cashText.SetText("$" + GameApp.GetInstance().GetGameState().GetCash().ToString("N0"));

            Weapon weapon = player.GetWeapon();
            if (weapon.GetWeaponType() == WeaponType.Saw)
            {
                weaponInfoText.SetText("");
            }
            else
            {
                weaponInfoText.SetText(" x" + weapon.BulletCount);
            }

            PlayingState playingState = gameScene.PlayingState;
            Vector2      lastTouchPos = inputController.LastTouchPos;

            joystickThumb.Rect = new Rect(lastTouchPos.x - AutoRect.AutoValue(0.5f * GameUITexturePosition.MoveJoystickThumb.width), lastTouchPos.y - AutoRect.AutoValue(0.5f * GameUITexturePosition.MoveJoystickThumb.height), AutoRect.AutoValue(GameUITexturePosition.MoveJoystickThumb.width), AutoRect.AutoValue(GameUITexturePosition.MoveJoystickThumb.height));

            shootjoystickThumb.Rect = new Rect(inputController.LastShootTouch.x - AutoRect.AutoValue(0.5f * GameUITexturePosition.ShootJoystickThumb.width), inputController.LastShootTouch.y - AutoRect.AutoValue(0.5f * GameUITexturePosition.ShootJoystickThumb.height), AutoRect.AutoValue(GameUITexturePosition.ShootJoystickThumb.width), AutoRect.AutoValue(GameUITexturePosition.ShootJoystickThumb.height));

            /*
             *
             *
             *
             * Vector2 thumbCenter = inputController.ThumbCenter;
             * joystickImage.Rect = new Rect((thumbCenter.x - inputController.ThumbRadius), ((Screen.height - thumbCenter.y) - inputController.ThumbRadius), AutoRect.AutoValue(169), AutoRect.AutoValue(168));
             * thumbCenter = inputController.ShootThumbCenter;
             * shootjoystickImage.Rect = new Rect((thumbCenter.x - inputController.ThumbRadius), ((Screen.height - thumbCenter.y) - inputController.ThumbRadius), AutoRect.AutoValue(169), AutoRect.AutoValue(168));
             *
             *
             * if (inputController.GetMoveTouchFingerID() == -1)
             * {
             *  joystickImage.Visible = false;
             *  joystickThumb.Visible = false;
             * }
             * else
             * {
             *  joystickImage.Visible = true;
             *  joystickThumb.Visible = true;
             * }
             *
             * if (inputController.GetShootingTouchFingerID() == -1)
             * {
             *  shootjoystickImage.Visible = false;
             *  shootjoystickThumb.Visible = false;
             * }
             * else
             * {
             *  shootjoystickImage.Visible = true;
             *  shootjoystickThumb.Visible = true;
             * }
             */
        }
    }
Beispiel #5
0
    // Use this for initialization
    IEnumerator Start()
    {
        yield return(0);

        uiPos = new UIPosition();
        //texPos = new GameUITexturePosition();

        float screenRatioX = ((float)Screen.width) / 960.00f;

        buttonRect = new Rect[4];
        buttonRect[ButtonNames.WEAPON_SWITCH] = new Rect(650, 540, 205, 89);
        buttonRect[ButtonNames.BOMB]          = new Rect(0.4f * Screen.width, 0.25f * Screen.height, 0.24f * Screen.width, 0.08f * Screen.height);
        buttonRect[ButtonNames.CONTINUE]      = new Rect(0.4f * Screen.width, 0.25f * Screen.height, 0.14f * Screen.width, 0.14f * Screen.height);
        buttonRect[ButtonNames.START_OVER]    = new Rect(0.4f * Screen.width, 0.25f * Screen.height, 0.14f * Screen.width, 0.14f * Screen.height);


        if (AutoRect.GetPlatform() == Platform.IPad)
        {
            uiPos.PlayerLogo           = new Rect(-16 - 32, 566 + 64, 116, 81);
            uiPos.PlayerLogoBackground = new Rect(0 - 32, 556 + 64, 134, 88);
            uiPos.HPBackground         = new Rect(94 - 32, 590 - 12 + 64, 288, 50);
            uiPos.HPImage = new Rect(94 - 32, 590 - 12 + 64, 288, 50);
            uiPos.WeaponLogoBackground = new Rect(960 - 148 + 32, 640 - 74 + 54, 148, 88);
            uiPos.WeaponLogo           = new Rect(960 - 180 + 32, 640 - 84 + 64, 194, 112);
            uiPos.BulletsLogo          = new Rect(960 - 420 + 32, 640 - 94 + 64, 194, 112);
            uiPos.WeaponInfo           = new Rect(656 + 32, 558 + 64, 100, 64);
            uiPos.PauseButton          = new Rect(408, 588, 160, 166);
            uiPos.CashText             = new Rect(0, 576 + 64, 1024, 64);
            uiPos.Mask   = new Rect(0, 0, 1024, 768);
            uiPos.Switch = new Rect(960 - 268 + 32, 640 - 90 + 12 + 64, 148, 88);
        }



        gameScene = GameApp.GetInstance().GetGameScene();
        player    = gameScene.GetPlayer();

        m_UIManager = gameObject.AddComponent <UIManager>() as UIManager;
        m_UIManager.SetParameter(8, 1, false);
        m_UIManager.SetUIHandler(this);



        int  avatarLogoIndex = (int)player.GetAvatarType();
        Rect logoRect        = GameUITexturePosition.GetAvatarLogoRect(avatarLogoIndex);

        //Player Logo
        playerLogoImage      = new UIImage();
        playerLogoImage.Rect = AutoRect.AutoPos(uiPos.PlayerLogo);

        playerLogoImage.SetTexture(gameuiMaterial, logoRect, AutoRect.AutoSize(logoRect));
        //playerLogoImage.SetTextureSize(new Vector2(texPos.PlayerLogo.width, texPos.PlayerLogo.height));

        //HP
        hpBackground = new UIImage();
        hpBackground.SetTexture(gameuiMaterial, GameUITexturePosition.HPBackground, AutoRect.AutoSize(GameUITexturePosition.HPBackground));
        hpBackground.Rect = AutoRect.AutoPos(uiPos.HPBackground);


        dayclear = new UIImage();
        dayclear.SetTexture(gameuiMaterial, GameUITexturePosition.DayClear, AutoRect.AutoSize(GameUITexturePosition.DayClear));
        dayclear.Rect    = AutoRect.AutoPos(uiPos.DayClear);
        dayclear.Visible = false;
        dayclear.Enable  = false;
        hpImage          = new UIImage();
        hpImage.SetTexture(gameuiMaterial, GameUITexturePosition.HPImage, AutoRect.AutoSize(GameUITexturePosition.HPImage));


        playerLogoBackgroundImage = new UIImage();
        playerLogoBackgroundImage.SetTexture(gameuiMaterial, GameUITexturePosition.PlayerLogoBackground, AutoRect.AutoSize(GameUITexturePosition.PlayerLogoBackground));
        playerLogoBackgroundImage.Rect = AutoRect.AutoPos(uiPos.PlayerLogoBackground);

        //Weapon Switch
        weaponBackground      = new UIImage();
        weaponBackground.Rect = AutoRect.AutoPos(uiPos.WeaponLogoBackground);
        weaponBackground.SetTexture(gameuiMaterial, GameUITexturePosition.WeaponLogoBackground, AutoRect.AutoSize(GameUITexturePosition.WeaponLogoBackground));


        int  weaponLogoIndex = GameApp.GetInstance().GetGameState().GetWeaponIndex(player.GetWeapon());
        Rect weaponlogoRect  = GameUITexturePosition.GetWeaponLogoRect(weaponLogoIndex);

        weaponLogo      = new UIClickButton();
        weaponLogo.Rect = AutoRect.AutoPos(uiPos.WeaponLogo);
        weaponLogo.SetTexture(UIButtonBase.State.Normal, gameuiMaterial, weaponlogoRect, AutoRect.AutoSize(weaponlogoRect));
        weaponLogo.SetTexture(UIButtonBase.State.Pressed, gameuiMaterial, weaponlogoRect, AutoRect.AutoSize(weaponlogoRect));


        switchImg      = new UIImage();
        switchImg.Rect = AutoRect.AutoPos(uiPos.Switch);
        switchImg.SetTexture(gameuiMaterial, GameUITexturePosition.Switch, AutoRect.AutoSize(GameUITexturePosition.Switch));
        switchImg.Enable = true;

        Material buttonsMaterial = UIResourceMgr.GetInstance().GetMaterial("Buttons");

        bulletsLogo      = new UIImage();
        bulletsLogo.Rect = AutoRect.AutoPos(uiPos.BulletsLogo);
        Rect bulletlogoRect = ButtonsTexturePosition.GetBulletsLogoRect((int)player.GetWeapon().GetWeaponType());

        bulletsLogo.SetTexture(buttonsMaterial, bulletlogoRect, AutoRect.AutoSize(bulletlogoRect));
        bulletsLogo.Enable = false;



        InputController inputController = player.InputController;
        //Move Joystick
        Vector2 thumbCenter = inputController.ThumbCenter;

        joystickImage      = new UIImage();
        joystickImage.Rect = new Rect((thumbCenter.x - inputController.ThumbRadius), ((Screen.height - thumbCenter.y) - inputController.ThumbRadius), AutoRect.AutoValue(169), AutoRect.AutoValue(168));
        joystickImage.SetTexture(gameuiMaterial, GameUITexturePosition.MoveJoystick, AutoRect.AutoSize(GameUITexturePosition.MoveJoystick));

        joystickThumb = new UIImage();
        joystickThumb.SetTexture(gameuiMaterial, GameUITexturePosition.MoveJoystickThumb, AutoRect.AutoSize(GameUITexturePosition.MoveJoystickThumb));

        thumbCenter             = inputController.ShootThumbCenter;
        shootjoystickImage      = new UIImage();
        shootjoystickImage.Rect = new Rect((thumbCenter.x - inputController.ThumbRadius), ((Screen.height - thumbCenter.y) - inputController.ThumbRadius), AutoRect.AutoValue(169), AutoRect.AutoValue(168));
        shootjoystickImage.SetTexture(gameuiMaterial, GameUITexturePosition.ShootJoystick, AutoRect.AutoSize(GameUITexturePosition.ShootJoystick));
        shootjoystickImage.SetRotation(Mathf.Deg2Rad * 180);

        shootjoystickThumb = new UIImage();
        shootjoystickThumb.SetTexture(gameuiMaterial, GameUITexturePosition.ShootJoystickThumb, AutoRect.AutoSize(GameUITexturePosition.ShootJoystickThumb));


        pauseButton      = new UIClickButton();
        pauseButton.Rect = AutoRect.AutoPos(uiPos.PauseButton);
        pauseButton.SetTexture(UIButtonBase.State.Normal, gameuiMaterial, GameUITexturePosition.PauseButtonNormal, AutoRect.AutoSize(GameUITexturePosition.PauseButtonNormal));
        pauseButton.SetTexture(UIButtonBase.State.Pressed, gameuiMaterial, GameUITexturePosition.PauseButtonPressed, AutoRect.AutoSize(GameUITexturePosition.PauseButtonPressed));


        //Cash
        cashText = new UIText();
        //cashText.Rect = new Rect(0.05f * Screen.width, 0.75f * Screen.height, 400, 50);
        cashText.AlignStyle = UIText.enAlignStyle.center;
        cashText.Rect       = AutoRect.AutoPos(uiPos.CashText);
        cashText.Set(ConstData.FONT_NAME1, "$" + GameApp.GetInstance().GetGameState().GetCash().ToString("N0"), ColorName.fontColor_orange);



        //Weapon Info
        weaponInfoText            = new UIText();
        weaponInfoText.AlignStyle = UIText.enAlignStyle.left;

        weaponInfoText.Rect = AutoRect.AutoPos(uiPos.WeaponInfo);
        weaponInfoText.Set(ConstData.FONT_NAME2, fpsStr, ColorName.fontColor_darkorange);



        fpsText            = new UIText();
        fpsText.AlignStyle = UIText.enAlignStyle.left;
        fpsText.Rect       = AutoRect.AutoPos(uiPos.LevelInfo);
        fpsText.Set(ConstData.FONT_NAME3, "", Color.white);

        dayInfoPanel = new DayInfoPanel();
        dayInfoPanel.SetDay(GameApp.GetInstance().GetGameState().LevelNum);

        mask = new UIImage();
        mask.SetTexture(gameuiMaterial, GameUITexturePosition.Mask, AutoRect.AutoSize(uiPos.Mask));
        mask.Rect = AutoRect.AutoValuePos(uiPos.Mask);

        Vector2 size = AutoRect.AutoSize(GameUITexturePosition.SemiMaskSize);
        Rect    pos  = AutoRect.AutoPos(uiPos.RightSemiMask);

        if (AutoRect.GetPlatform() == Platform.IPad)
        {
            size = new Vector2(512, 768);
            pos  = new Rect(512, 0, 512, 768);
        }
        semiMask = new UIImage();
        semiMask.SetTexture(gameuiMaterial, GameUITexturePosition.Mask, size);
        semiMask.Rect = pos;



        unlockPanel = new UnlockPanel();


        m_UIManager.Add(dayInfoPanel);
        m_UIManager.Add(hpBackground);
        m_UIManager.Add(hpImage);
        m_UIManager.Add(playerLogoBackgroundImage);
        m_UIManager.Add(playerLogoImage);
        m_UIManager.Add(joystickImage);
        m_UIManager.Add(joystickThumb);
        m_UIManager.Add(shootjoystickImage);
        m_UIManager.Add(shootjoystickThumb);
        m_UIManager.Add(weaponBackground);
        m_UIManager.Add(weaponLogo);
        m_UIManager.Add(switchImg);
        m_UIManager.Add(pauseButton);
        m_UIManager.Add(semiMask);
        if (Application.loadedLevelName == SceneName.SCENE_TUTORIAL)
        {
            m_UIManager.Add(dialog);
        }
        m_UIManager.Add(bulletsLogo);
        m_UIManager.Add(weaponInfoText);
        //m_UIManager.Add(cashText);
        m_UIManager.Add(mask);

        m_UIManager.Add(dayclear);
        //m_UIManager.Add(fpsText);

        m_UIManager.Add(unlockPanel);


        semiMask.Enable  = false;
        semiMask.Visible = false;
        dayInfoPanel.Show();
        uiInited = true;

        EnableTutorialOKButton(false);
        mask.Enable  = false;
        mask.Visible = false;

        SetWeaponLogo(player.GetWeapon().GetWeaponType());

        panels[GameUIName.PAUSE] = new PauseMenuUI();
        ((PauseMenuUI)panels[GameUIName.PAUSE]).SetGameUIScript(this);

        panels[GameUIName.GAME_OVER] = new GameOverUI();
        panels[GameUIName.NEW_ITEM]  = new NewItemUI();

        //unlockPanel.Show();
        for (int i = 0; i < GameUIName.UI_COUNT; i++)
        {
            m_UIManager.Add(panels[i]);
        }
        startTime = Time.time;
    }