Skip to content

Commit

Permalink
Remove cruft
Browse files Browse the repository at this point in the history
  • Loading branch information
plaidpants committed Jan 28, 2022
1 parent ee48050 commit bb0f3fc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 58 deletions.
3 changes: 3 additions & 0 deletions Assets/RockSphere.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class RockSphere : NetworkBehaviour
// [Server]
public override void OnStartServer()
{
// call the base function, probably is empty
base.OnStartServer();

// get the current radius and position from parent gameobject
radius = transform.position.magnitude;
pos = transform.position;
Expand Down
84 changes: 26 additions & 58 deletions Assets/RocketSphere.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,21 @@ public class RocketSphere : NetworkBehaviour
// Cache it here and Destroy it in OnDestroy to prevent a memory leak.
Material cachedMaterial;

// create a random color for each player as they are created on the server
void OnDestroy()
{
Destroy(cachedMaterial);
}

public override void OnStartServer()
{
// call the base function, probably is empty
base.OnStartServer();

// create a random color for each player as they are created on the server
RocketColor = new Color(Random.Range(0.3f, 1.0f), Random.Range(0.3f, 1.0f), Random.Range(0.3f, 1.0f));
}

void OnDestroy()
{
Destroy(cachedMaterial);
// need to maintain this separately so we can sync state on client connect with existing objects
visible = false;
}

// Use this for initialization
Expand All @@ -74,7 +79,7 @@ void Start()
transform.position = Vector3.zero;
transform.rotation = Quaternion.identity;

// Move rocket out to radius
// Move rocket child gameobject out to radius
Vector3 pos = Vector3.forward * radius;
Quaternion rot = Quaternion.FromToRotation(Vector3.forward, pos);

Expand All @@ -83,35 +88,29 @@ void Start()
rocket.transform.position = pos;
rocket.transform.rotation = rot;

// find the engine child object
// find the engine child object and attach the particle generator
GameObject engine = transform.Find("Rocket").Find("Engine").gameObject;
engineParticleSystem = engine.GetComponent<ParticleSystem>();
emissionModule = engineParticleSystem.emission;
mainModule = engineParticleSystem.main;
engineSound = transform.Find("Rocket").transform.GetComponent<AudioSource>();
hyperspaceSound = transform.GetComponent<AudioSource>();

// find the rb
// find the rb so we can apply torque during the Update()
rb = transform.GetComponent<Rigidbody>();

//OnChangeColour(RocketColor, RocketColor);

// PlayerTracker.SetTrackingObject(rocket.gameObject);
// Debug.Log("set");

// Keep the player objects through level changes
DontDestroyOnLoad(this);

// need to maintain this separately so we can sync state on client connect with existing objects
visible = false;

// attach the PC camera follow script to the local player
if (isLocalPlayer)
Camera.main.GetComponent<CameraFollowRocket>().player = transform.gameObject.transform.Find("Rocket").gameObject.transform;
// attach the PC camera follow script to the local player so PC players can play with the VR players
if (isLocalPlayer)
Camera.main.GetComponent<CameraFollowRocket>().player = transform.gameObject.transform.Find("Rocket").gameObject.transform;

// spawn the ship on the server
CmdSpawnShip();
// update the color to match the color on the server
ChangeColour();

// spawn the ship on the server
CmdSpawnShipDelay();
}

void ChangeColour()
Expand Down Expand Up @@ -146,7 +145,6 @@ private void OnLevelWasLoaded(int level)
Camera.main.GetComponent<CameraFollowRocket>().player = transform.gameObject.transform.Find("Rocket").gameObject.transform;
}


void MySetActive(bool active, Quaternion rotation)
{
if (active == false)
Expand Down Expand Up @@ -186,26 +184,19 @@ void CmdMySetActive(bool active, Quaternion rotation)
}

[Command]
void CmdSpawnShip()
void CmdSpawnShipDelay()
{
rpcSpawnShipDelay();

//RpcSpawnShip();
}

[ClientRpc]
void RpcSpawnShip()
{
SpawnShip();
}

void SpawnShip()
{
if (!isLocalPlayer) return;

// make sure the color is correct, might not need this
CmdChangeColour();

// re-enable this rocket on all clients through server
// re-enable this rocket on all clients through server at the direction the user is looking at the moment
CmdMySetActive(true, Camera.main.transform.rotation);
}

Expand All @@ -217,11 +208,10 @@ void rpcSpawnShipDelay()
Invoke("SpawnShip", 5);
}

// we only process collisions on the server
[ServerCallback]
void OnTriggerEnter(Collider other)
{
//if (!isLocalPlayer) return;

// Rocket is already destroyed, ignore
if (!rocket.activeSelf) return;

Expand All @@ -239,8 +229,6 @@ void OnTriggerEnter(Collider other)

// spawn a new ship, do this on the local player client and it will re-enable on all clients
rpcSpawnShipDelay();

//Invoke("SpawnShip", 5);
}

// we only shoot on the server
Expand Down Expand Up @@ -343,19 +331,6 @@ void CmdEngineOff()
RpcEngineOff();
}

[Command]
void CmdUpdateState()
{

}

[Client]
public override void OnStartClient()
{
if(!isLocalPlayer)
CmdUpdateState();
}

//??? this would be nice to animate between radius levels
[Client]
void Hyperspace()
Expand All @@ -373,20 +348,11 @@ void Hyperspace()
hyperspaceSound.Play();
}

// this is called on the rocket that fired for all observers
[ClientRpc]
void RpcOnFire()
{
// create the shot locally on each client and run them independently
//Fire();
}

// this is called on the server
[Command]
void CmdFire()
{
Fire();
RpcOnFire();
}

// this is called on the rocket that hyperspaced for all observers
Expand All @@ -405,6 +371,8 @@ void CmdHyperspace()

void Update()
{
//if (!rocket) return;

if (rocket.activeSelf != visible)
{
// we are out of sync with the server
Expand Down
Binary file modified ProjectSettings/GraphicsSettings.asset
Binary file not shown.
Binary file modified ProjectSettings/ProjectSettings.asset
Binary file not shown.

0 comments on commit bb0f3fc

Please sign in to comment.