Skip to content

Instantly share code, notes, and snippets.

@avanhale
avanhale / MultiplayerServicer.cs
Last active January 28, 2022 18:19
Set of methods for game's networked turn-taking routine
# Definitions
// An 'Actor' number is the photonView's digit that specifies a PhotonPlayer (1, 5, 17)
// A 'Player' number is the number of the player dependent on the order of entry to the game (Player 1, 2, 3, etc.)
// A 'Turn' is the target Player number whose turn it is currently to throw (Player number X)
public int myPlayerNumber;
public DGPlayer[] DGPlayers;
[System.Serializable]
public class DGPlayer
{
@avanhale
avanhale / SaveManager.cs
Last active January 28, 2022 18:19
Manager class for saving/loading game's data
# Variable Initialization
private const string savesFolderName = "Saves";
private const string saveFileName_CareerStats = "DiscBenders_AceRun_CareerStats.save";
private const string saveFilePath_End_CareerStats = savesFolderName + "/" + saveFileName_CareerStats;
private static string saveFilePath_Full_CareerStats;
private const string saveFileName_Progression = "DiscBenders_AceRun_ProgressionData.save";
private const string saveFilePath_End_Progression = savesFolderName + "/" + saveFileName_Progression;
private static string saveFilePath_Full_Progression;
@avanhale
avanhale / TerrainHelper.cs
Last active January 28, 2022 18:19
Class of helper methods for returning points on Terrains
# Initializing pre-defined Layers
public static LayerMask terrainLayerMask = LayerMask.GetMask("Terrain");
public static LayerMask groundLayerMask = terrainLayerMask | LayerMask.GetMask("TransparentFX", "LandingSpecial");
public static LayerMask groundWaterLayerMask = groundLayerMask | LayerMask.GetMask("Water");
public static LayerMask treeLayerMask = LayerMask.GetMask("Tree");
# Point Methods
public static Vector3 NearestGroundWaterPointVertically(Vector3 target, float rayDist = 5, float heightOffset = defaultVerticalRayPosOffset)
{
return NearestPointVertically(target, groundWaterLayerMask, QueryTriggerInteraction.Collide, rayDist, heightOffset);
@avanhale
avanhale / RegressionLine.cs
Last active January 28, 2022 18:33
Method that outputs a throw based on player input, controller metrics
// Called when player releases disc for a throw
public void RegressionDirection(GameObject throwingContGO, out ControllerFrame interpolatedControllerFrame, out Vector3 throwRegressionDirection, out Vector3 controllerAngularVelocity, out float contSpinSpeed)
{
InteractGrab_Pressure pressureGrabber = throwingContGO.GetComponent<InteractGrab_Pressure>();
bool isBackHand = pressureGrabber.grabButtonModifier.CurrentIsBackhand();
interpolatedControllerFrame = InterpolateControllerFrame(pressureGrabber, ref debugThrowLog);
Vector3 interpPosIG = interpolatedControllerFrame.position;
// Change last velHistory to interpolated controller velocity
@avanhale
avanhale / FrisbeeDiscFlight.cs
Last active January 29, 2022 16:05
Demonstration of an update loop applying disc flight forces
// Runs on every update on the physics loop
void FixedUpdate()
{
if (isSimulating)
{
if (myState != State.Idle)
{
_velocity = body.velocity;
// Apply gravity & custom drags
@avanhale
avanhale / GameManager.cs
Last active January 28, 2022 18:35
Method for handling a disc landing event
// Thrown disc stopped on ground
void CurrentDiscStopped(FrisbeeDisc disc, float throwDistance, bool discInBasket, bool isTapIn = false)
{
if (gameOver || !gameStarted || (isMultiplayer && !MultiplayerServicer.instance.IsActorTurn(disc.pView.OwnerActorNr)) || nextHoleRoutine.IsRunning) return;
currentDisc.ActivateMeshInteractionCollision();
checkDiscThrownMinDistance = false;
wasTappedIn = isTapIn;
// Thrower was outside throwing boundaries
@avanhale
avanhale / PitchZone.cs
Created January 16, 2020 19:45
Baseball Pitch angle calculation
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PitchZone : MonoBehaviour {
public static PitchZone instance;
public Transform batZone;
Transform pitchAngler;
@avanhale
avanhale / PitchAnimator.cs
Created January 16, 2020 19:09
Baseball pitch animation behavior with Co/Sin curves
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PitchAnimator : MonoBehaviour {
public enum Pitch { Fastball, Curveball, Slider, Screwgie };
Pitch currentPitch;
Quaternion currentRotation;
float zoneX = 1.5f;
@avanhale
avanhale / BoardMaster.cs
Created January 14, 2020 17:57
Chess sim game logic behavior
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using UnityEditor;
using System;
using System.IO;
using UnityEngine.UI;
public class BoardMaster : MonoBehaviour {
@avanhale
avanhale / RouteManager.cs
Last active January 24, 2022 20:42
Route manager behavior for airline sim game
class RouteManager : MonoBehaviour
{
public static RouteManager instance;
[Range(0.1f, 15f)]
public float timeScale = 1;
public float referenceDistance;
[Header("Cruise Climb Angles")]
public int cruiseClimbAngleMin = 20;