コード例 #1
0
ファイル: UICircularMenu.cs プロジェクト: Szejp/SurvivalGame
    private void Update()
    {
        if (!Application.isPlaying)
        {
            return;
        }

        if (Input.GetMouseButtonDown(1))
        {
            BuilderBehaviour.Instance.ChangeMode(BuildMode.None);
        }

        if (Controller == ControllerType.KeyboardAndTouch ? Input.GetKeyDown(OpenCircularKey) : Input.GetButtonDown(GamepadInputOpenName))
        {
            Show();
        }
        else if (Controller == ControllerType.KeyboardAndTouch ? Input.GetKeyUp(OpenCircularKey) : Input.GetButtonUp(GamepadInputOpenName))
        {
            Hide();
        }

        if (!IsActive)
        {
            return;
        }

        Selection.fillAmount = Mathf.Lerp(Selection.fillAmount, Fill, .2f);

        Vector3 BoundsScreen = new Vector3((float)Screen.width / 2f, (float)Screen.height / 2f, 0f);

        Vector3 RelativeBounds = Input.mousePosition - BoundsScreen;

        float CurrentRotation = ((Controller == ControllerType.KeyboardAndTouch) ? Mathf.Atan2(RelativeBounds.x, RelativeBounds.y)
            : Mathf.Atan2(CrossPlatformInputManager.GetAxis(GamepadInputAxisX), CrossPlatformInputManager.GetAxis(GamepadInputAxisY))) * 57.29578f;

        if (CurrentRotation < 0f)
        {
            CurrentRotation += 360f;
        }

        float CursorRot = -(CurrentRotation - Selection.fillAmount * 360f / 2f);

        float Average = 9999;

        GameObject Nearest = null;

        for (int i = 0; i < Elements; i++)
        {
            GameObject Temp = CurrentCategory.Buttons[i].gameObject;

            Temp.transform.localScale = Vector3.one;

            float Rotation = Convert.ToSingle(Temp.name);

            if (Mathf.Abs(Rotation - CurrentRotation) < Average)
            {
                Nearest = Temp;

                Average = Mathf.Abs(Rotation - CurrentRotation);
            }
        }

        SelectedSeg = Nearest;

        CursorRot = -(Convert.ToSingle(SelectedSeg.name) - Selection.fillAmount * 360f / 2f);

        Selection.transform.localRotation = Quaternion.Slerp(Selection.transform.localRotation, Quaternion.Euler(0, 0, CursorRot), 15f * Time.deltaTime);

        for (int i = 0; i < Elements; i++)
        {
            UICircularButton Button = CurrentCategory.Buttons[i].GetComponent <UICircularButton>();

            if (Button.gameObject != SelectedSeg)
            {
                Button.Icon.color = Color.Lerp(Button.Icon.color, ButtonNormalColor, 15f * Time.deltaTime);
            }
            else
            {
                Button.Icon.color = Color.Lerp(Button.Icon.color, ButtonHoverColor, 15f * Time.deltaTime);
            }
        }

        CurrentCategory.NavigationText.text = SelectedSeg.GetComponent <UICircularButton>().Text;

        if (Input.GetMouseButtonUp(0))
        {
            SelectedSeg.GetComponent <UICircularButton>().Animator.Play(SelectedSeg.GetComponent <UICircularButton>().AnimatorPressStateName);

            SelectedSeg.GetComponent <UICircularButton>().Actions.Invoke();
        }
    }
