// Use this for initialization
 void Start()
 {
     levelChoice = 0;
     image       = gameObject.GetComponent <Image>();
     RPCWrapper.RegisterMethod(UpdateColorWin);
     RPCWrapper.RegisterMethod(LoadWeaponLevel);
 }
	public void ValidateLevel(){
		if(levelChosen != 0){
			RPCWrapper.RPC("LoadWeaponLevel", RPCMode.Server);
			Application.LoadLevel ("Android - WeaponScene");
			PhaseLoader.Prepare (levelChosen);
		}
	}
    public void ValidateButtonPressed()
    {
        RPCWrapper.RPC("TryLaunchingGame", RPCMode.Server);

        // Register LoadGame() in the RPC wrapper.
        RPCWrapper.RegisterMethod(LoadGame);
    }
    void Start()
    {
        RPCWrapper.RegisterMethod(UpdateRoll);
        RPCWrapper.RegisterMethod(JumpPlayer);

        GetReferenceToPlayer();
        GetReferenceToWorld();
    }
 // Launch the game if the play "button" is targetted when the user press the button on his tablet.
 public void TryLaunchingGame()
 {
     if (targetted)
     {
         RPCWrapper.RPC("LoadGame", RPCMode.Others);              // Say the clients to launch the game.
         Application.LoadLevel("Windows - LevelScene");
     }
 }
    private void Start()
    {
        // Get the image component.
        imageComponent = gameObject.GetComponent <SpriteRenderer>();

        // Register in the RPC wrapper.
        RPCWrapper.RegisterMethod(SetTargetActive);

        // In the doubt. Note that the aiming manager will call this method as soon as it begins.
        SetTargetActive(false);
    }
 // Make the average between the two corner (compute center), and calculate position of the corners in the screen space. Stop the camera, not needed anymore.
 private void ComputeCenterCalibration()
 {
     centerCalibration       = Quaternion.Slerp(upperLeftCalibration, lowerRightCalibration, 0.5f);
     localUpperLeftRotation  = Quaternion.Inverse(upperLeftCalibration) * centerCalibration;
     localLowerRightRotation = Quaternion.Inverse(lowerRightCalibration) * centerCalibration;
     calibrating             = false;
     RPCWrapper.RPC("SetTargetActive", RPCMode.Server, !calibrating);
     if (!alwaysDisplayCamera)
     {
         cameraStream.Stop();
     }
 }
    private void OnGUI()
    {
        if (cameraStream.isPlaying)         // Display camera.
        {
            GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), cameraStream, ScaleMode.ScaleAndCrop);
        }

        if (calibrating)         // Calibration buttons.
        {
            if (!upperLeftCalibrationDone && GUILayout.Button("Upper left calibration", GUILayout.Height(150)))
            {
                upperLeftCalibration     = Input.gyro.attitude;
                upperLeftCalibrationDone = true;
                if (lowerRightCalibrationDone)
                {
                    ComputeCenterCalibration();
                }
            }
            if (!lowerRightCalibrationDone && GUILayout.Button("Lower right calibration", GUILayout.Height(150)))
            {
                lowerRightCalibration     = Input.gyro.attitude;
                lowerRightCalibrationDone = true;
                if (upperLeftCalibrationDone)
                {
                    ComputeCenterCalibration();
                }
            }
        }
        else         // Recalibrate button.
        if (GUILayout.Button("Recalibrate", GUILayout.Height(150)))
        {
            upperLeftCalibrationDone  = false;
            lowerRightCalibrationDone = false;
            calibrating = true;
            RPCWrapper.RPC("SetTargetActive", RPCMode.Server, !calibrating);
            if (!cameraStream.isPlaying)                     // If the camera is not already playing and we want to recalibrate.
            {
                cameraStream.Play();
            }
        }

        if (debugMode)
        {
            GUILayout.Label("Upper left : " + (upperLeftCalibrationDone ? localUpperLeftRotation.ToString() : "None"));
            GUILayout.Label("Lower right : " + (lowerRightCalibrationDone ? localLowerRightRotation.ToString() : "None"));
            GUILayout.Label("Calibration : " + (upperLeftCalibrationDone && lowerRightCalibrationDone ? (Quaternion.Inverse(centerCalibration) * Input.gyro.attitude).ToString() : "None"));
            if (upperLeftCalibrationDone && lowerRightCalibrationDone)
            {
                GUILayout.Label("(x, y) = (" + point.x + ", " + point.y + ")");
            }
        }
    }
Beispiel #9
0
 private void LoadNextPhase()
 {
     if (!isFinalPhase)
     {
         RPCWrapper.RPC("LoadNextPhase", RPCMode.Others, (int)nextPhaseType, nextLevel, nextPhase);               // Tell the clients to load the next phase.
         PhaseLoader.Load(nextLevel, nextPhase, nextPhaseType);
     }
     else
     {
         RPCWrapper.RPC("LoadScoreScene", RPCMode.Others);              // Tell the clients to load scores scene.
         Application.LoadLevel("Windows - ScoreScene");
     }
 }
Beispiel #10
0
    private void Start()
    {
        if (target == null)
        {
            Debug.LogError(GetType().Name + " : The field 'target' is empty");
        }

        if (bulletPrefab == null)
        {
            Debug.LogError(GetType().Name + " : The field 'bullet' is empty");
        }

        RPCWrapper.RegisterMethod(ShootButtonPressed);
    }
