Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Fixed menu so it draws on top, various fixes/enhancements to stations #43

Merged
merged 3 commits into from
Jul 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions CyanEmu/Scripts/CyanEmuPlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public class CyanEmuPlayerController : MonoBehaviour
private enum Stance {
STANDING,
CROUCHING,
PRONE
PRONE,
SITTING
}

public const float DEFAULT_RUN_SPEED_ = 4;
Expand All @@ -39,6 +40,7 @@ private enum Stance {
private const float STANDING_HEIGHT_ = 1.6f;
private const float CROUCHING_HEIGHT_ = 1.0f;
private const float PRONE_HEIGHT_ = 0.5f;
private const float SITTING_HEIGHT_ = 0.88f;

private const float STICK_TO_GROUND_FORCE_ = 2f;
private const float RATE_OF_AIR_ACCELERATION_ = 5f;
Expand Down Expand Up @@ -90,6 +92,7 @@ private enum Stance {
private CollisionFlags collisionFlags_;
private bool peviouslyGrounded_;
private bool legacyLocomotion_;
private bool updatePosition_;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this is in a global scope, I would have renamed this to give it more context, but I'm not going to go super nit here and force you to change things just for this.


private Texture2D reticleTexture_;

Expand Down Expand Up @@ -150,6 +153,7 @@ private void Awake()
cameraHolder.transform.SetParent(playerCamera_.transform, false);
camera_ = cameraHolder.AddComponent<Camera>();
camera_.cullingMask &= ~(1 << 18); // remove mirror reflection
updatePosition_ = false;

// TODO, make based on avatar armspan/settings
cameraHolder.transform.localScale = Vector3.one * AVATAR_SCALE_;
Expand Down Expand Up @@ -290,7 +294,7 @@ private void CreateMenu()
menu_.layer = menuLayer;
menu_.transform.parent = transform.parent;
Canvas canvas = menu_.AddComponent<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceCamera;
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
canvas.worldCamera = camera_;
canvas.planeDistance = camera_.nearClipPlane + 0.1f;
canvas.sortingOrder = 1000;
Expand Down Expand Up @@ -504,15 +508,17 @@ public void EnterStation(CyanEmuStationHelper station)
currentStation_.ExitStation();
}

currentStation_ = station;

if (!station.IsMobile)
{
characterController_.enabled = false;
Teleport(station.EnterLocation, false);
mouseLook_.SetBaseRotation(station.EnterLocation);
mouseLook_.SetRotation(Quaternion.identity);
}

currentStation_ = station;
stance_ = Stance.SITTING;
updatePosition_ = true;
}

public void ExitStation(CyanEmuStationHelper station)
Expand All @@ -526,6 +532,8 @@ public void ExitStation(CyanEmuStationHelper station)
}
mouseLook_.SetBaseRotation(null);
jump_ = false;
stance_ = Stance.STANDING;
updatePosition_ = true;
}

public void PickupObject(CyanEmuPickupHelper pickup)
Expand Down Expand Up @@ -852,7 +860,7 @@ private void UpdateStance()
{
bool updatePosition = false;

if (Input.GetKeyDown(CyanEmuSettings.Instance.crouchKey))
if (Input.GetKeyDown(CyanEmuSettings.Instance.crouchKey) && currentStation_ == null)
{
updatePosition = true;
if (stance_ == Stance.CROUCHING)
Expand All @@ -864,7 +872,7 @@ private void UpdateStance()
stance_ = Stance.CROUCHING;
}
}
if (Input.GetKeyDown(CyanEmuSettings.Instance.proneKey))
if (Input.GetKeyDown(CyanEmuSettings.Instance.proneKey) && currentStation_ == null)
{
updatePosition = true;
if (stance_ == Stance.PRONE)
Expand All @@ -881,9 +889,11 @@ private void UpdateStance()
if (updatePosition)
{
Vector3 cameraPosition = playerCamera_.transform.localPosition;
cameraPosition.y = (stance_ == Stance.STANDING ? STANDING_HEIGHT_ : stance_ == Stance.CROUCHING ? CROUCHING_HEIGHT_ : PRONE_HEIGHT_);
cameraPosition.y = (stance_ == Stance.STANDING ? STANDING_HEIGHT_ : stance_ == Stance.CROUCHING ? CROUCHING_HEIGHT_ : stance_ == Stance.PRONE ? PRONE_HEIGHT_ : SITTING_HEIGHT_);
playerCamera_.transform.localPosition = cameraPosition;
}

updatePosition_ = false;
}

private void GetInput(out Vector2 speed, out Vector2 input)
Expand Down