コード例 #2
0
    private void Update()
    {
        if (!Application.isPlaying)
        {
            return;
        }

#if WINTERBYTE
        if (BaseBuilder.Instance.CurrentMode == BuildMode.Placement)
        {
            if (BaseBuilder.Instance.CurrentPreview == null)
            {
                return;
            }

            if (BaseBuilder.Instance.CurrentPreview.GetComponent <CustomGenericPart>() == null)
            {
                return;
            }

            if (!BaseBuilder.Instance.CurrentPreview.GetComponent <CustomGenericPart>().HasRequiredPlacementItems())
            {
                BaseBuilder.Instance.ChangeMode(BuildMode.None);
            }
        }

        if (!BuildingWheel.Window.IsOpen)
        {
            return;
        }
#else
        if (Input.GetMouseButtonDown(1))
        {
            BaseBuilder.Instance.ChangeMode(BuildMode.None);
        }

        if (Controller == ControllerType.Keyboard ? Input.GetKeyDown(OpenCircularKey) : Input.GetButtonDown(GamepadInputOpenName))
        {
            for (int i = 0; i < ElementsAtDisabled.Length; i++)
            {
                ElementsAtDisabled[i].SetActive(false);
            }

            Animator.CrossFade(ShowStateName, 0.1f);

            Cursor.lockState = CursorLockMode.None;
            Cursor.visible   = true;

            IsActive = true;
        }
        else if (Controller == ControllerType.Keyboard ? Input.GetKeyUp(OpenCircularKey) : Input.GetButtonUp(GamepadInputOpenName))
        {
            for (int i = 0; i < ElementsAtDisabled.Length; i++)
            {
                ElementsAtDisabled[i].SetActive(true);
            }

            Animator.CrossFade(HideStateName, 0.1f);

            Cursor.lockState = CursorLockMode.Locked;
            Cursor.visible   = false;

            IsActive = false;
        }

        if (Blur != null)
        {
            Blur.enabled = (Controller == ControllerType.Keyboard ? Input.GetKey(OpenCircularKey) : Input.GetButton(GamepadInputOpenName));
        }

        if (!IsActive)
        {
            return;
        }
#endif

        Selection.fillAmount = Mathf.Lerp(Selection.fillAmount, Fill, .2f);

        Vector3 BoundsScreen = new Vector3((float)Screen.width / 2f, (float)Screen.height / 2f, 0f);

        Vector3 RelativeBounds = Input.mousePosition - BoundsScreen;

        float CurrentRotation = ((Controller == ControllerType.Keyboard) ? Mathf.Atan2(RelativeBounds.x, RelativeBounds.y) : Mathf.Atan2(Input.GetAxis(GamepadInputAxisX), Input.GetAxis(GamepadInputAxisY))) * 57.29578f;

        if (CurrentRotation < 0f)
        {
            CurrentRotation += 360f;
        }

        float CursorRot = -(CurrentRotation - Selection.fillAmount * 360f / 2f);

        float Average = 9999;

        GameObject Nearest = null;

        for (int i = 0; i < Elements; i++)
        {
            GameObject Temp = CurrentCategory.Buttons[i].gameObject;

            Temp.transform.localScale = Vector3.one;

            float Rotation = System.Convert.ToSingle(Temp.name);

            if (Mathf.Abs(Rotation - CurrentRotation) < Average)
            {
                Nearest = Temp;

                Average = Mathf.Abs(Rotation - CurrentRotation);
            }
        }

        SelectedSegment = Nearest;

        CursorRot = -(System.Convert.ToSingle(SelectedSegment.name) - Selection.fillAmount * 360f / 2f);

        Selection.transform.localRotation = Quaternion.Slerp(Selection.transform.localRotation, Quaternion.Euler(0, 0, CursorRot), 15f * Time.deltaTime);

        for (int i = 0; i < Elements; i++)
        {
            UICircularButton Button = CurrentCategory.Buttons[i].GetComponent <UICircularButton>();

            if (Button.gameObject != SelectedSegment)
            {
                Button.Icon.color = Color.Lerp(Button.Icon.color, ButtonNormalColor, 15f * Time.deltaTime);
            }
            else
            {
                Button.Icon.color = Color.Lerp(Button.Icon.color, ButtonHoverColor, 15f * Time.deltaTime);
            }
        }

        CurrentCategory.NavigationText.text = SelectedSegment.GetComponent <UICircularButton>().Text;

        if (Input.GetMouseButtonUp(0))
        {
            SelectedSegment.GetComponent <UICircularButton>().Animator.Play(SelectedSegment.GetComponent <UICircularButton>().AnimatorPressStateName);

            SelectedSegment.GetComponent <UICircularButton>().Actions.Invoke();
        }
    }