*
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class DigitalPanelController : Predicate {
|
||||
|
||||
private string _currentDigits = "";
|
||||
public GameObject guiPrototype;
|
||||
private Canvas _guiInstance;
|
||||
public bool locked = true;
|
||||
public string password = "4815";
|
||||
public PlayerSensor sensor;
|
||||
private GameAction _showPadAction;
|
||||
|
||||
public string CurrentDigits {
|
||||
get { return _currentDigits; }
|
||||
set {
|
||||
_currentDigits = value;
|
||||
OnPasswordUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPasswordUpdated() {
|
||||
if (_currentDigits == password) {
|
||||
HideGui();
|
||||
locked = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowGui() {
|
||||
if (_guiInstance == null) {
|
||||
_guiInstance = ((GameObject)Instantiate(guiPrototype)).GetComponent<Canvas>();
|
||||
_guiInstance.GetComponent<DigitalPanelGuiController>().Panel = this;
|
||||
|
||||
var c = FindObjectOfType<GameController>();
|
||||
c.ShowUI(_guiInstance.GetComponent<UiController>());
|
||||
|
||||
Time.timeScale = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void HideGui() {
|
||||
if (_guiInstance != null) {
|
||||
var c = FindObjectOfType<GameController>();
|
||||
c.ShowPreviousUi(true);
|
||||
Destroy(_guiInstance.gameObject);
|
||||
}
|
||||
Time.timeScale = 1;
|
||||
}
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
if (sensor != null) {
|
||||
sensor.PlayerEnter += sensor_PlayerEnter;
|
||||
sensor.PlayerExit += sensor_PlayerExit;
|
||||
}
|
||||
|
||||
_showPadAction = new GameAction(gameObject, "use pad");
|
||||
}
|
||||
|
||||
bool GuiVisible() {
|
||||
return _guiInstance != null;
|
||||
}
|
||||
|
||||
void OnAction(ActionArgs a) {
|
||||
if (!GuiVisible()) {
|
||||
ShowGui();
|
||||
}
|
||||
}
|
||||
|
||||
void sensor_PlayerExit(PlayerSensor senso, GameObject player) {
|
||||
ActionController.RemoveAction(_showPadAction);
|
||||
}
|
||||
|
||||
void sensor_PlayerEnter(PlayerSensor senso, GameObject player) {
|
||||
if (locked) {
|
||||
ActionController.AddAction(_showPadAction);
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
}
|
||||
|
||||
protected override bool CheckInternal() {
|
||||
return locked;
|
||||
}
|
||||
|
||||
protected override bool CheckInternal(object param) {
|
||||
return CheckInternal();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user