sfx wip
This commit is contained in:
55
Assets/Scripts/AudioManager.cs
Normal file
55
Assets/Scripts/AudioManager.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class AudioManager : MonoBehaviour
|
||||
{
|
||||
public static AudioManager instance { get; private set;}
|
||||
void Awake(){
|
||||
instance =this;
|
||||
}
|
||||
[SerializeField]private AudioSource sfxSource;
|
||||
[SerializeField]private AudioSource dropSfxSource;
|
||||
[SerializeField]private AudioClip[] lowHits, midHits, hardHits;
|
||||
[SerializeField]private AudioClip[] drop;
|
||||
[SerializeField]private float dropMinPitch = 0.5f;
|
||||
[SerializeField]private float dropMaxPitch = 1.5f;
|
||||
public void PlaySFX(AudioClip clip){
|
||||
sfxSource.PlayOneShot(clip);
|
||||
}
|
||||
|
||||
public static void PlaySfx(AudioClip clip){
|
||||
instance.PlaySFX(clip);
|
||||
}
|
||||
|
||||
|
||||
public static void HitSfx(float magnitude){
|
||||
instance.hitSfx(magnitude);
|
||||
}
|
||||
public static void DropSfx(float magnitude){
|
||||
instance.dropSfx(magnitude);
|
||||
}
|
||||
|
||||
void hitSfx(float magnitude){
|
||||
AudioClip selectedClip;
|
||||
|
||||
if(magnitude < 0.5f){
|
||||
selectedClip = lowHits[Random.Range(0,lowHits.Length)];
|
||||
}else if(magnitude < 1){
|
||||
selectedClip = midHits[Random.Range(0,midHits.Length)];
|
||||
}else{
|
||||
selectedClip = hardHits[Random.Range(0,hardHits.Length)];
|
||||
}
|
||||
Debug.Log("Playing hit sfx for " + magnitude);
|
||||
sfxSource.PlayOneShot(selectedClip);
|
||||
}
|
||||
|
||||
void dropSfx(float magnitude){
|
||||
float diff = dropMaxPitch - dropMinPitch;
|
||||
float mult = magnitude / 10f;
|
||||
dropSfxSource.pitch = dropMinPitch + (diff * mult);
|
||||
dropSfxSource.volume = mult;
|
||||
Debug.Log($"Playing drop sfx for { magnitude } : {mult}, pitch: {dropSfxSource.pitch}, volume: {dropSfxSource.volume}");
|
||||
dropSfxSource.Play();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/AudioManager.cs.meta
Normal file
11
Assets/Scripts/AudioManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3794a8bd2bce81343918a99c2ac2b04c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -156,17 +156,24 @@ public class GameManager : MonoBehaviour
|
||||
PointerEventData ped = (PointerEventData) e as PointerEventData;
|
||||
if(dragging){
|
||||
Vector2 v = ((ped.position-startPos)/inputSensitivity);
|
||||
if(v.magnitude > 1){v = v.normalized;}
|
||||
stopCooldown=0;
|
||||
|
||||
ball.simulated=true;
|
||||
ball.AddForce(-v * forceMultiplier);
|
||||
CurStrokes--;
|
||||
Shoot(v);
|
||||
}
|
||||
dragging = false;
|
||||
ballProjection.position = Vector3.zero;
|
||||
}
|
||||
|
||||
void Shoot(Vector2 v){
|
||||
if(v.magnitude > 1){v = v.normalized;}
|
||||
stopCooldown=0;
|
||||
|
||||
ball.simulated=true;
|
||||
ball.AddForce(-v * forceMultiplier);
|
||||
CurStrokes--;
|
||||
|
||||
AudioManager.HitSfx(v.magnitude);
|
||||
}
|
||||
|
||||
public void OnMouseDrag(BaseEventData e){
|
||||
if(CurStrokes <= 0){return;}
|
||||
|
||||
@@ -187,8 +194,20 @@ public class GameManager : MonoBehaviour
|
||||
ballProjection.GetChild(0).localScale = new Vector3(ballProjection.GetChild(0).localScale.x,ballProjectionScaleMin + (scaleDiff*v.magnitude));
|
||||
}
|
||||
|
||||
int _tempScore;
|
||||
int _tempStrokes;
|
||||
|
||||
public void UpdateUI(){
|
||||
if(Score != _tempScore){
|
||||
LeanTween.scale(ScoreTxt.gameObject, ScoreTxt.transform.localScale * 1.5f * (Score - _tempScore), 0.5f).setEasePunch();
|
||||
_tempScore = Score;
|
||||
|
||||
}
|
||||
|
||||
if(CurStrokes != _tempStrokes){
|
||||
_tempStrokes = CurStrokes;
|
||||
LeanTween.scale(StrokesTxt.gameObject, StrokesTxt.transform.localScale * 1.5f, 0.5f).setEasePunch();
|
||||
}
|
||||
ScoreTxt.text = Score.ToString();
|
||||
StrokesTxt.text = CurStrokes.ToString();
|
||||
}
|
||||
@@ -199,7 +218,11 @@ public class GameManager : MonoBehaviour
|
||||
}
|
||||
|
||||
public void Restrt(){
|
||||
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
|
||||
LoadingScreen.LoadLevel(SceneManager.GetActiveScene().name);
|
||||
}
|
||||
|
||||
public void MainMenu(){
|
||||
LoadingScreen.LoadLevel("MainMenu");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
11
Assets/Scripts/GolfBall.cs
Normal file
11
Assets/Scripts/GolfBall.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(Collider2D))]
|
||||
public class GolfBall : MonoBehaviour
|
||||
{
|
||||
void OnCollisionEnter2D(Collision2D other){
|
||||
AudioManager.DropSfx(other.relativeVelocity.magnitude);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/GolfBall.cs.meta
Normal file
11
Assets/Scripts/GolfBall.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a37c01b08a7e76148b877317a5a1839c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
82
Assets/Scripts/LoadingScreen.cs
Normal file
82
Assets/Scripts/LoadingScreen.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
public class LoadingScreen : MonoBehaviour
|
||||
{
|
||||
public static LoadingScreen instance {get; private set;}
|
||||
|
||||
[SerializeField]private Image loadingProgress;
|
||||
[SerializeField]private Text loadingProgressTxt;
|
||||
|
||||
void Awake(){
|
||||
if(instance != null){Destroy(gameObject);return;}
|
||||
instance =this;
|
||||
canvasGroup = GetComponent<CanvasGroup>();
|
||||
}
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
|
||||
public static void LoadLevel(string levelName){
|
||||
if(instance==null){Debug.LogError("No loading screen found, Raw load"); SceneManager.LoadScene(levelName); return;}
|
||||
|
||||
instance.loadLevel(levelName);
|
||||
}
|
||||
|
||||
public void loadLevel(string levelName){
|
||||
if (loading) { return; }
|
||||
loading = true;
|
||||
StartCoroutine(_loadlLevel(levelName));
|
||||
}
|
||||
|
||||
public static bool loading {get; private set;}
|
||||
private CanvasGroup canvasGroup;
|
||||
IEnumerator _loadlLevel(string levelName)
|
||||
{
|
||||
// AudioManager.instnace.SetMusic(-1);
|
||||
loading = true;
|
||||
canvasGroup.alpha = 0;
|
||||
canvasGroup.blocksRaycasts = true;
|
||||
|
||||
SetProgress(0);
|
||||
while (canvasGroup.alpha < 1f)
|
||||
{
|
||||
canvasGroup.alpha += 0.03f;
|
||||
yield return new WaitForFixedUpdate();
|
||||
}
|
||||
|
||||
AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(levelName);
|
||||
|
||||
while (!asyncOperation.isDone)
|
||||
{
|
||||
SetProgress(asyncOperation.progress);
|
||||
yield return null;
|
||||
}
|
||||
Debug.Log("Loaded scene " + levelName);
|
||||
yield return new WaitForSecondsRealtime(0.2f);
|
||||
|
||||
canvasGroup.blocksRaycasts = false;
|
||||
|
||||
while (canvasGroup.alpha > 0)
|
||||
{
|
||||
canvasGroup.alpha -= 0.03f;
|
||||
yield return new WaitForSecondsRealtime(0.015f);
|
||||
|
||||
}
|
||||
Debug.Log("Loading scene vanishing");
|
||||
|
||||
loading = false;
|
||||
}
|
||||
|
||||
void SetProgress(float value)
|
||||
{
|
||||
loadingProgress.fillAmount = value;
|
||||
loadingProgressTxt.text = (int)(value * 100) + "%";
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/LoadingScreen.cs.meta
Normal file
11
Assets/Scripts/LoadingScreen.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c96dca695722fe4da45f43ca719beab
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14
Assets/Scripts/MainMenu.cs
Normal file
14
Assets/Scripts/MainMenu.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class MainMenu : MonoBehaviour
|
||||
{
|
||||
public void Leave(){
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
void Start(){
|
||||
// MessageBox.ShowMessage("Welcome to Infinite Golf 2D.\nThis is a slow paced 2d endless golf game, All the levels are proceduraly generated and you will be rewarded for putting the ball in every and each hole.\n\nGood Luck","Welcome");
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/MainMenu.cs.meta
Normal file
11
Assets/Scripts/MainMenu.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a507081d00d64e14693b0a4025bbf7a6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
58
Assets/Scripts/MessageBox.cs
Normal file
58
Assets/Scripts/MessageBox.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class MessageBox : MonoBehaviour
|
||||
{
|
||||
public static MessageBox instance { get; private set;}
|
||||
void Awake(){
|
||||
if(instance != null){Destroy(gameObject);}
|
||||
instance = this;
|
||||
canvasGroup = GetComponent<CanvasGroup>();
|
||||
|
||||
closeButton.onClick.AddListener(()=>{SetActive(false);});
|
||||
}
|
||||
|
||||
private CanvasGroup canvasGroup;
|
||||
[SerializeField]private Text messageTxt;
|
||||
[SerializeField]private Text titleTxt;
|
||||
[SerializeField]private Button closeButton;
|
||||
void Start()
|
||||
{
|
||||
DontDestroyOnLoad(gameObject);
|
||||
SetActive(false);
|
||||
}
|
||||
|
||||
void SetActive(bool value){
|
||||
// StartCoroutine(setActive(value));
|
||||
canvasGroup.alpha= value ? 1 : 0;
|
||||
canvasGroup.blocksRaycasts = value;
|
||||
canvasGroup.interactable = value;
|
||||
}
|
||||
private static string message;
|
||||
public static void ShowMessage(string message,string title = "Notice"){
|
||||
if(instance == null){Debug.LogError("Message was shown before message box was init");return;}
|
||||
|
||||
instance.showMessage(message,title);
|
||||
}
|
||||
|
||||
public void showMessage(string _message, string title){
|
||||
message = _message;
|
||||
titleTxt.text = title;
|
||||
StartCoroutine(_showMessage());
|
||||
SetActive(true);
|
||||
}
|
||||
|
||||
IEnumerator _showMessage(){
|
||||
messageTxt.text = "";
|
||||
closeButton.gameObject.SetActive(false);
|
||||
for(int i=0; i < message.Length; i++){
|
||||
messageTxt.text += message[i];
|
||||
|
||||
yield return new WaitForSeconds(0.02f);
|
||||
}
|
||||
closeButton.gameObject.SetActive(true);
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/MessageBox.cs.meta
Normal file
11
Assets/Scripts/MessageBox.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b28c4484cf4e7b248aa4b447227376ad
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
110
Assets/Scripts/TweenHelper.cs
Normal file
110
Assets/Scripts/TweenHelper.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
public class TweenHelper : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
public float delay = 1;
|
||||
public LeanTweenType position_type, scale_type;
|
||||
public Vector3 startPos;
|
||||
public float position_time=1;
|
||||
public float scale_time=1;
|
||||
public Vector3 startScale;
|
||||
|
||||
Vector3 defaultPos, defaultScale;
|
||||
|
||||
[Header("Monitor data")]
|
||||
public Vector3 curPosition;
|
||||
public Vector3 curScale;
|
||||
|
||||
void Awake(){
|
||||
defaultPos = transform.position;
|
||||
defaultScale=transform.localScale;
|
||||
|
||||
|
||||
transform.position = startPos;
|
||||
transform.localScale = startScale;
|
||||
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
Intro();
|
||||
}
|
||||
|
||||
public void Intro(){
|
||||
|
||||
TweenManager.Add(this);
|
||||
StartCoroutine(start());
|
||||
}
|
||||
|
||||
public void Outro(){
|
||||
if(position_type != LeanTweenType.notUsed){
|
||||
LeanTween.move(gameObject, startPos, position_time).setEase(position_type);
|
||||
}
|
||||
|
||||
if(scale_type != LeanTweenType.notUsed){
|
||||
LeanTween.scale(gameObject, startScale, scale_time).setEase(scale_type);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator start(){
|
||||
yield return new WaitForSeconds(delay);
|
||||
|
||||
LeanTween.move(gameObject, defaultPos, position_time).setEase(position_type);
|
||||
LeanTween.scale(gameObject, defaultScale, scale_time).setEase(scale_type);
|
||||
}
|
||||
|
||||
|
||||
void OnDrawGizmos(){
|
||||
curPosition = transform.position;
|
||||
curScale = transform.localScale;
|
||||
|
||||
Gizmos.DrawLine(startPos, curPosition);
|
||||
}
|
||||
bool init = false;
|
||||
void OnValidation(){
|
||||
if(!init){
|
||||
init=true;
|
||||
}else{
|
||||
return;
|
||||
}
|
||||
startPos = transform.position;
|
||||
startScale = transform.localScale;
|
||||
}
|
||||
|
||||
|
||||
public void OutroAll(){
|
||||
TweenManager.OutroAll();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static class TweenManager{
|
||||
public static List<TweenHelper> Tweens{get; private set;}
|
||||
|
||||
public static void Add(TweenHelper tween){
|
||||
if(Tweens == null){Tweens = new List<TweenHelper>();}
|
||||
if(Tweens.Contains(tween)){return;}
|
||||
Tweens.Add(tween);
|
||||
}
|
||||
|
||||
public static void Outro(TweenHelper tween){
|
||||
tween.Outro();
|
||||
Tweens.Remove(tween);
|
||||
|
||||
}
|
||||
|
||||
public static void OutroAll(){
|
||||
foreach(TweenHelper tween in Tweens){
|
||||
if(tween == null){continue;}
|
||||
tween.Outro();
|
||||
}
|
||||
|
||||
for(int i=Tweens.Count-1; i >= 0; i--){
|
||||
Tweens.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/TweenHelper.cs.meta
Normal file
11
Assets/Scripts/TweenHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: acb52149a22340d47882ac5267b7adf5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user