Human interactor inside hall
This commit is contained in:
@@ -6,6 +6,8 @@ public class Building : MonoBehaviour
|
||||
public BuildingData buildingData;
|
||||
public int curLevel;
|
||||
public Outline[] outlines;
|
||||
public bool autoGetOutlines = true;
|
||||
|
||||
public DateTime lastCollected;
|
||||
|
||||
void OnDrawGizmos() {
|
||||
@@ -17,7 +19,7 @@ public class Building : MonoBehaviour
|
||||
|
||||
void Awake(){
|
||||
//if(outline == null){outline = GetComponent<Outline>();}
|
||||
outlines = GetComponentsInChildren<Outline>();
|
||||
if(autoGetOutlines){ outlines = GetComponentsInChildren<Outline>(); }
|
||||
ToggleOutlines(false);
|
||||
Selector.OnSelectedChanged.AddListener(OnSelectedChanged);
|
||||
transform.tag = "Building";
|
||||
|
||||
@@ -10,6 +10,7 @@ public class BuildingData : ScriptableObject
|
||||
new BuildingLevel(1,new List<BuildingStat>(), 1000)
|
||||
};
|
||||
|
||||
|
||||
public string description;
|
||||
public bool collectable;
|
||||
public CollectablesData.ResourceType resourceType;
|
||||
|
||||
@@ -49,7 +49,7 @@ public class CameraManager : MonoBehaviour
|
||||
|
||||
|
||||
public void JoinMainHall(){
|
||||
Selector.enabled=false;
|
||||
Selector.insideHall=true;
|
||||
Selector.selectBuilding(null);
|
||||
leaveHallBtn.SetActive(true);
|
||||
defaultPos = cam.position;
|
||||
@@ -58,7 +58,7 @@ public class CameraManager : MonoBehaviour
|
||||
}
|
||||
|
||||
public void LeaveMainHall(){
|
||||
Selector.enabled=true;
|
||||
Selector.insideHall=false;
|
||||
leaveHallBtn.SetActive(false);
|
||||
StartCoroutine(ToggleMainHallCamera(false));
|
||||
}
|
||||
|
||||
45
Assets/Game/Scripts/HumanInteractor.cs
Normal file
45
Assets/Game/Scripts/HumanInteractor.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class HumanInteractor : MonoBehaviour
|
||||
{
|
||||
public GameObject[] showingObjects;
|
||||
public UnityEvent OnInteraction;
|
||||
public UnityEvent OnClose;
|
||||
private bool showing;
|
||||
[SerializeField]
|
||||
public bool Showing => showing;
|
||||
void Start()
|
||||
{
|
||||
Selector.OnSelectedChanged.AddListener(OnSelectionChanged);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void OnSelectionChanged(){
|
||||
Toggle(Selector.selectedHuman==this);
|
||||
}
|
||||
|
||||
public void Toggle(){
|
||||
showing = !showing;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public void Toggle(bool value){
|
||||
showing = value;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
|
||||
public void Refresh(){
|
||||
foreach(GameObject go in showingObjects){
|
||||
go.SetActive(showing);
|
||||
}
|
||||
if(!showing){
|
||||
OnClose.Invoke();
|
||||
}else{
|
||||
OnInteraction.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/HumanInteractor.cs.meta
Normal file
11
Assets/Game/Scripts/HumanInteractor.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6b405ebb2bab8172fa7c1cca9a228d73
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -24,9 +24,16 @@ public class WorldItemSelector : MonoBehaviour
|
||||
// //Selector.selectBuilding(null);
|
||||
// }
|
||||
Selector.selectBuilding(selectedB);
|
||||
|
||||
if(Selector.insideHall){
|
||||
HumanInteractor interactor = hit.collider.GetComponent<HumanInteractor>();
|
||||
Selector.selectHuman(interactor);
|
||||
}
|
||||
}else{
|
||||
Selector.selectBuilding(null);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public Vector3? GetTouchingWorldPoint(Vector2 screenPoint){
|
||||
@@ -109,17 +116,26 @@ public class WorldItemSelector : MonoBehaviour
|
||||
}
|
||||
|
||||
public static class Selector{
|
||||
public static bool enabled=true;
|
||||
//public static bool enabled=true;
|
||||
public static bool insideHall = false;
|
||||
public static bool movingPointValid;
|
||||
public static Building movingBuilding;
|
||||
public static bool isMovingBuilding => movingBuilding!=null;
|
||||
public static Building selectedBuilding;
|
||||
public static BuildingData selectedData => selectedBuilding.buildingData;
|
||||
|
||||
public static HumanInteractor selectedHuman;
|
||||
public static UnityEvent OnSelectedChanged = new UnityEvent();
|
||||
|
||||
public static void selectBuilding(Building e){
|
||||
selectedBuilding = e;
|
||||
if(!enabled){selectedBuilding=null;}
|
||||
if(insideHall){selectedBuilding=null;}
|
||||
OnSelectedChanged.Invoke();
|
||||
}
|
||||
|
||||
public static void selectHuman(HumanInteractor e){
|
||||
selectedHuman = e;
|
||||
if(!insideHall){selectedHuman=null;}
|
||||
OnSelectedChanged.Invoke();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user