non-vr lobby, version fix

This commit is contained in:
joonasp
2022-06-29 14:45:17 +03:00
parent 5774be9822
commit 04baadfad1
1774 changed files with 573069 additions and 1533 deletions

View File

@@ -3,11 +3,12 @@ using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;
using Photon.Pun;
using Random = UnityEngine.Random;
namespace Bow
{
public class ArcheryRange : MonoBehaviour
public class ArcheryRange : MonoBehaviourPunCallbacks
{
public TMP_Text highScoreText;
public TMP_Text timeLeftText;
@@ -71,7 +72,8 @@ namespace Bow
(float) Math.Round(Random.Range(minRandomOffset.y, maxRandomOffset.y)),
Random.Range(minRandomOffset.z, maxRandomOffset.z));
var prefab = Instantiate(targetPrefab, randomPos, Quaternion.identity, null);
//var prefab = Instantiate(targetPrefab, randomPos, Quaternion.identity, null);
var prefab = PhotonNetwork.Instantiate("TargetUFO_Network", randomPos, Quaternion.identity);
ArcheryTarget target = prefab.GetComponent<ArcheryTarget>();
@@ -88,7 +90,8 @@ namespace Bow
{
foreach (var target in _targets.Where(target => target != null))
{
Destroy(target.gameObject);
//Destroy(target.gameObject);
PhotonNetwork.Destroy(target.gameObject.GetPhotonView());
}

View File

@@ -1,10 +1,11 @@
using System;
using UnityEngine;
using Photon.Pun;
using Random = UnityEngine.Random;
namespace Bow
{
public class ArcheryTarget : MonoBehaviour
public class ArcheryTarget : MonoBehaviourPun
{
public GameObject pointsText;
public Vector3 endPosition;
@@ -51,11 +52,9 @@ namespace Bow
new Vector3(endPosition.x, position.y, desiredZ), step);
}
public void OnArrowHit(Arrow arrow)
[PunRPC]
public void OnArrowHitPun()
{
if (arrow == null) return;
var position = transform.position;
float score = (float) Math.Round(Vector3.Distance(position, endPosition));
@@ -65,9 +64,16 @@ namespace Bow
PointsText target = prefab.GetComponent<PointsText>();
target.SetPoints(score);
}
public void OnArrowHit(Arrow arrow)
{
if (arrow == null) return;
Destroy(arrow.gameObject);
Destroy(gameObject);
photonView.RPC("OnArrowHitPun", RpcTarget.All);
PhotonNetwork.Destroy(photonView);
}
}
}

View File

