我们的游戏世界(背包【仓库】,交易,任务,简单经济系统,装备)实现(基于仙剑demo聊聊游戏世界)第一篇谈谈交易
2015-06-12 08:27
911 查看
一直不知道应该把下一步我们要更新的代码怎么归类,在网上看了下这个分类,我觉得这个完全是针对玩家体验的,比如说,装备系统,(背包)仓库系统,交易系统这些都是相辅相成的,分开真的好吗?而这里的世界系统仅仅涉及一个场景跳转,我想问,强化,仓库,交易这些不都发生在游戏世界中吗,为啥说他们是独立的呢,就因为看到的不一样,其实这些都是游戏世界中的一个部分,说白了,他们只是游戏经济系统中的一个部分,因为这些东西都可以在游戏虚拟世界中货币化,要靠游戏中提供的经济模型来支撑,当然单机游戏里面经济模型较为简单,因为不需要考虑货币通胀等等问题(这个要放大的话就要写好多字,我大学主修的就是经济学【第二学位修的计算机】,建立一个经济数学模型,我自己没有信心搞出来,所以我就不多说话了),我们就我们的仙剑demo,来简单看看游戏中的这些东西代码怎么写吧,如果做网游的话,那么就让数值策划去担心游戏经济模型,我们这里就不考虑了。
首先,我们看看游戏中的交易代码是怎么实现的。
先看看效果吧,看看游戏里是什么样的。
对话结束后,进入实质的购买界面
可以看到左边的商店物品列表
右边是自身的包裹,这个是怎么实现的呢?我们看下李铁匠身上绑定的脚本
我们看下这就是npc李铁匠,上面的AI脚本,我们前面讲过了,这里我们只需要看npcsetup和shopitemlist,npcsetup是一个设置人物npc交互的脚本
using UnityEngine; using System.Collections; using System.Collections.Generic; public class NpcSetup : MonoBehaviour { public enum NameTagSetup {NpcName,PlayerName,Other}; public enum NpcType {RegularNpc,ShopKeeper,QuestNpc,SaveNpc}; public enum FaceSetup {NpcFace,PlayerFace,Other}; public enum QuestNpcState{StartQuest,InProgress,Complete,AfterComplete}; public NpcType npcType; public string npcName; public Texture2D npcFace; private bool startCountDialogBox; [System.Serializable] public class MessageBoxSetting { public bool enableNameTag = true; public NameTagSetup nameTagSetup; public string otherNameTag; public bool enableFace = true; public FaceSetup faceSetup; public Texture2D otherFace; [Multiline] public string message; } public List<MessageBoxSetting> dialogSetting = new List<MessageBoxSetting>(); public int questID; public QuestNpcState questNpcState; public List<MessageBoxSetting> dialogQuest = new List<MessageBoxSetting>(); public List<MessageBoxSetting> dialogQuestInProgress = new List<MessageBoxSetting>(); public List<MessageBoxSetting> dialogQuestComplete = new List<MessageBoxSetting>(); public List<MessageBoxSetting> dialogQuestAfterComplete = new List<MessageBoxSetting>(); private HeroController playerControl; private int indexDialog; private int indexCurrentQuest; private bool disableMovePlayer; private Quest_Data questData; private QuestWindow questWindow; public GUI_Menu inventory; private GameObject player; public static bool resetMessageBox; public static bool disableNext; //Editor Variable [HideInInspector] public int sizeDialog=0; [HideInInspector] public int sizeDialogQuest=0; [HideInInspector] public int sizeDialogQuestInProgress=0; [HideInInspector] public int sizeDialogQuestComplete=0; [HideInInspector] public int sizeDialogQuestAfterComplete=0; [HideInInspector] public List<bool> showSizeDialog = new List<bool>(); [HideInInspector] public List<bool> showSizeDialogQuest = new List<bool>(); [HideInInspector] public List<bool> showSizeDialogQuestInProgress = new List<bool>(); [HideInInspector] public List<bool> showSizeDialogQuestComplete = new List<bool>(); [HideInInspector] public List<bool> showSizeDialogQuestAfterComplete = new List<bool>(); // Use this for initialization void Start () { // Change this tag to Npc if(this.tag != "Npc") this.tag = "Npc"; if(this.gameObject.layer != 13) this.gameObject.layer = 13; indexDialog = 0; playerControl = GameObject.FindGameObjectWithTag("Player").GetComponent<HeroController>(); if(npcType == NpcType.QuestNpc) { questData = GameObject.Find("QuestData").GetComponent<Quest_Data>(); questWindow = GameObject.Find("GUI Manager/QuestWindow").GetComponent<QuestWindow>(); player = GameObject.FindGameObjectWithTag("Player"); inventory = player.transform.FindChild("Inventory").GetComponent<GUI_Menu>(); } } // Update is called once per frame void Update () { if(npcType == NpcType.RegularNpc || npcType == NpcType.ShopKeeper || npcType == NpcType.SaveNpc) NpcDetect(); else if(npcType == NpcType.QuestNpc) QuestNpcDetect(); } void NpcDetect() { if(disableMovePlayer) DisableMove(); if(startCountDialogBox) { SetupDialogBox(indexDialog); if(Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.KeypadEnter)) { SoundManager.instance.PlayingSound("Next_Dialog"); if(indexDialog < dialogSetting.Count-1) { indexDialog++; }else { if(npcType == NpcType.ShopKeeper || npcType == NpcType.SaveNpc) CallNextCommand(); indexDialog = 0; startCountDialogBox = false; MessageBox.showMessageBox = false; MessageBox.showNameTag = false; MessageBox.showFace = false; Invoke("EnableMovePlayer",0.3f); } } } } void QuestNpcDetect() { if(disableMovePlayer) DisableMove(); if(startCountDialogBox) { if(questNpcState == QuestNpcState.StartQuest) SetupDialogBoxQuest(indexDialog,dialogQuest); else if(questNpcState == QuestNpcState.InProgress) SetupDialogBoxQuest(indexDialog,dialogQuestInProgress); else if(questNpcState == QuestNpcState.Complete) SetupDialogBoxQuest(indexDialog,dialogQuestComplete); else if(questNpcState == QuestNpcState.AfterComplete) SetupDialogBoxQuest(indexDialog,dialogQuestAfterComplete); if(questNpcState == QuestNpcState.StartQuest) { if(Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.KeypadEnter) || resetMessageBox) { if(!QuestWindow.enableWindow) SoundManager.instance.PlayingSound("Next_Dialog"); if(indexDialog < dialogQuest.Count-1) { indexDialog++; if(indexDialog == dialogQuest.Count-1) { QuestWindow.enableWindow = true; QuestWindow.enableButtonAccept = true; disableNext = true; questWindow.SetupQuestWindow(questID); } }else if(!disableNext) { disableNext = false; indexDialog = 0; startCountDialogBox = false; MessageBox.showMessageBox = false; MessageBox.showNameTag = false; MessageBox.showFace = false; resetMessageBox = false; Invoke("EnableMovePlayer",0.3f); } } }else if(Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.KeypadEnter)) { SoundManager.instance.PlayingSound("Next_Dialog"); if(questNpcState == QuestNpcState.InProgress) { if(indexDialog < dialogQuestInProgress.Count-1) { indexDialog++; }else { indexDialog = 0; startCountDialogBox = false; MessageBox.showMessageBox = false; MessageBox.showNameTag = false; MessageBox.showFace = false; QuestWindow.enableWindow = false; Invoke("EnableMovePlayer",0.3f); } } else if(questNpcState == QuestNpcState.Complete) { if(indexDialog < dialogQuestComplete.Count-1) { indexDialog++; }else { if(!questData.questSetting[indexCurrentQuest].repeatQuest) { questData.questSetting[indexCurrentQuest].questState = 3; }else { questData.questSetting[indexCurrentQuest].questState = 0; } GiveReward(questID); indexDialog = 0; startCountDialogBox = false; MessageBox.showMessageBox = false; MessageBox.showNameTag = false; MessageBox.showFace = false; Invoke("EnableMovePlayer",0.3f); } } else if(questNpcState == QuestNpcState.AfterComplete) { if(indexDialog < dialogQuestAfterComplete.Count-1) { indexDialog++; }else { indexDialog = 0; startCountDialogBox = false; MessageBox.showMessageBox = false; MessageBox.showNameTag = false; MessageBox.showFace = false; Invoke("EnableMovePlayer",0.3f); } } } } } public void DisableMove() { playerControl.dontMove = true; playerControl.dontClick = true; } public void CallDialogBox() { startCountDialogBox = true; MessageBox.showMessageBox = true; disableMovePlayer = true; } void EnableMovePlayer() { disableMovePlayer = false; playerControl.ResetState(); } void SetupDialogBox(int i) { if(dialogSetting[i].enableNameTag) { if(dialogSetting[i].nameTagSetup == NameTagSetup.PlayerName) MessageBox.nameTagStatic = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerStatus>().playerName; else if(dialogSetting[i].nameTagSetup == NameTagSetup.NpcName) MessageBox.nameTagStatic = npcName; else if(dialogSetting[i].nameTagSetup == NameTagSetup.Other) MessageBox.nameTagStatic = dialogSetting[i].otherNameTag; MessageBox.showNameTag = true; }else { MessageBox.showNameTag = false; } if(dialogSetting[i].enableFace) { if(dialogSetting[i].faceSetup == FaceSetup.PlayerFace) MessageBox.faceStatic = GameObject.FindGameObjectWithTag("Player").GetComponent<HeroController>().heroImage; else if(dialogSetting[i].faceSetup == FaceSetup.NpcFace) MessageBox.faceStatic = npcFace; else if(dialogSetting[i].faceSetup == FaceSetup.Other) MessageBox.faceStatic = dialogSetting[i].otherFace; MessageBox.showFace = true; }else { MessageBox.showFace = false; } MessageBox.messageStatic = dialogSetting[i].message; } void SetupDialogBoxQuest(int i,List<MessageBoxSetting> mBoxQuest) { if(mBoxQuest[i].enableNameTag) { if(mBoxQuest[i].nameTagSetup == NameTagSetup.PlayerName) MessageBox.nameTagStatic = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerStatus>().playerName; else if(mBoxQuest[i].nameTagSetup == NameTagSetup.NpcName) MessageBox.nameTagStatic = npcName; else if(mBoxQuest[i].nameTagSetup == NameTagSetup.Other) MessageBox.nameTagStatic = mBoxQuest[i].otherNameTag; MessageBox.showNameTag = true; }else { MessageBox.showNameTag = false; } if(mBoxQuest[i].enableFace) { if(mBoxQuest[i].faceSetup == FaceSetup.PlayerFace) MessageBox.faceStatic = GameObject.FindGameObjectWithTag("Player").GetComponent<HeroController>().heroImage; else if(mBoxQuest[i].faceSetup == FaceSetup.NpcFace) MessageBox.faceStatic = npcFace; else if(mBoxQuest[i].faceSetup == FaceSetup.Other) MessageBox.faceStatic = mBoxQuest[i].otherFace; MessageBox.showFace = true; }else { MessageBox.showFace = false; } MessageBox.messageStatic = mBoxQuest[i].message; } void CallNextCommand() { if(npcType == NpcType.ShopKeeper) { GUI_Menu.instance.CallShop(this.gameObject); }else if(npcType == NpcType.QuestNpc) { }else if(npcType == NpcType.SaveNpc) { GUI_Menu.instance.CallSaveWindow(this.gameObject); } } public void SetupDialogQuest(int id) { for(int i=0;i<questData.questSetting.Count;i++) { if(questID == questData.questSetting[i].questID) { if(questData.questSetting[i].questState == 1) CheckConditionQuest(id); if(questData.questSetting[i].questState == 0) { questNpcState = QuestNpcState.StartQuest; if(indexDialog == dialogQuest.Count-1) { QuestWindow.enableWindow = true; QuestWindow.enableButtonAccept = true; disableNext = true; questWindow.SetupQuestWindow(questID); } }else if(questData.questSetting[i].questState == 1) { questNpcState = QuestNpcState.InProgress; questWindow.SetupQuestWindow(questID); QuestWindow.enableWindow = true; }else if(questData.questSetting[i].questState == 2) { questNpcState = QuestNpcState.Complete; }else if(questData.questSetting[i].questState == 3) { questNpcState = QuestNpcState.AfterComplete; } indexCurrentQuest = i; break; } } } void CheckConditionQuest(int id) { for(int i=0;i<questData.questSetting.Count;i++) { if(questID == questData.questSetting[i].questID) { if(questData.questSetting[i].questCondition == Quest_Data.QuestCondition.Hunting) { if(questData.questSetting[i].killCount >= (int)questData.questSetting[i].idCondition.y) { questData.questSetting[i].killCount = 0; questData.questSetting[i].questState = 2; } }else { if(CheckConditionItem((int)questData.questSetting[i].idCondition.x,(int)questData.questSetting[i].idCondition.y)) { questData.questSetting[i].killCount = 0; questData.questSetting[i].questState = 2; } } break; } } } bool CheckConditionItem(int id,int amout) { for(int i =0;i<inventory.bag_item.Count;i++) { if(inventory.bag_item[i].item_id == id && inventory.bag_item[i].item_amount >= amout) { inventory.bag_item[i].item_amount -= amout; if(inventory.bag_item[i].item_amount <= 0) { inventory.bag_item[i].item_id = 0; } return true; } } return false; } void GiveReward(int id) { for(int i=0;i<questData.questSetting.Count;i++) { if(questID == questData.questSetting[i].questID) { inventory.GiveItem((int)questData.questSetting[i].itemIDReward.x,(int)questData.questSetting[i].itemIDReward.y); Debug.Log("Give"); break; } } } }可以拿来直接使用,主要代码都是用来控制头像更换和简单的剧情任务对话,
我们可以根据自己游戏的需要自己来修改,如左边,这个本来就不是重点,重点我们看看交易过程是什么样的
/// <summary> /// Npc shop. /// This script use to create a shop to sell item /// </summary> using UnityEngine; using System.Collections; using System.Collections.Generic; public class ShopItemlist : MonoBehaviour { public List<int> itemID = new List<int>(); void Start() { if(this.gameObject.tag == "Untagged") this.gameObject.tag = "Npc_Shop"; } }
shopitemlist脚本我们一看,只有短短的这么几行,那我们的交易是如何实现的呢?
我们看这个shopItemList的引用
在gui_menu.cs中
//Check on NPC Shop if(hit.collider.tag == "Npc_Shop" && !CheckHoverInventory() && !CheckHoverEquipment() && !CheckHoverSkillWindow() && CheckHoverSlotHotkey() == -1 && itemShop[0].openItemShop == false){ OpenItemShopWindow(); itemShop[0].itemID = hit.collider.GetComponent<ShopItemlist>().itemID; }我们看,hit.collider.tag这个我们前面鼠标点选的时候就说明了,这个摄像机发射一条射线,与物体相交的检测,我们利用这个方法还做了‘水果忍者’游戏,其实这一句就是把我们在李铁匠身上定义的物品列表赋值给我们真正的shop代码的itemshop数组,那商店怎么画出来的呢,我们看代码
private void ShowItemShopWindow(){ if(itemShop[0].openItemShop){ if(useStyle){ GUI.SetNextControlName("ItemShopWindow"); itemShop[0].windowItemShopRect = GUI.Window(itemShop[0].windowItemShopID, itemShop[0].windowItemShopRect, FunctionItemShopWindow, itemShop[0].nameItemShopWindow, guiStyleGroup[0].windowItemShopStyle); }else{ GUI.SetNextControlName("ItemShopWindow"); itemShop[0].windowItemShopRect = GUI.Window(itemShop[0].windowItemShopID, itemShop[0].windowItemShopRect, FunctionItemShopWindow, itemShop[0].nameItemShopWindow); } if(Input.GetKeyDown(KeyCode.Escape)){ itemShop[0].openItemShop = false; } } }就是这么画出来的,上面就是一个u3d提供的话窗体的方法,我们的商店就是这么画出来的,当然画出来,里面要有卖东西的列表,这个列表在哪呢?看FunctionItemShopWindow方法
[HideInInspector] public Vector2 scrollPositionShop; /** * Shopdraw */ private void FunctionItemShopWindow(int windowID){ GUI.DragWindow(new Rect(0,0,250,60)); itemShop[0].scrollViewRect.height = (((itemShop[0].itemID.Count-1) * itemShop[0].slotItemRect.height) * itemShop[0].space) + itemShop[0].offset.y + (itemShop[0].slotItemRect.height/2 + itemShop[0].offset.y/2); scrollPositionShop = GUI.BeginScrollView(itemShop[0].scrollViewPosition , scrollPositionShop, itemShop[0].scrollViewRect); for(int i = 0; i < itemShop[0].itemID.Count; i++){ if(useStyle){ GUI.Box(new Rect(itemShop[0].slotItemRect.x + itemShop[0].offset.x, itemShop[0].slotItemRect.y + ((i * itemShop[0].slotItemRect.height) * itemShop[0].space) + itemShop[0].offset.y, itemShop[0].slotItemRect.width, itemShop[0].slotItemRect.height), new GUIContent("","itemShopWindow"+(i).ToString()), guiStyleGroup[0].itemShopSlotStyle); GUI.Box(new Rect(itemShop[0].descriptionRect.x + itemShop[0].offset.x, itemShop[0].descriptionRect.y + ((i * itemShop[0].descriptionRect.height) * itemShop[0].space) + itemShop[0].offset.y, itemShop[0].descriptionRect.width, itemShop[0].descriptionRect.height), new GUIContent("","itemShopWindow"+(i).ToString()), guiStyleGroup[0].descriptionItemShopStyle); GUI.Box(new Rect(itemShop[0].itemNameRect.x + itemShop[0].offset.x, itemShop[0].itemNameRect.y + ((i * itemShop[0].itemNameRect.height) * itemShop[0].spaceItemName) + itemShop[0].offset.y, itemShop[0].itemNameRect.width, itemShop[0].itemNameRect.height), new GUIContent(Item_Data.instance.Get_Item(itemShop[0].itemID[i]).item_Name ,"itemShopWindow"+(i).ToString()), guiStyleGroup[0].itemShopItemNameStyle); GUI.Box(new Rect(itemShop[0].itemTypeRect.x + itemShop[0].offset.x, itemShop[0].itemTypeRect.y + ((i * itemShop[0].itemTypeRect.height) * itemShop[0].spaceItemType) + itemShop[0].offset.y, itemShop[0].itemTypeRect.width, itemShop[0].itemTypeRect.height), new GUIContent(Item_Data.instance.Get_Item(itemShop[0].itemID[i]).item_Type ,"itemShopWindow"+(i).ToString()), guiStyleGroup[0].itemShopItemTypeStyle); GUI.Box(new Rect(itemShop[0].itemDescriptionRect.x + itemShop[0].offset.x, itemShop[0].itemDescriptionRect.y + ((i * itemShop[0].itemDescriptionRect.height) * itemShop[0].spaceItemDescription) + itemShop[0].offset.y, itemShop[0].itemDescriptionRect.width, itemShop[0].itemDescriptionRect.height), new GUIContent(Item_Data.instance.Get_Item(itemShop[0].itemID[i]).description ,"itemShopWindow"+(i).ToString()), guiStyleGroup[0].itemShopDescriptionStyle); GUI.Box(new Rect(itemShop[0].priceRect.x + itemShop[0].offset.x, itemShop[0].priceRect.y + ((i * itemShop[0].priceRect.height) * itemShop[0].spacePrice) + itemShop[0].offset.y, itemShop[0].priceRect.width, itemShop[0].priceRect.height), new GUIContent(Item_Data.instance.Get_Item(itemShop[0].itemID[i]).price.ToString() ,"itemShopWindow"+(i).ToString()), guiStyleGroup[0].itemShopPriceStyle); if(GUI.Button(new Rect(itemShop[0].buttonBuyRect.x + itemShop[0].offset.x, itemShop[0].buttonBuyRect.y + ((i * itemShop[0].buttonBuyRect.height) * itemShop[0].spaceButtonBuy) + itemShop[0].offset.y, itemShop[0].buttonBuyRect.width, itemShop[0].buttonBuyRect.height), new GUIContent("BUY","itemShopWindow"+(i).ToString()), guiStyleGroup[0].itemShopButtonBuyStyle)){ if(itemShop[0].itemID[i] != null && showDropAmount == false){ item_pickup = new Bag(); item_pickup.item_id = itemShop[0].itemID[i]; item_pickup.isItem = true; item_pickup.equipmentType = Item_Data.instance.Get_Item(itemShop[0].itemID[i]).equipment_Type; isBuyItem = true; //amountItemDrop = "1"; showDropAmount = true; } } }else{ GUI.Box(new Rect(itemShop[0].slotItemRect.x + itemShop[0].offset.x, itemShop[0].slotItemRect.y + ((i * itemShop[0].slotItemRect.height) * itemShop[0].space) + itemShop[0].offset.y, itemShop[0].slotItemRect.width, itemShop[0].slotItemRect.height), new GUIContent("","itemShopWindow"+(i).ToString())); GUI.Box(new Rect(itemShop[0].descriptionRect.x + itemShop[0].offset.x, itemShop[0].descriptionRect.y + ((i * itemShop[0].descriptionRect.height) * itemShop[0].space) + itemShop[0].offset.y, itemShop[0].descriptionRect.width, itemShop[0].descriptionRect.height), new GUIContent("" ,"itemShopWindow"+(i).ToString())); GUI.Box(new Rect(itemShop[0].itemNameRect.x + itemShop[0].offset.x, itemShop[0].itemNameRect.y + ((i * itemShop[0].itemNameRect.height) * itemShop[0].spaceItemName) + itemShop[0].offset.y, itemShop[0].itemNameRect.width, itemShop[0].itemNameRect.height), new GUIContent(Item_Data.instance.Get_Item(itemShop[0].itemID[i]).item_Name ,"itemShopWindow"+(i).ToString())); GUI.Box(new Rect(itemShop[0].itemTypeRect.x + itemShop[0].offset.x, itemShop[0].itemTypeRect.y + ((i * itemShop[0].itemTypeRect.height) * itemShop[0].spaceItemType) + itemShop[0].offset.y, itemShop[0].itemTypeRect.width, itemShop[0].itemTypeRect.height), new GUIContent(Item_Data.instance.Get_Item(itemShop[0].itemID[i]).item_Type ,"itemShopWindow"+(i).ToString())); GUI.Box(new Rect(itemShop[0].itemDescriptionRect.x + itemShop[0].offset.x, itemShop[0].itemDescriptionRect.y + ((i * itemShop[0].itemDescriptionRect.height) * itemShop[0].spaceItemDescription) + itemShop[0].offset.y, itemShop[0].itemDescriptionRect.width, itemShop[0].itemDescriptionRect.height), new GUIContent(Item_Data.instance.Get_Item(itemShop[0].itemID[i]).description ,"itemShopWindow"+(i).ToString())); GUI.Box(new Rect(itemShop[0].priceRect.x + itemShop[0].offset.x, itemShop[0].priceRect.y + ((i * itemShop[0].priceRect.height) * itemShop[0].spacePrice) + itemShop[0].offset.y, itemShop[0].priceRect.width, itemShop[0].priceRect.height), new GUIContent(Item_Data.instance.Get_Item(itemShop[0].itemID[i]).price.ToString() ,"itemShopWindow"+(i).ToString())); if(GUI.Button(new Rect(itemShop[0].buttonBuyRect.x + itemShop[0].offset.x, itemShop[0].buttonBuyRect.y + ((i * itemShop[0].buttonBuyRect.height) * itemShop[0].spaceButtonBuy) + itemShop[0].offset.y, itemShop[0].buttonBuyRect.width, itemShop[0].buttonBuyRect.height), new GUIContent("BUY","itemShopWindow"+(i).ToString()))){ if(itemShop[0].itemID[i] != null && showDropAmount == false){ item_pickup = new Bag(); item_pickup.item_id = itemShop[0].itemID[i]; item_pickup.isItem = true; item_pickup.equipmentType = Item_Data.instance.Get_Item(itemShop[0].itemID[i]).equipment_Type; isBuyItem = true; //amountItemDrop = "1"; showDropAmount = true; } } } if(Item_Data.instance.Get_Item(itemShop[0].itemID[i]) != null){ GUI.DrawTexture(new Rect(itemShop[0].slotItemRect.x + itemShop[0].offset.x, itemShop[0].slotItemRect.y + ((i * itemShop[0].slotItemRect.height) * itemShop[0].space) + itemShop[0].offset.y, itemShop[0].slotItemRect.width, itemShop[0].slotItemRect.height), Item_Data.instance.Get_Item(itemShop[0].itemID[i]).item_Img); } } if(pickupStay){ float maxSpacePos = (itemShop[0].scrollViewRect.height - scrollPositionShop.y) / (itemShop[0].slotItemRect.height * itemShop[0].space); Vector3 mousePos = Input.mousePosition; if(itemImg_Pickup != null){ GUI.DrawTexture(new Rect((mousePos.x - itemShop[0].scrollViewPosition.x)-20-itemShop[0].windowItemShopRect.x, (Screen.height - (mousePos.y + itemShop[0].scrollViewPosition.y - itemShop[0].valueTuningIconFollowMouse))-20-itemShop[0].windowItemShopRect.y + (scrollPositionShop.y - maxSpacePos* (-1*(itemShop[0].slotItemRect.height * itemShop[0].space/100))), 40,40),itemImg_Pickup); } } GUI.EndScrollView(); ShowDescriptionBag(itemShop[0].windowItemShopRect , id_Hover); ShowDescriptionBag(itemShop[0].windowItemShopRect , id_Hover); if(useStyle){ GUI.Box(itemShop[0].moneyRect,money.ToString(),guiStyleGroup[0].goldStyle); if(GUI.Button(itemShop[0].buttonCancelRect,"",guiStyleGroup[0].itemShopCancel)){ itemShop[0].openItemShop = false; } }else{ GUI.Box(itemShop[0].moneyRect,money.ToString()); if(GUI.Button(itemShop[0].buttonCancelRect,"X")){ itemShop[0].openItemShop = false; } } GUI.DrawTexture(itemShop[0].coinIconRect, coinIcon); }
哇,好多,代码虽然多,其实不难理解,用u3d自带api也好,用ngui编辑界面再画也罢,实现效果其实都差不多, itemShop这个是我们在李铁匠身上设定的shop列表,根据这个列表,我们用for循环画出卖的所有item,当买这个button确定之后,方法中触发这样一个方法
if(itemShop[0].itemID[i] != null && showDropAmount == false){ item_pickup = new Bag(); item_pickup.item_id = itemShop[0].itemID[i]; item_pickup.isItem = true; item_pickup.equipmentType = Item_Data.instance.Get_Item(itemShop[0].itemID[i]).equipment_Type; isBuyItem = true; //amountItemDrop = "1"; showDropAmount = true; }
就是我们的拾取物品代码,我们可以直接以上面这几行为例,绑在一个物品上,做场景中的矿石或草药(我们在demo已经加了这方面野外物品拾取,不过做的方式类似于宝箱)获取。就这样,我们的shop就画出来了。
相关文章推荐
- (转载)个人笔记之-----构造函数
- 垂死或涅槃重生 -- Delphi XE5 我们将宣布感情的回归
- Xcode 升级后,常常遇到的遇到的警告、错误,解决方法
- ASP.NET API盘点
- uva 11992 为矩阵更新查询段树
- Encode_2
- xcode5下一个ffmpeg静态库配置
- 为什么使用快排?
- wget下载整个网站
- 与满二叉树完全二叉树
- ubuntu 下安装nginx
- Structure from Motion Using OpenCV
- 《大话设计模式》--分公司=一部门--组合模式<Composite>(19)
- jsp 使内容变成灰色 不可编辑
- 关于JAVA中事件分发和监听机制实现的代码实例-绝对原创实用
- Dynamics AX 2012 R3 Demo 安装与配置 - 导入测试数据 (Step 4)
- CDH报错:Traceback (most recent call last): File "<string>", line 1, in <module> File "<string>"
- 【BZOJ3270】博物馆 概率DP 高斯消元
- 关于C(m,n)%p的故事
- java string is immutable