Implement InteractionTypes
This commit is contained in:
parent
542a8cc360
commit
a021e621b9
@ -1713,7 +1713,7 @@ Prefab:
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4689370038551000, guid: 3da42b42c71f841c2a977cfb5255b00f, type: 2}
|
||||
propertyPath: m_LocalRotation.y
|
||||
value: 0
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4689370038551000, guid: 3da42b42c71f841c2a977cfb5255b00f, type: 2}
|
||||
propertyPath: m_LocalRotation.z
|
||||
@ -1721,7 +1721,7 @@ Prefab:
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4689370038551000, guid: 3da42b42c71f841c2a977cfb5255b00f, type: 2}
|
||||
propertyPath: m_LocalRotation.w
|
||||
value: 1
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4689370038551000, guid: 3da42b42c71f841c2a977cfb5255b00f, type: 2}
|
||||
propertyPath: m_RootOrder
|
||||
@ -1744,6 +1744,20 @@ Prefab:
|
||||
propertyPath: m_LocalScale.z
|
||||
value: 0.75
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 114171175549544602, guid: 3da42b42c71f841c2a977cfb5255b00f,
|
||||
type: 2}
|
||||
propertyPath: TextProperties.Text
|
||||
value: \n\n Toggle Door
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4689370038551000, guid: 3da42b42c71f841c2a977cfb5255b00f, type: 2}
|
||||
propertyPath: m_LocalEulerAnglesHint.y
|
||||
value: 180
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 114171175549544602, guid: 3da42b42c71f841c2a977cfb5255b00f,
|
||||
type: 2}
|
||||
propertyPath: TextProperties.FontSize
|
||||
value: 36
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_ParentPrefab: {fileID: 100100000, guid: 3da42b42c71f841c2a977cfb5255b00f, type: 2}
|
||||
m_IsPrefabParent: 0
|
||||
@ -2005,7 +2019,7 @@ Prefab:
|
||||
- target: {fileID: 114327153796435004, guid: 660bef6a67fed4941b963e96ff20a5e0,
|
||||
type: 2}
|
||||
propertyPath: WillTrigger.Array.size
|
||||
value: 2
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4974430339442808, guid: 660bef6a67fed4941b963e96ff20a5e0, type: 2}
|
||||
propertyPath: m_LocalPosition.x
|
||||
@ -2069,12 +2083,17 @@ Prefab:
|
||||
type: 2}
|
||||
propertyPath: WillTrigger.Array.data[0]
|
||||
value:
|
||||
objectReference: {fileID: 865482261}
|
||||
objectReference: {fileID: 310461193}
|
||||
- target: {fileID: 114327153796435004, guid: 660bef6a67fed4941b963e96ff20a5e0,
|
||||
type: 2}
|
||||
propertyPath: WillTrigger.Array.data[1]
|
||||
value:
|
||||
objectReference: {fileID: 310461193}
|
||||
- target: {fileID: 114327153796435004, guid: 660bef6a67fed4941b963e96ff20a5e0,
|
||||
type: 2}
|
||||
propertyPath: Hologram
|
||||
value:
|
||||
objectReference: {fileID: 865482261}
|
||||
m_RemovedComponents: []
|
||||
m_ParentPrefab: {fileID: 100100000, guid: 660bef6a67fed4941b963e96ff20a5e0, type: 2}
|
||||
m_IsPrefabParent: 0
|
||||
@ -2576,6 +2595,11 @@ Prefab:
|
||||
propertyPath: m_RootOrder
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 114171175549544602, guid: 3da42b42c71f841c2a977cfb5255b00f,
|
||||
type: 2}
|
||||
propertyPath: TextProperties.Text
|
||||
value:
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_ParentPrefab: {fileID: 100100000, guid: 3da42b42c71f841c2a977cfb5255b00f, type: 2}
|
||||
m_IsPrefabParent: 0
|
||||
|
@ -26,6 +26,7 @@ namespace Cyber.Controls {
|
||||
|
||||
private CursorHandler CursorHandler;
|
||||
private Vector3 Rotation;
|
||||
private GameObject LastLookedAt;
|
||||
|
||||
private void Start() {
|
||||
CursorHandler = GameObject.Find("/Systems/CursorHandler").GetComponent<CursorHandler>();
|
||||
@ -50,17 +51,27 @@ namespace Cyber.Controls {
|
||||
Character.SetRotation(Rotation);
|
||||
|
||||
// Interactions
|
||||
if (Input.GetButtonDown("Activate")) {
|
||||
GameObject LookedAtObject = GetLookedAtGameObject();
|
||||
if (LookedAtObject != null) {
|
||||
Interactable LookingAt = LookedAtObject.GetComponent<Interactable>();
|
||||
if (LookingAt != null && (LookingAt.transform.position - Character.GetPosition()).magnitude < Character.InteractionDistance) {
|
||||
LookingAt.Interact(Character);
|
||||
if (LookingAt.GetInteractableSyncdata().PublicInteractions) {
|
||||
Client.Send(PktType.Interact, new InteractionPkt(LookingAt.ID, InteractionType.Press));
|
||||
GameObject LookedAtObject = GetLookedAtGameObject();
|
||||
if (LookedAtObject != null) {
|
||||
Interactable LookingAt = LookedAtObject.GetComponent<Interactable>();
|
||||
if (LookingAt != null && (LookingAt.transform.position - Character.GetPosition()).magnitude < Character.InteractionDistance) {
|
||||
if (Input.GetButtonDown("Activate")) {
|
||||
InteractWith(LookingAt, InteractionType.Activate);
|
||||
}
|
||||
if (Input.GetButtonUp("Activate")) {
|
||||
InteractWith(LookingAt, InteractionType.Deactivate);
|
||||
}
|
||||
if (LookedAtObject != LastLookedAt) {
|
||||
InteractWith(LookingAt, InteractionType.Enter);
|
||||
if (LastLookedAt != null) {
|
||||
InteractWith(LastLookedAt.GetComponent<Interactable>(), InteractionType.Exit);
|
||||
}
|
||||
}
|
||||
LastLookedAt = LookedAtObject;
|
||||
}
|
||||
} else if (LastLookedAt != null) {
|
||||
InteractWith(LastLookedAt.GetComponent<Interactable>(), InteractionType.Exit);
|
||||
LastLookedAt = null;
|
||||
}
|
||||
} else if (Character.Moving()) {
|
||||
// The debug console is open, stop the player.
|
||||
@ -68,6 +79,13 @@ namespace Cyber.Controls {
|
||||
}
|
||||
}
|
||||
|
||||
private void InteractWith(Interactable interactable, InteractionType type) {
|
||||
interactable.Interact(Character, type);
|
||||
if (interactable.GetInteractableSyncdata().PublicInteractions) {
|
||||
Client.Send(PktType.Interact, new InteractionPkt(interactable.ID, type));
|
||||
}
|
||||
}
|
||||
|
||||
private GameObject GetLookedAtGameObject() {
|
||||
RaycastHit Hit;
|
||||
Physics.Raycast(Camera.transform.position, Camera.transform.forward, out Hit, Character.InteractionDistance);
|
||||
|
@ -6,7 +6,7 @@ namespace Cyber.Entities {
|
||||
/// </summary>
|
||||
public enum InteractionType : byte {
|
||||
|
||||
Press, Release, Enter, Exit
|
||||
Activate, Deactivate, Enter, Exit
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ using UnityEngine.Networking;
|
||||
using Cyber.Networking;
|
||||
using Cyber.Console;
|
||||
using System;
|
||||
using Cyber.Util;
|
||||
|
||||
namespace Cyber.Entities.SyncBases {
|
||||
|
||||
@ -18,6 +19,12 @@ namespace Cyber.Entities.SyncBases {
|
||||
/// </summary>
|
||||
public Interactable[] WillTrigger;
|
||||
|
||||
/// <summary>
|
||||
/// The informational hologram that will pop up when the player hovers
|
||||
/// over this button.
|
||||
/// </summary>
|
||||
public Hologram Hologram;
|
||||
|
||||
/// <summary>
|
||||
/// The button mesh that will blink.
|
||||
/// </summary>
|
||||
@ -46,14 +53,22 @@ namespace Cyber.Entities.SyncBases {
|
||||
/// for <see cref="BlinkLength"/> seconds, and calls Interact
|
||||
/// on the <see cref="WillTrigger"/>.
|
||||
/// </summary>
|
||||
public override void Interact(SyncBase Trigger) {
|
||||
BlinkTime = Time.time;
|
||||
if (WillTrigger.Length > 0) {
|
||||
foreach (Interactable Triggerable in WillTrigger) {
|
||||
Triggerable.Interact(this);
|
||||
public override void Interact(SyncBase Trigger, InteractionType type) {
|
||||
if (type == InteractionType.Activate) {
|
||||
BlinkTime = Time.time;
|
||||
if (WillTrigger.Length > 0) {
|
||||
foreach (Interactable Triggerable in WillTrigger) {
|
||||
Triggerable.Interact(this, InteractionType.Activate);
|
||||
}
|
||||
} else {
|
||||
Term.Println("FIXME: The button '" + gameObject.name + "' was pressed, but it doesn't have anything to trigger.");
|
||||
}
|
||||
} else if (Hologram != null) {
|
||||
if (type == InteractionType.Enter) {
|
||||
Hologram.Visible = true;
|
||||
} else if (type == InteractionType.Exit) {
|
||||
Hologram.Visible = false;
|
||||
}
|
||||
} else {
|
||||
Term.Println("FIXME: The button '" + gameObject.name + "' was pressed, but it doesn't have anything to trigger.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,15 +56,17 @@ namespace Cyber.Entities.SyncBases {
|
||||
/// </summary>
|
||||
/// <param name="Trigger">Determines the keycode given to the
|
||||
/// <see cref="Program"/>.</param>
|
||||
public override void Interact(SyncBase Trigger) {
|
||||
Hologram.Visible = true;
|
||||
if (Trigger == KeyLeft) {
|
||||
Screen.SetTextProperties(new TextTextureProperties("\n Pressed left!"));
|
||||
} else if (Trigger == KeyRight) {
|
||||
Screen.SetTextProperties(new TextTextureProperties("\n Pressed right!"));
|
||||
} else {
|
||||
Screen.SetTextProperties(new TextTextureProperties(""));
|
||||
Hologram.Visible = false;
|
||||
public override void Interact(SyncBase trigger, InteractionType type) {
|
||||
if (type == InteractionType.Activate) {
|
||||
Hologram.Visible = true;
|
||||
if (trigger == KeyLeft) {
|
||||
Screen.SetTextProperties(new TextTextureProperties("\n Pressed left!"));
|
||||
} else if (trigger == KeyRight) {
|
||||
Screen.SetTextProperties(new TextTextureProperties("\n Pressed right!"));
|
||||
} else {
|
||||
Screen.SetTextProperties(new TextTextureProperties(""));
|
||||
Hologram.Visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,8 +23,10 @@ namespace Cyber.Entities.SyncBases {
|
||||
/// <summary>
|
||||
/// Toggles the openness of the door.
|
||||
/// </summary>
|
||||
public override void Interact(SyncBase Trigger) {
|
||||
IsOpen = !IsOpen;
|
||||
public override void Interact(SyncBase trigger, InteractionType type) {
|
||||
if (type == InteractionType.Activate) {
|
||||
IsOpen = !IsOpen;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -14,7 +14,7 @@ namespace Cyber.Entities.SyncBases {
|
||||
/// <summary>
|
||||
/// All interactables should implement their interactions by overriding this.
|
||||
/// </summary>
|
||||
public abstract void Interact(SyncBase Trigger);
|
||||
public abstract void Interact(SyncBase trigger, InteractionType type);
|
||||
|
||||
/// <summary>
|
||||
/// Get Interaction information about this interactible.
|
||||
|
@ -242,7 +242,9 @@ namespace Cyber.Networking.Clientside {
|
||||
|
||||
SyncBase Target = Spawner.SyncDB.Get(Interaction.InteractSyncBaseID);
|
||||
if (Target != null && Target is Interactable) {
|
||||
((Interactable) Target).Interact(Spawner.SyncDB.Get(Interaction.OwnerSyncBaseID));
|
||||
((Interactable) Target).Interact(
|
||||
Spawner.SyncDB.Get(Interaction.OwnerSyncBaseID),
|
||||
Interaction.InteractionType);
|
||||
} else {
|
||||
Term.Println("Server has sent an erroneus SyncBase ID!");
|
||||
}
|
||||
|
@ -215,7 +215,7 @@ namespace Cyber.Networking.Serverside {
|
||||
Vector3 Delta = Interacted.gameObject.transform.position - Sender.gameObject.transform.position;
|
||||
float ServerInteractionDistance = Sender.InteractionDistance + Sender.MovementSpeed * 0.5f;
|
||||
if (Delta.magnitude <= ServerInteractionDistance) {
|
||||
Interacted.Interact(Sender);
|
||||
Interacted.Interact(Sender, Interaction.InteractionType);
|
||||
NetworkServer.SendToAll(PktType.Interact, Interaction);
|
||||
if (Interacted.GetInteractableSyncdata().RequiresSyncing) {
|
||||
Syncer.DirtSyncBase(Interacted.ID);
|
||||
|
@ -1,12 +1,12 @@
|
||||
using UnityEngine;
|
||||
using Cyber.Util;
|
||||
|
||||
namespace Cyber.Entities.SyncBases {
|
||||
namespace Cyber.Util {
|
||||
|
||||
/// <summary>
|
||||
/// Helper component for hologram meshes.
|
||||
/// </summary>
|
||||
public class Hologram : Interactable {
|
||||
public class Hologram : MonoBehaviour {
|
||||
|
||||
/// <summary>
|
||||
/// Whether the hologram is visible or not.
|
||||
@ -21,38 +21,19 @@ namespace Cyber.Entities.SyncBases {
|
||||
|
||||
private float CurrentScale;
|
||||
|
||||
public override void Interact(SyncBase Trigger) {
|
||||
Visible = !Visible;
|
||||
}
|
||||
|
||||
public override void Deserialize(UnityEngine.Networking.NetworkReader reader) {
|
||||
}
|
||||
|
||||
public override void Serialize(UnityEngine.Networking.NetworkWriter writer) {
|
||||
}
|
||||
|
||||
public override SyncHandletype GetSyncHandletype() {
|
||||
return new SyncHandletype(false, 10);
|
||||
}
|
||||
|
||||
public override InteractableSyncdata GetInteractableSyncdata() {
|
||||
return new InteractableSyncdata(false, false);
|
||||
}
|
||||
|
||||
private void Start() {
|
||||
CurrentScale = Visible ? 1 : 0;
|
||||
CurrentScale = GetTargetScale();
|
||||
UpdateScale();
|
||||
}
|
||||
|
||||
private void Update() {
|
||||
float Scale = Visible ? 1 : 0;
|
||||
if (Scale != CurrentScale) {
|
||||
if (GetTargetScale() != CurrentScale) {
|
||||
UpdateScale();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateScale() {
|
||||
float Scale = Visible ? 1 : 0;
|
||||
float Scale = GetTargetScale();
|
||||
CurrentScale = Mathf.Lerp(CurrentScale, Scale, 8f * Time.deltaTime);
|
||||
if (Mathf.Abs(Scale - CurrentScale) < 0.05) {
|
||||
CurrentScale = Scale;
|
||||
@ -60,5 +41,9 @@ namespace Cyber.Entities.SyncBases {
|
||||
transform.localScale =
|
||||
new Vector3(CurrentScale, CurrentScale, CurrentScale);
|
||||
}
|
||||
|
||||
private float GetTargetScale() {
|
||||
return Visible ? 1 : 0;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user