détection de l'utilisation de CrossPlatformInput

Toutes les questions sur le développement Mobile, y compris la partie script.
Avatar de l’utilisateur
Paullux
Messages : 68
Inscription : 12 Nov 2015 17:11
Contact :

détection de l'utilisation de CrossPlatformInput

Message par Paullux » 27 Mai 2018 06:32

Bonjour,

Je fais un jeu Android avec des commandes à l'écran, un joystick et des boutons. Pour orienté la caméra, j'utilise aussi le gyroscope du téléphone et un glissé sur l'écran pour orienter la vue.

Le problème est quand je veux utilisé le joystick la vue se retourne, du coup je veux inhiber le glissé sur l'écran lorsque l'appui se situe au niveau du joystick ou des boutons généré par CrossPlatformInput.

Voici le code associé à la caméra aujourd'hui :

Code : Tout sélectionner

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;

public class RotateCamera : MonoBehaviour {

    Vector3 FirstPoint;
    Vector3 SecondPoint;
    float xAngle;
    float yAngle;
    float xAngleTemp;
    float yAngleTemp;

    void Start()
    {
        Input.gyro.enabled = true;
        xAngle = 0;
        yAngle = 0;
        transform.rotation = Quaternion.Euler(yAngle, xAngle, 0);
    }

    void Update()
    {

        if (!Input.gyro.enabled) Input.gyro.enabled = true;
        transform.Rotate(-Input.gyro.rotationRateUnbiased.x, -Input.gyro.rotationRateUnbiased.y, 0);
        float z = transform.eulerAngles.z;
        transform.Rotate(0, 0, -z);

        if (CrossPlatformInputManager.GetAxis("Horizontal") == 0 && CrossPlatformInputManager.GetAxis("Vertical") == 0)
        {
            if (Input.touchCount > 0)
            {
                if (Input.GetTouch(0).phase == TouchPhase.Began)
                {
                    FirstPoint = Input.GetTouch(0).position;
                    xAngleTemp = xAngle;
                    yAngleTemp = yAngle;
                }
                if (Input.GetTouch(0).phase == TouchPhase.Moved)
                {
                    SecondPoint = Input.GetTouch(0).position;
                    xAngle = xAngleTemp + (SecondPoint.x - FirstPoint.x) * 180 / Screen.width;
                    yAngle = yAngleTemp + (SecondPoint.y - FirstPoint.y) * 90 / Screen.height;
                    transform.rotation = Quaternion.Euler(-yAngle, xAngle, 0.0f);
                }
            }
        }
    }
}
Si vous savez comment résoudre le problème, je suis preneur.
J'ai créé un ensemble de jeux :

Un HUB : https://bit.ly/2J6EZTO
Un jeu avec contrôle tactile à l'écran : https://bit.ly/2J3IkTw
Un jeu en VR : https://bit.ly/2h5jdzk
Un jeu en AR : https://bit.ly/2LgMvIo

Il s'agit de FPS pour Android.

Avatar de l’utilisateur
Paullux
Messages : 68
Inscription : 12 Nov 2015 17:11
Contact :

Re: détection de l'utilisation de CrossPlatformInput

Message par Paullux » 27 Mai 2018 15:08

J'ai trouvé :

Code : Tout sélectionner

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
using UnityEngine.EventSystems;

public class RotateCamera : MonoBehaviour {

    Vector3 FirstPoint;
    Vector3 SecondPoint;
    float xAngle;
    float yAngle;
    float xAngleTemp;
    float yAngleTemp;

    void Start()
    {
        Input.gyro.enabled = true;
        xAngle = 0;
        yAngle = 0;
        transform.rotation = Quaternion.Euler(yAngle, xAngle, 0);
    }

    void Update()
    {

        if (!Input.gyro.enabled) Input.gyro.enabled = true;
        transform.Rotate(-Input.gyro.rotationRateUnbiased.x, -Input.gyro.rotationRateUnbiased.y, 0);
        float z = transform.eulerAngles.z;
        transform.Rotate(0, 0, -z);


        if (Input.touchCount > 0 && !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
        {
            if (Input.GetTouch(0).phase == TouchPhase.Began)
            {
                FirstPoint = Input.GetTouch(0).position;
                xAngleTemp = xAngle;
                yAngleTemp = yAngle;
            }
            if (Input.GetTouch(0).phase == TouchPhase.Moved)
            {
                SecondPoint = Input.GetTouch(0).position;
                xAngle = xAngleTemp + (SecondPoint.x - FirstPoint.x) * 180 / Screen.width;
                yAngle = yAngleTemp + (SecondPoint.y - FirstPoint.y) * 90 / Screen.height;
                transform.rotation = Quaternion.Euler(-yAngle, xAngle, 0.0f);
            }
        }
    }
}
J'ai créé un ensemble de jeux :

Un HUB : https://bit.ly/2J6EZTO
Un jeu avec contrôle tactile à l'écran : https://bit.ly/2J3IkTw
Un jeu en VR : https://bit.ly/2h5jdzk
Un jeu en AR : https://bit.ly/2LgMvIo

Il s'agit de FPS pour Android.

Répondre

Revenir vers « Développement plateformes mobile Iphone et Android »