目录
一、 人员分工
装备组人员:3人
分工:
1.
系统分析
项目创建
公共类设计
2.
系统目标
编码规范
运行环境
数据库与数据表设计
3.
人员分工
开发问题及解决
系统功能结构
业务流程图
UML类图
模块设计
二、 业务流程图
装备业务流程图
三、 系统功能结构图
装备功能模块
四、 UML类图
五、 详细设计
(1)背包界面
Press”i”,打开背包栏
(2)物品栏界面
(3)人物装备界面
Press”c”,打开人物装备栏
六、 遇到的问题和解决方法
float x = y * gameObject.GetComponent<Camera>().aspect;
Request error (error): UnityEditor.AsyncHTTPClient:Done(State, Int32)
七、附录(代码实现)
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[System.Serializable]
public class Item
{
public string itemName; //itemName of the item
public int itemID; //itemID of the item
public string itemDesc; //itemDesc of the item
public Sprite itemIcon; //itemIcon of the item
public GameObject itemModel; //itemModel of the item
public int itemValue = 1; //itemValue is at start 1
public ItemType itemType; //itemType of the Item
public float itemWeight; //itemWeight of the item
public int maxStack = 1;
public int indexItemInList = 999;
public int rarity;
[SerializeField]
public List<ItemAttribute> itemAttributes = new List<ItemAttribute>();
public Item(){}
public Item(string name, int id, string desc, Sprite icon, GameObject model, int maxStack, ItemType type, string sendmessagetext, List<ItemAttribute> itemAttributes) //function to create a instance of the Item
{
itemName = name;
itemID = id;
itemDesc = desc;
itemIcon = icon;
itemModel = model;
itemType = type;
this.maxStack = maxStack;
this.itemAttributes = itemAttributes;
}
public Item getCopy()
{
return (Item)this.MemberwiseClone();
}
}
using UnityEngine;
using System.Collections;
public class PickUpItem : MonoBehaviour
{
public Item item;
private Inventory _inventory;
private GameObject _player;
// Use this for initialization
void Start()
{
_player = GameObject.FindGameObjectWithTag("Player");
if (_player != null)
_inventory = _player.GetComponent<PlayerInventory>().inventory.GetComponent<Inventory>();
}
// Update is called once per frame
void Update()
{
if (_inventory != null && Input.GetKeyDown(KeyCode.E))
{
float distance = Vector3.Distance(this.gameObject.transform.position, _player.transform.position);
if (distance <= 3)
{
bool check = _inventory.checkIfItemAllreadyExist(item.itemID, item.itemValue);
if (check)
Destroy(this.gameObject);
else if (_inventory.ItemsInInventory.Count < (_inventory.width * _inventory.height))
{
_inventory.addItemToInventory(item.itemID, item.itemValue);
_inventory.updateItemList();
_inventory.stackableSettings();
Destroy(this.gameObject);
}
}
}
if (Input.GetMouseButton(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);//从摄像机发出到点击坐标的射线
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo))
{
Debug.DrawLine(ray.origin, hitInfo.point);//划出射线,只有在scene视图中才能看到
GameObject gameObj = hitInfo.collider.gameObject;
Debug.Log("click object name is " + gameObj.name);
if (gameObj.tag == "Item")//当射线碰撞目标为boot类型的物品 ,执行拾取操作
{
_inventory.addItemToInventory(item.itemID, item.itemValue);
_inventory.updateItemList();
_inventory.stackableSettings();
Destroy(this.gameObject);
Debug.Log("pick up!");
}
}
}
}
}
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System;
public class ConsumeItem : MonoBehaviour, IPointerDownHandler
{
public Item item;
private static Tooltip tooltip;
public ItemType[] itemTypeOfSlot;
public static EquipmentSystem eS;
public GameObject duplication;
public static GameObject mainInventory;
void Start()
{
item = GetComponent<ItemOnObject>().item;
if (GameObject.FindGameObjectWithTag("Tooltip") != null)
tooltip = GameObject.FindGameObjectWithTag("Tooltip").GetComponent<Tooltip>();
if (GameObject.FindGameObjectWithTag("EquipmentSystem") != null)
eS = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerInventory>().characterSystem.GetComponent<EquipmentSystem>();
if (GameObject.FindGameObjectWithTag("MainInventory") != null)
mainInventory = GameObject.FindGameObjectWithTag("MainInventory");
}
public void OnPointerDown(PointerEventData data)
{
if (this.gameObject.transform.parent.parent.parent.GetComponent<EquipmentSystem>() == null)
{
bool gearable = false;
Inventory inventory = transform.parent.parent.parent.GetComponent<Inventory>();
if (eS != null)
itemTypeOfSlot = eS.itemTypeOfSlots;
if (data.button == PointerEventData.InputButton.Right)
{
//item from craft system to inventory
if (transform.parent.GetComponent<CraftResultSlot>() != null)
{
bool check = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerInventory>().inventory.GetComponent<Inventory>().checkIfItemAllreadyExist(item.itemID, item.itemValue);
if (!check)
{
GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerInventory>().inventory.GetComponent<Inventory>().addItemToInventory(item.itemID, item.itemValue);
GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerInventory>().inventory.GetComponent<Inventory>().stackableSettings();
}
CraftSystem cS = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerInventory>().craftSystem.GetComponent<CraftSystem>();
cS.deleteItems(item);
CraftResultSlot result = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerInventory>().craftSystem.transform.GetChild(3).GetComponent<CraftResultSlot>();
result.temp = 0;
tooltip.deactivateTooltip();
gearable = true;
GameObject.FindGameObjectWithTag("MainInventory").GetComponent<Inventory>().updateItemList();
}
else
{
bool stop = false;
if (eS != null)
{
for (int i = 0; i < eS.slotsInTotal; i++)
{
if (itemTypeOfSlot[i].Equals(item.itemType))
{
if (eS.transform.GetChild(1).GetChild(i).childCount == 0)
{
stop = true;
if (eS.transform.GetChild(1).GetChild(i).parent.parent.GetComponent<EquipmentSystem>() != null && this.gameObject.transform.parent.parent.parent.GetComponent<EquipmentSystem>() != null) { }
else
inventory.EquiptItem(item);
this.gameObject.transform.SetParent(eS.transform.GetChild(1).GetChild(i));
this.gameObject.GetComponent<RectTransform>().localPosition = Vector3.zero;
eS.gameObject.GetComponent<Inventory>().updateItemList();
inventory.updateItemList();
gearable = true;
if (duplication != null)
Destroy(duplication.gameObject);
break;
}
}
}
if (!stop)
{
for (int i = 0; i < eS.slotsInTotal; i++)
{
if (itemTypeOfSlot[i].Equals(item.itemType))
{
if (eS.transform.GetChild(1).GetChild(i).childCount != 0)
{
GameObject otherItemFromCharacterSystem = eS.transform.GetChild(1).GetChild(i).GetChild(0).gameObject;
Item otherSlotItem = otherItemFromCharacterSystem.GetComponent<ItemOnObject>().item;
if (item.itemType == ItemType.UFPS_Weapon)
{
inventory.UnEquipItem1(otherItemFromCharacterSystem.GetComponent<ItemOnObject>().item);
inventory.EquiptItem(item);
}
else
{
inventory.EquiptItem(item);
if (item.itemType != ItemType.Backpack)
inventory.UnEquipItem1(otherItemFromCharacterSystem.GetComponent<ItemOnObject>().item);
}
if (this == null)
{
GameObject dropItem = (GameObject)Instantiate(otherSlotItem.itemModel);
dropItem.AddComponent<PickUpItem>();
dropItem.GetComponent<PickUpItem>().item = otherSlotItem;
dropItem.transform.localPosition = GameObject.FindGameObjectWithTag("Player").transform.localPosition;
inventory.OnUpdateItemList();
}
else
{
otherItemFromCharacterSystem.transform.SetParent(this.transform.parent);
otherItemFromCharacterSystem.GetComponent<RectTransform>().localPosition = Vector3.zero;
if (this.gameObject.transform.parent.parent.parent.GetComponent<Hotbar>() != null)