This commit is contained in:
2022-12-16 22:04:23 +05:30
parent 1d555e0aee
commit 7d3d4cfe2c
137 changed files with 95785 additions and 496 deletions

View File

@@ -67,8 +67,8 @@ public class AdsManager : MonoBehaviour
}
private static UnityEvent onInterestitialClosed = new UnityEvent();
public static void AddOnInterestitialClosed(UnityAction e){
if(onInterestitialClosed==null){onInterestitialClosed = new UnityEvent();}
public static void SetOnInterestitialClosed(UnityAction e){
onInterestitialClosed = new UnityEvent();
onInterestitialClosed.AddListener(e);
}

View File

@@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
[RequireComponent(typeof(AudioSource))]
@@ -26,6 +27,8 @@ public class AudioManager : MonoBehaviour
[SerializeField]private AudioClip bpFound;
[SerializeField]private AudioClip reward;
[SerializeField]private AudioClip gemsCollect;
[SerializeField]private AudioClip confettiExplosion;
[Header("Gold")]
public AudioClip collectGoldBegin;
@@ -191,13 +194,17 @@ public class AudioManager : MonoBehaviour
audioSrc.PlayOneShot(minigameDied);
}
public void ConfettiExplosion(){
audioSrc.PlayOneShot(confettiExplosion);
}
public void TypeWriter(){
audioSrc.PlayOneShot(typewriters[Random.Range(0, typewriters.Length)],0.1f);
}
public void CollectGold(int amount){
public async void CollectGold(int amount){
audioSrc.PlayOneShot(collectGoldBegin);
await Task.Delay(300);
// int index = Mathf.Clamp((Mathf.Clamp(amount,0,100) / 100) * collectGoldArray.Length,0,collectGoldArray.Length-1);
int index =0;
if(amount < 10){

View File

@@ -28,11 +28,7 @@ public class ChestOpener : MonoBehaviour
}
public async void OpenChest(ChestDataObject chestData){
if(chestData == EpicChestData){
AudioManager.instnace.EpicChestOpen();
}else{
AudioManager.instnace.ChestOpen();
}
chestOpenPopup.SetActive(true);
okButton.SetActive(false);
@@ -103,11 +99,13 @@ public class ChestOpener : MonoBehaviour
//Chest opens here
confettiFX.Play();
StartCoroutine(PlaySFX(chestData == EpicChestData));
Debug.Log("Chest opening");
while (chestAnim.GetCurrentAnimatorStateInfo(0).IsName("openAnim")){
await Task.Delay(10);
}
Debug.Log("Chest opened");
DBmanager.SetGems(DBmanager.Gems + gemsCount);
DBmanager.SetCoins(DBmanager.Coins + goldCount);
@@ -119,4 +117,17 @@ public class ChestOpener : MonoBehaviour
okButton.SetActive(true);
}
IEnumerator PlaySFX(bool isEpic){
yield return new WaitForSeconds(1f);
if(isEpic){
AudioManager.instnace.EpicChestOpen();
}else{
AudioManager.instnace.ChestOpen();
}
yield return new WaitForSeconds(0.8f);
confettiFX.GetComponent<AudioSource>().Play();
}
}

View File

@@ -6,17 +6,26 @@ using UnityEngine.Events;
public class ControlSettings : MonoBehaviour
{
private const string ControlOnRightKey = "ControlOnRight";
private const string HapticKey = "ControlOnRight";
public Button left;
public Button right;
public Toggle HapticToggle;
public static bool ControlIsOnRight = true;
public static bool HapticEnabled = true;
public UnityEvent OnChanged;
void Awake()
{
if(PlayerPrefs.HasKey(ControlOnRightKey)){
ControlIsOnRight = PlayerPrefs.GetInt(ControlOnRightKey) == 1;
}
if(PlayerPrefs.HasKey(HapticKey)){
HapticEnabled = PlayerPrefs.GetInt(HapticKey) == 1;
}
left.onClick.AddListener(()=>{ChangeControlSide(true);});
right.onClick.AddListener(()=>{ChangeControlSide(false);});
HapticToggle.onValueChanged.AddListener(ToggleHaptic);
UpdateSettingsPage();
}
@@ -25,12 +34,21 @@ public class ControlSettings : MonoBehaviour
PlayerPrefs.SetInt(ControlOnRightKey, value? 1: 0);
PlayerPrefs.Save();
UpdateSettingsPage();
AudioManager.instnace.UIClick();
OnChanged.Invoke();
AudioManager.instnace.UIClick();
}
public void ToggleHaptic(bool value){
PlayerPrefs.SetInt(HapticKey, value ? 1 : 0);
PlayerPrefs.Save();
HapticEnabled = value;
}
void UpdateSettingsPage(){
left.transform.GetChild(0).GetComponent<Image>().color = (!ControlIsOnRight) ? Color.blue : Color.green;
right.transform.GetChild(0).GetComponent<Image>().color = (ControlIsOnRight) ? Color.blue : Color.green;
HapticToggle.isOn = HapticEnabled;
}
}