Beispiel #11
0
 public void OnLevelPressed()
 {
     if (image.sprite == nonValidated)
     {
         image.sprite = validated;
         GameObject.Find("Button").GetComponent <LevelChosen>().levelChosen = levelNumber;
         RPCWrapper.RPC("UpdateColorWin", RPCMode.Server, levelNumber);
     }
     else
     {
         image.sprite = nonValidated;
         GameObject.Find("Button").GetComponent <LevelChosen>().levelChosen = 0;
         RPCWrapper.RPC("UpdateColorWin", RPCMode.Server, 0);
     }
 }
    private Vector3 lastPoint = Vector3.zero;     // For the last frame.

    private void Start()
    {
        // Set if the calibration happens now or not.
        calibrating = beginWithCalibration;
        RPCWrapper.RPC("SetTargetActive", RPCMode.Server, !calibrating);

        // Enable gyroscope.
        Input.gyro.enabled = true;

        // Initialize camera.
        cameraStream = new WebCamTexture();
        if (calibrating)
        {
            cameraStream.Play();
        }
    }
Beispiel #13
0
    public void UpdateTarget(Vector3 newPositionInScreen)
    {
        // Convert coordinates from [-1, 1] to [0, screenDimension].
        newPositionInScreen.x++;
        newPositionInScreen.y++;
        newPositionInScreen.x *= Screen.width / 2.0f;
        newPositionInScreen.y *= Screen.height / 2.0f;

        // Screen space to world space.
        Vector3 newPosition = Camera.main.ScreenToWorldPoint(newPositionInScreen);

        newPosition.z      = transform.position.z; // Keep initial z position.
        transform.position = newPosition;          // Apply new position.

        if (sendPositionToAndroid)
        {
            RPCWrapper.RPC("UpdateCamera", RPCMode.Others, newPosition);
        }
    }
Beispiel #14
0
    void Update()
    {
        Vector3 eulerAngles = (calibration * Input.gyro.attitude).eulerAngles;

        // Get "roll" (strictly speaking, it is not exactly the roll).
        roll = (int)(eulerAngles.y > 180 ? eulerAngles.y - 360 : eulerAngles.y);          // Maps roll to [-180, 180].

        // Recalibrate if the device orientation changed too much.
        if (!fisrtCalibrationDone ||
            Mathf.Abs(eulerAngles.x > 180 ? eulerAngles.x - 360 : eulerAngles.x) >= 2 * marginToRecalibrate ||
            Mathf.Abs(eulerAngles.z > 180 ? eulerAngles.z - 360 : eulerAngles.z) >= marginToRecalibrate)
        {
            Calibrate();
        }

        // Update the roll on the server side.
        if (Network.connections.Length > 0)
        {
            RPCWrapper.RPC("UpdateRoll", RPCMode.Others, roll);
        }

        //get input by accelerometer



        Vector3 dir = Vector3.zero;

        dir.y = -Input.acceleration.y;
        //Debug.Log (" Add input acc" + dir.y);
        if (dir.sqrMagnitude > 1)
        {
            dir.Normalize();
        }

        dir *= Time.deltaTime;
        //Debug.Log (" before rpc" + dir.y);
        if (Network.connections.Length > 0)
        {
            RPCWrapper.RPC("JumpPlayer", RPCMode.Others, dir);
        }
    }
    private void Update()
    {
        if (!calibrating)
        {
            // Map to [-1, 1] * [-1, 1].
            Quaternion localRotation = Quaternion.Inverse(centerCalibration) * Input.gyro.attitude;
            point.x = 2 * (localRotation.y - localLowerRightRotation.y) / (localUpperLeftRotation.y - localLowerRightRotation.y) - 1;
            point.y = 2 * (localRotation.x - localUpperLeftRotation.x) / (localLowerRightRotation.x - localUpperLeftRotation.x) - 1;
            LowPassFilter();
            point.x     = Mathf.Min(1, Mathf.Max(-1, point.x));
            point.y     = Mathf.Min(1, Mathf.Max(-1, point.y));
            lastPoint.x = point.x;
            lastPoint.y = point.y;

            // Update point position on the server.
            if (upperLeftCalibrationDone && lowerRightCalibrationDone && Network.connections.Length > 0)
            {
                RPCWrapper.RPC("UpdateTarget", RPCMode.Server, point);
            }
        }
    }
Beispiel #16
0
 public void ShootButtonPressed()
 {
     RPCWrapper.RPC("ShootButtonPressed", RPCMode.Server);
 }
Beispiel #17
0
 private void Start()
 {
     // Register UpdateTarget() in the RPC wrapper.
     RPCWrapper.RegisterMethod(UpdateTarget);
 }
Beispiel #18
0
 private void Start()
 {
     // Server tells clients when to load next phase.
     RPCWrapper.RegisterMethod(LoadNextPhase);
     RPCWrapper.RegisterMethod(LoadScoreScene);
 }
 // Use this for initialization
 void Start()
 {
     RPCWrapper.RegisterMethod(UpdateCamera);
 }
Beispiel #20
0
 void Start()
 {
     RPCWrapper.RegisterMethod(OnButtonPressedWin);
 }
 public void OnButtonPressedAndroid()
 {
     RPCWrapper.RPC("OnButtonPressedWin", RPCMode.Server);
     PhaseLoader.Load();
 }
Beispiel #22
0
 void Start()
 {
     // Register TryLaunchingGame() in the RPC wrapper.
     RPCWrapper.RegisterMethod(TryLaunchingGame);
 }