Init repository
This commit is contained in:
Executable file
+34
@@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class AudioBundleLoader : MonoBehaviour
|
||||
{
|
||||
public string AudioAssetBundleName = "AudioAssets.bunl";
|
||||
public AssetBundle AudioAssetBundle;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
SceneManager.activeSceneChanged += delegate
|
||||
{
|
||||
if (AudioAssetBundle)
|
||||
AudioAssetBundle.Unload(true);
|
||||
};
|
||||
InitializeAudioAssetBundle();
|
||||
}
|
||||
public void InitializeAudioAssetBundle()
|
||||
{
|
||||
Debug.Log("Setting asset bundles... (1)");
|
||||
AudioAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "Audio", "AudioAssets.bunl"));
|
||||
}
|
||||
public AssetBundle GetAudioAssetBundle()
|
||||
{
|
||||
return AudioAssetBundle;
|
||||
}
|
||||
public AudioClip GetAudioClipFromAssetBundle(string AudioFileName)
|
||||
{
|
||||
return AudioAssetBundle.LoadAsset<AudioClip>(AudioFileName);
|
||||
}
|
||||
|
||||
}
|
||||
Executable file
+21
@@ -0,0 +1,21 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class LoadImageFromStreamingAssets : MonoBehaviour
|
||||
{
|
||||
public Image LoadToObject;
|
||||
public string ImagePathFromStreamingAssets;
|
||||
void Start()
|
||||
{
|
||||
Texture2D texture = new(2,2);
|
||||
texture.LoadImage(File.ReadAllBytes(Path.Combine(Application.streamingAssetsPath, ImagePathFromStreamingAssets)));
|
||||
|
||||
Debug.Log("Loaded texture " + texture.name);
|
||||
|
||||
if (LoadToObject)
|
||||
{
|
||||
LoadToObject.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable file
+15
@@ -0,0 +1,15 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Video;
|
||||
public class LoadVideoFromStreamingAssets : MonoBehaviour
|
||||
{
|
||||
|
||||
public VideoPlayer videoPlayer;
|
||||
public string VideoPathFromStreamingAssets;
|
||||
void Start()
|
||||
{
|
||||
videoPlayer.url = Path.Combine(Application.streamingAssetsPath, VideoPathFromStreamingAssets);
|
||||
}
|
||||
}
|
||||
Executable file
+26
@@ -0,0 +1,26 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.Video;
|
||||
|
||||
public class VideoBundleLoader : MonoBehaviour
|
||||
{
|
||||
public AssetBundle VideoAssetBundle;
|
||||
public string VideoAssetBundleName = "VideoAssets.bunl";
|
||||
|
||||
private void Start()
|
||||
{
|
||||
SceneManager.activeSceneChanged += delegate
|
||||
{
|
||||
if (VideoAssetBundle)
|
||||
VideoAssetBundle.Unload(true);
|
||||
};
|
||||
VideoAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "Video", VideoAssetBundleName));
|
||||
}
|
||||
|
||||
public VideoClip GetVideoClipFromAssetBundle(AssetBundle VideoAssetBundle, string VideoFileName)
|
||||
{
|
||||
return VideoAssetBundle.LoadAsset<VideoClip>(VideoFileName);
|
||||
}
|
||||
|
||||
}
|
||||
Executable file
+99
@@ -0,0 +1,99 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Video;
|
||||
|
||||
public class VideoTest : MonoBehaviour
|
||||
{
|
||||
public GameObject VideoPlayerObject;
|
||||
VideoPlayer videoPlayer;
|
||||
public string VideoFileName = "test1.mp4";
|
||||
|
||||
public bool ScriptPlaysVideoOnMouseDown = false;
|
||||
public bool ScriptStopsVideoOnMouseDown = false;
|
||||
public RawImage UIViewport;
|
||||
public bool UseAssetBundles = false;
|
||||
public AssetBundle VideoBundle;
|
||||
public VideoBundleLoader BundleLoader;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
videoPlayer = VideoPlayerObject.GetComponent<VideoPlayer>();
|
||||
if (UseAssetBundles && BundleLoader)
|
||||
VideoBundle = BundleLoader.VideoAssetBundle;
|
||||
}
|
||||
|
||||
public void SetVideoFileName(string filename)
|
||||
{
|
||||
VideoFileName = filename;
|
||||
}
|
||||
|
||||
void OnMouseDown()
|
||||
{
|
||||
if (ScriptPlaysVideoOnMouseDown)
|
||||
{
|
||||
PlayVideo();
|
||||
}
|
||||
else if (ScriptStopsVideoOnMouseDown)
|
||||
{
|
||||
StopVideo();
|
||||
}
|
||||
else
|
||||
{
|
||||
SetVideoUrlFromBundle();
|
||||
}
|
||||
}
|
||||
public void SetVideoUrl()
|
||||
{
|
||||
VideoFileName = Path.Combine(Application.streamingAssetsPath, "Video", VideoFileName);
|
||||
if (!File.Exists(VideoFileName))
|
||||
{
|
||||
Debug.LogError("Video not found: " + VideoFileName);
|
||||
VideoFileName = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
videoPlayer.url = VideoFileName;
|
||||
videoPlayer.Stop();
|
||||
Debug.LogError("Set videoPlayer URL to " + VideoFileName);
|
||||
}
|
||||
//VideoPlayerObject.transform.localScale = new Vector3(videoPlayer.clip.width / 16 / 4, videoPlayer.clip.height / 16 / 4);
|
||||
}
|
||||
|
||||
public void SetVideoUrlFromBundle()
|
||||
{
|
||||
if (VideoBundle == null)
|
||||
{
|
||||
Debug.Log("Failed to load VideoBundle!");
|
||||
return;
|
||||
}
|
||||
VideoClip clip = VideoBundle.LoadAsset<VideoClip>(VideoFileName);
|
||||
videoPlayer.clip = clip;
|
||||
videoPlayer.Stop();
|
||||
Debug.LogError("Loaded video from assetbundle: " + VideoBundle.name + " " + clip.name);
|
||||
}
|
||||
|
||||
public void PlayVideo()
|
||||
{
|
||||
Debug.Log("Tried playing " + VideoFileName);
|
||||
videoPlayer.Play();
|
||||
}
|
||||
public void PlayUIVideo()
|
||||
{
|
||||
if (UIViewport)
|
||||
{
|
||||
videoPlayer.renderMode = VideoRenderMode.RenderTexture;
|
||||
//videoPlayer.Prepare();
|
||||
|
||||
UIViewport.texture = videoPlayer.texture;
|
||||
videoPlayer.Play();
|
||||
}
|
||||
}
|
||||
public void StopVideo()
|
||||
{
|
||||
Debug.Log("Tried stopping playback of " + VideoFileName);
|
||||
if (videoPlayer.isPaused)
|
||||
videoPlayer.Stop();
|
||||
videoPlayer.Pause();
|
||||
}
|
||||
}
|
||||
Executable file
BIN
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
Executable file
+742
@@ -0,0 +1,742 @@
|
||||
// CHANGE LOG
|
||||
//
|
||||
// CHANGES || version VERSION
|
||||
//
|
||||
// "Enable/Disable Headbob, Changed look rotations - should result in reduced camera jitters" || version 1.0.1
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using System.Net;
|
||||
#endif
|
||||
|
||||
public class FirstPersonController : MonoBehaviour
|
||||
{
|
||||
private Rigidbody rb;
|
||||
|
||||
#region Camera Movement Variables
|
||||
|
||||
public Camera playerCamera;
|
||||
|
||||
public float fov = 60f;
|
||||
public bool invertCamera = false;
|
||||
public bool cameraCanMove = true;
|
||||
public float mouseSensitivity = 2f;
|
||||
public float maxLookAngle = 50f;
|
||||
|
||||
// Crosshair
|
||||
public bool lockCursor = true;
|
||||
public bool crosshair = true;
|
||||
public Sprite crosshairImage;
|
||||
public Color crosshairColor = Color.white;
|
||||
|
||||
// Internal Variables
|
||||
private float yaw = 0.0f;
|
||||
private float pitch = 0.0f;
|
||||
private Image crosshairObject;
|
||||
|
||||
#region Camera Zoom Variables
|
||||
|
||||
public bool enableZoom = true;
|
||||
public bool holdToZoom = false;
|
||||
public KeyCode zoomKey = KeyCode.Mouse1;
|
||||
public float zoomFOV = 30f;
|
||||
public float zoomStepTime = 5f;
|
||||
|
||||
// Internal Variables
|
||||
private bool isZoomed = false;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Movement Variables
|
||||
|
||||
public bool playerCanMove = true;
|
||||
public float walkSpeed = 5f;
|
||||
public float maxVelocityChange = 10f;
|
||||
|
||||
// Internal Variables
|
||||
private bool isWalking = false;
|
||||
|
||||
#region Sprint
|
||||
|
||||
public bool enableSprint = true;
|
||||
public bool unlimitedSprint = false;
|
||||
public KeyCode sprintKey = KeyCode.LeftShift;
|
||||
public float sprintSpeed = 7f;
|
||||
public float sprintDuration = 5f;
|
||||
public float sprintCooldown = .5f;
|
||||
public float sprintFOV = 80f;
|
||||
public float sprintFOVStepTime = 10f;
|
||||
|
||||
// Sprint Bar
|
||||
public bool useSprintBar = true;
|
||||
public bool hideBarWhenFull = true;
|
||||
public Image sprintBarBG;
|
||||
public Image sprintBar;
|
||||
public float sprintBarWidthPercent = .3f;
|
||||
public float sprintBarHeightPercent = .015f;
|
||||
|
||||
// Internal Variables
|
||||
private CanvasGroup sprintBarCG;
|
||||
private bool isSprinting = false;
|
||||
private float sprintRemaining;
|
||||
private float sprintBarWidth;
|
||||
private float sprintBarHeight;
|
||||
private bool isSprintCooldown = false;
|
||||
private float sprintCooldownReset;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Jump
|
||||
|
||||
public bool enableJump = true;
|
||||
public KeyCode jumpKey = KeyCode.Space;
|
||||
public float jumpPower = 5f;
|
||||
|
||||
// Internal Variables
|
||||
private bool isGrounded = false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Crouch
|
||||
|
||||
public bool enableCrouch = true;
|
||||
public bool holdToCrouch = true;
|
||||
public KeyCode crouchKey = KeyCode.LeftControl;
|
||||
public float crouchHeight = .75f;
|
||||
public float speedReduction = .5f;
|
||||
|
||||
// Internal Variables
|
||||
private bool isCrouched = false;
|
||||
private Vector3 originalScale;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Head Bob
|
||||
|
||||
public bool enableHeadBob = true;
|
||||
public Transform joint;
|
||||
public float bobSpeed = 10f;
|
||||
public Vector3 bobAmount = new Vector3(.15f, .05f, 0f);
|
||||
|
||||
// Internal Variables
|
||||
private Vector3 jointOriginalPos;
|
||||
private float timer = 0;
|
||||
|
||||
#endregion
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
rb = GetComponent<Rigidbody>();
|
||||
|
||||
crosshairObject = GetComponentInChildren<Image>();
|
||||
|
||||
// Set internal variables
|
||||
playerCamera.fieldOfView = fov;
|
||||
originalScale = transform.localScale;
|
||||
jointOriginalPos = joint.localPosition;
|
||||
|
||||
if (!unlimitedSprint)
|
||||
{
|
||||
sprintRemaining = sprintDuration;
|
||||
sprintCooldownReset = sprintCooldown;
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if(lockCursor)
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
|
||||
if(crosshair)
|
||||
{
|
||||
crosshairObject.sprite = crosshairImage;
|
||||
crosshairObject.color = crosshairColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
crosshairObject.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
#region Sprint Bar
|
||||
|
||||
sprintBarCG = GetComponentInChildren<CanvasGroup>();
|
||||
|
||||
if(useSprintBar)
|
||||
{
|
||||
sprintBarBG.gameObject.SetActive(true);
|
||||
sprintBar.gameObject.SetActive(true);
|
||||
|
||||
float screenWidth = Screen.width;
|
||||
float screenHeight = Screen.height;
|
||||
|
||||
sprintBarWidth = screenWidth * sprintBarWidthPercent;
|
||||
sprintBarHeight = screenHeight * sprintBarHeightPercent;
|
||||
|
||||
sprintBarBG.rectTransform.sizeDelta = new Vector3(sprintBarWidth, sprintBarHeight, 0f);
|
||||
sprintBar.rectTransform.sizeDelta = new Vector3(sprintBarWidth - 2, sprintBarHeight - 2, 0f);
|
||||
|
||||
if(hideBarWhenFull)
|
||||
{
|
||||
sprintBarCG.alpha = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintBarBG.gameObject.SetActive(false);
|
||||
sprintBar.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
float camRotation;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
#region Camera
|
||||
|
||||
// Control camera movement
|
||||
if(cameraCanMove)
|
||||
{
|
||||
yaw = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * mouseSensitivity;
|
||||
|
||||
if (!invertCamera)
|
||||
{
|
||||
pitch -= mouseSensitivity * Input.GetAxis("Mouse Y");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Inverted Y
|
||||
pitch += mouseSensitivity * Input.GetAxis("Mouse Y");
|
||||
}
|
||||
|
||||
// Clamp pitch between lookAngle
|
||||
pitch = Mathf.Clamp(pitch, -maxLookAngle, maxLookAngle);
|
||||
|
||||
transform.localEulerAngles = new Vector3(0, yaw, 0);
|
||||
playerCamera.transform.localEulerAngles = new Vector3(pitch, 0, 0);
|
||||
}
|
||||
|
||||
#region Camera Zoom
|
||||
|
||||
if (enableZoom)
|
||||
{
|
||||
// Changes isZoomed when key is pressed
|
||||
// Behavior for toogle zoom
|
||||
if(Input.GetKeyDown(zoomKey) && !holdToZoom && !isSprinting)
|
||||
{
|
||||
if (!isZoomed)
|
||||
{
|
||||
isZoomed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
isZoomed = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Changes isZoomed when key is pressed
|
||||
// Behavior for hold to zoom
|
||||
if(holdToZoom && !isSprinting)
|
||||
{
|
||||
if(Input.GetKeyDown(zoomKey))
|
||||
{
|
||||
isZoomed = true;
|
||||
}
|
||||
else if(Input.GetKeyUp(zoomKey))
|
||||
{
|
||||
isZoomed = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Lerps camera.fieldOfView to allow for a smooth transistion
|
||||
if(isZoomed)
|
||||
{
|
||||
playerCamera.fieldOfView = Mathf.Lerp(playerCamera.fieldOfView, zoomFOV, zoomStepTime * Time.deltaTime);
|
||||
}
|
||||
else if(!isZoomed && !isSprinting)
|
||||
{
|
||||
playerCamera.fieldOfView = Mathf.Lerp(playerCamera.fieldOfView, fov, zoomStepTime * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Sprint
|
||||
|
||||
if(enableSprint)
|
||||
{
|
||||
if(isSprinting)
|
||||
{
|
||||
isZoomed = false;
|
||||
playerCamera.fieldOfView = Mathf.Lerp(playerCamera.fieldOfView, sprintFOV, sprintFOVStepTime * Time.deltaTime);
|
||||
|
||||
// Drain sprint remaining while sprinting
|
||||
if(!unlimitedSprint)
|
||||
{
|
||||
sprintRemaining -= 1 * Time.deltaTime;
|
||||
if (sprintRemaining <= 0)
|
||||
{
|
||||
isSprinting = false;
|
||||
isSprintCooldown = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Regain sprint while not sprinting
|
||||
sprintRemaining = Mathf.Clamp(sprintRemaining += 1 * Time.deltaTime, 0, sprintDuration);
|
||||
}
|
||||
|
||||
// Handles sprint cooldown
|
||||
// When sprint remaining == 0 stops sprint ability until hitting cooldown
|
||||
if(isSprintCooldown)
|
||||
{
|
||||
sprintCooldown -= 1 * Time.deltaTime;
|
||||
if (sprintCooldown <= 0)
|
||||
{
|
||||
isSprintCooldown = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintCooldown = sprintCooldownReset;
|
||||
}
|
||||
|
||||
// Handles sprintBar
|
||||
if(useSprintBar && !unlimitedSprint)
|
||||
{
|
||||
float sprintRemainingPercent = sprintRemaining / sprintDuration;
|
||||
sprintBar.transform.localScale = new Vector3(sprintRemainingPercent, 1f, 1f);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Jump
|
||||
|
||||
// Gets input and calls jump method
|
||||
if(enableJump && Input.GetKeyDown(jumpKey) && isGrounded)
|
||||
{
|
||||
Jump();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Crouch
|
||||
|
||||
if (enableCrouch)
|
||||
{
|
||||
if(Input.GetKeyDown(crouchKey) && !holdToCrouch)
|
||||
{
|
||||
Crouch();
|
||||
}
|
||||
|
||||
if(Input.GetKeyDown(crouchKey) && holdToCrouch)
|
||||
{
|
||||
isCrouched = false;
|
||||
Crouch();
|
||||
}
|
||||
else if(Input.GetKeyUp(crouchKey) && holdToCrouch)
|
||||
{
|
||||
isCrouched = true;
|
||||
Crouch();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
CheckGround();
|
||||
|
||||
if(enableHeadBob)
|
||||
{
|
||||
HeadBob();
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
#region Movement
|
||||
|
||||
if (playerCanMove)
|
||||
{
|
||||
// Calculate how fast we should be moving
|
||||
Vector3 targetVelocity = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
|
||||
|
||||
// Checks if player is walking and isGrounded
|
||||
// Will allow head bob
|
||||
if (targetVelocity.x != 0 || targetVelocity.z != 0 && isGrounded)
|
||||
{
|
||||
isWalking = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
isWalking = false;
|
||||
}
|
||||
|
||||
// All movement calculations shile sprint is active
|
||||
if (enableSprint && Input.GetKey(sprintKey) && sprintRemaining > 0f && !isSprintCooldown)
|
||||
{
|
||||
targetVelocity = transform.TransformDirection(targetVelocity) * sprintSpeed;
|
||||
|
||||
// Apply a force that attempts to reach our target velocity
|
||||
Vector3 velocity = rb.velocity;
|
||||
Vector3 velocityChange = (targetVelocity - velocity);
|
||||
velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
|
||||
velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
|
||||
velocityChange.y = 0;
|
||||
|
||||
// Player is only moving when valocity change != 0
|
||||
// Makes sure fov change only happens during movement
|
||||
if (velocityChange.x != 0 || velocityChange.z != 0)
|
||||
{
|
||||
isSprinting = true;
|
||||
|
||||
if (isCrouched)
|
||||
{
|
||||
Crouch();
|
||||
}
|
||||
|
||||
if (hideBarWhenFull && !unlimitedSprint)
|
||||
{
|
||||
sprintBarCG.alpha += 5 * Time.deltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
rb.AddForce(velocityChange, ForceMode.VelocityChange);
|
||||
}
|
||||
// All movement calculations while walking
|
||||
else
|
||||
{
|
||||
isSprinting = false;
|
||||
|
||||
if (hideBarWhenFull && sprintRemaining == sprintDuration)
|
||||
{
|
||||
sprintBarCG.alpha -= 3 * Time.deltaTime;
|
||||
}
|
||||
|
||||
targetVelocity = transform.TransformDirection(targetVelocity) * walkSpeed;
|
||||
|
||||
// Apply a force that attempts to reach our target velocity
|
||||
Vector3 velocity = rb.velocity;
|
||||
Vector3 velocityChange = (targetVelocity - velocity);
|
||||
velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
|
||||
velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
|
||||
velocityChange.y = 0;
|
||||
|
||||
rb.AddForce(velocityChange, ForceMode.VelocityChange);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
// Sets isGrounded based on a raycast sent straigth down from the player object
|
||||
private void CheckGround()
|
||||
{
|
||||
Vector3 origin = new Vector3(transform.position.x, transform.position.y - (transform.localScale.y * .5f), transform.position.z);
|
||||
Vector3 direction = transform.TransformDirection(Vector3.down);
|
||||
float distance = .75f;
|
||||
|
||||
if (Physics.Raycast(origin, direction, out RaycastHit hit, distance))
|
||||
{
|
||||
Debug.DrawRay(origin, direction * distance, Color.red);
|
||||
isGrounded = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
isGrounded = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void Jump()
|
||||
{
|
||||
// Adds force to the player rigidbody to jump
|
||||
if (isGrounded)
|
||||
{
|
||||
rb.AddForce(0f, jumpPower, 0f, ForceMode.Impulse);
|
||||
isGrounded = false;
|
||||
}
|
||||
|
||||
// When crouched and using toggle system, will uncrouch for a jump
|
||||
if(isCrouched && !holdToCrouch)
|
||||
{
|
||||
Crouch();
|
||||
}
|
||||
}
|
||||
|
||||
private void Crouch()
|
||||
{
|
||||
// Stands player up to full height
|
||||
// Brings walkSpeed back up to original speed
|
||||
if(isCrouched)
|
||||
{
|
||||
transform.localScale = new Vector3(originalScale.x, originalScale.y, originalScale.z);
|
||||
walkSpeed /= speedReduction;
|
||||
|
||||
isCrouched = false;
|
||||
}
|
||||
// Crouches player down to set height
|
||||
// Reduces walkSpeed
|
||||
else
|
||||
{
|
||||
transform.localScale = new Vector3(originalScale.x, crouchHeight, originalScale.z);
|
||||
walkSpeed *= speedReduction;
|
||||
|
||||
isCrouched = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void HeadBob()
|
||||
{
|
||||
if(isWalking)
|
||||
{
|
||||
// Calculates HeadBob speed during sprint
|
||||
if(isSprinting)
|
||||
{
|
||||
timer += Time.deltaTime * (bobSpeed + sprintSpeed);
|
||||
}
|
||||
// Calculates HeadBob speed during crouched movement
|
||||
else if (isCrouched)
|
||||
{
|
||||
timer += Time.deltaTime * (bobSpeed * speedReduction);
|
||||
}
|
||||
// Calculates HeadBob speed during walking
|
||||
else
|
||||
{
|
||||
timer += Time.deltaTime * bobSpeed;
|
||||
}
|
||||
// Applies HeadBob movement
|
||||
joint.localPosition = new Vector3(jointOriginalPos.x + Mathf.Sin(timer) * bobAmount.x, jointOriginalPos.y + Mathf.Sin(timer) * bobAmount.y, jointOriginalPos.z + Mathf.Sin(timer) * bobAmount.z);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Resets when play stops moving
|
||||
timer = 0;
|
||||
joint.localPosition = new Vector3(Mathf.Lerp(joint.localPosition.x, jointOriginalPos.x, Time.deltaTime * bobSpeed), Mathf.Lerp(joint.localPosition.y, jointOriginalPos.y, Time.deltaTime * bobSpeed), Mathf.Lerp(joint.localPosition.z, jointOriginalPos.z, Time.deltaTime * bobSpeed));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Custom Editor
|
||||
#if UNITY_EDITOR
|
||||
[CustomEditor(typeof(FirstPersonController)), InitializeOnLoadAttribute]
|
||||
public class FirstPersonControllerEditor : Editor
|
||||
{
|
||||
FirstPersonController fpc;
|
||||
SerializedObject SerFPC;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
fpc = (FirstPersonController)target;
|
||||
SerFPC = new SerializedObject(fpc);
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
SerFPC.Update();
|
||||
|
||||
EditorGUILayout.Space();
|
||||
GUILayout.Label("Modular First Person Controller", new GUIStyle(GUI.skin.label) { alignment = TextAnchor.MiddleCenter, fontStyle = FontStyle.Bold, fontSize = 16 });
|
||||
GUILayout.Label("By Jess Case", new GUIStyle(GUI.skin.label) { alignment = TextAnchor.MiddleCenter, fontStyle = FontStyle.Normal, fontSize = 12 });
|
||||
GUILayout.Label("version 1.0.1", new GUIStyle(GUI.skin.label) { alignment = TextAnchor.MiddleCenter, fontStyle = FontStyle.Normal, fontSize = 12 });
|
||||
EditorGUILayout.Space();
|
||||
|
||||
#region Camera Setup
|
||||
|
||||
EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
|
||||
GUILayout.Label("Camera Setup", new GUIStyle(GUI.skin.label) { alignment = TextAnchor.MiddleCenter, fontStyle = FontStyle.Bold, fontSize = 13 }, GUILayout.ExpandWidth(true));
|
||||
EditorGUILayout.Space();
|
||||
|
||||
fpc.playerCamera = (Camera)EditorGUILayout.ObjectField(new GUIContent("Camera", "Camera attached to the controller."), fpc.playerCamera, typeof(Camera), true);
|
||||
fpc.fov = EditorGUILayout.Slider(new GUIContent("Field of View", "The camera’s view angle. Changes the player camera directly."), fpc.fov, fpc.zoomFOV, 179f);
|
||||
fpc.cameraCanMove = EditorGUILayout.ToggleLeft(new GUIContent("Enable Camera Rotation", "Determines if the camera is allowed to move."), fpc.cameraCanMove);
|
||||
|
||||
GUI.enabled = fpc.cameraCanMove;
|
||||
fpc.invertCamera = EditorGUILayout.ToggleLeft(new GUIContent("Invert Camera Rotation", "Inverts the up and down movement of the camera."), fpc.invertCamera);
|
||||
fpc.mouseSensitivity = EditorGUILayout.Slider(new GUIContent("Look Sensitivity", "Determines how sensitive the mouse movement is."), fpc.mouseSensitivity, .1f, 10f);
|
||||
fpc.maxLookAngle = EditorGUILayout.Slider(new GUIContent("Max Look Angle", "Determines the max and min angle the player camera is able to look."), fpc.maxLookAngle, 40, 90);
|
||||
GUI.enabled = true;
|
||||
|
||||
fpc.lockCursor = EditorGUILayout.ToggleLeft(new GUIContent("Lock and Hide Cursor", "Turns off the cursor visibility and locks it to the middle of the screen."), fpc.lockCursor);
|
||||
|
||||
fpc.crosshair = EditorGUILayout.ToggleLeft(new GUIContent("Auto Crosshair", "Determines if the basic crosshair will be turned on, and sets is to the center of the screen."), fpc.crosshair);
|
||||
|
||||
// Only displays crosshair options if crosshair is enabled
|
||||
if(fpc.crosshair)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.PrefixLabel(new GUIContent("Crosshair Image", "Sprite to use as the crosshair."));
|
||||
fpc.crosshairImage = (Sprite)EditorGUILayout.ObjectField(fpc.crosshairImage, typeof(Sprite), false);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
fpc.crosshairColor = EditorGUILayout.ColorField(new GUIContent("Crosshair Color", "Determines the color of the crosshair."), fpc.crosshairColor);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
#region Camera Zoom Setup
|
||||
|
||||
GUILayout.Label("Zoom", new GUIStyle(GUI.skin.label) { alignment = TextAnchor.MiddleLeft, fontStyle = FontStyle.Bold, fontSize = 13 }, GUILayout.ExpandWidth(true));
|
||||
|
||||
fpc.enableZoom = EditorGUILayout.ToggleLeft(new GUIContent("Enable Zoom", "Determines if the player is able to zoom in while playing."), fpc.enableZoom);
|
||||
|
||||
GUI.enabled = fpc.enableZoom;
|
||||
fpc.holdToZoom = EditorGUILayout.ToggleLeft(new GUIContent("Hold to Zoom", "Requires the player to hold the zoom key instead if pressing to zoom and unzoom."), fpc.holdToZoom);
|
||||
fpc.zoomKey = (KeyCode)EditorGUILayout.EnumPopup(new GUIContent("Zoom Key", "Determines what key is used to zoom."), fpc.zoomKey);
|
||||
fpc.zoomFOV = EditorGUILayout.Slider(new GUIContent("Zoom FOV", "Determines the field of view the camera zooms to."), fpc.zoomFOV, .1f, fpc.fov);
|
||||
fpc.zoomStepTime = EditorGUILayout.Slider(new GUIContent("Step Time", "Determines how fast the FOV transitions while zooming in."), fpc.zoomStepTime, .1f, 10f);
|
||||
GUI.enabled = true;
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Movement Setup
|
||||
|
||||
EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
|
||||
GUILayout.Label("Movement Setup", new GUIStyle(GUI.skin.label) { alignment = TextAnchor.MiddleCenter, fontStyle = FontStyle.Bold, fontSize = 13 }, GUILayout.ExpandWidth(true));
|
||||
EditorGUILayout.Space();
|
||||
|
||||
fpc.playerCanMove = EditorGUILayout.ToggleLeft(new GUIContent("Enable Player Movement", "Determines if the player is allowed to move."), fpc.playerCanMove);
|
||||
|
||||
GUI.enabled = fpc.playerCanMove;
|
||||
fpc.walkSpeed = EditorGUILayout.Slider(new GUIContent("Walk Speed", "Determines how fast the player will move while walking."), fpc.walkSpeed, .1f, fpc.sprintSpeed);
|
||||
GUI.enabled = true;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
#region Sprint
|
||||
|
||||
GUILayout.Label("Sprint", new GUIStyle(GUI.skin.label) { alignment = TextAnchor.MiddleLeft, fontStyle = FontStyle.Bold, fontSize = 13 }, GUILayout.ExpandWidth(true));
|
||||
|
||||
fpc.enableSprint = EditorGUILayout.ToggleLeft(new GUIContent("Enable Sprint", "Determines if the player is allowed to sprint."), fpc.enableSprint);
|
||||
|
||||
GUI.enabled = fpc.enableSprint;
|
||||
fpc.unlimitedSprint = EditorGUILayout.ToggleLeft(new GUIContent("Unlimited Sprint", "Determines if 'Sprint Duration' is enabled. Turning this on will allow for unlimited sprint."), fpc.unlimitedSprint);
|
||||
fpc.sprintKey = (KeyCode)EditorGUILayout.EnumPopup(new GUIContent("Sprint Key", "Determines what key is used to sprint."), fpc.sprintKey);
|
||||
fpc.sprintSpeed = EditorGUILayout.Slider(new GUIContent("Sprint Speed", "Determines how fast the player will move while sprinting."), fpc.sprintSpeed, fpc.walkSpeed, 20f);
|
||||
|
||||
//GUI.enabled = !fpc.unlimitedSprint;
|
||||
fpc.sprintDuration = EditorGUILayout.Slider(new GUIContent("Sprint Duration", "Determines how long the player can sprint while unlimited sprint is disabled."), fpc.sprintDuration, 1f, 20f);
|
||||
fpc.sprintCooldown = EditorGUILayout.Slider(new GUIContent("Sprint Cooldown", "Determines how long the recovery time is when the player runs out of sprint."), fpc.sprintCooldown, .1f, fpc.sprintDuration);
|
||||
//GUI.enabled = true;
|
||||
|
||||
fpc.sprintFOV = EditorGUILayout.Slider(new GUIContent("Sprint FOV", "Determines the field of view the camera changes to while sprinting."), fpc.sprintFOV, fpc.fov, 179f);
|
||||
fpc.sprintFOVStepTime = EditorGUILayout.Slider(new GUIContent("Step Time", "Determines how fast the FOV transitions while sprinting."), fpc.sprintFOVStepTime, .1f, 20f);
|
||||
|
||||
fpc.useSprintBar = EditorGUILayout.ToggleLeft(new GUIContent("Use Sprint Bar", "Determines if the default sprint bar will appear on screen."), fpc.useSprintBar);
|
||||
|
||||
// Only displays sprint bar options if sprint bar is enabled
|
||||
if(fpc.useSprintBar)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
fpc.hideBarWhenFull = EditorGUILayout.ToggleLeft(new GUIContent("Hide Full Bar", "Hides the sprint bar when sprint duration is full, and fades the bar in when sprinting. Disabling this will leave the bar on screen at all times when the sprint bar is enabled."), fpc.hideBarWhenFull);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.PrefixLabel(new GUIContent("Bar BG", "Object to be used as sprint bar background."));
|
||||
fpc.sprintBarBG = (Image)EditorGUILayout.ObjectField(fpc.sprintBarBG, typeof(Image), true);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.PrefixLabel(new GUIContent("Bar", "Object to be used as sprint bar foreground."));
|
||||
fpc.sprintBar = (Image)EditorGUILayout.ObjectField(fpc.sprintBar, typeof(Image), true);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
fpc.sprintBarWidthPercent = EditorGUILayout.Slider(new GUIContent("Bar Width", "Determines the width of the sprint bar."), fpc.sprintBarWidthPercent, .1f, .5f);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
fpc.sprintBarHeightPercent = EditorGUILayout.Slider(new GUIContent("Bar Height", "Determines the height of the sprint bar."), fpc.sprintBarHeightPercent, .001f, .025f);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
GUI.enabled = true;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Jump
|
||||
|
||||
GUILayout.Label("Jump", new GUIStyle(GUI.skin.label) { alignment = TextAnchor.MiddleLeft, fontStyle = FontStyle.Bold, fontSize = 13 }, GUILayout.ExpandWidth(true));
|
||||
|
||||
fpc.enableJump = EditorGUILayout.ToggleLeft(new GUIContent("Enable Jump", "Determines if the player is allowed to jump."), fpc.enableJump);
|
||||
|
||||
GUI.enabled = fpc.enableJump;
|
||||
fpc.jumpKey = (KeyCode)EditorGUILayout.EnumPopup(new GUIContent("Jump Key", "Determines what key is used to jump."), fpc.jumpKey);
|
||||
fpc.jumpPower = EditorGUILayout.Slider(new GUIContent("Jump Power", "Determines how high the player will jump."), fpc.jumpPower, .1f, 20f);
|
||||
GUI.enabled = true;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Crouch
|
||||
|
||||
GUILayout.Label("Crouch", new GUIStyle(GUI.skin.label) { alignment = TextAnchor.MiddleLeft, fontStyle = FontStyle.Bold, fontSize = 13 }, GUILayout.ExpandWidth(true));
|
||||
|
||||
fpc.enableCrouch = EditorGUILayout.ToggleLeft(new GUIContent("Enable Crouch", "Determines if the player is allowed to crouch."), fpc.enableCrouch);
|
||||
|
||||
GUI.enabled = fpc.enableCrouch;
|
||||
fpc.holdToCrouch = EditorGUILayout.ToggleLeft(new GUIContent("Hold To Crouch", "Requires the player to hold the crouch key instead if pressing to crouch and uncrouch."), fpc.holdToCrouch);
|
||||
fpc.crouchKey = (KeyCode)EditorGUILayout.EnumPopup(new GUIContent("Crouch Key", "Determines what key is used to crouch."), fpc.crouchKey);
|
||||
fpc.crouchHeight = EditorGUILayout.Slider(new GUIContent("Crouch Height", "Determines the y scale of the player object when crouched."), fpc.crouchHeight, .1f, 1);
|
||||
fpc.speedReduction = EditorGUILayout.Slider(new GUIContent("Speed Reduction", "Determines the percent 'Walk Speed' is reduced by. 1 being no reduction, and .5 being half."), fpc.speedReduction, .1f, 1);
|
||||
GUI.enabled = true;
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Head Bob
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
|
||||
GUILayout.Label("Head Bob Setup", new GUIStyle(GUI.skin.label) { alignment = TextAnchor.MiddleCenter, fontStyle = FontStyle.Bold, fontSize = 13 }, GUILayout.ExpandWidth(true));
|
||||
EditorGUILayout.Space();
|
||||
|
||||
fpc.enableHeadBob = EditorGUILayout.ToggleLeft(new GUIContent("Enable Head Bob", "Determines if the camera will bob while the player is walking."), fpc.enableHeadBob);
|
||||
|
||||
|
||||
GUI.enabled = fpc.enableHeadBob;
|
||||
fpc.joint = (Transform)EditorGUILayout.ObjectField(new GUIContent("Camera Joint", "Joint object position is moved while head bob is active."), fpc.joint, typeof(Transform), true);
|
||||
fpc.bobSpeed = EditorGUILayout.Slider(new GUIContent("Speed", "Determines how often a bob rotation is completed."), fpc.bobSpeed, 1, 20);
|
||||
fpc.bobAmount = EditorGUILayout.Vector3Field(new GUIContent("Bob Amount", "Determines the amount the joint moves in both directions on every axes."), fpc.bobAmount);
|
||||
GUI.enabled = true;
|
||||
|
||||
#endregion
|
||||
|
||||
//Sets any changes from the prefab
|
||||
if(GUI.changed)
|
||||
{
|
||||
EditorUtility.SetDirty(fpc);
|
||||
Undo.RecordObject(fpc, "FPC Change");
|
||||
SerFPC.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Executable file
+28
@@ -0,0 +1,28 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class TimeText3D : MonoBehaviour
|
||||
{
|
||||
public TMP_Text TextObject;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (TextObject)
|
||||
{
|
||||
string Time = TimeController.PublicFormattedTimeOfDay;
|
||||
TextObject.text = "In-game time: " + Time;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTimeFormat(bool is24hour)
|
||||
{
|
||||
TimeController.MilitaryTime = is24hour;
|
||||
}
|
||||
|
||||
private void OnMouseDown()
|
||||
{
|
||||
SetTimeFormat(!TimeController.MilitaryTime);
|
||||
}
|
||||
}
|
||||
Executable file
+33
@@ -0,0 +1,33 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class AdvLevelMan : MonoBehaviour
|
||||
{
|
||||
public Slider loadingBar;
|
||||
public TMP_Text loadingText;
|
||||
|
||||
public void SwitchSceneAdv(string levelName)
|
||||
{
|
||||
StartCoroutine(LoadSceneAsync(levelName));
|
||||
}
|
||||
|
||||
IEnumerator LoadSceneAsync(string levelName)
|
||||
{
|
||||
Debug.Log($"Loading scene {levelName}");
|
||||
AsyncOperation op = SceneManager.LoadSceneAsync(levelName);
|
||||
while (!op.isDone)
|
||||
{
|
||||
float progress = Mathf.Clamp01(op.progress / .9f);
|
||||
//Debug.Log(op.progress);
|
||||
loadingBar.value = progress;
|
||||
loadingText.text = $"<align=center>{(progress * 100f).ToString("0.00")}%";
|
||||
if ((progress * 100f) >= 98)
|
||||
loadingText.text = "Doing stuff...";
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable file
+75
@@ -0,0 +1,75 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class BigWorld : MonoBehaviour
|
||||
{
|
||||
public bool useAudioBundle = false;
|
||||
public AudioBundleLoader BundleLoader;
|
||||
public List<string> AudioClipNames = new() {
|
||||
"Gion3.ogg",
|
||||
"OriginStation.ogg",
|
||||
"TrainToTheFuture.ogg",
|
||||
"Finality.ogg"
|
||||
};
|
||||
public AssetBundle AudioBundle;
|
||||
public AudioSource ambientAudioSource;
|
||||
public AudioClip CurrentAmbient;
|
||||
public bool AutoPlayAmbient = true;
|
||||
private readonly System.Random random = new();
|
||||
[ShowOnly] public float AudioChangesOn = 0f;
|
||||
[ShowOnly] public bool AudioIsPlaying = false;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (BundleLoader)
|
||||
{
|
||||
AudioBundle = BundleLoader.AudioAssetBundle;
|
||||
}
|
||||
if (AutoPlayAmbient)
|
||||
{
|
||||
Debug.Log("Automatically playing ambient...");
|
||||
PlayAmbient();
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayAmbient()
|
||||
{
|
||||
if (useAudioBundle)
|
||||
{
|
||||
string AudioClipName = AudioClipNames[random.Next(AudioClipNames.Count)];
|
||||
Debug.Log("Attempting to load audiobundle...");
|
||||
if (ambientAudioSource)
|
||||
{
|
||||
AudioClip clip = BundleLoader.GetAudioClipFromAssetBundle(/*"Default/" + */AudioClipName);
|
||||
if (!clip)
|
||||
Debug.LogError($"AudioClip {AudioClipName} could not be loaded.");
|
||||
else
|
||||
{
|
||||
ambientAudioSource.clip = clip;
|
||||
ambientAudioSource.Play();
|
||||
ambientAudioSource.clip = clip;
|
||||
AudioChangesOn = clip.length;
|
||||
Debug.LogError($"Tried playing ambience: {clip.name} with a length of {clip.length}");
|
||||
AudioIsPlaying = true;
|
||||
//TimesAmbientSet++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (AutoPlayAmbient)
|
||||
{
|
||||
if (ambientAudioSource.isPlaying)
|
||||
{
|
||||
AudioChangesOn -= Time.fixedDeltaTime;
|
||||
}
|
||||
if (AudioChangesOn <= 0f && AudioIsPlaying)
|
||||
{
|
||||
Debug.LogError("Clip has finished playing. Choosing a random clip...");
|
||||
PlayAmbient();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable file
+123
@@ -0,0 +1,123 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class HomeWorld_Initialize : MonoBehaviour
|
||||
{
|
||||
public AudioSource audioSource;
|
||||
public AudioClip OpenMenuClip1;
|
||||
public float PlayVolume = 0.8f;
|
||||
public string StartingClipName = "UI_OpenMenu_Start.wav";
|
||||
|
||||
private readonly System.Random random = new();
|
||||
//[ShowOnly] public float AudioElapsedTimePlaying = 0;
|
||||
[ShowOnly] public float AudioChangesOn = 0f;
|
||||
[ShowOnly] public bool AudioIsPlaying = false;
|
||||
public List<string> AudioClipNames = new() {
|
||||
"Gion3.ogg",
|
||||
"OriginStation.ogg",
|
||||
"TrainToTheFuture.ogg",
|
||||
"AsBefore.ogg"
|
||||
//"Finality-HOYO-MiX.ogg"
|
||||
};
|
||||
public bool useAssetBundle = false;
|
||||
public AudioBundleLoader BundleLoader;
|
||||
public AssetBundle AudioBundle;
|
||||
public RectTransform SettingsPanel;
|
||||
private Resolution GameResolutionPre;
|
||||
public Toggle FullscreenToggle;
|
||||
|
||||
private async void Start()
|
||||
{
|
||||
if (useAssetBundle)
|
||||
{
|
||||
/*BundleLoader.InitializeAudioAssetBundle();
|
||||
new WaitForSeconds(2);*/
|
||||
AudioBundle = BundleLoader.GetAudioAssetBundle();
|
||||
OpenMenuClip1 = BundleLoader.GetAudioClipFromAssetBundle(StartingClipName);
|
||||
}
|
||||
else if (!OpenMenuClip1)
|
||||
OpenMenuClip1 = await JTN.Utils.LoadClip(Path.Combine(Application.streamingAssetsPath, StartingClipName));
|
||||
if (audioSource && OpenMenuClip1)
|
||||
audioSource.PlayOneShot(OpenMenuClip1, PlayVolume);
|
||||
/* if (SettingsPanel)
|
||||
{
|
||||
if (Screen.currentResolution.height != GameResolutionPre.height)
|
||||
{
|
||||
SettingsPanel.sizeDelta = new Vector2(SettingsPanel.sizeDelta.x, Screen.currentResolution.height);
|
||||
GameResolutionPre = Screen.currentResolution;
|
||||
}
|
||||
if (Screen.currentResolution.width != GameResolutionPre.width)
|
||||
{
|
||||
SettingsPanel.sizeDelta = new Vector2(Screen.currentResolution.width, SettingsPanel.sizeDelta.y);
|
||||
GameResolutionPre = Screen.currentResolution;
|
||||
}
|
||||
}*/
|
||||
|
||||
if (PlayerPrefs.HasKey("FullscreenState") && FullscreenToggle)
|
||||
{
|
||||
if (PlayerPrefs.GetInt("FullscreenState") == 1)
|
||||
{
|
||||
FullscreenToggle.isOn = true;
|
||||
} else
|
||||
{
|
||||
FullscreenToggle.isOn = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (BundleLoader.AudioAssetBundle)
|
||||
{
|
||||
if (!audioSource.isPlaying)
|
||||
PlayBGM();
|
||||
else
|
||||
{
|
||||
AudioChangesOn -= Time.fixedDeltaTime;
|
||||
}
|
||||
if (AudioChangesOn <= 0f && AudioIsPlaying)
|
||||
{
|
||||
Debug.LogError("Clip has finished playing. Choosing a random clip...");
|
||||
PlayBGM();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*private void Update()
|
||||
{
|
||||
if (SettingsPanel)
|
||||
{
|
||||
if (Screen.currentResolution.height != GameResolutionPre.height &&
|
||||
Screen.currentResolution.width != GameResolutionPre.width)
|
||||
{
|
||||
SettingsPanel.sizeDelta = new Vector2(Screen.currentResolution.width, Screen.currentResolution.height);
|
||||
}
|
||||
GameResolutionPre = Screen.currentResolution;
|
||||
}
|
||||
}*/
|
||||
public void PlayBGM()
|
||||
{
|
||||
string AudioClipName = AudioClipNames[random.Next(AudioClipNames.Count)];
|
||||
Debug.Log("Attempting to load audiobundle...");
|
||||
if (audioSource)
|
||||
{
|
||||
AudioClip clip = BundleLoader.GetAudioClipFromAssetBundle(/*"Default/" + */AudioClipName);
|
||||
if (!clip)
|
||||
Debug.LogError($"AudioClip {AudioClipName} could not be loaded.");
|
||||
else
|
||||
{
|
||||
audioSource.clip = clip;
|
||||
audioSource.Play();
|
||||
audioSource.clip = clip;
|
||||
AudioChangesOn = clip.length;
|
||||
Debug.LogError($"Tried playing ambience: {clip.name} with a length of {clip.length}");
|
||||
AudioIsPlaying = true;
|
||||
//TimesAmbientSet++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Executable file
+117
@@ -0,0 +1,117 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class TimeController : MonoBehaviour
|
||||
{
|
||||
public TMP_Text TODIndicator;
|
||||
public Slider TODSlider;
|
||||
[HideInInspector]
|
||||
public GameObject sun;
|
||||
[HideInInspector]
|
||||
public Light sunLight;
|
||||
|
||||
[Range(0, 24)]
|
||||
public float timeOfDay = 12;
|
||||
|
||||
public float secondsPerMinute = 60;
|
||||
[HideInInspector]
|
||||
public float secondsPerHour;
|
||||
[HideInInspector]
|
||||
public float secondsPerDay;
|
||||
|
||||
// Realistic - 1
|
||||
// Normal - 2400
|
||||
public float timeMultiplier = 2400;
|
||||
|
||||
public static string PublicFormattedTimeOfDay = "00:00";
|
||||
|
||||
[ShowOnly]
|
||||
public string StringTimeOfDay = "00:00";
|
||||
public static bool MilitaryTime = false;
|
||||
public float MinutesBy = 60;
|
||||
|
||||
void Start()
|
||||
{
|
||||
sun = gameObject;
|
||||
sunLight = gameObject.GetComponent<Light>();
|
||||
|
||||
secondsPerHour = secondsPerMinute * 60;
|
||||
secondsPerDay = secondsPerHour * 24;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
SunUpdate();
|
||||
|
||||
timeOfDay += (Time.deltaTime / secondsPerDay) * timeMultiplier;
|
||||
StringTimeOfDay = FormatTime(timeOfDay, MilitaryTime);
|
||||
PublicFormattedTimeOfDay = StringTimeOfDay;
|
||||
|
||||
if (timeOfDay >= 24)
|
||||
timeOfDay = 0;
|
||||
|
||||
|
||||
if (TODIndicator)
|
||||
TODIndicator.text = StringTimeOfDay;
|
||||
if (TODSlider)
|
||||
{
|
||||
TODSlider.onValueChanged.RemoveAllListeners();
|
||||
TODSlider.onValueChanged.AddListener(delegate { UpdateTime(TODSlider.value); });
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateTime(Single ResultTime)
|
||||
{
|
||||
if (TODSlider)
|
||||
timeOfDay = ResultTime;
|
||||
}
|
||||
public string FormatTime(float TimeOfDay, bool military = true)
|
||||
{
|
||||
TimeSpan timeSpan = TimeSpan.FromHours(TimeOfDay);
|
||||
string hours = timeSpan.Hours.ToString();
|
||||
string minutes = timeSpan.Minutes.ToString();
|
||||
|
||||
if (minutes == "0")
|
||||
minutes += "0";
|
||||
if (timeSpan.Minutes <= 9)
|
||||
minutes = "0" + timeSpan.Minutes;
|
||||
if (timeSpan.Hours < 10 && military)
|
||||
{
|
||||
if (hours == "0")
|
||||
hours += "0";
|
||||
else
|
||||
hours = "0" + hours;
|
||||
}
|
||||
if (!military)
|
||||
{
|
||||
var IntHours = int.Parse(hours);
|
||||
|
||||
if (IntHours <= 12)
|
||||
{
|
||||
if (hours == "0")
|
||||
hours = "12";
|
||||
|
||||
minutes += " AM";
|
||||
}
|
||||
else
|
||||
{
|
||||
minutes += " PM";
|
||||
hours = (IntHours - 12).ToString();
|
||||
}
|
||||
};
|
||||
|
||||
var output = String.Format("{0}:{1}", hours, minutes);
|
||||
return output;
|
||||
}
|
||||
public void SunUpdate()
|
||||
{
|
||||
if (TODSlider)
|
||||
TODSlider.value = timeOfDay;
|
||||
sun.transform.localRotation = Quaternion.Euler(((timeOfDay / 24) * 360f) - 90, 90, 0);
|
||||
}
|
||||
}
|
||||
Executable file
+50
@@ -0,0 +1,50 @@
|
||||
using JTN;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PausePanel : MonoBehaviour
|
||||
{
|
||||
public GameObject PauseMenuPanel;
|
||||
public GameObject PauseButton;
|
||||
public KeyCode PauseKey = KeyCode.Escape;
|
||||
public bool Paused;
|
||||
public FirstPersonController PlayerController;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (PauseMenuPanel && PauseButton)
|
||||
{
|
||||
if (Input.GetKeyDown(PauseKey))
|
||||
{
|
||||
Debug.Log("Paused with " + PauseKey.ToString());
|
||||
Pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
Debug.Log("Pause state: " + Paused);
|
||||
if (!Paused)
|
||||
{
|
||||
PlayerController.enabled = false;
|
||||
PauseButton.SetActive(false);
|
||||
PauseMenuPanel.SetActive(true);
|
||||
|
||||
Paused = true;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Time.timeScale = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayerController.enabled = true;
|
||||
PauseButton.SetActive(true);
|
||||
PauseMenuPanel.SetActive(false);
|
||||
|
||||
Paused = false;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Time.timeScale = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable file
+45
@@ -0,0 +1,45 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class DropDownScenePopulator : MonoBehaviour
|
||||
{
|
||||
public List<Dropdown.OptionData> optionDataList;
|
||||
public Dropdown scenenavigator;
|
||||
public string SelectedSceneName = "";
|
||||
void Start()
|
||||
{
|
||||
if (scenenavigator)
|
||||
{
|
||||
optionDataList = new List<Dropdown.OptionData>();
|
||||
for (int i = 0; i < SceneManager.sceneCountInBuildSettings; ++i)
|
||||
{
|
||||
string name = System.IO.Path.GetFileNameWithoutExtension(SceneUtility.GetScenePathByBuildIndex(i));
|
||||
optionDataList.Add(new Dropdown.OptionData(name));
|
||||
}
|
||||
scenenavigator.ClearOptions();
|
||||
scenenavigator.AddOptions(optionDataList);
|
||||
scenenavigator.onValueChanged.AddListener((t) => {
|
||||
//SetSceneOptionData(optionDataList[scenenavigator.value]);
|
||||
SelectedSceneName = optionDataList[scenenavigator.value].text;
|
||||
Debug.LogError("Selected scene in navigator: " + optionDataList[scenenavigator.value].text);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void SwitchScene()
|
||||
{
|
||||
Time.timeScale = 1;
|
||||
Debug.Log(SelectedSceneName);
|
||||
Debug.Log(string.Format("Setting current scene to {0}", SelectedSceneName));
|
||||
SceneManager.LoadScene(SelectedSceneName);
|
||||
}
|
||||
|
||||
public void ReloadScene()
|
||||
{
|
||||
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
|
||||
}
|
||||
}
|
||||
Executable file
+47
@@ -0,0 +1,47 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.PostProcessing;
|
||||
|
||||
public class SettingsPanel : MonoBehaviour
|
||||
{
|
||||
public GameObject settingsPanel;
|
||||
public GameObject settingsPanelDeactivator;
|
||||
public bool DisableSettingsPanelWhenLinkedGameobjectIsActivated = false;
|
||||
public TMP_Dropdown GraphicsQualityDropdown;
|
||||
public PostProcessVolume PostProcessVolume;
|
||||
private void Update()
|
||||
{
|
||||
if (settingsPanel && DisableSettingsPanelWhenLinkedGameobjectIsActivated && settingsPanelDeactivator.activeInHierarchy)
|
||||
{
|
||||
settingsPanel.SetActive(false);
|
||||
settingsPanelDeactivator.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (GraphicsQualityDropdown)
|
||||
{
|
||||
string[] QualityNames = QualitySettings.names;
|
||||
List<TMP_Dropdown.OptionData> Options = new();
|
||||
GraphicsQualityDropdown.ClearOptions();
|
||||
foreach (string QualityName in QualityNames)
|
||||
{
|
||||
Options.Add(new TMP_Dropdown.OptionData(QualityName));
|
||||
}
|
||||
|
||||
GraphicsQualityDropdown.AddOptions(Options);
|
||||
GraphicsQualityDropdown.value = QualitySettings.GetQualityLevel();
|
||||
}
|
||||
}
|
||||
|
||||
public void SwitchQualitySettings(int index)
|
||||
{
|
||||
if (GraphicsQualityDropdown)
|
||||
{
|
||||
QualitySettings.SetQualityLevel(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable file
+5
@@ -0,0 +1,5 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class ShowOnlyAttribute : PropertyAttribute
|
||||
{
|
||||
}
|
||||
Executable file
+69
@@ -0,0 +1,69 @@
|
||||
using System.IO;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace JTN
|
||||
{
|
||||
public class Startup : MonoBehaviour
|
||||
{
|
||||
public bool changeResolutionAutomatically;
|
||||
public bool useStartupScriptHere;
|
||||
public TMP_Text MessageText;
|
||||
[ShowOnly] public int MissingAssetFiles = 0;
|
||||
public List<string> FilesThatMustExistInStreamingAssetsToSwitchScenes = new List<string>() {
|
||||
Path.Combine("Audio", "AudioAssets.bunl")
|
||||
};
|
||||
public string MissingFiles = "";
|
||||
public void resoChange()
|
||||
{
|
||||
if (!PlayerPrefs.HasKey("FullscreenState"))
|
||||
{
|
||||
if (changeResolutionAutomatically && useStartupScriptHere)
|
||||
{
|
||||
Screen.SetResolution(1533, 720, false);
|
||||
Debug.Log("Changed game resolution to 1533x720");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int FullscreenState = PlayerPrefs.GetInt("FullscreenState");
|
||||
if (FullscreenState == 0)
|
||||
{
|
||||
Screen.fullScreenMode = FullScreenMode.Windowed;
|
||||
Screen.SetResolution(1533, 720, false);
|
||||
Debug.Log("Changed game resolution to 1533x720");
|
||||
} else
|
||||
{
|
||||
Debug.Log($"Set game resolution to {Screen.currentResolution} (fullscreen)");
|
||||
Screen.fullScreenMode = FullScreenMode.FullScreenWindow;
|
||||
}
|
||||
}
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
if (useStartupScriptHere)
|
||||
{
|
||||
resoChange();
|
||||
foreach (string Filename in FilesThatMustExistInStreamingAssetsToSwitchScenes)
|
||||
if (!File.Exists(Path.Combine(Application.streamingAssetsPath, Filename)))
|
||||
{
|
||||
MissingAssetFiles++;
|
||||
MissingFiles += "\n" + Path.Combine(Application.streamingAssetsPath, Filename);
|
||||
}
|
||||
|
||||
if (MissingAssetFiles == 0)
|
||||
{
|
||||
Debug.Log("No missing files were found. Loading next scene.");
|
||||
JTN.Utils.SwitchScene("HomeWorld_Journey1");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageText.text = $"{MissingAssetFiles} asset(s) that are required to run the game have been moved, deleted or renamed.\n\nSearched for but was not found:<size=28>{MissingFiles}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable file
+263
@@ -0,0 +1,263 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace JTN
|
||||
{
|
||||
public class Utils : MonoBehaviour
|
||||
{
|
||||
public bool scrolling;
|
||||
public GameObject objectRot;
|
||||
public GameObject sn;
|
||||
public float movespeed = 3;
|
||||
public float srate = 2;
|
||||
private float tm = 0;
|
||||
private bool once = false;
|
||||
private GameObject currentObjectRot;
|
||||
|
||||
public string GameObjectList;
|
||||
public bool DestroyParentIfNotDevelopment = false;
|
||||
public GameObject Parent;
|
||||
public TMP_InputField timeScaler;
|
||||
public bool UnlockCursorInThisScene = false;
|
||||
public static bool PublicUnlockCursorInThisScene = false;
|
||||
public FirstPersonController playerController;
|
||||
public GameObject Player;
|
||||
public Animation animationToPlay;
|
||||
public GameObject DeactivateObjectOnGameObjectActivate;
|
||||
public GameObject PlayAnimOnActive;
|
||||
public string animName;
|
||||
public bool PlayOnceOnly = true;
|
||||
int timesAnimPlayed = 0;
|
||||
public GameObject LoadSceneOnObjectActivateOrDeactivate;
|
||||
public bool RunOnDeactivate;
|
||||
public string SceneToLoad;
|
||||
public AudioSource audioSource;
|
||||
public AdvLevelMan AdvancedLevelManager;
|
||||
private int LoadedTimes = 0;
|
||||
|
||||
public static void SwitchScene(String SceneName)
|
||||
{
|
||||
Debug.LogError("Attempting to load scene " + SceneName);
|
||||
try
|
||||
{
|
||||
SceneManager.LoadScene(SceneName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e.ToString());
|
||||
Debug.LogError("Try using the developer menu to open " + SceneName);
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<AudioClip> LoadClip(string path)
|
||||
{
|
||||
AudioClip clip = null;
|
||||
using (UnityWebRequest uwr = UnityWebRequestMultimedia.GetAudioClip(path, AudioType.WAV))
|
||||
{
|
||||
uwr.SendWebRequest();
|
||||
|
||||
// wrap tasks in try/catch, otherwise it'll fail silently
|
||||
try
|
||||
{
|
||||
while (!uwr.isDone) await Task.Delay(5);
|
||||
|
||||
if (uwr.result == UnityWebRequest.Result.ConnectionError) Debug.Log($"{uwr.error}");
|
||||
else
|
||||
{
|
||||
clip = DownloadHandlerAudioClip.GetContent(uwr);
|
||||
Debug.Log("Loaded AudioClip from " + path);
|
||||
}
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
Debug.Log($"{err.Message}, {err.StackTrace}");
|
||||
}
|
||||
}
|
||||
|
||||
return clip;
|
||||
}
|
||||
|
||||
public void TimeScale()
|
||||
{
|
||||
if (timeScaler)
|
||||
{
|
||||
var numTime = float.Parse(timeScaler.text);
|
||||
Time.timeScale = numTime;
|
||||
}
|
||||
}
|
||||
|
||||
public void CustomTimeScale(float timeScale)
|
||||
{
|
||||
Time.timeScale = timeScale;
|
||||
}
|
||||
|
||||
public void DisableTextMeshProButton(Button Button)
|
||||
{
|
||||
Button.interactable = false;
|
||||
}
|
||||
public void EnableTextMeshProButton(Button Button)
|
||||
{
|
||||
Button.interactable = true;
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
if (scrolling)
|
||||
{
|
||||
currentObjectRot = Instantiate(objectRot, sn.transform.position, sn.transform.rotation);
|
||||
}
|
||||
|
||||
GameObject[] allObjects = UnityEngine.Object.FindObjectsOfType<GameObject>();
|
||||
foreach (GameObject go in allObjects)
|
||||
GameObjectList = GameObjectList + ", " + go.name;
|
||||
if (!Debug.isDebugBuild || Application.platform != RuntimePlatform.WindowsEditor)
|
||||
Destroy(Parent);
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (scrolling)
|
||||
{
|
||||
if (tm < srate)
|
||||
{
|
||||
tm += Time.deltaTime;
|
||||
}
|
||||
else if (!once && tm < srate)
|
||||
{
|
||||
tm = 0;
|
||||
currentObjectRot = Instantiate(objectRot, sn.transform.position, sn.transform.rotation);
|
||||
}
|
||||
currentObjectRot.GetComponent<RectTransform>().position = currentObjectRot.GetComponent<RectTransform>().position + (Vector3.forward * movespeed) * Time.deltaTime;
|
||||
once = true;
|
||||
}
|
||||
|
||||
if (LoadSceneOnObjectActivateOrDeactivate && AdvancedLevelManager)
|
||||
if (RunOnDeactivate)
|
||||
{
|
||||
if (!LoadSceneOnObjectActivateOrDeactivate.activeInHierarchy && LoadedTimes == 0)
|
||||
{
|
||||
Debug.Log("Loading scene " + SceneToLoad);
|
||||
AdvancedLevelManager.SwitchSceneAdv(SceneToLoad);
|
||||
LoadedTimes++;
|
||||
}
|
||||
}
|
||||
else if (!RunOnDeactivate && LoadSceneOnObjectActivateOrDeactivate.activeInHierarchy && LoadedTimes == 0)
|
||||
{
|
||||
Debug.Log("Loading scene " + SceneToLoad);
|
||||
AdvancedLevelManager.SwitchSceneAdv(SceneToLoad);
|
||||
LoadedTimes++;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ToggleActive(GameObject obj)
|
||||
{
|
||||
obj.SetActive(!obj.activeInHierarchy);
|
||||
}
|
||||
public static void ToggleAnimState(Animation anim)
|
||||
{
|
||||
anim.enabled = !anim.enabled;
|
||||
}
|
||||
|
||||
public static void SetGameObjectToActive(GameObject obj)
|
||||
{
|
||||
obj.SetActive(true);
|
||||
}
|
||||
|
||||
public void PlayAudioClipOnce(AudioClip clip)
|
||||
{
|
||||
if (!audioSource)
|
||||
Debug.LogError("No audio source was linked when running the script attached to " + gameObject.name);
|
||||
else
|
||||
audioSource.PlayOneShot(clip);
|
||||
}
|
||||
public static void SetGameObjectToInactive(GameObject obj)
|
||||
{
|
||||
obj.SetActive(false);
|
||||
}
|
||||
public void SetFullscreen (bool FullscreenState)
|
||||
{
|
||||
Debug.Log($"Set fullscreen pref to {FullscreenState}");
|
||||
if (FullscreenState)
|
||||
{
|
||||
PlayerPrefs.SetInt("FullscreenState", 1);
|
||||
Screen.fullScreenMode = FullScreenMode.FullScreenWindow;
|
||||
Screen.SetResolution(1533, 720, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayerPrefs.SetInt("FullscreenState", 0);
|
||||
Screen.fullScreenMode = FullScreenMode.Windowed;
|
||||
Screen.SetResolution(1533, 720, false);
|
||||
}
|
||||
|
||||
}
|
||||
public void DisableAnim(Animation anim)
|
||||
{
|
||||
anim.enabled = false;
|
||||
}
|
||||
|
||||
public static void PlayAnimByName(Animation anim, string animName)
|
||||
{
|
||||
anim.PlayQueued(animName);
|
||||
}
|
||||
public void PlayAnimation(string animName)
|
||||
{
|
||||
if (animationToPlay)
|
||||
animationToPlay.PlayQueued(animName);
|
||||
}
|
||||
public void playOutAnim(Animation anim)
|
||||
{
|
||||
PlayAnimByName(anim, "SetPanOUT");
|
||||
}
|
||||
public void playInAnim(Animation anim)
|
||||
{
|
||||
PlayAnimByName(anim, "SetPanOUT");
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
PublicUnlockCursorInThisScene = UnlockCursorInThisScene;
|
||||
if (!UnlockCursorInThisScene)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.LeftAlt))
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
if (playerController)
|
||||
playerController.cameraCanMove = false;
|
||||
}
|
||||
else if (Input.GetKeyUp(KeyCode.LeftAlt))
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
if (playerController)
|
||||
playerController.cameraCanMove = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
|
||||
if (DeactivateObjectOnGameObjectActivate)
|
||||
if (gameObject.activeInHierarchy)
|
||||
{
|
||||
DeactivateObjectOnGameObjectActivate.SetActive(false);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
if (PlayAnimOnActive)
|
||||
if (PlayAnimOnActive.activeInHierarchy)
|
||||
{
|
||||
if (timesAnimPlayed < 1)
|
||||
{
|
||||
if (PlayOnceOnly)
|
||||
timesAnimPlayed++;
|
||||
PlayAnimOnActive.SetActive(false);
|
||||
PlayAnimation(animName);
|
||||
Debug.Log("Looping state: " + animationToPlay.clip.isLooping);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user