Избавление от инициализаций на Awak'е
This commit is contained in:
parent
f32d7dd69b
commit
01be828953
@ -15,7 +15,11 @@ public class Bootstrap : MonoBehaviour
|
||||
[SerializeField] private VitrinaCatcher vitrinaCatcher;
|
||||
[SerializeField] private DualAvatarController avatarController;
|
||||
[SerializeField] private GameManager gameManager;
|
||||
[SerializeField] private CharacterController characterController;
|
||||
[SerializeField] private CharacterEventBus characterEventBus;
|
||||
|
||||
[SerializeField] private CountersCollector countersCollector;
|
||||
[SerializeField] private Defender defender;
|
||||
private void Awake() => Initialize();
|
||||
|
||||
private void Initialize()
|
||||
@ -44,9 +48,8 @@ public class Bootstrap : MonoBehaviour
|
||||
prizeSystem.Initialize();
|
||||
videoUtility.Initialize();
|
||||
|
||||
|
||||
#if !UNITY_EDITOR
|
||||
Defender.Instance.StartCoroutine(Defender.Instance.CheckLicenseCoroutine());
|
||||
CheckLicense();
|
||||
#endif
|
||||
DifficultyManager.Instance.dummyBots = false;
|
||||
|
||||
@ -56,10 +59,16 @@ public class Bootstrap : MonoBehaviour
|
||||
|
||||
gameManager.Initialize();
|
||||
board.Init();
|
||||
characterEventBus.Initialize();
|
||||
characterController.Initialize();
|
||||
|
||||
countersCollector.Initialize();
|
||||
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
private void CheckLicense() => defender.StartCoroutine(defender.CheckLicenseCoroutine());
|
||||
|
||||
private static void InitializePrefs()
|
||||
{
|
||||
PlayerPrefs.SetString("Serial", ConfigManager.Config.Serial);
|
||||
|
||||
@ -64,44 +64,6 @@ public class Defender : MonoBehaviour
|
||||
private const uint WAIT_OBJECT_0 = 0x00000000;
|
||||
|
||||
|
||||
private static Defender _instance;
|
||||
|
||||
public static Defender Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
// Ищем существующий экземпляр
|
||||
_instance = FindAnyObjectByType<Defender>();
|
||||
|
||||
// Если не нашли - создаем новый
|
||||
if (_instance == null)
|
||||
{
|
||||
GameObject go = new GameObject(typeof(Defender).Name);
|
||||
_instance = go.AddComponent<Defender>();
|
||||
|
||||
// Опционально: делаем объект неуничтожаемым при смене сцены
|
||||
DontDestroyOnLoad(go);
|
||||
}
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
if (_instance != null && _instance != this)
|
||||
{
|
||||
Destroy(gameObject); // Уничтожаем дубликат
|
||||
return;
|
||||
}
|
||||
|
||||
_instance = this;
|
||||
DontDestroyOnLoad(gameObject); // Опционально
|
||||
}
|
||||
|
||||
|
||||
public IEnumerator CheckLicenseCoroutine()
|
||||
{
|
||||
// Ждём один кадр, чтобы Unity завершил инициализацию
|
||||
|
||||
@ -7,7 +7,7 @@ public class CountersCollector : MonoBehaviour
|
||||
{
|
||||
public static ConcurrentDictionary<string, string> Counters = new();
|
||||
|
||||
void Awake()
|
||||
public void Initialize()
|
||||
{
|
||||
InvokeRepeating("Refresh", 0, 5);
|
||||
}
|
||||
|
||||
@ -6,7 +6,6 @@ using PrizeSystem;
|
||||
public class CharacterController : MonoBehaviour
|
||||
{
|
||||
|
||||
#region PRIVATE_FIELDS
|
||||
[SerializeField] private Transform charactersContainer;
|
||||
[SerializeField] private Transform charactersPool;
|
||||
|
||||
@ -22,9 +21,6 @@ public class CharacterController : MonoBehaviour
|
||||
[SerializeField] private float speed;
|
||||
public static CharacterController I;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
public static int CharactersAmount => I.characters.Length;
|
||||
public static Sprite CurrentChipImage => CurrentCharacter.chipImage;
|
||||
public static Character CurrentCharacter => I.characters[I.currentIndex];
|
||||
@ -94,8 +90,12 @@ public class CharacterController : MonoBehaviour
|
||||
I.StartCoroutine(I.MoveLocal(I.charactersContainer, I.shownLocalPosition, I.speed));
|
||||
}
|
||||
//================================= end : PUBLIC API =================================//
|
||||
private void Awake() => I = this;
|
||||
private void Start() => SetupCharacters();
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
I = this;
|
||||
SetupCharacters();
|
||||
}
|
||||
|
||||
private void SetupCharacters()
|
||||
{
|
||||
@ -109,7 +109,6 @@ public class CharacterController : MonoBehaviour
|
||||
int botsToSpawn = Mathf.Min(GameManager.instance.botsAmount, characterPrefabs.Count);
|
||||
GameManager.instance.botsAmount = botsToSpawn;
|
||||
|
||||
|
||||
//characters = new Character[GameManager.instance.botsAmount];
|
||||
characters = new Character[botsToSpawn];
|
||||
for (int i = 0; i < characters.Length; i++)
|
||||
|
||||
@ -3,9 +3,7 @@ using UnityEngine.Events;
|
||||
|
||||
public class CharacterEventBus : MonoBehaviour
|
||||
{
|
||||
public static CharacterEventBus Instance => instance ?? Initialize();
|
||||
|
||||
private static CharacterEventBus instance;
|
||||
public static CharacterEventBus Instance { get; private set; }
|
||||
|
||||
public UnityEvent OnCharacterAppeared;
|
||||
public UnityEvent OnBotTurn;
|
||||
@ -15,15 +13,8 @@ public class CharacterEventBus : MonoBehaviour
|
||||
public UnityEvent OnLevelDown;
|
||||
public UnityEvent OnDraw;
|
||||
|
||||
|
||||
private void Awake()
|
||||
public void Initialize()
|
||||
{
|
||||
instance = this;
|
||||
}
|
||||
|
||||
static CharacterEventBus Initialize()
|
||||
{
|
||||
instance = GameObject.FindAnyObjectByType<CharacterEventBus>();
|
||||
return instance;
|
||||
Instance = this;
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ public class GamemodePanel : MenuPanel
|
||||
|
||||
private float totalTime => frameDuration + characterDelay + characterDuration;
|
||||
|
||||
private void Awake()
|
||||
public void Initialize()
|
||||
{
|
||||
signStart = modeSign.anchoredPosition;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user