67 lines
1.8 KiB
C#
67 lines
1.8 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
|
|
public class LockSwitch : Predicate {
|
|
public string keyName = "";
|
|
public string keyClass = "Key";
|
|
public string unlockText = "unlock";
|
|
public PlayerSensor sensor;
|
|
public bool locked = true;
|
|
private GameAction _action;
|
|
private Notification _notify;
|
|
|
|
protected override bool CheckInternal ()
|
|
{
|
|
return !locked;
|
|
}
|
|
protected override bool CheckInternal (object param)
|
|
{
|
|
return Check ();
|
|
}
|
|
|
|
|
|
// Use this for initialization
|
|
void Start () {
|
|
sensor.PlayerEnter += HandlePlayerEnter;
|
|
sensor.PlayerExit += HandlePlayerExit;
|
|
_action = new GameAction(gameObject, "use " + keyName);
|
|
_notify = new Notification(){source = gameObject};
|
|
|
|
_notify.text = NotificationsController.AppendString(_notify.text, "Use ", NotificationElement.Text);
|
|
_notify.text = NotificationsController.AppendString(_notify.text, keyName, NotificationElement.Item);
|
|
_notify.text = NotificationsController.AppendString(_notify.text, " to ", NotificationElement.Text);
|
|
_notify.text = NotificationsController.AppendString(_notify.text, unlockText, NotificationElement.ImportantText);
|
|
}
|
|
|
|
void HandlePlayerEnter (PlayerSensor s, GameObject player)
|
|
{
|
|
if(locked){
|
|
var inventory = player.GetComponent<Inventory>();
|
|
if((inventory != null) && (inventory.QueryItem(keyName, keyClass, null) != null)){
|
|
ActionController.AddAction(_action);
|
|
}else{
|
|
NotificationsController.AddNotification(_notify);
|
|
}
|
|
}
|
|
}
|
|
|
|
void OnAction(ActionArgs a){
|
|
if(locked){
|
|
locked = false;
|
|
ActionController.RemoveAction(_action);
|
|
NotificationsController.RemoveNotification(_notify);
|
|
}
|
|
}
|
|
|
|
void HandlePlayerExit (PlayerSensor s, GameObject player)
|
|
{
|
|
ActionController.RemoveAction(_action);
|
|
NotificationsController.RemoveNotification(_notify);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update () {
|
|
|
|
}
|
|
}
|