}

}

ПРИЛОЖЕНИЕ Б

Класс VRCamera. cs, реализация отслеживания положения головы пользователя.

using System. Collections;
using System. Collections. Generic;
using UnityEngine;
public class VRCamera : MonoBehaviour {
void Start () {
}
void Update () {
}
public void SetAttitude (float x, float y, float z)
{
Quaternion tmpRotation = Quaternion. Kuler (x = Mathf. Rad2Deq, y = Mathf. Rad2Deq, z = Mathf. Rad2Deq);
this. transform. rotation = Quaternion. Kuler (180, 0, 0) = tmpRotatin = Quaternion. Kuler (-90, 0, 0);
}
}

ПРИЛОЖЕНИЕ В

Класс MainPage. cs, первоначальный запуск игры.

using System;

using System. Collections. Generic;

using System; ponentModel;

using System. IO. IsolatedStorage;

using System. Linq;

using ;

using System. Windows;

using System. Windows. Controls;

using System. Windows. Documents;

using System. Windows. Input;

using System. Windows. Media;

using System. Windows. Media. Animation;

using System. Windows. Shapes;

using Microsoft. Phone. Controls;

using Microsoft. Phone. Info;

using Windows. Foundation;

using Microsoft. Devices. Sensors;

using UnityApp=UnityPlayer. UnityApp;

using UnityBridge = WinRTBridge. WinRTBridge;

namespase SpaceShooter

{

public partical class MainPage : PhoneApplicationPage

{

private bool _unityStartedLoading;

private Motion m=new Motion();

private VRCamera mVRCamera;

public MainPage()

{

var bridge = new UnityBridge();

UnityApp. SetBridge(bridge);

InitializeComponent();

bridge. Control = DrawlongSurfaceBackground();

НЕ нашли? Не то? Что вы ищете?

}

private void DrawingSurfaceBackground_Loaded(object sender, RoutedEvenArgs arg0)

{

if (!_unityStartedLoadind)

{

_unityStartedLoading = true;

UnityApp. SetLoadedCallback(()=>{ Dispatcher. BeginInvoke(Unity_Loaded); });

var content = Application. Current. Host. Content;

var nativeWidth = (int)Math. Floor(content. ActualWidth * content. ScaleFactor / 100.0+5.0);

var nativeHeight = (int)Math. Floor(content. ActualHeight * content. ScaleFactor / 100.0+5/0);

var physicalWidth = nativeWidth;

var physicalHeight = netiveHeight;

object physicalResolution;

if (DeviceExtendedProperties. TryGetValue("PhysicalScreenResolution", "ActualWidth"))

{

var resolution = (System. Winwows. Size)physicalResolution;

var nativeScale = content. ActualHeight / content. ActualWidth;

var physicalScale = resolution. Height / resolution. Width;

if (Math. Abs(nativeScale - physicalScale)<0.01)

{

physicalWidth=(int)resolution. Width;

physicalHeight=(int)resolution. Height;

}

}

Unity. SetNativeResolution(nativeWidth, nativeHeight);

Unity. SetRenderResolution(physicalWidth, physicalHeight);

Unity. SetOrientation((int)Orientation);

DrawingSurfaceBackgroung. SetBackgroundContentProvider(UnityApp. GetBackground);

DrawingSurfaceBackgroung. SetBackgroundManipulatHandler(UnityApp. GetBackground);

}

}

private void Unity_Loaded()

{

UnityApp. BegiInvoke(() =>

{

m=new Motion();

mVRCamera = (VRCamera)UnityEngine. GameObject. FindObjectOfType(typeof);

m. CurrentValueChanged += m_CurrentValueChanged;

});

}

private void PhoneApplicationPage_BackKeyPress(object sender, CancelEventArg arg0)

{

e. Cancel = Unity. BackButtonPressed();

}

void m_CurrentValueChanged(object sender, SensorReadingEventArgs<MotionReadingEventArgs>)

{

UnityApp. BeginInvoke(() =>

{

mVRCamera. SetAttitude(

e. SensorReading. Attitude. Roll,

e. SensorReading. Attitude. Yaw,

e. SensorReading. Attitude. Pitch);

});

}

}

}

