私は、ゲームオブジェクトを表示非表示にしてソートするのに奇妙な問題があります。実際にソートするだけで、どのゲームオブジェクトが1番目、2番目、3番目に表示されているかを並べ替えることができます。私のコードの下GameObjectを非表示にしてすべて表示ソートGameObject Unityを隠すC#
:
menu.cs(3保管してshow在庫)
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class menu : MonoBehaviour {
public GameObject showInventory;
public GameObject showRawStorage1;
public GameObject showRawStorage2;
public GameObject showRawStorage3;
public Button storage1;
public Button storage2;
public Button storage3;
bool active = false;
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update() {
}
public void onClickshowPlant() {
if (active == true) {
showInventory.SetActive (false);
active = false;
} else if (active == false) {
showInventory.SetActive(true);
active = true;
}
}
public void onClickStorage1() {
HideAllSlot();
ShowStorage1();
}
public void onClickStorage2() {
HideAllSlot();
ShowStorage2();
}
public void onClickStorage3() {
HideAllSlot();
ShowStorage3();
}
public void HideAllSlot() {
showRawStorage1.SetActive (false);
showRawStorage2.SetActive (false);
showRawStorage3.SetActive (false);
}
public void ShowAllSlot() {
showRawStorage3.SetActive (true);
showRawStorage2.SetActive (true);
showRawStorage1.SetActive (true);
}
public void ShowStorage1() {
showRawStorage1.SetActive (true);
}
public void ShowStorage2() {
showRawStorage2.SetActive (true);
}
public void ShowStorage3() {
showRawStorage3.SetActive (true);
}
}
Inventory.cs(スロットストレージと私はストレージをスロットにそれを追加している表示項目を生成する)
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
public class inventory : MonoBehaviour {
public List<GameObject> slotsx = new List<GameObject>();
public player Player;
public List<item> itemx = new List<item>();
public GameObject slots;
public GameObject toolTip;
public GameObject dragitemicon;
public bool draggingitem = false;
public item getdragitem;
item itemxs;
public int indexofdragitem;
public Sprite icon;
int maxItemRaw = 20;
int maxItemValuable = 5;
int maxItemAdmirable = 3;
int sisa;
itemDatabase database;
int totalSlot = 60;
int currentStorage = 1;
int view = 20;
menu menux;
// Use this for initialization
void Start() {
Player = new player();
int slotAmount = 0;
database = GameObject.FindGameObjectWithTag ("itemDatabase").GetComponent<itemDatabase>();
//Generate the Slot and Slot Name at Storage 1;
for(int i = 1; i <= 20; i++) {
GameObject Slot = (GameObject) Instantiate(slots);
Slot.GetComponent<slotScript>().slotNumber = slotAmount;
slotsx.Add(Slot);
Player.items.Add(new item());
addChilParent (this.gameObject,Slot);
Slot.name = "slot-" + i;
Slot.SetActive (true);
slotAmount++;
}
//Generate the Slot and Slot Name at Storage 2;
for(int i = 21; i <= 40; i++) {
GameObject Slot = (GameObject) Instantiate(slots);
Slot.GetComponent<slotScript>().slotNumber = slotAmount;
slotsx.Add(Slot);
Player.items.Add(new item());
GameObject Rawstorage2 = GameObject.Find("RawStorage 2");
addChilParent (Rawstorage2,Slot);
Slot.name = "slot-" + i;
Slot.SetActive (true);
slotAmount++;
}
//Generate the Slot and Slot Name at Storage 3;
for(int i = 41; i <= 60; i++) {
GameObject Slot = (GameObject) Instantiate(slots);
Slot.GetComponent<slotScript>().slotNumber = slotAmount;
slotsx.Add(Slot);
Player.items.Add(new item());
GameObject Rawstorage3 = GameObject.Find("RawStorage 3");
addChilParent (Rawstorage3,Slot);
Slot.name = "slot-" + i;
Slot.SetActive (true);
slotAmount++;
}
AddItem (1);
AddItem (2);
}
// Update is called once per frame
void Update() {
if (draggingitem) {
Vector3 post = (Input.mousePosition - GameObject.FindGameObjectWithTag("Canvas").GetComponent<RectTransform>().localPosition);
dragitemicon.GetComponent<RectTransform>().position = new Vector3(post.x + 25, post.y - 25, post.z);
}
}
//Add Slot Child To GridSlot Game Object
public void addChilParent(GameObject parentx, GameObject childx) {
//childx.transform.parent = parentx.gameObject.transform;
childx.transform.SetParent (parentx.gameObject.transform);
}
//Add Item Method
void AddItem(int ID) {
for (int i = 0; i < database.items.Count; i++) {
if(database.items[i].itemID == ID) {
itemxs = new item (database.items [i].itemName,
database.items [i].itemID,
database.items [i].itemDesc,
database.items [i].harvest,
database.items [i].itemTime,
database.items [i].stdprice,
database.items [i].hightprice,
database.items [i].itemStock,
database.items [i].Lvlunlock,
database.items [i].rawTree,
database.items [i].itemType,
database.items [i].itemProd,
database.items [i].itemIcon,
database.items [i].itemLocation,
database.items [i].itemExp);
CheckInventoryExist(itemxs);
break;
}
}
}
//Add Item In Empty Slot
void AddItemEmptySlot (item items, int sisa) {
items.itemStock = sisa;
for (int i = 0; i < Player.items.Count; i++) {
if(Player.items[i].itemName == null) {
Player.items[i] = items;
break;
}
}
}
//Check Inventory is Exist
void CheckInventoryExist(item IdItem) {
sisa = IdItem.harvest;
for (int i = 0; i < Player.items.Count; i++) {
if(IdItem.itemType == item.ItemType.Raw) {
for (int j = 1; j <= IdItem.harvest; j++) {
if(IdItem.itemID == Player.items[i].itemID && Player.items[i].itemID != null && Player.items[i].itemStock < maxItemRaw) {
Player.items[i].itemStock = Player.items[i].itemStock + 1;
sisa = sisa - 1;
}
}
if(sisa > 0 && sisa < IdItem.harvest) {
AddItemEmptySlot(IdItem,sisa);
break;
}
if (i == Player.items.Count - 1 && sisa == IdItem.harvest) {
AddItemEmptySlot(IdItem, sisa);
break;
}
}
if(IdItem.itemType == item.ItemType.Valuable) {
for (int j = 1; j <= IdItem.harvest; j++) {
if(IdItem.itemID == Player.items[i].itemID && Player.items[i].itemID != null && Player.items[i].itemStock < maxItemValuable) {
Player.items[i].itemStock = Player.items[i].itemStock + 1;
sisa = sisa - 1;
}
}
if(sisa > 0 && sisa < IdItem.harvest) {
AddItemEmptySlot(IdItem,sisa);
break;
}
if (i == Player.items.Count - 1 && sisa == IdItem.harvest) {
AddItemEmptySlot(IdItem, sisa);
break;
}
}
if(IdItem.itemType == item.ItemType.Admirable) {
for (int j = 1; j <= IdItem.harvest; j++) {
if(IdItem.itemID == Player.items[i].itemID && Player.items[i].itemID != null && Player.items[i].itemStock < maxItemAdmirable) {
Player.items[i].itemStock = Player.items[i].itemStock + 1;
sisa = sisa - 1;
}
}
if(sisa > 0 && sisa < IdItem.harvest) {
AddItemEmptySlot(IdItem,sisa);
break;
}
if (i == Player.items.Count - 1 && sisa == IdItem.harvest) {
AddItemEmptySlot(IdItem, sisa);
break;
}
}
}
}
}
問題は私が実行するときです。
public void onClickshowPlant() {
if (active == true) {
showInventory.SetActive (false);
active = false;
} else if (active == false) {
showInventory.SetActive(true);
active = true;
HideAllSlot();
ShowStorage1();
}
}
は、アイテムが消えて表示されていません:それは、すべてのインベントリストレージソートストレージ3、2、
1.私が入れ表示します。
しかし、私がHideAllSlot()とShowStorage1()を削除すると、項目は表示され、Storage 3,2,1でソート順になります。だから私はklikインベントリを表示する私は最初のショーがストレージ1であり、ストレージ2と3が隠れている欲しい。どうやってするか ?何か案が ?
ありがとうございました。