Buildings added, Info and Upgrade Menus Display data, Scriptable Object improved
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -10,6 +10,10 @@ MonoBehaviour:
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 0f0adcd9d9fe1cd78b1cc91fd454aa46, type: 3}
|
||||
m_Name: Communication Center
|
||||
m_Name: Generic Building
|
||||
m_EditorClassIdentifier:
|
||||
buildingName: Communication Center
|
||||
buildingName: Generic Building
|
||||
levels:
|
||||
- level: 1
|
||||
stats: []
|
||||
description: This is just a Generic Building
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f14a9fbb66d4461eabb30a42aa5007a
|
||||
guid: 049b5ae28348bbbe9ade489466ecf9a8
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
33
Assets/Game/ScriptableObjects/BuildingData/Hall.asset
Normal file
33
Assets/Game/ScriptableObjects/BuildingData/Hall.asset
Normal file
@@ -0,0 +1,33 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 0f0adcd9d9fe1cd78b1cc91fd454aa46, type: 3}
|
||||
m_Name: Hall
|
||||
m_EditorClassIdentifier:
|
||||
buildingName: Hall
|
||||
levels:
|
||||
- level: 1
|
||||
stats:
|
||||
- name: Stat 1
|
||||
value: 120
|
||||
- name: Power
|
||||
value: 2
|
||||
- name: Energy
|
||||
value: 50
|
||||
- level: 2
|
||||
stats:
|
||||
- name: Stat 1
|
||||
value: 200
|
||||
- name: Power
|
||||
value: 30
|
||||
- name: Energy
|
||||
value: 500
|
||||
description: This is the Hall (Main Hall)
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 877632c6c68b29db29d24a00ca56d609
|
||||
guid: b8064a67361de4c648b86f3642bb0317
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
@@ -10,6 +10,12 @@ MonoBehaviour:
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 0f0adcd9d9fe1cd78b1cc91fd454aa46, type: 3}
|
||||
m_Name: Greenhouse
|
||||
m_Name: Mine
|
||||
m_EditorClassIdentifier:
|
||||
buildingName: Greenhouse
|
||||
buildingName: Mine
|
||||
levels:
|
||||
- level: 1
|
||||
stats:
|
||||
- name: Production rate
|
||||
value: 10%
|
||||
description: This is a mine
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bdcfae8248ea0e27fa898d27a47a42a0
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
23
Assets/Game/ScriptableObjects/BuildingData/MoonMineral.asset
Normal file
23
Assets/Game/ScriptableObjects/BuildingData/MoonMineral.asset
Normal file
@@ -0,0 +1,23 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 0f0adcd9d9fe1cd78b1cc91fd454aa46, type: 3}
|
||||
m_Name: MoonMineral
|
||||
m_EditorClassIdentifier:
|
||||
buildingName: Moon Minerals Mine
|
||||
levels:
|
||||
- level: 1
|
||||
stats:
|
||||
- name: Minerals
|
||||
value: 5
|
||||
- name: Power
|
||||
value: 10
|
||||
description: This is a Moon Minerals Mine
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f0a72c466f9c377ead12bf642749171
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
23
Assets/Game/ScriptableObjects/BuildingData/O2Mine.asset
Normal file
23
Assets/Game/ScriptableObjects/BuildingData/O2Mine.asset
Normal file
@@ -0,0 +1,23 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 0f0adcd9d9fe1cd78b1cc91fd454aa46, type: 3}
|
||||
m_Name: O2Mine
|
||||
m_EditorClassIdentifier:
|
||||
buildingName: Oxygen Mine
|
||||
levels:
|
||||
- level: 1
|
||||
stats:
|
||||
- name: Oxygen
|
||||
value: 10
|
||||
- name: Power
|
||||
value: 2
|
||||
description: This is an Oxygen Mine
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a238dc5ab1ae2deaaaaf77548375bd68
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -12,4 +12,22 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 0f0adcd9d9fe1cd78b1cc91fd454aa46, type: 3}
|
||||
m_Name: Research Facility
|
||||
m_EditorClassIdentifier:
|
||||
buildingName: Research Facility
|
||||
buildingName: Research Lab
|
||||
levels:
|
||||
- level: 1
|
||||
stats:
|
||||
- name: Power
|
||||
value: 250
|
||||
- name: Speed
|
||||
value: 50
|
||||
- name: Something else
|
||||
value: 40 %
|
||||
- level: 2
|
||||
stats:
|
||||
- name: Power
|
||||
value: 600
|
||||
- name: Speed
|
||||
value: 90
|
||||
- name: Something else
|
||||
value: 80 %
|
||||
description: This is a Research Lab
|
||||
|
||||
@@ -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