데이터 형식 클래스 변수에 값을 전달하는 간단한 질문과 이상한 점이 있습니다. 아래Unity with C# 스크립트 : 클래스 데이터 형식 클래스 데이터 전달 값이 두 번 이상한
코드 :
itemDatabase.cs
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class itemDatabase : MonoBehaviour {
public List<item> items = new List<item>();
// Use this for initialization
void Start() {
// Add Data To Item List With Class Item
// ------------------------------- Item Corps (Raw - Big Tree) ------------------------------- //
items.Add (new item ("Lemon", 1, "Honey Lemon", 9, 1020, 75, 158, 0, 1, item.RawTree.BigTree, item.ItemType.Raw, item.ItemProd.Corps, "Corps"));
}
// Update is called once per frame
void Update() {
}
}
생성자 :
,369 :using UnityEngine;
using System.Collections;
// Make Class Item
public class item {
public string itemName;
public int itemID;
public string itemDesc;
public string itemIcon;
public GameObject itemModel;
public int itemTime;
public int hightprice;
public int stdprice;
public int itemStock;
public int harvest;
public RawTree rawTree;
public ItemType itemType;
public ItemProd itemProd;
public int Lvlunlock;
private string baseName;
public enum ItemType {
Raw,
Admirable,
Valuable
}
public enum RawTree {
BigTree,
SmallTree,
Field,
None
}
public enum ItemProd {
AnimalBarm,
Mining,
Corps,
Dairy,
JuiceJamMaker,
Merchant,
Kitchen,
Bakery,
CraftHouse
}
public item (string name, int ID, string desc, int harvestx, int time, int stdpricex, int hightpricex, int stock, int Lvlunlockx, RawTree RawTree, ItemType type, ItemProd prod, string folderx) {
itemName = name;
itemID = ID;
itemDesc = desc;
harvest = harvestx;
itemTime = time;
stdprice = stdpricex;
hightprice = hightpricex;
itemStock = stock;
Lvlunlock = Lvlunlockx;
rawTree = RawTree;
itemType = type;
itemProd = prod;
**// line : 60
// itemName contain : "Lemon" // folderx contain : "Corps"**
this.baseName = folderx + "/"; **// basename is directory source picture**
itemIcon = this.baseName + itemName;
Debug.Log ("item name : " + itemName); **// result : "Lemon"**
Debug.Log ("item icon : " + itemIcon); **// result : "Corps/Lemon/Lemon" Why this appear "Corps/Lemon/Lemon" not "Corps/Lemon" ???? this is a mistake right ??**
Debug.Log ("this.basename : " + this.baseName); **// result : "Corps/Lemon" why this appear "Corps/Lemon" not "corps/" ???? this is also a mistake right ???**
}
this.baseName는 예제 디렉토리 사진의 근원이다
this.baseName = "군단/레몬". 그래서 폴더 "군단"파일 "레몬"에서. this.baseName = folderx + "/"; folderx는 itemDatabase : items.Add (새 항목 ("Lemon", 1, "Honey Lemon", 9, 1020, 75, 158, 0, 1, item.RawTree.BigTree, item.ItemType.Raw, item)에서 입력됩니다. ItemProd.Corps, "Corps")); 당신이 난 그냥
에서 값을 전달 볼 수 // "군단"가 // 라인 (60)과 (항목 추가 방법에서) 라인 80에서 항목 방법
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);
// Line 80
Debug.Log ("Item Icon 1 : " + database.items[i].itemIcon); // result "Corps/Lemon"
Debug.Log ("Item Icon 2 : " + itemxs.itemIcon); // result "Corps/Lemon/Lemon";
CheckInventoryExist(itemxs);
break;
}
}
}
문제의 시작을 추가 folderx 참조
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);
내가 디버그하면 값이 높아집니다.
// Line 80
Debug.Log ("Item Icon 1 : " + database.items[i].itemIcon); // result "Corps/Lemon"
Debug.Log ("Item Icon 2 : " + itemxs.itemIcon); // result "Corps/Lemon/Lemon";
모든 아이디어 ??
데니스
확인할 정보가 충분하지 않습니다. 더 많은 코드가 필요합니다. 왜 폴더 x와 baseName을 수정할 지 코드를 추가하지 않으시겠습니까? –
충분하니? 그것을 확인하십시오. –
baseName은 무엇입니까? 데이터 타입은 좀 더 자세한 내용을 넣어주세요 –