Scriptable Objects + Upgrade Menu
This commit is contained in:
@@ -4,7 +4,7 @@ using UnityEngine;
|
||||
|
||||
public class Building : MonoBehaviour
|
||||
{
|
||||
public string buildingName;
|
||||
public BuildingData buildingData;
|
||||
public Outline outline;
|
||||
|
||||
void Awake(){
|
||||
@@ -17,21 +17,8 @@ public class Building : MonoBehaviour
|
||||
if(Selector.selectedBuilding == null){outline.enabled=false; return;}
|
||||
|
||||
outline.enabled = Selector.selectedBuilding == this;
|
||||
Debug.Log(buildingName); // this function debugs 4 names and not always the one u clicked.
|
||||
// SetRightUpgradeButton(); // function to let the button know what menu to open, also runs 4+ times.
|
||||
// Debug.Log(buildingName);
|
||||
}
|
||||
|
||||
/* void SetRightUpgradeButton(){
|
||||
|
||||
switch (buildingName)
|
||||
{
|
||||
case "Research Facility":
|
||||
Debug.Log("research facility menu");
|
||||
break;
|
||||
|
||||
case "Green House":
|
||||
Debug.Log("green house menu");
|
||||
break;
|
||||
}
|
||||
} */
|
||||
/* */
|
||||
}
|
||||
|
||||
7
Assets/Game/Scripts/BuildingData.cs
Normal file
7
Assets/Game/Scripts/BuildingData.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(fileName = "Building01", menuName = "GameData/BuildingData", order = 1)]
|
||||
public class BuildingData : ScriptableObject
|
||||
{
|
||||
public string buildingName;
|
||||
}
|
||||
11
Assets/Game/Scripts/BuildingData.cs.meta
Normal file
11
Assets/Game/Scripts/BuildingData.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f0adcd9d9fe1cd78b1cc91fd454aa46
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
31
Assets/Game/Scripts/SelectedItemMenu.cs
Normal file
31
Assets/Game/Scripts/SelectedItemMenu.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using UnityEngine.UI;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SelectedItemMenu : MonoBehaviour
|
||||
{
|
||||
public Text nameTxt;
|
||||
public Button upgradeBtn;
|
||||
|
||||
public UpgradeMenuItem[] menus;
|
||||
void Start()
|
||||
{
|
||||
upgradeBtn.onClick.AddListener(OnUpgradeClicked);
|
||||
}
|
||||
|
||||
void OnUpgradeClicked(){
|
||||
//int relatedMenuIndex = -1;
|
||||
for(int i = 0; i < menus.Length; i++){
|
||||
menus[i].menuObject.SetActive(menus[i].relatedBuildings.Contains(Selector.selectedBuilding.buildingData));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[System.Serializable]
|
||||
public class UpgradeMenuItem{
|
||||
public GameObject menuObject;
|
||||
public List<BuildingData> relatedBuildings;
|
||||
}
|
||||
11
Assets/Game/Scripts/SelectedItemMenu.cs.meta
Normal file
11
Assets/Game/Scripts/SelectedItemMenu.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6abc3c74e694775039c22bf2106e989e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -18,7 +18,7 @@ public class WorldItemSelector : MonoBehaviour
|
||||
if(Physics.Raycast(ray,out hit, Mathf.Infinity, layerMask)){
|
||||
Building selectedB = hit.collider.GetComponent<Building>();
|
||||
if(selectedB!=null){
|
||||
Debug.Log("Selected building : " + selectedB.buildingName);
|
||||
Debug.Log("Selected building : " + selectedB.buildingData.buildingName);
|
||||
Selector.selectBuilding(selectedB);
|
||||
}else{
|
||||
Debug.Log("No target here, Unselecting");
|
||||
@@ -32,8 +32,20 @@ public class WorldItemSelector : MonoBehaviour
|
||||
public void RefreshUI(){
|
||||
selectedItemUI.gameObject.SetActive(Selector.selectedBuilding !=null);
|
||||
if(Selector.selectedBuilding!=null){
|
||||
selectedItemUI.GetChild(0).GetComponent<Text>().text = Selector.selectedBuilding.buildingName;
|
||||
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;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user