@@ -0,0 +1,124 @@
using System;
using System.Collections;
using Audio;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;
namespace Bow
{
public class Arrow_Network : XRGrabInteractable
{
public AudioClipGroup hitSounds;
public float speed = 2000.0f;
public Transform tip = null;
public float maxLifetimeAfterShot = 60f;
private bool _inAir = false;
private Vector3 _lastPosition = Vector3.zero;
private Rigidbody _rigidbody = null;
private float _timeToDestroyOn;
protected override void Awake()
{
base.Awake();
_rigidbody = GetComponent<Rigidbody>();
_timeToDestroyOn = float.MaxValue;
}
private void FixedUpdate()
{
if (!_inAir) return;
CheckForCollision();
_lastPosition = tip.position;
if (_timeToDestroyOn <= Time.time)
{
Destroy(gameObject);
}
}
private void CheckForCollision()
{
RaycastHit hit;
if (Physics.Linecast(_lastPosition, tip.position, out hit, LayerMask.GetMask("Default"),
QueryTriggerInteraction.Ignore))
{
hit.collider.gameObject.SendMessage("OnArrowHit", this,
SendMessageOptions.DontRequireReceiver);
Stop();
hitSounds.Play();
}
}
private void Stop()
{
_inAir = false;
SetPhysics(false);
}
public void Release(float pullValue)
{
_inAir = true;
SetPhysics(true);
MaskAndFire(pullValue);
StartCoroutine(RotateWithVelocity());
_lastPosition = tip.position;
}
private void SetPhysics(bool usePhysics)
{
_rigidbody.isKinematic = !usePhysics;
_rigidbody.useGravity = usePhysics;
}
private void MaskAndFire(float power)
{
colliders[0].enabled = false;
interactionLayerMask = 1 << LayerMask.NameToLayer("IgnoreInteraction");
Vector3 force = transform.forward * (power * speed);
_rigidbody.AddForce(force);
_timeToDestroyOn = Time.time + maxLifetimeAfterShot;
}
private IEnumerator RotateWithVelocity()
{
yield return new WaitForFixedUpdate();
while (_inAir)
{
Quaternion newRotation = Quaternion.LookRotation(_rigidbody.velocity, transform.up);
transform.rotation = newRotation;
yield return null;
}
}
public new void OnSelectEntered(XRBaseInteractor interactor)
{
base.OnSelectEntered(interactor);
}
public new void OnSelectExited(XRBaseInteractor interactor)
{
base.OnSelectExited(interactor);
}
public new void OnSelectExiting(XRBaseInteractor interactor)
{
base.OnSelectExiting(interactor);
}
protected override void OnDestroy()
{
base.OnDestroy();
colliders.Clear();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3b7c8b14231b4ca409541c41bd62389b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +1,9 @@
using UnityEngine;
using Photon.Pun;
namespace Bow
{
public class StartTarget : MonoBehaviour
public class StartTarget : MonoBehaviourPun
{
public ArcheryRange archeryRange;
public Canvas textCanvas;
@@ -16,28 +17,43 @@ namespace Bow
_boxCollider = GetComponent<BoxCollider>();
}
public void OnArrowHitPun()
{
HideTarget();
archeryRange.StartRound();
}
[PunRPC]
private void HideTargetPun()
{
_meshRenderer.enabled = false;
_boxCollider.enabled = false;
textCanvas.enabled = false;
}
[PunRPC]
public void ShowTargetPun()
{
_meshRenderer.enabled = true;
_boxCollider.enabled = true;
textCanvas.enabled = true;
}
public void OnArrowHit(Arrow arrow)
{
if (arrow == null) return;
Destroy(arrow.gameObject);
HideTarget();
archeryRange.StartRound();
OnArrowHitPun();
}
private void HideTarget()
{
_meshRenderer.enabled = false;
_boxCollider.enabled = false;
textCanvas.enabled = false;
photonView.RPC("HideTargetPun", RpcTarget.AllBuffered);
}
public void ShowTarget()
{
_meshRenderer.enabled = true;
_boxCollider.enabled = true;
textCanvas.enabled = true;
photonView.RPC("ShowTargetPun", RpcTarget.AllBuffered);
}
}
}

View File

@@ -4,9 +4,10 @@ using System.Runtime.InteropServices;
using Breakout;
using Unity.Mathematics;
using UnityEngine;
using Photon.Pun;
using Random = UnityEngine.Random;
public class BreakoutManager : MonoBehaviour
public class BreakoutManager : MonoBehaviourPunCallbacks
{
public GameObject defaultBreakablePrefab;
public GameObject extraBallBreakablePrefab;
@@ -71,7 +72,8 @@ public class BreakoutManager : MonoBehaviour
private void SpawnBall()
{
Instantiate(ballPrefab, startBallSpawnPoint.transform.position, Quaternion.identity, null);
PhotonNetwork.Instantiate("Ball_Network", startBallSpawnPoint.transform.position, Quaternion.identity);
//Instantiate(ballPrefab, startBallSpawnPoint.transform.position, Quaternion.identity, null);
_ballCount += 1;
}
@@ -95,11 +97,13 @@ public class BreakoutManager : MonoBehaviour
if (Random.value <= extraBallBreakableChance)
{
box = Instantiate(extraBallBreakablePrefab, point.position, Quaternion.identity, null);
box = PhotonNetwork.Instantiate("Breakable Cube Extra Ball_Network", point.position, Quaternion.identity);
//box = Instantiate(extraBallBreakablePrefab, point.position, Quaternion.identity, null);
}
else
{
box = Instantiate(defaultBreakablePrefab, point.position, Quaternion.identity, null);
box = PhotonNetwork.Instantiate("Breakable Cube_Network", point.position, Quaternion.identity);
//box = Instantiate(defaultBreakablePrefab, point.position, Quaternion.identity, null);
}
var cube = box.GetComponent<BreakableCube>();

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9be41c0129d74704ca81497976da049c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: