Timer Mode

dev-hazim
Ali Sharoz 1 month ago
parent 761fe0f0e3
commit c128924706

@ -0,0 +1,5 @@
{
"recommendations": [
"visualstudiotoolsforunity.vstuc"
]
}

@ -0,0 +1,10 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Unity",
"type": "vstuc",
"request": "attach"
}
]
}

@ -0,0 +1,55 @@
{
"files.exclude": {
"**/.DS_Store": true,
"**/.git": true,
"**/.gitmodules": true,
"**/*.booproj": true,
"**/*.pidb": true,
"**/*.suo": true,
"**/*.user": true,
"**/*.userprefs": true,
"**/*.unityproj": true,
"**/*.dll": true,
"**/*.exe": true,
"**/*.pdf": true,
"**/*.mid": true,
"**/*.midi": true,
"**/*.wav": true,
"**/*.gif": true,
"**/*.ico": true,
"**/*.jpg": true,
"**/*.jpeg": true,
"**/*.png": true,
"**/*.psd": true,
"**/*.tga": true,
"**/*.tif": true,
"**/*.tiff": true,
"**/*.3ds": true,
"**/*.3DS": true,
"**/*.fbx": true,
"**/*.FBX": true,
"**/*.lxo": true,
"**/*.LXO": true,
"**/*.ma": true,
"**/*.MA": true,
"**/*.obj": true,
"**/*.OBJ": true,
"**/*.asset": true,
"**/*.cubemap": true,
"**/*.flare": true,
"**/*.mat": true,
"**/*.meta": true,
"**/*.prefab": true,
"**/*.unity": true,
"build/": true,
"Build/": true,
"Library/": true,
"library/": true,
"obj/": true,
"Obj/": true,
"ProjectSettings/": true,
"temp/": true,
"Temp/": true
},
"dotnet.defaultSolution": "PlumberUltimateAds.sln"
}

@ -214,6 +214,7 @@ public class _2dxFX_GrayScale : MonoBehaviour
CanvasImage.material = ForceMaterial; CanvasImage.material = ForceMaterial;
} }
} }
Start();
} }
} }

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: a55ee4efaad27d948ba5f03fc6d7bc80
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: ed9b95dc6ed6d0647ad7f1a8f305385d
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -37,7 +37,7 @@ AnimatorStateMachine:
m_ChildStates: m_ChildStates:
- serializedVersion: 1 - serializedVersion: 1
m_State: {fileID: 20000} m_State: {fileID: 20000}
m_Position: {x: 0, y: 0, z: 0} m_Position: {x: 110, y: -50, z: 0}
m_ChildStateMachines: [] m_ChildStateMachines: []
m_AnyStateTransitions: [] m_AnyStateTransitions: []
m_EntryTransitions: [] m_EntryTransitions: []

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -19,6 +19,18 @@ public class GameManager
{ {
PlayerPrefs.SetInt("currentLevelNo", value); PlayerPrefs.SetInt("currentLevelNo", value);
} }
}
public static int CurrentLevelNo_Timer
{
get
{
return PlayerPrefs.GetInt("currentLevelNo_Timer", 1);
}
set
{
PlayerPrefs.SetInt("currentLevelNo_Timer", value);
}
} }
public static int CurrentLevelGroupIndex public static int CurrentLevelGroupIndex

