重做物品系统
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MuHua;
|
||||
|
||||
/// <summary>
|
||||
/// 资源管理器
|
||||
/// </summary>
|
||||
public class AssetsManager : ModuleSingle<AssetsManager> {
|
||||
|
||||
public List<InventoryItemConst> items;
|
||||
|
||||
protected override void Awake() => NoReplace(false);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c361800b57f418848ab005dbaca34a7c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,33 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MuHua;
|
||||
|
||||
/// <summary>
|
||||
/// 物品 - 管理器
|
||||
/// </summary>
|
||||
public class ManagerItem : ModuleSingle<ManagerItem> {
|
||||
/// <summary> 装备列表 </summary>
|
||||
public List<EquipmentConst> equipments;
|
||||
|
||||
protected override void Awake() => NoReplace(false);
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 物品奖励
|
||||
/// </summary>
|
||||
public class ItemReward {
|
||||
/// <summary> 物品列表 </summary>
|
||||
public List<InventoryItem> items;
|
||||
|
||||
public void Settings<T>(List<T> list) where T : InventoryItemConst {
|
||||
items = new List<InventoryItem>();
|
||||
list.ForEach(obj => items.Add(obj.To()));
|
||||
}
|
||||
|
||||
public (InventoryItem, int) Get(int max = 1) {
|
||||
int count = Random.Range(1, max + 1);
|
||||
int index = Random.Range(0, items.Count);
|
||||
return (items[index], count);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 287f1e957d7061a42977427a98b178b5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,44 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MuHua;
|
||||
|
||||
/// <summary>
|
||||
/// 全局管理器
|
||||
/// </summary>
|
||||
public class SingleManager : ModuleSingle<SingleManager> {
|
||||
|
||||
public Inventory inventory;
|
||||
public Equipment equipment;
|
||||
|
||||
public ItemReward materialReward;
|
||||
public ItemReward equipmentReward;
|
||||
|
||||
protected override void Awake() => NoReplace();
|
||||
|
||||
private void Start() {
|
||||
inventory = new Inventory(40);
|
||||
equipment = new Equipment();
|
||||
|
||||
// materialReward = new ItemReward();
|
||||
// materialReward.Settings(ManagerItem.I.materials);
|
||||
equipmentReward = new ItemReward();
|
||||
equipmentReward.Settings(ManagerItem.I.equipments);
|
||||
|
||||
UIShortcutMenu shortcutMenu = UIPopupManager.I.shortcutMenu;
|
||||
shortcutMenu.Add("背包", () => { ModuleUI.Settings(Page.Backpack); });
|
||||
shortcutMenu.Add("奖励/材料", RewardMaterial);
|
||||
shortcutMenu.Add("奖励/装备", RewardEquipment);
|
||||
|
||||
ValueSystem.I.Initial();
|
||||
}
|
||||
|
||||
private void RewardMaterial() {
|
||||
(InventoryItem item, int count) = materialReward.Get(10);
|
||||
inventory.AddItem(item, count);
|
||||
}
|
||||
private void RewardEquipment() {
|
||||
(InventoryItem item, int count) = equipmentReward.Get(1);
|
||||
inventory.AddItem(item, count);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 50f6b4ec374a86846b626668e0b5627e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MuHua;
|
||||
|
||||
/// <summary>
|
||||
/// 数值系统
|
||||
/// </summary>
|
||||
public class ValueSystem : Module<ValueSystem> {
|
||||
/// <summary> 对战数值 </summary>
|
||||
public ValueContainer battle;
|
||||
|
||||
/// <summary> 初始化 </summary>
|
||||
public void Initial() {
|
||||
battle = new ValueContainer();
|
||||
battle.AddInstance(ValueType.Integer, "生命");
|
||||
battle.AddInstance(ValueType.Integer, "金币");
|
||||
battle.AddInstance(ValueType.Integer, "水晶");
|
||||
|
||||
Debug.Log(battle["生命"].value);
|
||||
|
||||
ValueModifier modifier = new ValueModifier { Fixed = 100 };
|
||||
battle["生命"].AddModifier(modifier, true);
|
||||
|
||||
Debug.Log(battle["生命"].value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b9b82c2b1930d5f4b8b002d671c4e28c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user