Buildings added, Info and Upgrade Menus Display data, Scriptable Object improved
This commit is contained in:
@@ -5,20 +5,28 @@ using UnityEngine;
|
||||
public class Building : MonoBehaviour
|
||||
{
|
||||
public BuildingData buildingData;
|
||||
public Outline outline;
|
||||
public int curLevel;
|
||||
public Outline[] outlines;
|
||||
|
||||
void Awake(){
|
||||
if(outline == null){outline = GetComponent<Outline>();}
|
||||
outline.enabled=false;
|
||||
//if(outline == null){outline = GetComponent<Outline>();}
|
||||
outlines = GetComponentsInChildren<Outline>();
|
||||
ToggleOutlines(false);
|
||||
Selector.OnSelectedChanged.AddListener(OnSelectedChanged);
|
||||
}
|
||||
|
||||
void OnSelectedChanged(){
|
||||
if(Selector.selectedBuilding == null){outline.enabled=false; return;}
|
||||
if(Selector.selectedBuilding == null){ToggleOutlines(false); return;}
|
||||
|
||||
outline.enabled = Selector.selectedBuilding == this;
|
||||
ToggleOutlines(Selector.selectedBuilding == this);
|
||||
// Debug.Log(buildingName);
|
||||
}
|
||||
|
||||
void ToggleOutlines(bool value){
|
||||
foreach(Outline outline in outlines){
|
||||
outline.enabled = value;
|
||||
}
|
||||
}
|
||||
|
||||
/* */
|
||||
}
|
||||
|
||||
@@ -1,7 +1,36 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
[CreateAssetMenu(fileName = "Building01", menuName = "GameData/BuildingData", order = 1)]
|
||||
public class BuildingData : ScriptableObject
|
||||
{
|
||||
public string buildingName;
|
||||
|
||||
public List<BuildingLevel> levels = new List<BuildingLevel>{
|
||||
new BuildingLevel(1,new List<BuildingStat>())
|
||||
};
|
||||
|
||||
public string description;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class BuildingStat{
|
||||
public string name;
|
||||
public string value;
|
||||
|
||||
public BuildingStat(string _name, string _value){
|
||||
name= _name;
|
||||
value = _value;
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class BuildingLevel{
|
||||
public int level = 0;
|
||||
public List<BuildingStat> stats;
|
||||
|
||||
public BuildingLevel(int _level, List<BuildingStat> _stats){
|
||||
level = _level;
|
||||
stats = _stats;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,41 +2,76 @@ using UnityEngine.UI;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
using TMPro;
|
||||
public class SelectedItemMenu : MonoBehaviour
|
||||
{
|
||||
public Text nameTxt;
|
||||
public Button upgradeBtn;
|
||||
public Button infoBtn;
|
||||
|
||||
public UpgradeMenuItem[] menus;
|
||||
|
||||
[Header("info menu")]
|
||||
public GameObject infoMenu;
|
||||
public TMP_Text descriptionTxt;
|
||||
|
||||
[Header("upgrade menu")]
|
||||
public GameObject upgradeMenu;
|
||||
public Transform upgrade_statParent;
|
||||
|
||||
void Start()
|
||||
{
|
||||
Selector.OnSelectedChanged.AddListener(OnSelectionChanged);
|
||||
upgradeBtn.onClick.AddListener(OnUpgradeClicked);
|
||||
infoBtn.onClick.AddListener(OnInfoClicked);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
void OnUpgradeClicked(){
|
||||
// Debug.Log("Opening Upgrade Menu for : " + Selector.selectedBuilding.buildingData.name);
|
||||
for(int i = 0; i < menus.Length; i++){
|
||||
menus[i].upgradeMenu.SetActive(menus[i].relatedBuildings.Contains(Selector.selectedBuilding.buildingData));
|
||||
void OnSelectionChanged()
|
||||
{
|
||||
if (Selector.selectedBuilding != null)
|
||||
{
|
||||
infoBtn.gameObject.SetActive(true);
|
||||
if (Selector.selectedBuilding.buildingData.levels.Count <= 1)
|
||||
{
|
||||
upgradeBtn.gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
upgradeBtn.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
upgradeBtn.gameObject.SetActive(false);
|
||||
infoBtn.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
void OnInfoClicked(){
|
||||
// Debug.Log("Opening Info Menu for : " + Selector.selectedBuilding.buildingData.name);
|
||||
for(int i = 0; i < menus.Length; i++){
|
||||
menus[i].infoMenu.SetActive(menus[i].relatedBuildings.Contains(Selector.selectedBuilding.buildingData));
|
||||
void OnUpgradeClicked()
|
||||
{
|
||||
Debug.Log("Opening Upgrade Menu for : " + Selector.selectedBuilding.buildingData.name);
|
||||
|
||||
upgradeMenu.SetActive(true);
|
||||
List<BuildingStat> stats = Selector.selectedBuilding.buildingData.levels[Selector.selectedBuilding.curLevel].stats;
|
||||
for (int i = 0; i < upgrade_statParent.childCount; i++)
|
||||
{
|
||||
bool hasDataForThis = i < stats.Count;
|
||||
upgrade_statParent.GetChild(i).gameObject.SetActive(hasDataForThis);
|
||||
if (hasDataForThis)
|
||||
{
|
||||
upgrade_statParent.GetChild(i).GetChild(0).GetComponent<TMP_Text>().text = stats[i].name;
|
||||
upgrade_statParent.GetChild(i).GetChild(1).GetComponent<TMP_Text>().text = stats[i].value;
|
||||
}
|
||||
}
|
||||
if (upgrade_statParent.childCount > stats.Count)
|
||||
{
|
||||
Debug.LogError("Please add another slot for stats in upgrade menu.\nSlots not enough for " + Selector.selectedBuilding.buildingData.name + " , " + upgrade_statParent.childCount + " slots for " + stats.Count + " stats");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnInfoClicked()
|
||||
{
|
||||
Debug.Log("Opening Info Menu for : " + Selector.selectedBuilding.buildingData.name);
|
||||
|
||||
|
||||
[System.Serializable]
|
||||
public class UpgradeMenuItem{
|
||||
public GameObject upgradeMenu;
|
||||
public GameObject infoMenu;
|
||||
public List<BuildingData> relatedBuildings;
|
||||
}
|
||||
infoMenu.SetActive(true);
|
||||
descriptionTxt.text = Selector.selectedBuilding.buildingData.description;
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@ public class WorldItemSelector : MonoBehaviour
|
||||
public float moveThreshold = 1;
|
||||
public LayerMask layerMask;
|
||||
|
||||
public Transform selectedItemUI;
|
||||
public void SelectScreenPoint(Vector2 screenPoint){
|
||||
Ray ray = Camera.main.ScreenPointToRay(screenPoint);
|
||||
RaycastHit hit = new RaycastHit();
|
||||
@@ -24,30 +23,12 @@ public class WorldItemSelector : MonoBehaviour
|
||||
Debug.Log("No target here, Unselecting");
|
||||
Selector.selectBuilding(null);
|
||||
}
|
||||
RefreshUI();
|
||||
}else{
|
||||
Selector.selectBuilding(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void RefreshUI(){
|
||||
selectedItemUI.gameObject.SetActive(Selector.selectedBuilding !=null);
|
||||
if(Selector.selectedBuilding!=null){
|
||||
selectedItemUI.GetChild(0).GetComponent<Text>().text = Selector.selectedBuilding.buildingData.buildingName;
|
||||
}
|
||||
|
||||
// switch (Selector.selectedBuilding.buildingData.buildingName)
|
||||
// {
|
||||
// case "Research Facility":
|
||||
// Debug.Log("research facility menu");
|
||||
// break;
|
||||
|
||||
// case "Green House":
|
||||
// Debug.Log("green house menu");
|
||||
// break;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
private Vector2 startedPos= Vector2.zero;
|
||||
public void OnPointerDown(BaseEventData e){
|
||||
|
||||
Reference in New Issue
Block a user