@ -91,6 +91,7 @@ public class GamePlayManager : MonoBehaviour
private Vector3 _levelContainerPosition; private Vector3 _levelContainerPosition;
private bool isRotating; private bool isRotating;
public static bool isTimerLevel;
private void Awake() private void Awake()
{ {
@ -179,7 +180,7 @@ public class GamePlayManager : MonoBehaviour
GameScene.instance.UpdateUI(); GameScene.instance.UpdateUI();
Timer.Schedule(this, 0.5f, ShowMessagePopup); Timer.Schedule(this, 0.5f, ShowMessagePopup);
RecursivePipeColors(); RecursivePipeColors();
visibleCellList.ForEach(delegate(Cell obj) visibleCellList.ForEach(delegate (Cell obj)
{ {
obj.UpdatePipeColor(); obj.UpdatePipeColor();
}); });
@ -217,7 +218,7 @@ public class GamePlayManager : MonoBehaviour
} }
RecursivePipeColors(); RecursivePipeColors();
yield return new WaitForSeconds(0.1f); yield return new WaitForSeconds(0.1f);
visibleCellList.ForEach(delegate(Cell obj) visibleCellList.ForEach(delegate (Cell obj)
{ {
obj.UpdatePipeColor(); obj.UpdatePipeColor();
}); });
@ -227,11 +228,11 @@ public class GamePlayManager : MonoBehaviour
private void RecursivePipeColors() private void RecursivePipeColors()
{ {
visibleCellList.ForEach(delegate(Cell obj) visibleCellList.ForEach(delegate (Cell obj)
{ {
obj.RemoveAllPipeColor(); obj.RemoveAllPipeColor();
}); });
startCellList.ForEach(delegate(Cell cell) startCellList.ForEach(delegate (Cell cell)
{ {
if (cell.pipeCellType == CellType.Start) if (cell.pipeCellType == CellType.Start)
{ {
@ -454,6 +455,8 @@ public class GamePlayManager : MonoBehaviour
gameOverPopup.Open(); gameOverPopup.Open();
confettiParticle.Play(); confettiParticle.Play();
yield return new WaitForSeconds(0.5f); yield return new WaitForSeconds(0.5f);
if (!isTimerLevel)
{
if (GameManager.currentLevelGroup.CompletedLevel < GameManager.CurrentLevelNo) if (GameManager.currentLevelGroup.CompletedLevel < GameManager.CurrentLevelNo)
{ {
int sl = GameManager.StarLevel; int sl = GameManager.StarLevel;
@ -486,10 +489,46 @@ public class GamePlayManager : MonoBehaviour
GameScene.instance.UpdateUI(); GameScene.instance.UpdateUI();
} }
} }
}
else
{
if (GameManager.currentLevelGroup.CompletedLevel_Timer < GameManager.CurrentLevelNo)
{
int sl = GameManager.StarLevel;
for (int i = 0; i < GameManager.currentLevelGroup.StarXPReward; i++)
{
GameManager.AddStar(1);
starLevel.text = GameManager.StarLevel + string.Empty;
nextStarLevel.text = (GameManager.StarLevel + 1).ToString();
if (fillBar.fillAmount > GameManager.StarLevelProgress)
{
while (fillBar.fillAmount < 1f)
{
fillBar.fillAmount += 0.01f;
yield return new WaitForSeconds(0.01f);
}
fillBar.fillAmount = 0f;
}
while (fillBar.fillAmount < GameManager.StarLevelProgress)
{
fillBar.fillAmount += 0.01f;
yield return new WaitForSeconds(0.01f);
}
}
if (sl < GameManager.StarLevel)
{
RankedUpText.text = GameManager.StarLevel.ToString();
ShowRankedUpScreen();
confettiParticle.Play();
GameManager.Coin += UnityEngine.Random.Range(30, 45);
GameScene.instance.UpdateUI();
}
}
}
nextBtn.interactable = true; nextBtn.interactable = true;
// closeBtn.interactable = true; // closeBtn.interactable = true;
GameManager.currentLevelGroup.SetLevelCompleted(GameManager.CurrentLevelNo, Time.time - startTime); GameManager.currentLevelGroup.SetLevelCompleted(GameManager.CurrentLevelNo, Time.time - startTime);
if(AdmobController.isInterAdAvailable) if (AdmobController.isInterAdAvailable)
IronSource.Agent.showInterstitial(); IronSource.Agent.showInterstitial();
} }
@ -506,6 +545,9 @@ public class GamePlayManager : MonoBehaviour
public void NextGame() public void NextGame()
{ {
if (!isTimerLevel)
{
if (GameManager.CurrentLevelNo > GameManager.currentLevelGroup.CompletedLevel) if (GameManager.CurrentLevelNo > GameManager.currentLevelGroup.CompletedLevel)
{ {
if (GameManager.Coin < GameConfig.instance.numCoinForSkipGame) if (GameManager.Coin < GameConfig.instance.numCoinForSkipGame)
@ -516,6 +558,20 @@ public class GamePlayManager : MonoBehaviour
GameManager.Coin -= GameConfig.instance.numCoinForSkipGame; GameManager.Coin -= GameConfig.instance.numCoinForSkipGame;
GameManager.currentLevelGroup.SetLevelCompleted(GameManager.CurrentLevelNo, Time.time - startTime); GameManager.currentLevelGroup.SetLevelCompleted(GameManager.CurrentLevelNo, Time.time - startTime);
} }
}
else
{
if (GameManager.CurrentLevelNo > GameManager.currentLevelGroup.CompletedLevel_Timer)
{
if (GameManager.Coin < GameConfig.instance.numCoinForSkipGame)
{
Toast.instance.ShowMessage("You don't have enough coins");
return;
}
GameManager.Coin -= GameConfig.instance.numCoinForSkipGame;
GameManager.currentLevelGroup.SetLevelCompleted(GameManager.CurrentLevelNo, Time.time - startTime);
}
}
menuPopup.Close(); menuPopup.Close();
Sound.instance.PlayButton(); Sound.instance.PlayButton();
if (GameManager.currentLevelGroup.TotalLevel > GameManager.CurrentLevelNo) if (GameManager.currentLevelGroup.TotalLevel > GameManager.CurrentLevelNo)

@ -16,6 +16,7 @@ using MS;
using System.Collections.Generic; using System.Collections.Generic;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using UnityEngine.UI; using UnityEngine.UI;
@ -67,7 +68,7 @@ public class HomeScene : MonoBehaviour
public Popup[] popups; public Popup[] popups;
public static HomeScene instance; public static HomeScene instance;
public UnityEvent OnPlayButtonPressed=new UnityEvent();
private List<int> ReverseNumbers = new List<int>{4, 6, 10, 12, 16, 18,22,24,28,30,34,36,40,42,46,48}; private List<int> ReverseNumbers = new List<int>{4, 6, 10, 12, 16, 18,22,24,28,30,34,36,40,42,46,48};
private void Start() private void Start()
{ {
@ -113,7 +114,15 @@ public class HomeScene : MonoBehaviour
public void ShowDetailLevel(LevelGroupButton lb) public void ShowDetailLevel(LevelGroupButton lb)
{ {
int completedLevel = lb.levelGroup.CompletedLevel; int completedLevel = 0;
if(!GamePlayManager.isTimerLevel)
{
completedLevel = lb.levelGroup.CompletedLevel;
}
else
{
completedLevel = lb.levelGroup.CompletedLevel_Timer;
}
LD_TitleLbl.text = lb.levelGroup.LevelGroupName.ToUpper(); LD_TitleLbl.text = lb.levelGroup.LevelGroupName.ToUpper();
LD_LevelCompletdLbl.text = completedLevel + " / " + lb.levelGroup.TotalLevel; LD_LevelCompletdLbl.text = completedLevel + " / " + lb.levelGroup.TotalLevel;
// LD_AwardGoldImage.SetActive(completedLevel >= lb.levelGroup.TotalLevel); // LD_AwardGoldImage.SetActive(completedLevel >= lb.levelGroup.TotalLevel);
@ -281,6 +290,7 @@ public class HomeScene : MonoBehaviour
public void PlayButton() public void PlayButton()
{ {
OnPlayButtonPressed.Invoke();
Sound.instance.PlayButton(); Sound.instance.PlayButton();
} }

@ -32,7 +32,6 @@ public class LevelGroup : ScriptableObject
public Sprite LevelDetailBG; public Sprite LevelDetailBG;
public Sprite LevelHeaderBG; public Sprite LevelHeaderBG;
public int CompletedLevel public int CompletedLevel
{ {
get get
@ -44,6 +43,17 @@ public class LevelGroup : ScriptableObject
PlayerPrefs.SetInt("Completed_" + LevelGroupName.ToUpper(), value); PlayerPrefs.SetInt("Completed_" + LevelGroupName.ToUpper(), value);
} }
} }
public int CompletedLevel_Timer
{
get
{
return PlayerPrefs.GetInt("Completed_" + LevelGroupName.ToUpper() + "_Timer", 0);
}
set
{
PlayerPrefs.SetInt("Completed_" + LevelGroupName.ToUpper() + "_Timer", value);
}
}
public float AverageCompletedTime public float AverageCompletedTime
{ {
@ -67,6 +77,8 @@ public class LevelGroup : ScriptableObject
} }
public void SetLevelCompleted(int LevelNo, float TimeToComplete) public void SetLevelCompleted(int LevelNo, float TimeToComplete)
{
if (!GamePlayManager.isTimerLevel)
{ {
if (CompletedLevel <= LevelNo) if (CompletedLevel <= LevelNo)
{ {
@ -76,4 +88,16 @@ public class LevelGroup : ScriptableObject
averageCompletedTime = Mathf.Abs(averageCompletedTime * (float)(CompletedLevel - 1) + TimeToComplete); averageCompletedTime = Mathf.Abs(averageCompletedTime * (float)(CompletedLevel - 1) + TimeToComplete);
averageCompletedTime = (AverageCompletedTime = averageCompletedTime / (float)CompletedLevel); averageCompletedTime = (AverageCompletedTime = averageCompletedTime / (float)CompletedLevel);
} }
else
{
if (CompletedLevel_Timer <= LevelNo)
{
CompletedLevel_Timer = LevelNo;
}
float averageCompletedTime = AverageCompletedTime;
averageCompletedTime = Mathf.Abs(averageCompletedTime * (float)(CompletedLevel_Timer - 1) + TimeToComplete);
averageCompletedTime = (AverageCompletedTime = averageCompletedTime / (float)CompletedLevel_Timer);
}
}
} }

@ -28,7 +28,7 @@ public class LevelGroupButton : MonoBehaviour
public GameObject AwardGoldImage; public GameObject AwardGoldImage;
private void Start() public void Start()
{ {
UpdateUI(); UpdateUI();
GetComponent<Button>().onClick.AddListener(delegate GetComponent<Button>().onClick.AddListener(delegate
@ -37,6 +37,10 @@ public class LevelGroupButton : MonoBehaviour
HomeScene.instance.PlayButton(); HomeScene.instance.PlayButton();
GameObject.FindWithTag("LevelGroupPopup").GetComponent<Popup>().Close(); GameObject.FindWithTag("LevelGroupPopup").GetComponent<Popup>().Close();
}); });
HomeScene.instance.OnPlayButtonPressed.AddListener(() =>
{
UpdateUI();
});
} }
private void Update() private void Update()
@ -48,7 +52,18 @@ public class LevelGroupButton : MonoBehaviour
{ {
base.name = levelGroup.LevelGroupName; base.name = levelGroup.LevelGroupName;
TitleLbl.text = base.name.ToUpper(); TitleLbl.text = base.name.ToUpper();
if (!GamePlayManager.isTimerLevel)
{
LevelCompletdLbl.text = levelGroup.CompletedLevel + " / " + levelGroup.TotalLevel; LevelCompletdLbl.text = levelGroup.CompletedLevel + " / " + levelGroup.TotalLevel;
AwardGoldImage.GetComponent<_2dxFX_GrayScale>().enabled = !(levelGroup.CompletedLevel >= levelGroup.TotalLevel); AwardGoldImage.GetComponent<_2dxFX_GrayScale>().enabled = !(levelGroup.CompletedLevel >= levelGroup.TotalLevel);
} }
else
{
LevelCompletdLbl.text = levelGroup.CompletedLevel_Timer + " / " + levelGroup.TotalLevel;
AwardGoldImage.GetComponent<_2dxFX_GrayScale>().enabled = !(levelGroup.CompletedLevel_Timer >= levelGroup.TotalLevel);
}
}
} }

@ -48,8 +48,18 @@ public class LevelGroupState : MonoBehaviour
{ {
base.name = levelGroup.LevelGroupName; base.name = levelGroup.LevelGroupName;
TitleLbl.text = base.name.ToUpper(); TitleLbl.text = base.name.ToUpper();
if (!GamePlayManager.isTimerLevel)
{
LevelCompletdLbl.text = levelGroup.CompletedLevel + " / " + levelGroup.TotalLevel; LevelCompletdLbl.text = levelGroup.CompletedLevel + " / " + levelGroup.TotalLevel;
AvarageTimeLbl.text = levelGroup.AverageCompletedTimeString;
AwardGoldImage.GetComponent<_2dxFX_GrayScale>().enabled = !(levelGroup.CompletedLevel >= levelGroup.TotalLevel); AwardGoldImage.GetComponent<_2dxFX_GrayScale>().enabled = !(levelGroup.CompletedLevel >= levelGroup.TotalLevel);
}
else
{
LevelCompletdLbl.text = levelGroup.CompletedLevel_Timer + " / " + levelGroup.TotalLevel;
AwardGoldImage.GetComponent<_2dxFX_GrayScale>().enabled = !(levelGroup.CompletedLevel_Timer >= levelGroup.TotalLevel);
}
AvarageTimeLbl.text = levelGroup.AverageCompletedTimeString;
} }
} }

@ -38,6 +38,11 @@ namespace MS
public UnityEvent onClose; public UnityEvent onClose;
public UnityEvent onOpen; public UnityEvent onOpen;
public GameObject ChooseModePanel;
public void isTimerSetter(bool isTimer)
{
GamePlayManager.isTimerLevel = isTimer;
}
private void Start() private void Start()
{ {

@ -0,0 +1,87 @@
using System;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
public class TimerManager : MonoBehaviour
{
private TimeSpan _remainingTime;
private TimeSpan _initialTime;
private bool _isTimerRunning;
// Event triggered when the timer starts
public event Action TimerStarted;
// Event triggered when the timer ends
//public event Action TimerEnded;
public UnityEvent TimerEnded = new UnityEvent();
public TextMeshProUGUI timer;
public GameObject timerObj;
public GameObject gameoverPanelObj;
//public Textmeshprougui timertext;
private void Start()
{
if (GamePlayManager.isTimerLevel)
{
timerObj.SetActive(true);
InitializeTimer(0, 2, 0);
}
}
// Initialize the timer with hours, minutes, and seconds
public void InitializeTimer(int hours, int minutes, int seconds)
{
_initialTime = new TimeSpan(hours, minutes, seconds);
_remainingTime = _initialTime;
StartTimer();
}
// Start the timer
public void StartTimer()
{
if (_remainingTime.TotalSeconds > 0 && !_isTimerRunning)
{
_isTimerRunning = true;
TimerStarted?.Invoke(); // Trigger the TimerStarted event
}
}
// Stop the timer
public void StopTimer()
{
_isTimerRunning = false;
}
// Reset the timer to its initial value
public void ResetTimer()
{
StopTimer();
_remainingTime = _initialTime;
}
// Get the remaining time
public TimeSpan GetRemainingTime()
{
return _remainingTime;
}
// Update is called once per frame
void Update()
{
if (_isTimerRunning)
{
// Subtract deltaTime from the remaining time
_remainingTime = _remainingTime.Subtract(TimeSpan.FromSeconds(Time.deltaTime));
timer.text = _remainingTime.ToString("m\\:ss");
// If the timer has reached 0 or less, stop it
if (_remainingTime.TotalSeconds <= 0)
{
_remainingTime = TimeSpan.Zero;
_isTimerRunning = false;
TimerEnded?.Invoke(); // Trigger the TimerEnded event
}
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b99d58f7291a21a40999b35d7b8ba8e9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -1,2 +1,2 @@
m_EditorVersion: 2022.3.17f1 m_EditorVersion: 2022.3.49f1
m_EditorVersionWithRevision: 2022.3.17f1 (4fc78088f837) m_EditorVersionWithRevision: 2022.3.49f1 (4dae1bb8668d)

Loading…
Cancel
Save