Implement InteractionTypes

This commit is contained in:
excitedneon 2017-05-12 02:03:27 +03:00
parent 542a8cc360
commit a021e621b9
11 changed files with 106 additions and 58 deletions

View File

@ -1713,7 +1713,7 @@ Prefab:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4689370038551000, guid: 3da42b42c71f841c2a977cfb5255b00f, type: 2} - target: {fileID: 4689370038551000, guid: 3da42b42c71f841c2a977cfb5255b00f, type: 2}
propertyPath: m_LocalRotation.y propertyPath: m_LocalRotation.y
value: 0 value: 1
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4689370038551000, guid: 3da42b42c71f841c2a977cfb5255b00f, type: 2} - target: {fileID: 4689370038551000, guid: 3da42b42c71f841c2a977cfb5255b00f, type: 2}
propertyPath: m_LocalRotation.z propertyPath: m_LocalRotation.z
@ -1721,7 +1721,7 @@ Prefab:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4689370038551000, guid: 3da42b42c71f841c2a977cfb5255b00f, type: 2} - target: {fileID: 4689370038551000, guid: 3da42b42c71f841c2a977cfb5255b00f, type: 2}
propertyPath: m_LocalRotation.w propertyPath: m_LocalRotation.w
value: 1 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4689370038551000, guid: 3da42b42c71f841c2a977cfb5255b00f, type: 2} - target: {fileID: 4689370038551000, guid: 3da42b42c71f841c2a977cfb5255b00f, type: 2}
propertyPath: m_RootOrder propertyPath: m_RootOrder
@ -1744,6 +1744,20 @@ Prefab:
propertyPath: m_LocalScale.z propertyPath: m_LocalScale.z
value: 0.75 value: 0.75
objectReference: {fileID: 0} 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_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 3da42b42c71f841c2a977cfb5255b00f, type: 2} m_ParentPrefab: {fileID: 100100000, guid: 3da42b42c71f841c2a977cfb5255b00f, type: 2}
m_IsPrefabParent: 0 m_IsPrefabParent: 0
@ -2005,7 +2019,7 @@ Prefab:
- target: {fileID: 114327153796435004, guid: 660bef6a67fed4941b963e96ff20a5e0, - target: {fileID: 114327153796435004, guid: 660bef6a67fed4941b963e96ff20a5e0,
type: 2} type: 2}
propertyPath: WillTrigger.Array.size propertyPath: WillTrigger.Array.size
value: 2 value: 1
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4974430339442808, guid: 660bef6a67fed4941b963e96ff20a5e0, type: 2} - target: {fileID: 4974430339442808, guid: 660bef6a67fed4941b963e96ff20a5e0, type: 2}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x
@ -2069,12 +2083,17 @@ Prefab:
type: 2} type: 2}
propertyPath: WillTrigger.Array.data[0] propertyPath: WillTrigger.Array.data[0]
value: value:
objectReference: {fileID: 865482261} objectReference: {fileID: 310461193}
- target: {fileID: 114327153796435004, guid: 660bef6a67fed4941b963e96ff20a5e0, - target: {fileID: 114327153796435004, guid: 660bef6a67fed4941b963e96ff20a5e0,
type: 2} type: 2}
propertyPath: WillTrigger.Array.data[1] propertyPath: WillTrigger.Array.data[1]
value: value:
objectReference: {fileID: 310461193} objectReference: {fileID: 310461193}
- target: {fileID: 114327153796435004, guid: 660bef6a67fed4941b963e96ff20a5e0,
type: 2}
propertyPath: Hologram
value:
objectReference: {fileID: 865482261}
m_RemovedComponents: [] m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 660bef6a67fed4941b963e96ff20a5e0, type: 2} m_ParentPrefab: {fileID: 100100000, guid: 660bef6a67fed4941b963e96ff20a5e0, type: 2}
m_IsPrefabParent: 0 m_IsPrefabParent: 0
@ -2576,6 +2595,11 @@ Prefab:
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 114171175549544602, guid: 3da42b42c71f841c2a977cfb5255b00f,
type: 2}
propertyPath: TextProperties.Text
value:
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 3da42b42c71f841c2a977cfb5255b00f, type: 2} m_ParentPrefab: {fileID: 100100000, guid: 3da42b42c71f841c2a977cfb5255b00f, type: 2}
m_IsPrefabParent: 0 m_IsPrefabParent: 0

View File