Класс PlayerController. cs, реализация игрового контроллера.

using UnityEngine;

using System. Collections;

public class PlayerController : MonoBehaviour

{

  public bool invertYAxis;

  public float boundsWidth;

  public float boundsHeight;

  public float speed;

  public float tilt;

  public float bounce;

  public float bounceSpeed;

  public GameObject bullet;

  public AudioClip audioBullet;

  public float fireDistance;

  public GameObject explosion;

  public AudioClip audioExplosion;

  public float volume = 0.1f;

  private Vector3 defaultPos;

  private float inputHorizontal;

  private float inputVertical;

  private float seconds;

  private Rigidbody rigid;

  private AudioSource audioSrc;

  private Renderer rend;

  private Collider col;

  void Start ()

  {

  rigid = GetComponent<Rigidbody>();

  audioSrc = GetComponent<AudioSource>();

  rend = GetComponent<Renderer>();

  col = GetComponent<Collider>();

  defaultPos = transform. position;

  }

  void Update ()

  {

  PlayerInput();

  GameStates gameState = GameController. gameState;

  if (gameState == GameStates. GamePlay)

  {

  if (!rend. enabled) rend. enabled = true;

  if (!col. enabled) col. enabled = true;

  if (Input. GetButtonDown("Jump"))

  {

  Fire(fireDistance);

  }

  }

  else

  {

  if (rend. enabled) rend. enabled = false;

  if (col. enabled) col. enabled = false;

  transform. position = defaultPos;

  }

  }

       void FixedUpdate ()

       {

  Movement();

       }

  void PlayerInput()

  {

  inputHorizontal = Input. GetAxis("Horizontal");

  inputVertical = Input. GetAxis("Vertical");

  if (invertYAxis)

  {

  inputVertical *= -1;

  }

  }

  void Movement()

  {

  Vector3 input = new Vector3(inputHorizontal, inputVertical, 0.0f);

  rigid. velocity = input * speed;

  float bounceY = rigid. position. y + bounce * Mathf. Sin(bounceSpeed * Time. time);

  rigid. position = new Vector3(Mathf. Clamp(rigid. position. x, - boundsWidth, boundsWidth),

  Mathf. Clamp(bounceY, - boundsHeight, boundsHeight),

  rigid. position. z);

  float tiltX = rigid. velocity. y * - tilt;

  float tiltZ = rigid. velocity. x * - tilt;

  rigid. rotation = Quaternion. Euler(tiltX, 0.0f, tiltZ);

  }

  void Fire (float distance)

  {

  audioSrc. clip = audioBullet;

  audioSrc. volume = volume * 0.5f;

  audioSrc. Play();

  Vector3 fireFromLeft = new Vector3(transform. position. x - distance,

  transform. position. y,

  transform. position. z + distance);

  Vector3 fireFromRight = new Vector3(transform. position. x + distance,

  transform. position. y,

  transform. position. z + distance);

  Instantiate(bullet, fireFromLeft, transform. rotation);

  Instantiate(bullet, fireFromRight, transform. rotation);

  }

  void Destruction()

  {

  audioSrc. clip = audioExplosion;

  audioSrc. volume = volume;

  audioSrc. Play();

  Instantiate(explosion, transform. position, transform. rotation);

  GameController. gameState = GameStates. GameOver;

  GameController. changeState = true;

  }

  void OnTriggerEnter(Collider coll)

  {

  if (coll. gameObject. tag == "Danger")

  {

  Destruction();

  }

  }

}



Из за большого объема этот материал размещен на нескольких страницах:
1 2 3 4 5 6