Building movable, Position save, Overlapse prevention
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
public class Building : MonoBehaviour
|
||||
@@ -9,26 +7,44 @@ public class Building : MonoBehaviour
|
||||
public int curLevel;
|
||||
public Outline[] outlines;
|
||||
|
||||
void OnDrawGizmos() {
|
||||
Gizmos.color = Color.blue;
|
||||
//Gizmos.DrawWireSphere(transform.position + new Vector3(0,spaceRadius,0), spaceRadius);
|
||||
Collider col = GetComponent<Collider>();
|
||||
Gizmos.DrawWireCube(col.bounds.center, col.bounds.size);
|
||||
}
|
||||
|
||||
void Awake(){
|
||||
//if(outline == null){outline = GetComponent<Outline>();}
|
||||
outlines = GetComponentsInChildren<Outline>();
|
||||
ToggleOutlines(false);
|
||||
Selector.OnSelectedChanged.AddListener(OnSelectedChanged);
|
||||
transform.tag = "Building";
|
||||
}
|
||||
|
||||
void OnSelectedChanged(){
|
||||
if(Selector.selectedBuilding == null){ToggleOutlines(false); return;}
|
||||
|
||||
ToggleOutlines(Selector.selectedBuilding == this);
|
||||
ToggleOutlines(Selector.selectedBuilding == this);
|
||||
//GetComponent<Collider>().isTrigger=(Selector.movingBuilding==this);
|
||||
|
||||
}
|
||||
|
||||
void ToggleOutlines(bool value){
|
||||
bool isMoving = Selector.movingBuilding==this;
|
||||
foreach(Outline outline in outlines){
|
||||
outline.enabled = value;
|
||||
outline.OutlineColor = (isMoving) ? Color.green : Color.yellow;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Upgrade(){
|
||||
public void ChangeOutlineColor(Color color){
|
||||
foreach(Outline outline in outlines){
|
||||
outline.OutlineColor = color;
|
||||
}
|
||||
}
|
||||
|
||||
public void Upgrade(){
|
||||
if(curLevel >= buildingData.levels.Count-1){Debug.Log("Already max");return;}
|
||||
int cost = buildingData.levels[curLevel+1].price;
|
||||
// Debug.Log("Upgrading " + buildingData.buildingName + " for " + cost + " coins");
|
||||
@@ -40,11 +56,41 @@ public class Building : MonoBehaviour
|
||||
}
|
||||
|
||||
|
||||
await (DBmanager.SetCoins(DBmanager.Coins-cost));
|
||||
DBmanager.SetCoins(DBmanager.Coins-cost);
|
||||
Mathf.Clamp(curLevel++,0, buildingData.levels.Count-1);
|
||||
|
||||
await DBmanager.UpgradeBuilding(buildingData.buildingName, curLevel);
|
||||
DBmanager.UpgradeBuilding(buildingData.buildingName, curLevel);
|
||||
}
|
||||
//
|
||||
// public List<Collider> buildingsInsideMe = new List<Collider>();
|
||||
// public bool locationInvalid {get{return buildingsInsideMe.Count == 0;}}
|
||||
//
|
||||
// void OnTriggerEnter(Collider other) {
|
||||
// Debug.Log("Trigger enter : " + other.name);
|
||||
// if(other.GetComponent<Collider>().tag == "Building" && other != GetComponent<Collider>()){
|
||||
// if(buildingsInsideMe.Contains(other)){
|
||||
// //Already got him
|
||||
// }else{
|
||||
// buildingsInsideMe.Add(other);ChangeOutlineColor(locationInvalid ? Color.red : Color.green);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
// void OnTriggerExit(Collider other){
|
||||
// Debug.Log("Trigger exit : " + other.name);
|
||||
// if(other.GetComponent<Collider>().tag == "Building" && other != GetComponent<Collider>()){
|
||||
// if(buildingsInsideMe.Contains(other)){
|
||||
// buildingsInsideMe.Remove(other);
|
||||
// ChangeOutlineColor(locationInvalid ? Color.green : Color.red);
|
||||
// }else{
|
||||
// //Nothing to remove
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
/* */
|
||||
}
|
||||
@@ -54,9 +100,11 @@ public class Building : MonoBehaviour
|
||||
public class BuildingState{
|
||||
public string id;
|
||||
public int level;
|
||||
public Vector3 position;
|
||||
|
||||
public BuildingState(string m_id, int m_level){
|
||||
public BuildingState(string m_id, int m_level, Vector3 m_position){
|
||||
id = m_id;
|
||||
level = m_level;
|
||||
position = m_position;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user