白一迪同学未被采用的代码

master
SweetMe1ody 5 years ago
parent 040d273993
commit 488a1fe450

@ -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<string> textList = new List<string>();
// 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);
}
}
}

@ -0,0 +1,50 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GoodsDatabase : MonoBehaviour
{
public static GoodsDatabase instance;
public List<Goods> goodsInfo = new List<Goods>();
public Dictionary<GoodsType, string> goodsNameLookup;
public Dictionary<GoodsType, int> goodsPriceLookup;
public Dictionary<GoodsType, Sprite> goodsSpriteLookup;
// Start is called before the first frame update
private void Awake()
{
instance = this;
goodsNameLookup = new Dictionary<GoodsType, string>();
for(int i = 0; i < goodsInfo.Count; i++)
{
goodsNameLookup.Add(goodsInfo[i].goodsType, goodsInfo[i].goodsName);
}
goodsPriceLookup = new Dictionary<GoodsType, int>();
for (int i = 0; i < goodsInfo.Count; i++)
{
goodsPriceLookup.Add(goodsInfo[i].goodsType, goodsInfo[i].basePrice);
}
goodsSpriteLookup = new Dictionary<GoodsType, Sprite>();
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,
}

@ -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;
}
}
}

@ -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<Weapon>();
}*/
// 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();
}
}

@ -0,0 +1,52 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TownInfo : MonoBehaviour
{
public List<GameObject> goodsInTown = new List<GameObject>();
public Transform townGoodsTempTransform;
public GameObject goodsPrafab;
public List<Goods> goodsProduceInfo = new List<Goods>();
public Dictionary<GoodsType, int> townGoodsPrice;
// Start is called before the first frame update
private void Awake()
{
GenerateGoodsInTown();
}
public void GenerateGoodsInTown()
{
townGoodsPrice = new Dictionary<GoodsType, int>();
goodsInTown = new List<GameObject>();
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<SingleGoods>().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;
}
}

@ -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();
}
}
}
Loading…
Cancel
Save