View File

@@ -197,9 +197,10 @@ public class DesignLab : MonoBehaviour
if(DBmanager.Metal < boxPrices[selectedBoxIndex]){
MessageDialog.instance.ShowMessage("Error", "Not enough energy to open this box");
return;
}
DBmanager.SetMetal(DBmanager.Metal-boxPrices[selectedBoxIndex]);
AudioManager.instnace.OpenBP();
newBoxPanel.SetActive(true);
string rarityName = "Common";
@@ -253,6 +254,7 @@ public class DesignLab : MonoBehaviour
//UpgradeEffect.top_instance.Show(newSkinPanel.GetComponent<RectTransform>().position);
DBmanager.AddSkinBlueprint(skin);
AudioManager.instnace.ConfettiExplosion();
//Fullscreen FX
foreach (ParticleSystem particle in fullscreenFX)
@@ -268,6 +270,8 @@ public class DesignLab : MonoBehaviour
// UpgradeEffect.top_instance.Show(goldsPanel.GetComponent<RectTransform>().position);
//Confetti
confettiFX.Play();
AudioManager.instnace.ConfettiExplosion();
DBmanager.SetCoins(DBmanager.Coins + amount);
Refresh();
}

View File

@@ -6,7 +6,7 @@ using UnityEngine.SceneManagement;
public class MaintainceChecker : MonoBehaviour
{
public static int version = 24;
public static int version = 31;
public static MaintainceChecker instance;
public int checkInterval = 30;
float t;

View File

@@ -13,7 +13,7 @@ public class CameraFollower : MonoBehaviour
public float smoothness = 0.1f;
public CameraUpdateMode updateMode;
public static CameraFollower instance{get; private set;}
public static void UpdateFrame()=> instance.HandleFrame();
public static void UpdateFrame() {if(instance.updateMode == CameraUpdateMode.Manual){ instance.HandleFrame();}}
void Awake(){
instance=this;
}

View File

@@ -18,6 +18,7 @@ public class KillfeedMgr : MonoBehaviour
}
public void AddNewEntry(string message){
return;
for(int i =0; i < pool.Count; i++){
if(!pool[i].gameObject.activeSelf){
pool[i].SetEntry(message,entryAliveTime);

View File

@@ -37,6 +37,10 @@ public class MinigameManager : NetworkBehaviour
private void Awake()
{
defaultJoyPos = joystick.transform.GetChild(0).GetComponent<RectTransform>().localPosition;
SwitchUISides();
// if(!DBmanager.LoggedIn){SceneManager.LoadScene(0);}
SceneData.GameManager = this;
instance = this;
@@ -46,33 +50,62 @@ public class MinigameManager : NetworkBehaviour
safeZoneShrinkSpeed = mapRadius / safeZoneShrinkTime;
defaultJoyPos = joystick.transform.GetChild(0).GetComponent<RectTransform>().localPosition;
SwitchUISides();
}
Vector2 defaultJoyPos;
public void SwitchUISides(){
if(ControlSettings.ControlIsOnRight){
joystick.anchorMin = new Vector2(0,0);
joystick.anchorMax = new Vector2(0.5f, 1);
btn_boost.anchorMin = new Vector2(1,0);
btn_boost.anchorMax = new Vector2(1,0);
btn_boost.position = new Vector2(Screen.width-150, btn_boost.position.y);
Vector2 newDef = new Vector2(defaultJoyPos.x, defaultJoyPos.y);
if(isRanked){
if(ControlSettings.ControlIsOnRight){
RectTransform canvasRect = joystick.root.GetComponent<RectTransform>();
joystick.anchorMin = new Vector2(0f,0);
joystick.anchorMax = new Vector2(0.5f, 1);
joystick.localPosition = new Vector2(-canvasRect.sizeDelta.x /4f,0);
Vector2 newDef = new Vector2(defaultJoyPos.x, defaultJoyPos.y);
joystick.GetComponent<Joystick>().SetDefaultPosition(newDef);
joystick.GetComponent<Joystick>().SetDefaultPosition(newDef);
btn_boost.anchorMin = new Vector2(0,0);
btn_boost.anchorMax = new Vector2(0,0);
btn_boost.localPosition = new Vector2(150, btn_boost.localPosition.y);
Debug.Log(btn_boost.localPosition);
}else{
RectTransform canvasRect = joystick.root.GetComponent<RectTransform>();
joystick.anchorMin = new Vector2(0.5f,0);
joystick.anchorMax = new Vector2(1f, 1);
joystick.localPosition = new Vector2(canvasRect.sizeDelta.x /4f,0);
Vector2 newDef = new Vector2(-defaultJoyPos.x, defaultJoyPos.y);
joystick.GetComponent<Joystick>().SetDefaultPosition(newDef);
btn_boost.anchorMin = new Vector2(0,0);
btn_boost.anchorMax = new Vector2(0,0);
btn_boost.localPosition = new Vector2(150-(canvasRect.sizeDelta.x/2f), btn_boost.localPosition.y);
Debug.Log(btn_boost.localPosition);
}
}else{
joystick.anchorMin = new Vector2(0.5f,0);
joystick.anchorMax = new Vector2(1f, 1);
btn_boost.anchorMin = new Vector2(0,0);
btn_boost.anchorMax = new Vector2(0,0);
btn_boost.position = new Vector2(150, btn_boost.position.y);
Vector2 newDef = new Vector2(-defaultJoyPos.x, defaultJoyPos.y);
if(ControlSettings.ControlIsOnRight){
Debug.Log("Switching to right");
joystick.anchorMin = new Vector2(0,0);
joystick.anchorMax = new Vector2(0.5f, 1);
btn_boost.anchorMin = new Vector2(1,0);
btn_boost.anchorMax = new Vector2(1,0);
btn_boost.position = new Vector2(Screen.width-150, btn_boost.position.y);
Vector2 newDef = new Vector2(defaultJoyPos.x, defaultJoyPos.y);
joystick.GetComponent<Joystick>().SetDefaultPosition(newDef);
joystick.GetComponent<Joystick>().SetDefaultPosition(newDef);
}else{
joystick.anchorMin = new Vector2(0.5f,0);
joystick.anchorMax = new Vector2(1f, 1);
btn_boost.anchorMin = new Vector2(0,0);
btn_boost.anchorMax = new Vector2(0,0);
btn_boost.position = new Vector2(150, btn_boost.position.y);
Vector2 newDef = new Vector2(-defaultJoyPos.x, defaultJoyPos.y);
joystick.GetComponent<Joystick>().SetDefaultPosition(newDef);
}
}
}
@@ -115,7 +148,11 @@ public class MinigameManager : NetworkBehaviour
}
}
if(RankedGameStarted && players.Length < 2){
//Forfeited!
winnerId = (int)players[0].netId;
// players[0].WonRanked();
}
if(RankedGameStarted){
if(timeElapsed > safeZoneCoolTime){
if(!shrinkStarted){
@@ -144,11 +181,7 @@ public class MinigameManager : NetworkBehaviour
}
}
if(RankedGameStarted && players.Length < 2){
//Forfeited!
winnerId = (int)players[0].netId;
// players[0].WonRanked();
}
}
public void OnMapRadisuChanged(float oldVal, float newVal){
@@ -309,9 +342,15 @@ public class MinigameManager : NetworkBehaviour
{
StartCoroutine(setRespawn(player));
}
public void Restart(){
if(SceneData.localPlayer.GetComponent<SpaceshipController>().dead){
SetRespawn(SceneData.localPlayer);
// SetRespawn(SceneData.localPlayer);
AdsManager.SetOnInterestitialClosed(()=>{SetRespawn(SceneData.localPlayer);});
if(!SceneData.holder.ShowAds()){
SetRespawn(SceneData.localPlayer);
}
}else{
Debug.LogError("You aren't dead, you can't restart unless you are dead.");
}

View File

@@ -91,7 +91,6 @@ public class PickupItem : NetworkBehaviour
active=false;
// gameObject.SetActive(false);
StartCoroutine(MoveToPlayer(playerPos));
SceneData.GameManager.DeactivatePickupItem(this);
}
IEnumerator MoveToPlayer(Transform position){
@@ -105,6 +104,8 @@ public class PickupItem : NetworkBehaviour
ParticleSystem particle = EffectPool.Spawn(PickupEffect, transform.position).GetComponent<ParticleSystem>();
particle.startColor = type.GetColor();
}
SceneData.GameManager.DeactivatePickupItem(this);
gameObject.SetActive(false);
}

View File

@@ -47,14 +47,20 @@ public class SceneDataHolder : MonoBehaviour
}
public async void ShowAds(){
public void ShowAd(){
ShowAds();
}
public bool ShowAds(){
if(MinigameManager.instance.isRanked){
if(AdsManager.instance!=null && (DateTime.Now - lastShownTime).Minutes > 10){
AdsManager.instance.ShowInterestitial();
lastShownTime = DateTime.Now;
return true;
}
}
return false;
}
}

View File

@@ -170,6 +170,7 @@ public class SkinShopManager : MonoBehaviour
void onUpgrade(){
upgradePanel.Show(selectedSkin.name);
AudioManager.instnace.UIPopup();
}
public void onBuy(){

View File

@@ -180,13 +180,21 @@ public class SpaceshipController : NetworkBehaviour
}
CameraFollower.instance.ShakeBoost();
Vibrate();
// GameObject fx = EffectPool.Spawn(boostStartEffect, transform.position);
foreach(ParticleSystem particle in boostStartEffect){
particle.Play();
}
}
}
void Vibrate(){
#if UNITY_ANDROID
if(ControlSettings.HapticEnabled){
Handheld.Vibrate();
}
#endif
}
void OnBoostUp()
{
if (isLocalPlayer)
@@ -312,6 +320,7 @@ public class SpaceshipController : NetworkBehaviour
int lastClientUpdateTime = 0;
Vector3 lineCorrection;
float scale => Mathf.Clamp(1 + (trailTime * _scaleMultiplier), 1, 10);
long lastTime ;
void Update()
{
if (MinigameManager.instance.isRanked && !MinigameManager.instance.RankedGameStarted) { return; }
@@ -343,6 +352,12 @@ public class SpaceshipController : NetworkBehaviour
DBmanager.SetMostTime((int)survivalTime);
}
SceneData.SetTimerTxt(survivalTime);
body.position = Vector3.Lerp(body.position,targetState.Position,MovementSmoothnessFactor * movingSpeed * Vector2.Distance(targetState.Position, body.position));
body.rotation = Quaternion.Lerp(body.rotation, targetState.Rotation,MovementSmoothnessFactor*movingSpeed);
Debug.Log(lastTime - currentTick);
lastTime = targetState.Tick;
CameraFollower.UpdateFrame();
}
timer += Time.deltaTime;
@@ -387,8 +402,8 @@ public class SpaceshipController : NetworkBehaviour
// transform.Rotate(transform.up * input.x);
UpdateStates(currentTick, NetworkTime.rtt, input, curState.Position, curState.Rotation);
body.position = targetState.Position;
body.rotation = targetState.Rotation;
// body.position = targetState.Position;
// body.rotation = targetState.Rotation;
// body.position = Vector3.Lerp(body.position,targetState.Position,MovementSmoothnessFactor * movingSpeed);
// body.rotation = Quaternion.Lerp(body.rotation, targetState.Rotation,MovementSmoothnessFactor*movingSpeed);
}else if (isServer){
@@ -402,7 +417,7 @@ public class SpaceshipController : NetworkBehaviour
// HandleInput(m_Input);
// }
}
if(isLocalPlayer){CameraFollower.UpdateFrame();}
// if(isLocalPlayer){CameraFollower.UpdateFrame();}
float stateError = clientStateBuffer[bufferIndex].Difference(serverStateBuffer[latencyBufferIndex]);
foreach(ParticleSystem boostEffect in boostEffects){
@@ -478,6 +493,7 @@ public class SpaceshipController : NetworkBehaviour
}
[ClientRpc]
void RpcRubberband(Vector3 m_position, Quaternion m_rotation){
return;
PlayerState serverState = new PlayerState(){Tick=0, Position = m_position, Rotation = m_rotation};
PlayerState clientState = new PlayerState(){Tick=0, Position = transform.position, Rotation = transform.rotation};
float diff = serverState.Difference(clientState);
@@ -608,7 +624,7 @@ public class SpaceshipController : NetworkBehaviour
[ClientRpc]
void RpcShowDeathEffect(Vector2 position){
EffectPool.Spawn(DeathEffect, position);
EffectPool.Spawn(debrisEffect, position).GetComponent<DebrisEffect>().Play();
// EffectPool.Spawn(debrisEffect, position).GetComponent<DebrisEffect>().Play();
}
void OnKill()
@@ -624,7 +640,7 @@ public class SpaceshipController : NetworkBehaviour
[ClientRpc]
void RpcOnKill()
{
Vibrate();
}
void OnKillsChanged(int oldVal, int newVal)
@@ -700,6 +716,7 @@ public class SpaceshipController : NetworkBehaviour
{
MinigameManager.instance.SpawnLeftoverPickups(transform.position, (int)((float)Scores / 4f));
RpcShowDeathEffect(transform.position);
Debug.Log($"Sending death signal to {pname} by {killer}");
@@ -739,6 +756,7 @@ public class SpaceshipController : NetworkBehaviour
if (MinigameManager.instance.winnerId <= 0)
{
Debug.LogError("Winner ID not synced yet");
checkWinner(1000);
}
if (MinigameManager.instance.winnerId != netId)
{
@@ -757,6 +775,24 @@ public class SpaceshipController : NetworkBehaviour
}
}
async void checkWinner(int delay){
await System.Threading.Tasks.Task.Delay(delay);
if (MinigameManager.instance.winnerId != netId)
{
//LOSER!
MinigameManager.instance.rankedSummary.ShowLoss();
AudioManager.instnace.MinigameLost();
}
else
{
MinigameManager.instance.rankedSummary.ShowWin();
AudioManager.instnace.MinigameWon();
}
}
IEnumerator ShowRankedResults()
{
while (MinigameManager.instance.winnerId <= 0)

View File

@@ -330,6 +330,8 @@ public class SelectedItemMenu : MonoBehaviour
}
public void OnGoldmineCapUpgrade(){
HideUpgradeMenu();
if(Selector.selectedBuilding.GetComponent<GoldMine>()!=null){
int L = Selector.selectedBuilding.curLevel+1;
int C = GoldMine.GetCapacityRateByLevel(L);
@@ -340,7 +342,6 @@ public class SelectedItemMenu : MonoBehaviour
upgradeBtn.interactable= false;
Selector.selectedBuilding.Upgrade(newLevel:newLevel-1, gold_cost:GoldMine.GetGoldCostForCapacity(L), metal_cost: GoldMine.GetMetalCostForCapacity(L) );
// goldmineUpgradeMenu.SetActive(false);
HideUpgradeMenu();
OnUpgradeMenuClicked();
}else{
@@ -359,6 +360,7 @@ public class SelectedItemMenu : MonoBehaviour
}
public void OnGoldmineProdUpgrade(){
HideUpgradeMenu();
if(Selector.selectedBuilding.GetComponent<GoldMine>()!=null){
int L = Selector.selectedBuilding.curLevel+1;
@@ -379,9 +381,10 @@ public class SelectedItemMenu : MonoBehaviour
}
// goldmineUpgradeMenu.SetActive(false);
HideUpgradeMenu();
OnUpgradeMenuClicked();
HideUpgradeMenu();
}
void OnInfoClicked()