From 488a1fe4501d4a7bed2cf8280c320d0485bebbda Mon Sep 17 00:00:00 2001 From: SweetMe1ody <770757532@qq.com> Date: Thu, 8 Jul 2021 12:15:38 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BD=E4=B8=80=E8=BF=AA=E5=90=8C=E5=AD=A6?= =?UTF-8?q?=E6=9C=AA=E8=A2=AB=E9=87=87=E7=94=A8=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Script/work_of_byd/DialogSystem.cs | 50 +++++++++ Script/work_of_byd/GoodsDatabase.cs | 50 +++++++++ Script/work_of_byd/GoodsTrdePandle.cs | 128 ++++++++++++++++++++++ Script/work_of_byd/SingleWeapon.cs | 45 ++++++++ Script/work_of_byd/TownInfo.cs | 52 +++++++++ Script/work_of_byd/WeaponUpgradePandle.cs | 98 +++++++++++++++++ 6 files changed, 423 insertions(+) create mode 100644 Script/work_of_byd/DialogSystem.cs create mode 100644 Script/work_of_byd/GoodsDatabase.cs create mode 100644 Script/work_of_byd/GoodsTrdePandle.cs create mode 100644 Script/work_of_byd/SingleWeapon.cs create mode 100644 Script/work_of_byd/TownInfo.cs create mode 100644 Script/work_of_byd/WeaponUpgradePandle.cs diff --git a/Script/work_of_byd/DialogSystem.cs b/Script/work_of_byd/DialogSystem.cs new file mode 100644 index 0000000..f20a80e --- /dev/null +++ b/Script/work_of_byd/DialogSystem.cs @@ -0,0 +1,50 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +public class DialogSystem : MonoBehaviour +{ + [Header("UI组件")] + public Text textLable; + [Header("文本文件")] + public TextAsset textFile; + public int index; + List textList = new List(); + // Start is called before the first frame update + void Awake() + { + GetTextFromFile(textFile); + } + private void OnEnable() + { + textLable.text = textList[index]; + index++; + } + // Update is called once per frame + void Update() + { + if (Input.GetKeyDown(KeyCode.X) && index == textList.Count) + { + gameObject.SetActive(false); + index = 0; + return; + } + if (Input.GetKeyDown(KeyCode.X)) + { + textLable.text = textList[index]; + index++; + } + } + void GetTextFromFile(TextAsset file) + { + textList.Clear(); + index = 0; + var lineDate=file.text.Split('\n'); + foreach (var line in lineDate) + { + textList.Add(line); + } + + } +} diff --git a/Script/work_of_byd/GoodsDatabase.cs b/Script/work_of_byd/GoodsDatabase.cs new file mode 100644 index 0000000..620c137 --- /dev/null +++ b/Script/work_of_byd/GoodsDatabase.cs @@ -0,0 +1,50 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class GoodsDatabase : MonoBehaviour +{ + public static GoodsDatabase instance; + public List goodsInfo = new List(); + + public Dictionary goodsNameLookup; + public Dictionary goodsPriceLookup; + public Dictionary goodsSpriteLookup; + + // Start is called before the first frame update + private void Awake() + { + instance = this; + goodsNameLookup = new Dictionary(); + for(int i = 0; i < goodsInfo.Count; i++) + { + goodsNameLookup.Add(goodsInfo[i].goodsType, goodsInfo[i].goodsName); + } + goodsPriceLookup = new Dictionary(); + for (int i = 0; i < goodsInfo.Count; i++) + { + goodsPriceLookup.Add(goodsInfo[i].goodsType, goodsInfo[i].basePrice); + } + goodsSpriteLookup = new Dictionary(); + for (int i = 0; i < goodsInfo.Count; i++) + { + goodsSpriteLookup.Add(goodsInfo[i].goodsType, goodsInfo[i].sprite); + } + } +} +[System.Serializable] +public class Goods +{ + public GoodsType goodsType; + public string goodsName; + public int basePrice; + public Sprite sprite; + public bool isProducing; +} + +public enum GoodsType +{ + Redbottle, + Bluebottle, + +} \ No newline at end of file diff --git a/Script/work_of_byd/GoodsTrdePandle.cs b/Script/work_of_byd/GoodsTrdePandle.cs new file mode 100644 index 0000000..e07d7eb --- /dev/null +++ b/Script/work_of_byd/GoodsTrdePandle.cs @@ -0,0 +1,128 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; +//using DG.Tweening; + +public class GoodsTrdePandle : MonoBehaviour +{ + + public static GoodsTrdePandle instance; + public Image goodsImage; + public Text goodsNameText; + public Text goodsPrinceText; + public Text playerMoneyText; + + public Button sellButton; + public Button buyButton; + + public SingleGoods singleGoods; + public Transform sellsScrollView; + + public Inventory playerInventory; + public Item RedBottle; + public Item BlueBottle; + //调用其他的类 + public Character character; + public TownInfo townInfo; + // Start is called before the first frame update + private void Awake() + { + instance = this; + } + void Start() + { + Debug.Log(townInfo.goodsInTown.Count); + //Debug.Log(townInfo.townGoodsTempTransform.childCount); + OpenTradePanel(); + } + void Update() + { + playerMoneyText.text = character.money + ""; + } + public void OpenTradePanel() + { + //transform.DOScale(1, 0.3f); + for (int i = 0; i < sellsScrollView.childCount; i++) + { + Destroy(sellsScrollView.GetChild(i).gameObject); + } + for (int i = 0; i < townInfo.goodsInTown.Count; i++) + { + GameObject gameObject = Instantiate(townInfo.goodsInTown[i], sellsScrollView, false); + //gameObject.transform.DOScale(1, 0.3f); + //gameObject.transform.rotation = Quaternion.identity; + } + //townNameText.text = townInfo.townName; + //PlayerNameText.text= character.playerName; + playerMoneyText.text = character.money + ""; + + goodsImage.enabled = false; + //goodsNameText.text = ""; + goodsPrinceText.text = ""; + buyButton.interactable = false; + //sellButton.interactable = false; + } + public void CloseTradePanel() + { + if (singleGoods != null) + { + singleGoods.goodsNameText.color = Color.white; + singleGoods = null; + } + goodsImage.enabled = false; + goodsPrinceText.text = ""; + buyButton.interactable = false; + gameObject.SetActive(false); + } + public void UpdateUI() + { + if (singleGoods != null) + { + goodsImage.enabled = true; + goodsImage.sprite = singleGoods.goodsSprite; + goodsPrinceText.text = singleGoods.goodsPrice+""; + buyButton.interactable = true; + playerMoneyText.text = character.money + ""; + } + + + } + public void BuyGoods() + { + if(character.money>= singleGoods.goodsPrice) + { + //Destroy(singleGoods.gameObject); + character.money -= singleGoods.goodsPrice; + if (singleGoods.goodsName == "RedBottle") + { + AddNewGoods(RedBottle); + } + if (singleGoods.goodsName == "BuleBottle") + { + AddNewGoods(BlueBottle); + } + //character. + UpdateUI(); + + } + } + private void AddNewGoods(Item thisItem) + { + if (!playerInventory.itemList.Contains(thisItem)) + { + for (int i = 0; i < playerInventory.itemList.Count; i++) + { + if (playerInventory.itemList[i] == null) + { + playerInventory.itemList[i] = thisItem; + break; + } + } + } + else + { + thisItem.itemHeld += 1; + } + } +} diff --git a/Script/work_of_byd/SingleWeapon.cs b/Script/work_of_byd/SingleWeapon.cs new file mode 100644 index 0000000..f2895ab --- /dev/null +++ b/Script/work_of_byd/SingleWeapon.cs @@ -0,0 +1,45 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.EventSystems; + +public class SingleWeapon : MonoBehaviour +{ + public string WeaponName; + public Sprite weaponSprite; + public int UpgradePrice; + public Weapon weapon; + + public Text WeaponNameText; + //public GoodsDatabase goodsDatabase; + // Start is called before the first frame update + void Start() + { + WeaponNameText.color = Color.white; + WeaponNameText.text = WeaponName + ""; + weaponSprite = weapon.weaponSprite; + UpgradePrice = (weapon.level + 1) * 10; + } + /*public void UpdataInfo() + { + WeaponNameText.text = WeaponName+""; + weapon = transform.Find(WeaponName).GetComponent(); + }*/ + // Update is called once per frame + void Update() + { + UpgradePrice = (weapon.level + 1) * 10; + } + public void IPointerClick() + { + //Debug.Log("Down"); + WeaponNameText.color = Color.green; + if (WeaponUpgradePandle.instance.singleWeapon != null && WeaponUpgradePandle.instance.singleWeapon != this) + { + WeaponUpgradePandle.instance.singleWeapon.WeaponNameText.color = Color.white; + } + WeaponUpgradePandle.instance.singleWeapon = this; + WeaponUpgradePandle.instance.UpdateUI(); + } +} diff --git a/Script/work_of_byd/TownInfo.cs b/Script/work_of_byd/TownInfo.cs new file mode 100644 index 0000000..4285d1a --- /dev/null +++ b/Script/work_of_byd/TownInfo.cs @@ -0,0 +1,52 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TownInfo : MonoBehaviour +{ + public List goodsInTown = new List(); + public Transform townGoodsTempTransform; + public GameObject goodsPrafab; + + public List goodsProduceInfo = new List(); + + public Dictionary townGoodsPrice; + // Start is called before the first frame update + private void Awake() + { + GenerateGoodsInTown(); + } + + public void GenerateGoodsInTown() + { + townGoodsPrice = new Dictionary(); + goodsInTown = new List(); + for (int i = 0; i < goodsProduceInfo.Count; i++) + { + if (goodsProduceInfo[i].isProducing) + { + townGoodsPrice.Add(goodsProduceInfo[i].goodsType, GoodsDatabase.instance.goodsPriceLookup[goodsProduceInfo[i].goodsType]); + + goodsPrafab.GetComponent().goodsType = goodsProduceInfo[i].goodsType; + /*for (int j = 0; j < Random.Range(1,3); j++) + { + GameObject _gameObject = Instantiate(goodsPrafab, townGoodsTempTransform, false); + goodsInTown.Add(_gameObject); + }*/ + GameObject _gameObject = Instantiate(goodsPrafab, townGoodsTempTransform, false); + goodsInTown.Add(_gameObject); + Debug.Log(goodsInTown.Count); + } + else + { + townGoodsPrice.Add(goodsProduceInfo[i].goodsType, GoodsDatabase.instance.goodsPriceLookup[goodsProduceInfo[i].goodsType]); + } + + + } + } + int GetPrice(int _basePrice) + { + return _basePrice; + } +} diff --git a/Script/work_of_byd/WeaponUpgradePandle.cs b/Script/work_of_byd/WeaponUpgradePandle.cs new file mode 100644 index 0000000..47a9e68 --- /dev/null +++ b/Script/work_of_byd/WeaponUpgradePandle.cs @@ -0,0 +1,98 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +public class WeaponUpgradePandle : MonoBehaviour +{ + public static WeaponUpgradePandle instance; + public Image weaponsImage; + public Text weaponNameText; + public Text upgradePrinceText; + public Text playerMoneyText; + public Text nowLevelText; + public Text nextLevelText; + + public Button upgradeButton; + + public SingleWeapon singleWeapon; + public Transform weaponsScrollView; + //调用其他的类 + public Character character; + //public TownInfo townInfo; + // Start is called before the first frame update + private void Awake() + { + instance = this; + } + // Start is called before the first frame update + void Start() + { + OpenWeaponTradePanel(); + } + void Update() + { + playerMoneyText.text = character.money + ""; + } + public void OpenWeaponTradePanel() + { + //transform.DOScale(1, 0.3f); + /*for (int i = 0; i < weaponsScrollView.childCount; i++) + { + Destroy(sellsScrollView.GetChild(i).gameObject); + } + for (int i = 0; i < townInfo.goodsInTown.Count; i++) + { + GameObject gameObject = Instantiate(townInfo.goodsInTown[i], sellsScrollView, false); + //gameObject.transform.DOScale(1, 0.3f); + //gameObject.transform.rotation = Quaternion.identity; + }*/ + Debug.Log("剩余金钱为"+character.money); + playerMoneyText.text = character.money + ""; + weaponsImage.enabled = false; + upgradePrinceText.text = ""; + nowLevelText.text = ""; + nextLevelText.text = ""; + upgradeButton.interactable = false; + //sellButton.interactable = false; + } + public void CloseWeaponTradePanel() + { + if (singleWeapon != null) + { + singleWeapon.WeaponNameText.color = Color.white; + singleWeapon = null; + } + weaponsImage.enabled = false; + upgradePrinceText.text = ""; + nowLevelText.text = ""; + nextLevelText.text = ""; + upgradeButton.interactable = false; + gameObject.SetActive(false); + } + public void UpdateUI() + { + if (singleWeapon != null) + { + nowLevelText.text = singleWeapon.weapon.level+""; + nextLevelText.text = (singleWeapon.weapon.level + 1) + ""; + weaponsImage.enabled = true; + weaponsImage.sprite = singleWeapon.weaponSprite; + upgradePrinceText.text = (singleWeapon.weapon.level+1)*10 + ""; + upgradeButton.interactable = true; + playerMoneyText.text = character.money + ""; + } + + + } + public void UpgradeWeapons() + { + if (character.money >= singleWeapon.UpgradePrice) + { + character.money -= singleWeapon.UpgradePrice; + singleWeapon.weapon.level += 1; + UpdateUI(); + + } + } +}