2022-03-15 20:26:46 +08:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class ItemController : UnitySingleton<ItemController>
|
|
|
|
{
|
|
|
|
|
|
|
|
int displayIndex=0;
|
|
|
|
Item displayItem;
|
|
|
|
|
|
|
|
public List<Item> itemList = new List<Item>();
|
|
|
|
|
|
|
|
Player player;
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
player = FindObjectOfType<Player>();
|
|
|
|
Display();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//添加物品
|
|
|
|
public void AddItem(Item item) {
|
|
|
|
itemList.Add(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 用于Player获取物品
|
|
|
|
/// </summary>
|
|
|
|
public Item GetItem() {
|
|
|
|
return itemList[displayIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 用于强制改变Player的物品
|
|
|
|
/// </summary>
|
|
|
|
public void SetItem()
|
|
|
|
{
|
2022-04-06 10:05:29 +08:00
|
|
|
if(itemList[displayIndex]!=null)
|
2022-03-15 20:26:46 +08:00
|
|
|
player.weapon = itemList[displayIndex];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 展示正在使用的物品
|
|
|
|
/// </summary>
|
|
|
|
public void Display() {
|
|
|
|
SetItem();
|
|
|
|
displayItem = Instantiate(itemList[displayIndex],Vector3.zero,Quaternion.identity,transform);
|
|
|
|
displayItem.transform.localPosition = Vector3.zero;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void LeftChangeItem() {
|
2022-03-25 19:50:39 +08:00
|
|
|
player.WeaponReturn();
|
2022-03-15 20:26:46 +08:00
|
|
|
Destroy(displayItem.gameObject);
|
|
|
|
displayIndex = (displayIndex - 1 + itemList.Count)%itemList.Count;
|
|
|
|
Display();
|
2022-03-25 19:50:39 +08:00
|
|
|
player.WeaponInPosition();
|
2022-03-15 20:26:46 +08:00
|
|
|
}
|
|
|
|
public void RightChangeItem()
|
|
|
|
{
|
2022-03-25 19:50:39 +08:00
|
|
|
player.WeaponReturn();
|
2022-03-15 20:26:46 +08:00
|
|
|
Destroy(displayItem.gameObject);
|
|
|
|
displayIndex = (displayIndex + 1)%itemList.Count;
|
|
|
|
Display();
|
2022-03-25 19:50:39 +08:00
|
|
|
player.WeaponInPosition();
|
2022-03-15 20:26:46 +08:00
|
|
|
}
|
2022-03-19 23:02:32 +08:00
|
|
|
|
|
|
|
public void ToLastestItem() {
|
|
|
|
player.WeaponReturn();
|
|
|
|
Destroy(displayItem.gameObject);
|
|
|
|
displayIndex = itemList.Count-1;
|
|
|
|
Display();
|
|
|
|
player.WeaponInPosition();
|
|
|
|
}
|
2022-03-25 19:50:39 +08:00
|
|
|
|
|
|
|
public void ReplaceItem(Item newItem) {
|
|
|
|
player.WeaponReturn();
|
|
|
|
Destroy(displayItem.gameObject);
|
|
|
|
itemList[displayIndex] = newItem;
|
|
|
|
Display();
|
|
|
|
player.WeaponInPosition();
|
|
|
|
}
|
2022-03-15 20:26:46 +08:00
|
|
|
}
|