add project files
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
public class CamController : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
public Camera cam;
|
||||
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("smoothTime")]
|
||||
private float _smoothTime = 0.2f;
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("houseSmoothTime")]
|
||||
private float _houseSmoothTime = 0.2f;
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("followTargetOnX")]
|
||||
private bool _followTargetOnX;
|
||||
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("smoothFogDuration")]
|
||||
private float _smoothFogDuration = 0.5f;
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("houseFogStartDist")]
|
||||
private float _houseFogStartDist = 50f;
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("houseFogEndDist")]
|
||||
private float _houseFogEndDist = 50f;
|
||||
[SerializeField]
|
||||
private Animator anim;
|
||||
|
||||
private Player followTarget;
|
||||
|
||||
private Vector3 _posVelocity;
|
||||
|
||||
private float _fogEndDistanceBefore;
|
||||
|
||||
private float _fogStartDistanceBefore;
|
||||
|
||||
public void Warmup()
|
||||
{
|
||||
base.transform.position = followTarget.transform.position;
|
||||
anim.SetBool("HouseMode", value: false);
|
||||
anim.SetBool("RoomMode", value: false);
|
||||
anim.SetTrigger("Reset");
|
||||
anim.SetFloat("CamNew", 0f);
|
||||
anim.SetBool("HouseMode", value: false);
|
||||
}
|
||||
|
||||
public void SetTarget(Player followTarget)
|
||||
{
|
||||
this.followTarget = followTarget;
|
||||
}
|
||||
|
||||
public void Go()
|
||||
{
|
||||
anim.SetTrigger("Go");
|
||||
}
|
||||
|
||||
public void Win(bool best)
|
||||
{
|
||||
anim.SetBool("BestWin", best);
|
||||
anim.SetTrigger("Win");
|
||||
}
|
||||
|
||||
public void GameOver()
|
||||
{
|
||||
anim.SetTrigger("GameOver");
|
||||
}
|
||||
|
||||
public void Revive()
|
||||
{
|
||||
anim.SetTrigger("Revive");
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (followTarget == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Transform target = followTarget.movePlayer.toMove.transform;
|
||||
float smooth = _smoothTime;
|
||||
Vector3 targetPos = target.position;
|
||||
if (!_followTargetOnX)
|
||||
{
|
||||
targetPos.x = 0f;
|
||||
}
|
||||
base.transform.position = Vector3.SmoothDamp(base.transform.position, targetPos, ref _posVelocity, smooth, float.PositiveInfinity, Time.deltaTime);
|
||||
base.transform.rotation = followTarget.transform.rotation;
|
||||
}
|
||||
|
||||
private IEnumerator SmoothChangeFogRoutine(bool show)
|
||||
{
|
||||
float from = RenderSettings.fogEndDistance;
|
||||
float to = show ? _houseFogEndDist : _fogEndDistanceBefore;
|
||||
for (float t = 0f; t < _smoothFogDuration; t += Time.deltaTime)
|
||||
{
|
||||
RenderSettings.fogEndDistance = Mathf.Lerp(from, to, t / _smoothFogDuration);
|
||||
yield return null;
|
||||
}
|
||||
RenderSettings.fogEndDistance = to;
|
||||
}
|
||||
|
||||
public void ShopCam(string trigger)
|
||||
{
|
||||
anim.ResetTrigger("ExitShop");
|
||||
anim.SetTrigger(trigger);
|
||||
}
|
||||
|
||||
public void ExitShop()
|
||||
{
|
||||
anim.SetTrigger("ExitShop");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1fb2b7ab81861a2a54bcb6892a2c66e1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class CoreBehaviour : MonoBehaviour
|
||||
{
|
||||
private CoreDef _coreDef;
|
||||
|
||||
protected CoreDef CoreDef
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_coreDef == null)
|
||||
{
|
||||
CoreDefProvider provider = GetComponentInParent<CoreDefProvider>();
|
||||
if (provider != null)
|
||||
{
|
||||
_coreDef = provider.coreDef;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("CoreBehaviour should be a child of its CoreDefProvider");
|
||||
}
|
||||
}
|
||||
return _coreDef;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d61ce73996a3a258ffc275c88687ec4b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,341 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using Ambiance;
|
||||
using OHM.UnityToolkit.FSM;
|
||||
using OHM.UnityToolkit.Pooling;
|
||||
|
||||
public class CoreController : CoreBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
public CoreDef def;
|
||||
|
||||
[SerializeField]
|
||||
public CamController cam;
|
||||
|
||||
[SerializeField]
|
||||
public ScoreController scoreController;
|
||||
|
||||
[SerializeField]
|
||||
private Transform dynamicCont;
|
||||
|
||||
[SerializeField]
|
||||
public PickupSkinProvider pickupSkinProvider;
|
||||
|
||||
[HideInInspector]
|
||||
public UnityEvent onWarmup;
|
||||
|
||||
[HideInInspector]
|
||||
public UnityEvent onGameStarted;
|
||||
|
||||
[HideInInspector]
|
||||
public UnityEvent onGameWon;
|
||||
|
||||
[HideInInspector]
|
||||
public UnityEvent onGameOver;
|
||||
|
||||
[NonSerialized]
|
||||
public List<Section> debugForcedLevel;
|
||||
|
||||
private List<Section> _currentLevelPrefabs;
|
||||
|
||||
private List<Section> previousSectionsToRemove;
|
||||
|
||||
[NonSerialized]
|
||||
public int keyCountToSpawn;
|
||||
|
||||
public CoreCurrenciesController currenciesController = new CoreCurrenciesController();
|
||||
private System.Random random = new System.Random();
|
||||
private int _currentSeed;
|
||||
|
||||
public FiniteStateMachine<GameStateType> GameStateMachine = new FiniteStateMachine<GameStateType>();
|
||||
public GameStateType GS_WARMUP;
|
||||
|
||||
public GameStateType GS_STARTED;
|
||||
|
||||
public GameStateType GS_WON;
|
||||
|
||||
public GameStateType GS_GAME_OVER;
|
||||
|
||||
public float progressionRatio;
|
||||
|
||||
private Coroutine _warmupCoroutine;
|
||||
|
||||
private PlayerSkinDef _playerSkinDef;
|
||||
|
||||
public List<Section> CurrentSections { get; private set; }
|
||||
|
||||
public int CurrentSectionIndex { get; private set; }
|
||||
|
||||
public List<Section> CurrentLevelPrefabs => _currentLevelPrefabs;
|
||||
|
||||
public long CurrentLevelIdx { get; private set; }
|
||||
|
||||
public Player CurrentPlayer { get; private set; }
|
||||
|
||||
public static event Action<Section, int, int> OnSectionCreated;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
GS_WARMUP = new GameStateType
|
||||
{
|
||||
startAction = EnterWarmup
|
||||
};
|
||||
GS_STARTED = new GameStateType
|
||||
{
|
||||
startAction = EnterGame,
|
||||
updateAction = GameUpdate,
|
||||
getInputsListenerFunc = GameGetInputsListener
|
||||
};
|
||||
GS_WON = new GameStateType
|
||||
{
|
||||
startAction = EnterWon
|
||||
};
|
||||
GS_GAME_OVER = new GameStateType
|
||||
{
|
||||
startAction = EnterGameOver
|
||||
};
|
||||
GameStateMachine = new FiniteStateMachine<GameStateType>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
GameStateMachine.Update();
|
||||
}
|
||||
|
||||
public void Warmup(long levelIdx)
|
||||
{
|
||||
bool levelChanged = CurrentLevelIdx != levelIdx;
|
||||
if (levelChanged)
|
||||
{
|
||||
previousSectionsToRemove = ((def.GetProgression().removePreviousSectionsForNextGame && _currentLevelPrefabs != null) ? new List<Section>(_currentLevelPrefabs) : null);
|
||||
}
|
||||
int seed;
|
||||
if (!levelChanged && def.GetProgression().replaySameLevelsAfterGameOver)
|
||||
{
|
||||
seed = _currentSeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
seed = (_currentSeed = random.Next());
|
||||
}
|
||||
random = new System.Random(seed);
|
||||
CurrentLevelIdx = levelIdx;
|
||||
GameStateMachine.SetState(GS_WARMUP);
|
||||
}
|
||||
|
||||
private void EnterWarmup()
|
||||
{
|
||||
Cleanup();
|
||||
SetupAmbiance();
|
||||
if (_warmupCoroutine != null)
|
||||
{
|
||||
StopCoroutine(_warmupCoroutine);
|
||||
}
|
||||
_warmupCoroutine = StartCoroutine(WarmupCoroutine());
|
||||
}
|
||||
|
||||
private IEnumerator WarmupCoroutine()
|
||||
{
|
||||
yield return new WaitForEndOfFrame();
|
||||
GenerateLevel();
|
||||
yield return CreateCurrentSection();
|
||||
CurrentPlayer = CreatePlayer();
|
||||
scoreController.InitScore(CurrentPlayer.richManagePlayer.curScore);
|
||||
cam.Warmup();
|
||||
onWarmup.Invoke();
|
||||
}
|
||||
|
||||
public void ChangeRichValueStartRV()
|
||||
{
|
||||
CurrentPlayer.richManagePlayer.SetRichPoorValue(base.CoreDef.player.richValueStartABTestStartRich, true);
|
||||
}
|
||||
|
||||
private void SetupAmbiance()
|
||||
{
|
||||
int levelIdx = (int)CurrentLevelIdx;
|
||||
AmbianceController.Instance.SetLevelIdx(levelIdx, onFire: false, forceReload: true);
|
||||
}
|
||||
|
||||
private void Cleanup()
|
||||
{
|
||||
scoreController.Reset();
|
||||
currenciesController.Reset();
|
||||
CurrentSections = new List<Section>();
|
||||
CurrentPlayer = null;
|
||||
PoolsManager.ReleaseAllPooledChildren(dynamicCont);
|
||||
var children = new List<Transform>();
|
||||
foreach (Transform child in dynamicCont)
|
||||
{
|
||||
children.Add(child);
|
||||
}
|
||||
foreach (Transform child in children)
|
||||
{
|
||||
PoolsManager.ReleaseObject(child.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsReadyToPlay()
|
||||
{
|
||||
return CurrentPlayer != null && CurrentPlayer.IsReady;
|
||||
}
|
||||
|
||||
public void GenerateLevel()
|
||||
{
|
||||
List<Section> generated = LevelGenerator.GenerateLevel(base.CoreDef, CurrentLevelIdx, random, debugForcedLevel, previousSectionsToRemove);
|
||||
debugForcedLevel = null;
|
||||
CurrentSectionIndex = 0;
|
||||
_currentLevelPrefabs = CreateAllSection(generated);
|
||||
}
|
||||
|
||||
private Section CreateSection(Section prefab, Transform pos)
|
||||
{
|
||||
Section section = UnityEngine.Object.Instantiate(prefab, dynamicCont);
|
||||
section.Setup(base.CoreDef);
|
||||
if (pos != null)
|
||||
{
|
||||
section.transform.position = pos.position;
|
||||
section.transform.rotation = pos.rotation;
|
||||
}
|
||||
CurrentSections.Add(section);
|
||||
return section;
|
||||
}
|
||||
|
||||
private List<Section> CreateAllSection(List<Section> sectionsPrefabs)
|
||||
{
|
||||
var result = new List<Section>();
|
||||
|
||||
bool turnRight = UnityEngine.Random.Range(0, 1) == 0;
|
||||
ProgressionDef progression = def.GetProgression();
|
||||
bool useTurn = progression.useTurn;
|
||||
int sinceTurn = 0;
|
||||
for (int i = 0; i < sectionsPrefabs.Count; i++)
|
||||
{
|
||||
result.Add(sectionsPrefabs[i]);
|
||||
if (useTurn && i != 0 && i < sectionsPrefabs.Count - 2 && sinceTurn >= progression.turnEachSection)
|
||||
{
|
||||
result.Add(turnRight ? progression.GroundRight : progression.GroundLeft);
|
||||
result.Add(progression.SafeZone);
|
||||
sinceTurn = 0;
|
||||
turnRight = !turnRight;
|
||||
}
|
||||
sinceTurn++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private IEnumerator CreateCurrentSection()
|
||||
{
|
||||
Transform pos = null;
|
||||
for (int i = 0; i < _currentLevelPrefabs.Count; i++)
|
||||
{
|
||||
Section section = CreateSection(_currentLevelPrefabs[i], pos);
|
||||
yield return new WaitForEndOfFrame();
|
||||
pos = section.endLevel;
|
||||
}
|
||||
yield return new WaitForEndOfFrame();
|
||||
}
|
||||
|
||||
private Player CreatePlayer()
|
||||
{
|
||||
Player player = UnityEngine.Object.Instantiate(_playerSkinDef.prefab, dynamicCont);
|
||||
player.transform.position = Vector3.zero;
|
||||
player.onWin = (Action<int>)Delegate.Combine(player.onWin, new Action<int>(Win));
|
||||
player.onLose = (Action)Delegate.Combine(player.onLose, new Action(GameOver));
|
||||
player.richManagePlayer.onUpdateScore += OnUpdateScore;
|
||||
cam.SetTarget(player);
|
||||
return player;
|
||||
}
|
||||
|
||||
public void SetPlayerSkin(PlayerSkinDef skin)
|
||||
{
|
||||
_playerSkinDef = skin;
|
||||
if (CurrentPlayer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool wasShopMode = CurrentPlayer.ShopMode;
|
||||
UnityEngine.Object.Destroy(CurrentPlayer.gameObject);
|
||||
CurrentPlayer = CreatePlayer();
|
||||
if (wasShopMode)
|
||||
{
|
||||
CurrentPlayer.ShopSkinMode();
|
||||
}
|
||||
}
|
||||
|
||||
public void Go()
|
||||
{
|
||||
if (IsReadyToPlay())
|
||||
{
|
||||
CurrentPlayer.Go();
|
||||
onGameStarted.Invoke();
|
||||
GameStateMachine.SetState(GS_STARTED);
|
||||
}
|
||||
}
|
||||
|
||||
private void EnterGame()
|
||||
{
|
||||
UnityEngine.Debug.Log("Enter Game");
|
||||
cam.Go();
|
||||
}
|
||||
|
||||
private void GameUpdate()
|
||||
{
|
||||
}
|
||||
|
||||
private IInputsListener GameGetInputsListener()
|
||||
{
|
||||
return CurrentPlayer.movePlayer.swerveInput;
|
||||
}
|
||||
|
||||
private void OnUpdateScore(long score)
|
||||
{
|
||||
scoreController.UpdateScore(score, CurrentPlayer.movePlayer.transform, ScoreController.ScoreType.DEFAULT_SCORE);
|
||||
}
|
||||
|
||||
private void Win(int multCurrency)
|
||||
{
|
||||
scoreController.SetMultCurrency(multCurrency);
|
||||
|
||||
cam.Win(true);
|
||||
GameStateMachine.SetState(GS_WON);
|
||||
}
|
||||
|
||||
private void EnterWon()
|
||||
{
|
||||
UnityEngine.Debug.Log("VICTORY");
|
||||
onGameWon.Invoke();
|
||||
}
|
||||
|
||||
public void WinCurrencies()
|
||||
{
|
||||
currenciesController.WinCurrency((int)scoreController.Score, CurrentPlayer.movePlayer.transform);
|
||||
}
|
||||
|
||||
public void WinCurrenciesRaw(int rawValue)
|
||||
{
|
||||
currenciesController.WinCurrency(rawValue, CurrentPlayer.movePlayer.transform);
|
||||
}
|
||||
|
||||
private void GameOver()
|
||||
{
|
||||
cam.GameOver();
|
||||
GameStateMachine.SetState(GS_GAME_OVER);
|
||||
}
|
||||
|
||||
private void EnterGameOver()
|
||||
{
|
||||
UnityEngine.Debug.Log("GAME OVER");
|
||||
onGameOver.Invoke();
|
||||
}
|
||||
|
||||
public IInputsListener GetCurrentInputsListener()
|
||||
{
|
||||
Func<IInputsListener> func = GameStateMachine.CurrentState?.getInputsListenerFunc;
|
||||
return (func != null) ? func() : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 852b7e7f53808d1713022e11f3867cd1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class CoreCurrenciesController
|
||||
{
|
||||
public CoreCurrenciesDef Def { get; private set; }
|
||||
|
||||
public int CurrenciesWon { get; private set; }
|
||||
|
||||
public bool CurrenciesMultiplied { get; private set; }
|
||||
|
||||
public event Action<int, Transform> onWinCurrencies;
|
||||
|
||||
public event Action onMultiplyCurrencies;
|
||||
|
||||
public void Setup(CoreCurrenciesDef def)
|
||||
{
|
||||
Def = def;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
CurrenciesWon = 0;
|
||||
CurrenciesMultiplied = false;
|
||||
}
|
||||
|
||||
public void WinCurrency(int count, Transform from)
|
||||
{
|
||||
CurrenciesWon += count;
|
||||
if (this.onWinCurrencies != null)
|
||||
{
|
||||
this.onWinCurrencies(count, from);
|
||||
}
|
||||
}
|
||||
|
||||
public void MultiplyCurrencies(Transform from)
|
||||
{
|
||||
if (CurrenciesMultiplied)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int multiplier = Def.currencyMultiplier;
|
||||
int before = CurrenciesWon;
|
||||
CurrenciesWon = multiplier * before;
|
||||
if (this.onWinCurrencies != null)
|
||||
{
|
||||
this.onWinCurrencies((multiplier - 1) * before, from);
|
||||
}
|
||||
CurrenciesMultiplied = true;
|
||||
if (this.onMultiplyCurrencies != null)
|
||||
{
|
||||
this.onMultiplyCurrencies();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 644151d01a5601c503d45292c9b9faae
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,7 @@
|
||||
using System;
|
||||
|
||||
[Serializable]
|
||||
public class CoreCurrenciesDef
|
||||
{
|
||||
public int currencyMultiplier;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a9b8a46e988c53040b79adc9f608c69c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using OHM.UnityToolkit;
|
||||
|
||||
[CreateAssetMenu(fileName = "CoreGameDef", menuName = "GameSqueleton/New Core Game Def")]
|
||||
public class CoreDef : ScriptableObject
|
||||
{
|
||||
[Serializable]
|
||||
public class TextByRich : SerializableDictionary<int, TypeRich>
|
||||
{
|
||||
}
|
||||
|
||||
public PlayerDef player;
|
||||
|
||||
public float levelWidth;
|
||||
|
||||
public AI ai;
|
||||
|
||||
[Header("Revive")]
|
||||
public float maxReviveDuration;
|
||||
|
||||
public float reviveProtectionDuration;
|
||||
|
||||
[Header("Timing")]
|
||||
public float sectionEndingDuration = 0.5f;
|
||||
public float sectionTransitionDuration = 1f;
|
||||
[Header("Currencies")]
|
||||
public CoreCurrenciesDef currencies;
|
||||
|
||||
public GameObject keyPrefab;
|
||||
|
||||
[Header("Levels/ Progression")]
|
||||
[SerializeField]
|
||||
private ProgressionDef progression;
|
||||
|
||||
[Header("Debug")]
|
||||
public bool showHumanHand;
|
||||
|
||||
public TextByRich textByRich;
|
||||
|
||||
public ProgressionDef GetProgression()
|
||||
{
|
||||
return progression;
|
||||
}
|
||||
|
||||
public LevelDef GetLevel(long index)
|
||||
{
|
||||
List<LevelDef> list = GetProgression().levelsDiffPath;
|
||||
LevelDef result = null;
|
||||
int acc = 0;
|
||||
int cur = -1;
|
||||
foreach (LevelDef level in list)
|
||||
{
|
||||
if (acc > index)
|
||||
{
|
||||
break;
|
||||
}
|
||||
cur += level.levelCount;
|
||||
acc = cur + 1;
|
||||
result = level;
|
||||
}
|
||||
return result ?? list[0];
|
||||
}
|
||||
|
||||
public TypeRich GetTextRich(int rich)
|
||||
{
|
||||
TypeRich result = textByRich[0];
|
||||
int best = 0;
|
||||
foreach (KeyValuePair<int, TypeRich> kv in textByRich)
|
||||
{
|
||||
if (kv.Key <= rich && best <= kv.Key)
|
||||
{
|
||||
best = kv.Key;
|
||||
result = kv.Value;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool HaveMinLevelRich(string level, int rich)
|
||||
{
|
||||
foreach (KeyValuePair<int, TypeRich> kv in textByRich)
|
||||
{
|
||||
if (kv.Value.text == level)
|
||||
{
|
||||
return kv.Key <= rich;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9c69e165e588b999a307f701cc465be
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class CoreDefProvider : MonoBehaviour
|
||||
{
|
||||
public CoreDef coreDef;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 566646172f469626a847b3bfba33ac4a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,7 @@
|
||||
using System;
|
||||
using OHM.UnityToolkit;
|
||||
|
||||
[Serializable]
|
||||
public class DifficultyPoolElem : RandomPoolElement<int>
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9b028f39ddaa9a848bdfae81aba41706
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,7 @@
|
||||
using System;
|
||||
using OHM.UnityToolkit.FSM;
|
||||
|
||||
public class GameStateType : StateBase<GameStateType>
|
||||
{
|
||||
public Func<IInputsListener> getInputsListenerFunc;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0411764e0bdb459409c15b8159c63773
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Debug = UnityEngine.Debug;
|
||||
using OHM.UnityToolkit;
|
||||
|
||||
public static class LevelGenerator
|
||||
{
|
||||
public static List<Section> GenerateLevel(CoreDef def, long levelIdx, Random random, List<Section> forceLevel, List<Section> previousSections)
|
||||
{
|
||||
var result = new List<Section>();
|
||||
ProgressionDef progression = def.GetProgression();
|
||||
if (progression.initialSection != null)
|
||||
{
|
||||
result.Add(progression.initialSection);
|
||||
}
|
||||
if (forceLevel != null && forceLevel.Count >= 1)
|
||||
{
|
||||
result.AddRange(forceLevel);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.AddRange(GetLevelSectionList(def, levelIdx, random, previousSections));
|
||||
}
|
||||
Section final = progression.finalSectionABTest;
|
||||
if (final != null)
|
||||
{
|
||||
result.Add(final);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<Section> GetLevelSectionList(CoreDef def, long levelIdx, Random random, List<Section> sectionsToAvoid)
|
||||
{
|
||||
ProgressionDef progression = def.GetProgression();
|
||||
LevelDef level = def.GetLevel(levelIdx);
|
||||
var pool = new List<Section>(progression.sections);
|
||||
var result = new List<Section>();
|
||||
|
||||
if (sectionsToAvoid != null && sectionsToAvoid.Count >= 1)
|
||||
{
|
||||
pool.RemoveAll((Section s) => sectionsToAvoid.Contains(s));
|
||||
}
|
||||
foreach (Section forced in level.forcedSections)
|
||||
{
|
||||
if (forced != null)
|
||||
{
|
||||
result.Add(forced);
|
||||
pool.Remove(forced);
|
||||
}
|
||||
}
|
||||
for (int i = result.Count; i < level.sectionCount; i++)
|
||||
{
|
||||
Section drawn = DrawSection(level, def, i, levelIdx, pool, random, level.maxSectionYPerLevel);
|
||||
if (drawn != null)
|
||||
{
|
||||
result.Add(drawn);
|
||||
pool.Remove(drawn);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Section DrawSection(LevelDef level, CoreDef coreDef, int index, long levelIdx, List<Section> currentSectionsPool, Random random, int maxSectionYPerLevel)
|
||||
{
|
||||
var diffPool = new List<DifficultyPoolElem>(
|
||||
(level.randomDiffPoolAlt != null && level.randomDiffPoolAlt.Count >= 1 && index % 2 == 1)
|
||||
? level.randomDiffPoolAlt
|
||||
: level.randomDiffPool);
|
||||
|
||||
if (maxSectionYPerLevel <= 0)
|
||||
{
|
||||
foreach (DifficultyPoolElem elem in new List<DifficultyPoolElem>(diffPool))
|
||||
{
|
||||
List<Section> match = currentSectionsPool.Where((Section s) => s.difficulty == elem.element).ToList();
|
||||
if (match.Count >= 1 && match[0].differentPath)
|
||||
{
|
||||
diffPool.Remove(elem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int difficulty = RandomPoolUtils.DrawElementFromPool<DifficultyPoolElem, int>(random, diffPool);
|
||||
List<Section> candidates = currentSectionsPool.Where((Section s) => s.difficulty == difficulty).ToList();
|
||||
if (candidates.Count != 0)
|
||||
{
|
||||
return RandomExtensions.ListElem(random, candidates);
|
||||
}
|
||||
|
||||
Debug.LogFormat("No more section with diff {0}", difficulty);
|
||||
List<Section> fallback = currentSectionsPool.Where((Section s) => s.difficulty != difficulty).ToList();
|
||||
if (fallback.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Debug.LogWarningFormat("No section with difficulty {0} found, referenced in level {1}. Will use random other difficulty.", difficulty, levelIdx);
|
||||
return RandomExtensions.ListElem(random, fallback);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 396d866662b9cbc778a7b07df4c43850
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,57 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class ScoreController : CoreBehaviour
|
||||
{
|
||||
public enum ScoreType
|
||||
{
|
||||
DEFAULT_SCORE = 0
|
||||
}
|
||||
|
||||
public class ScoreEvent : UnityEvent<int, Transform, ScoreType>
|
||||
{
|
||||
}
|
||||
|
||||
[HideInInspector]
|
||||
public ScoreEvent onScore = new ScoreEvent();
|
||||
public long Score { get; private set; }
|
||||
|
||||
public int multCurrency { get; private set; }
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
Score = 0L;
|
||||
}
|
||||
|
||||
public void InitScore(long score)
|
||||
{
|
||||
Score = score;
|
||||
}
|
||||
|
||||
public void UpdateScore(long score, Transform obj, ScoreType type)
|
||||
{
|
||||
long delta = score - Score;
|
||||
if (delta != 0L)
|
||||
{
|
||||
Score = score;
|
||||
onScore.Invoke((int)delta, obj, type);
|
||||
}
|
||||
}
|
||||
|
||||
public void IncScore(long inc, Transform obj, ScoreType type)
|
||||
{
|
||||
Score += inc;
|
||||
onScore.Invoke((int)inc, obj, type);
|
||||
}
|
||||
|
||||
public void SetMultCurrency(int mult)
|
||||
{
|
||||
multCurrency = mult;
|
||||
Score *= mult;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Score = 0L;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 86d8ca6254653a88aa4884b95654e6ee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,94 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Section : CoreBehaviour
|
||||
{
|
||||
public int difficulty;
|
||||
|
||||
public Transform endLevel;
|
||||
|
||||
public bool differentPath;
|
||||
|
||||
public bool V_1_1;
|
||||
|
||||
public bool V_1_6;
|
||||
|
||||
public int sectionCountNormalSection = 1;
|
||||
public bool containIngameAds = true;
|
||||
public void Setup(CoreDef def)
|
||||
{
|
||||
}
|
||||
|
||||
[ContextMenu("TEST")]
|
||||
public void Test()
|
||||
{
|
||||
TestSection(this);
|
||||
}
|
||||
|
||||
public static void TestSection(Section b)
|
||||
{
|
||||
AppController app = Object.FindObjectOfType<AppController>();
|
||||
if (!(app == null))
|
||||
{
|
||||
CoreController core = app.coreGame;
|
||||
var forced = new List<Section> { b };
|
||||
if (core != null)
|
||||
{
|
||||
core.debugForcedLevel = forced;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static float WrapAngle(float angle)
|
||||
{
|
||||
angle %= 360f;
|
||||
if (angle > 180f)
|
||||
{
|
||||
angle -= 360f;
|
||||
}
|
||||
return angle;
|
||||
}
|
||||
|
||||
public float GetYRotationTurnSection(Vector3 pos, float curYRot, MovePlayer moveP)
|
||||
{
|
||||
float t = 0f;
|
||||
if (moveP.verti)
|
||||
{
|
||||
float from = base.transform.position.z;
|
||||
float to = endLevel.transform.position.z;
|
||||
if (from != to)
|
||||
{
|
||||
float r = (pos.z - from) / (to - from);
|
||||
if (r >= 0f)
|
||||
{
|
||||
t = Mathf.Min(r, 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
float from = base.transform.position.x;
|
||||
float to = endLevel.transform.position.x;
|
||||
if (from != to)
|
||||
{
|
||||
float r = (pos.x - from) / (to - from);
|
||||
if (r >= 0f)
|
||||
{
|
||||
t = Mathf.Min(r, 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
float targetY = WrapAngle(endLevel.transform.eulerAngles.y);
|
||||
if (t >= 0.99f)
|
||||
{
|
||||
moveP.EndTurn();
|
||||
return targetY;
|
||||
}
|
||||
return curYRot + Mathf.Max(t, 0f) * (targetY - curYRot);
|
||||
}
|
||||
|
||||
public Vector3 GetPosTurnSection(Vector3 pos, float curYRot, Player p)
|
||||
{
|
||||
return Vector3.zero;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c58648476830a0ac7dc699198dd29ebc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user