add project files
This commit is contained in:
@@ -0,0 +1,163 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using OHM.UnityToolkit.Inventory;
|
||||
|
||||
public class CustomizableController<Def, Data> where Def : CustomizableDef where Data : CustomizableDataBase, new()
|
||||
{
|
||||
public class CustomizationEvent : UnityEvent<Def>
|
||||
{
|
||||
}
|
||||
|
||||
public delegate List<Def> GetDefListDelegate();
|
||||
|
||||
public delegate CustomizablesDataBase<Data> GetSavedDataDelegate(SavedData savedData);
|
||||
|
||||
public delegate string GetCurrentDelegate(SavedData savedData);
|
||||
|
||||
public delegate void SetCurrentDelegate(SavedData savedData, string name);
|
||||
|
||||
public delegate void ApplyDelegate(Def def);
|
||||
|
||||
public delegate bool PayDelegate(TransactionUnit<SavedDataTUType> cost);
|
||||
|
||||
public delegate bool IsPremiumDelegate();
|
||||
|
||||
public delegate bool CanSetDefault();
|
||||
|
||||
public Def ForcedValue;
|
||||
|
||||
[HideInInspector]
|
||||
public UnityEvent onChanged = new UnityEvent();
|
||||
|
||||
public CustomizationEvent onPurchased = new CustomizationEvent();
|
||||
|
||||
private SavedDataController _savedDataController;
|
||||
|
||||
protected GetDefListDelegate getDefListDelegate;
|
||||
|
||||
private GetSavedDataDelegate _getSavedDataDelegate;
|
||||
|
||||
private ApplyDelegate _applyDelegate;
|
||||
|
||||
private PayDelegate _payDelegate;
|
||||
|
||||
private IsPremiumDelegate isPremiumDelegate;
|
||||
|
||||
public CustomizableController(SavedDataController _savedDataController, GetDefListDelegate getDefListDelegate, GetSavedDataDelegate _getSavedDataDelegate, ApplyDelegate _applyDelegate, PayDelegate _payDelegate, IsPremiumDelegate isPremiumDelegate)
|
||||
{
|
||||
this._savedDataController = _savedDataController;
|
||||
this.getDefListDelegate = getDefListDelegate;
|
||||
this._getSavedDataDelegate = _getSavedDataDelegate;
|
||||
this._applyDelegate = _applyDelegate;
|
||||
this._payDelegate = _payDelegate;
|
||||
this.isPremiumDelegate = isPremiumDelegate;
|
||||
}
|
||||
|
||||
public List<Def> GetDefList()
|
||||
{
|
||||
return getDefListDelegate();
|
||||
}
|
||||
|
||||
public Def GetCurrent()
|
||||
{
|
||||
if (ForcedValue != null)
|
||||
{
|
||||
return ForcedValue;
|
||||
}
|
||||
Def saved = GetSavedValue();
|
||||
if (saved == null)
|
||||
{
|
||||
SetDefault();
|
||||
return GetSavedValue();
|
||||
}
|
||||
return saved;
|
||||
}
|
||||
|
||||
private Def GetSavedValue()
|
||||
{
|
||||
string currentId = _getSavedDataDelegate(_savedDataController.SavedData).currentId;
|
||||
return GetDefList().Find((Def def) => def.name == currentId);
|
||||
}
|
||||
|
||||
public Data GetCurrentData()
|
||||
{
|
||||
return GetData(GetCurrent());
|
||||
}
|
||||
|
||||
public Data GetData(Def skin)
|
||||
{
|
||||
CustomizablesDataBase<Data> saved = _getSavedDataDelegate(_savedDataController.SavedData);
|
||||
Data data = saved.customizablesList.Find((Data d) => d.id == skin.name);
|
||||
if (data == null)
|
||||
{
|
||||
data = new Data();
|
||||
data.id = skin.name;
|
||||
saved.customizablesList.Add(data);
|
||||
_savedDataController.SaveData();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public virtual void SetDefault()
|
||||
{
|
||||
Def first = GetDefList()[0];
|
||||
GetData(first).unlocked = true;
|
||||
SetCurrentValue(first);
|
||||
}
|
||||
|
||||
public void ApplyCurrent()
|
||||
{
|
||||
_applyDelegate(GetCurrent());
|
||||
}
|
||||
|
||||
public void SetCurrentValue(Def skin)
|
||||
{
|
||||
GetData(skin);
|
||||
_getSavedDataDelegate(_savedDataController.SavedData).currentId = skin.name;
|
||||
_applyDelegate(skin);
|
||||
_savedDataController.SaveData();
|
||||
onChanged.Invoke();
|
||||
}
|
||||
|
||||
public virtual List<Def> GetUnlockedList()
|
||||
{
|
||||
return GetDefList().FindAll(IsUnlocked);
|
||||
}
|
||||
|
||||
public bool CanPurchase(Def skin)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Purchase(Def skin)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void SetUnlocked(Def def)
|
||||
{
|
||||
GetData(def).unlocked = true;
|
||||
_savedDataController.SaveData();
|
||||
}
|
||||
|
||||
public bool IsUnlocked(Def def)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsUnlocked(string id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsNewSkin(Def def)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsNewSkin(string id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48de4d209c7cbc24aa136acecdbe0138
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
[Serializable]
|
||||
public class CustomizableDataBase
|
||||
{
|
||||
public string id;
|
||||
|
||||
public bool unlocked;
|
||||
|
||||
public bool equipped = true;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4be5f8e384226712ab4fe17ea9a96041
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
public class CustomizableDef : ScriptableObject
|
||||
{
|
||||
[SerializeField]
|
||||
[Space]
|
||||
[FormerlySerializedAs("purchaseCost")]
|
||||
private long _purchaseCost;
|
||||
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("premium")]
|
||||
private bool _premium;
|
||||
|
||||
[Space]
|
||||
public Sprite thumbnail;
|
||||
|
||||
public long GetPurchaseCost()
|
||||
{
|
||||
return 0L;
|
||||
}
|
||||
|
||||
public bool Premium()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1fa940862b00b1f0829fea75281eead9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
[Serializable]
|
||||
public class CustomizablesDataBase<Data> where Data : CustomizableDataBase
|
||||
{
|
||||
public string currentId;
|
||||
|
||||
public List<Data> customizablesList = new List<Data>();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e752465c1f0faa4c9bd37d49d901cf6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,6 @@
|
||||
using System;
|
||||
|
||||
[Serializable]
|
||||
public class PickupsSkinData : CustomizableDataBase
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f2f553528ceb17488076110ecd4f78c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
using UnityEngine;
|
||||
using OHM.UnityToolkit.Localization;
|
||||
|
||||
[CreateAssetMenu(fileName = "Pickup Skin Def", menuName = "GameSqueleton/Pickup Skin Def")]
|
||||
public class PickupsSkinDef : CustomizableDef, ILevelLocked
|
||||
{
|
||||
public long unlockLevel;
|
||||
|
||||
public GameObject prefabGood;
|
||||
|
||||
public GameObject prefabBad;
|
||||
|
||||
public string GetLocalizedName()
|
||||
{
|
||||
return GetLocalizedName(base.name);
|
||||
}
|
||||
|
||||
public static string GetLocalizedName(string skinId)
|
||||
{
|
||||
return LocalizationManager.Instance.Localize(("skin_" + skinId).ToLowerInvariant());
|
||||
}
|
||||
|
||||
[ContextMenu("TEST")]
|
||||
private void TEST()
|
||||
{
|
||||
AppController app = UnityEngine.Object.FindObjectOfType<AppController>();
|
||||
if (app != null)
|
||||
{
|
||||
app.PickupsSkinsController.SetCurrentValue(this);
|
||||
}
|
||||
}
|
||||
|
||||
public long GetUnlockLevel()
|
||||
{
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee465fd3ba173b5fe8fc5ad328cc6b80
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
public class PickupsSkinsController : CustomizableController<PickupsSkinDef, PickupsSkinData>
|
||||
{
|
||||
public PickupsSkinsController(AppController appController)
|
||||
: base(appController.savedDataController,
|
||||
() => appController.metaDef.pickupsSkins,
|
||||
(SavedData data) => data.pickupsSkins,
|
||||
(PickupsSkinDef def) => appController.coreGame.pickupSkinProvider.SetSkin(def),
|
||||
appController.TryPayCost,
|
||||
() => false)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b453c11358cc45a7604ab6895fb4ca9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,6 @@
|
||||
using System;
|
||||
|
||||
[Serializable]
|
||||
public class PickupsSkinsData : CustomizablesDataBase<PickupsSkinData>
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f3e528769c7480f41be382bfcf050a6c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
public class PlayerSkinController : CustomizableController<PlayerSkinDef, PlayerSkinData>
|
||||
{
|
||||
public PlayerSkinController(AppController appController)
|
||||
: base(appController.savedDataController,
|
||||
() => appController.metaDef.playerSkins,
|
||||
(SavedData data) => data.playerSkins,
|
||||
(PlayerSkinDef def) => appController.coreGame.SetPlayerSkin(def),
|
||||
appController.TryPayCost,
|
||||
() => false)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52c84169e10d132c734bb986c3a90f01
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,6 @@
|
||||
using System;
|
||||
|
||||
[Serializable]
|
||||
public class PlayerSkinData : CustomizableDataBase
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 831e2536d8cbdac4686bc0f5b49ac162
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,28 @@
|
||||
using UnityEngine;
|
||||
using OHM.UnityToolkit.Localization;
|
||||
|
||||
[CreateAssetMenu(fileName = "Player Skin Def", menuName = "GameSqueleton/Player Skin Def")]
|
||||
public class PlayerSkinDef : CustomizableDef
|
||||
{
|
||||
public Player prefab;
|
||||
|
||||
public string GetLocalizedName()
|
||||
{
|
||||
return GetLocalizedName(base.name);
|
||||
}
|
||||
|
||||
public static string GetLocalizedName(string skinId)
|
||||
{
|
||||
return LocalizationManager.Instance.Localize(("skin_" + skinId).ToLowerInvariant());
|
||||
}
|
||||
|
||||
[ContextMenu("TEST")]
|
||||
private void TEST()
|
||||
{
|
||||
AppController app = UnityEngine.Object.FindObjectOfType<AppController>();
|
||||
if (app != null)
|
||||
{
|
||||
app.PlayerSkinController.SetCurrentValue(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6be5a0f90961ce0dd448ebbd1047a6d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,6 @@
|
||||
using System;
|
||||
|
||||
[Serializable]
|
||||
public class PlayerSkinsData : CustomizablesDataBase<PlayerSkinData>
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 45d90a0383183ba4f886131fc5d0666f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user