@ -26,6 +26,7 @@ namespace Cyber.Controls {
private CursorHandler CursorHandler; private CursorHandler CursorHandler;
private Vector3 Rotation; private Vector3 Rotation;
private GameObject LastLookedAt;
private void Start() { private void Start() {
CursorHandler = GameObject.Find("/Systems/CursorHandler").GetComponent<CursorHandler>(); CursorHandler = GameObject.Find("/Systems/CursorHandler").GetComponent<CursorHandler>();
@ -50,17 +51,27 @@ namespace Cyber.Controls {
Character.SetRotation(Rotation); Character.SetRotation(Rotation);
// Interactions // Interactions
if (Input.GetButtonDown("Activate")) { GameObject LookedAtObject = GetLookedAtGameObject();
GameObject LookedAtObject = GetLookedAtGameObject(); if (LookedAtObject != null) {
if (LookedAtObject != null) { Interactable LookingAt = LookedAtObject.GetComponent<Interactable>();
Interactable LookingAt = LookedAtObject.GetComponent<Interactable>(); if (LookingAt != null && (LookingAt.transform.position - Character.GetPosition()).magnitude < Character.InteractionDistance) {
if (LookingAt != null && (LookingAt.transform.position - Character.GetPosition()).magnitude < Character.InteractionDistance) { if (Input.GetButtonDown("Activate")) {
LookingAt.Interact(Character); InteractWith(LookingAt, InteractionType.Activate);
if (LookingAt.GetInteractableSyncdata().PublicInteractions) { }
Client.Send(PktType.Interact, new InteractionPkt(LookingAt.ID, InteractionType.Press)); 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()) { } else if (Character.Moving()) {
// The debug console is open, stop the player. // 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() { private GameObject GetLookedAtGameObject() {
RaycastHit Hit; RaycastHit Hit;
Physics.Raycast(Camera.transform.position, Camera.transform.forward, out Hit, Character.InteractionDistance); Physics.Raycast(Camera.transform.position, Camera.transform.forward, out Hit, Character.InteractionDistance);

View File

@ -6,7 +6,7 @@ namespace Cyber.Entities {
/// </summary> /// </summary>
public enum InteractionType : byte { public enum InteractionType : byte {
Press, Release, Enter, Exit Activate, Deactivate, Enter, Exit
} }
} }

View File

@ -5,6 +5,7 @@ using UnityEngine.Networking;
using Cyber.Networking; using Cyber.Networking;
using Cyber.Console; using Cyber.Console;
using System; using System;
using Cyber.Util;
namespace Cyber.Entities.SyncBases { namespace Cyber.Entities.SyncBases {
@ -18,6 +19,12 @@ namespace Cyber.Entities.SyncBases {
/// </summary> /// </summary>
public Interactable[] WillTrigger; public Interactable[] WillTrigger;
/// <summary>
/// The informational hologram that will pop up when the player hovers
/// over this button.
/// </summary>
public Hologram Hologram;
/// <summary> /// <summary>
/// The button mesh that will blink. /// The button mesh that will blink.
/// </summary> /// </summary>
@ -46,14 +53,22 @@ namespace Cyber.Entities.SyncBases {
/// for <see cref="BlinkLength"/> seconds, and calls Interact /// for <see cref="BlinkLength"/> seconds, and calls Interact
/// on the <see cref="WillTrigger"/>. /// on the <see cref="WillTrigger"/>.
/// </summary> /// </summary>
public override void Interact(SyncBase Trigger) { public override void Interact(SyncBase Trigger, InteractionType type) {
BlinkTime = Time.time; if (type == InteractionType.Activate) {
if (WillTrigger.Length > 0) { BlinkTime = Time.time;
foreach (Interactable Triggerable in WillTrigger) { if (WillTrigger.Length > 0) {
Triggerable.Interact(this); 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.");
} }
} }

View File

@ -56,15 +56,17 @@ namespace Cyber.Entities.SyncBases {
/// </summary> /// </summary>
/// <param name="Trigger">Determines the keycode given to the /// <param name="Trigger">Determines the keycode given to the
/// <see cref="Program"/>.</param> /// <see cref="Program"/>.</param>
public override void Interact(SyncBase Trigger) { public override void Interact(SyncBase trigger, InteractionType type) {
Hologram.Visible = true; if (type == InteractionType.Activate) {
if (Trigger == KeyLeft) { Hologram.Visible = true;
Screen.SetTextProperties(new TextTextureProperties("\n Pressed left!")); if (trigger == KeyLeft) {
} else if (Trigger == KeyRight) { Screen.SetTextProperties(new TextTextureProperties("\n Pressed left!"));
Screen.SetTextProperties(new TextTextureProperties("\n Pressed right!")); } else if (trigger == KeyRight) {
} else { Screen.SetTextProperties(new TextTextureProperties("\n Pressed right!"));
Screen.SetTextProperties(new TextTextureProperties("")); } else {
Hologram.Visible = false; Screen.SetTextProperties(new TextTextureProperties(""));
Hologram.Visible = false;
}
} }
} }

View File

@ -23,8 +23,10 @@ namespace Cyber.Entities.SyncBases {
/// <summary> /// <summary>
/// Toggles the openness of the door. /// Toggles the openness of the door.
/// </summary> /// </summary>
public override void Interact(SyncBase Trigger) { public override void Interact(SyncBase trigger, InteractionType type) {
IsOpen = !IsOpen; if (type == InteractionType.Activate) {
IsOpen = !IsOpen;
}
} }
/// <summary> /// <summary>

View File

@ -14,7 +14,7 @@ namespace Cyber.Entities.SyncBases {
/// <summary> /// <summary>
/// All interactables should implement their interactions by overriding this. /// All interactables should implement their interactions by overriding this.
/// </summary> /// </summary>
public abstract void Interact(SyncBase Trigger); public abstract void Interact(SyncBase trigger, InteractionType type);
/// <summary> /// <summary>
/// Get Interaction information about this interactible. /// Get Interaction information about this interactible.

View File

@ -242,7 +242,9 @@ namespace Cyber.Networking.Clientside {
SyncBase Target = Spawner.SyncDB.Get(Interaction.InteractSyncBaseID); SyncBase Target = Spawner.SyncDB.Get(Interaction.InteractSyncBaseID);
if (Target != null && Target is Interactable) { 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 { } else {
Term.Println("Server has sent an erroneus SyncBase ID!"); Term.Println("Server has sent an erroneus SyncBase ID!");
} }

View File

@ -215,7 +215,7 @@ namespace Cyber.Networking.Serverside {
Vector3 Delta = Interacted.gameObject.transform.position - Sender.gameObject.transform.position; Vector3 Delta = Interacted.gameObject.transform.position - Sender.gameObject.transform.position;
float ServerInteractionDistance = Sender.InteractionDistance + Sender.MovementSpeed * 0.5f; float ServerInteractionDistance = Sender.InteractionDistance + Sender.MovementSpeed * 0.5f;
if (Delta.magnitude <= ServerInteractionDistance) { if (Delta.magnitude <= ServerInteractionDistance) {
Interacted.Interact(Sender); Interacted.Interact(Sender, Interaction.InteractionType);
NetworkServer.SendToAll(PktType.Interact, Interaction); NetworkServer.SendToAll(PktType.Interact, Interaction);
if (Interacted.GetInteractableSyncdata().RequiresSyncing) { if (Interacted.GetInteractableSyncdata().RequiresSyncing) {
Syncer.DirtSyncBase(Interacted.ID); Syncer.DirtSyncBase(Interacted.ID);

View File

@ -1,12 +1,12 @@
using UnityEngine; using UnityEngine;
using Cyber.Util; using Cyber.Util;
namespace Cyber.Entities.SyncBases { namespace Cyber.Util {
/// <summary> /// <summary>
/// Helper component for hologram meshes. /// Helper component for hologram meshes.
/// </summary> /// </summary>
public class Hologram : Interactable { public class Hologram : MonoBehaviour {
/// <summary> /// <summary>
/// Whether the hologram is visible or not. /// Whether the hologram is visible or not.
@ -21,38 +21,19 @@ namespace Cyber.Entities.SyncBases {
private float CurrentScale; 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() { private void Start() {
CurrentScale = Visible ? 1 : 0; CurrentScale = GetTargetScale();
UpdateScale(); UpdateScale();
} }
private void Update() { private void Update() {
float Scale = Visible ? 1 : 0; if (GetTargetScale() != CurrentScale) {
if (Scale != CurrentScale) {
UpdateScale(); UpdateScale();
} }
} }
private void UpdateScale() { private void UpdateScale() {
float Scale = Visible ? 1 : 0; float Scale = GetTargetScale();
CurrentScale = Mathf.Lerp(CurrentScale, Scale, 8f * Time.deltaTime); CurrentScale = Mathf.Lerp(CurrentScale, Scale, 8f * Time.deltaTime);
if (Mathf.Abs(Scale - CurrentScale) < 0.05) { if (Mathf.Abs(Scale - CurrentScale) < 0.05) {
CurrentScale = Scale; CurrentScale = Scale;
@ -60,5 +41,9 @@ namespace Cyber.Entities.SyncBases {
transform.localScale = transform.localScale =
new Vector3(CurrentScale, CurrentScale, CurrentScale); new Vector3(CurrentScale, CurrentScale, CurrentScale);
} }
private float GetTargetScale() {
return Visible ? 1 : 0;
}
} }
} }