fix: more movement and observer tweaks and fixes
This commit is contained in:
@@ -15,6 +15,12 @@ public class EnvironmentObserver{
|
||||
IntersectingLength,
|
||||
}
|
||||
|
||||
enum ObserverGizmoDrawingCondition{
|
||||
Always,
|
||||
OnlyActive,
|
||||
Never
|
||||
}
|
||||
|
||||
public enum CastType{
|
||||
Ray,
|
||||
BoxOverlap,
|
||||
@@ -41,7 +47,6 @@ public class EnvironmentObserver{
|
||||
[FoldoutGroup("Settings")] public Vector3 direction;
|
||||
[FoldoutGroup("Settings")] public Vector3 offset;
|
||||
[PropertySpace(0, 5), FoldoutGroup("Settings")] public LayerMask ignoreLayers = ~0;
|
||||
|
||||
|
||||
[ShowIfGroup("Settings/CastsOnly", VisibleIf = "@castType == CastType.SphereCast || castType == CastType.SphereOverlap")]
|
||||
[FoldoutGroup("Settings")] public float width;
|
||||
@@ -71,27 +76,28 @@ public class EnvironmentObserver{
|
||||
[BoxGroup("Text/Hit")] public float hitTextSize;
|
||||
[BoxGroup("Text/Hit")] public Vector3 hitLocationOffset;
|
||||
[BoxGroup("Text/Hit")] public Vector3 hitRotationOffset;
|
||||
|
||||
[FoldoutGroup("Text"), SerializeField, ShowInInspector] ObserverGizmoDrawingCondition gizmoDrawingCondition;
|
||||
|
||||
[SerializeReference, PropertySpace(5, 5)]
|
||||
public List<EnvironmentObserver> children;
|
||||
|
||||
// NOTE: I had a ref for a RaycastHit here that would correspond to hit but idk if it's needed.
|
||||
public bool Evaluate(GameObject player){
|
||||
public bool Evaluate(GameObject source){
|
||||
if (active) {
|
||||
// Remove player's layer from LayerMask.
|
||||
ignoreLayers -= player.layer;
|
||||
ignoreLayers -= source.layer;
|
||||
|
||||
// Set some of the variables used later during casting
|
||||
Vector3 relativeStart = player.transform.position + offset;
|
||||
Vector3 relativeStartWithRotation = player.transform.position + player.transform.rotation * offset ;
|
||||
Vector3 relativeStart = source.transform.position + offset;
|
||||
Vector3 relativeStartWithRotation = source.transform.position + source.transform.rotation * offset ;
|
||||
|
||||
switch (castType) {
|
||||
case CastType.Ray:
|
||||
Physics.Raycast(relativeStart, player.transform.rotation * direction, out hit, length, ignoreLayers);
|
||||
Physics.Raycast(relativeStart, source.transform.rotation * direction, out hit, length, ignoreLayers);
|
||||
break;
|
||||
case CastType.BoxOverlap:
|
||||
overlapHits = Physics.OverlapBox(relativeStartWithRotation, size / 2f,
|
||||
player.transform.rotation * Quaternion.Euler(rotation), ignoreLayers);
|
||||
source.transform.rotation * Quaternion.Euler(rotation), ignoreLayers);
|
||||
|
||||
if (overlapHits.Length > 0) {
|
||||
return true;
|
||||
@@ -103,8 +109,8 @@ public class EnvironmentObserver{
|
||||
case CastType.BoxCast:
|
||||
// TODO: Make this not an if statement. Check that it works with NodeCanvas first
|
||||
if (Physics.BoxCast(relativeStartWithRotation, size / 2f,
|
||||
player.transform.rotation * Quaternion.Euler(rotation) * direction,
|
||||
out hit, player.transform.rotation * Quaternion.Euler(rotation), length,
|
||||
source.transform.rotation * Quaternion.Euler(rotation) * direction,
|
||||
out hit, source.transform.rotation * Quaternion.Euler(rotation), length,
|
||||
ignoreLayers)
|
||||
) {
|
||||
};
|
||||
@@ -112,7 +118,7 @@ public class EnvironmentObserver{
|
||||
case CastType.SphereCast:
|
||||
// TODO: Make this not an if statement. Check that it works with NodeCanvas first
|
||||
if (Physics.SphereCast(relativeStartWithRotation, width / 2f,
|
||||
player.transform.rotation * Quaternion.Euler(rotation) * direction,
|
||||
source.transform.rotation * Quaternion.Euler(rotation) * direction,
|
||||
out hit, length,
|
||||
ignoreLayers)
|
||||
) {
|
||||
@@ -127,29 +133,34 @@ public class EnvironmentObserver{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void DrawObserverGizmo(GameObject player){
|
||||
Vector3 relativeStart = player.transform.position + offset;
|
||||
Vector3 relativeStartWithRotation = player.transform.position + player.transform.rotation * (offset);
|
||||
public void DrawObserverGizmo(GameObject source){
|
||||
if (gizmoDrawingCondition == ObserverGizmoDrawingCondition.Never ||
|
||||
(gizmoDrawingCondition == ObserverGizmoDrawingCondition.OnlyActive ! & active)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 relativeStart = source.transform.position + offset;
|
||||
Vector3 relativeStartWithRotation = source.transform.position + source.transform.rotation * (offset);
|
||||
|
||||
// Setup the variables for boxcast, spherecast, etc
|
||||
// Create an offset start point for the center of the wirebox, since gizmos are drawn with their pivot in the center.
|
||||
Vector3 offsetWithRotationAndLength = (Quaternion.LookRotation(direction) * Quaternion.Euler(rotation)) * (Vector3.forward * (length / 2));
|
||||
Vector3 offsetFromCenter = relativeStartWithRotation + player.transform.rotation * offsetWithRotationAndLength;
|
||||
Vector3 offsetFromCenter = relativeStartWithRotation + source.transform.rotation * offsetWithRotationAndLength;
|
||||
|
||||
// Also create a rotation for use with the gizmos. Mainly just to shorten the lines
|
||||
Quaternion gizmosRotation = player.transform.rotation * Quaternion.LookRotation(direction) * Quaternion.Euler(rotation);
|
||||
Quaternion gizmosRotation = source.transform.rotation * Quaternion.LookRotation(direction) * Quaternion.Euler(rotation);
|
||||
Vector3 firstBoxOffset = gizmosRotation * (Vector3.forward * size.z);
|
||||
|
||||
Color gizmoColor = Evaluate(player) ? Color.green : Color.red;
|
||||
Color gizmoColor = Evaluate(source) ? Color.green : Color.red;
|
||||
gizmoColor = active ? gizmoColor : Color.gray;
|
||||
|
||||
using (Draw.ingame.WithColor(gizmoColor)){
|
||||
switch (castType) {
|
||||
case CastType.Ray:
|
||||
Draw.ingame.Line(relativeStart, relativeStart + (player.transform.rotation * direction.normalized) * length);
|
||||
Draw.ingame.Line(relativeStart, relativeStart + (source.transform.rotation * direction.normalized) * length);
|
||||
break;
|
||||
case CastType.BoxOverlap:
|
||||
Draw.ingame.WireBox(relativeStartWithRotation, player.transform.rotation * Quaternion.Euler(rotation), size);
|
||||
Draw.ingame.WireBox(relativeStartWithRotation, source.transform.rotation * Quaternion.Euler(rotation), size);
|
||||
break;
|
||||
case CastType.SphereCast:
|
||||
Draw.ingame.SolidCircle(relativeStartWithRotation, relativeStartWithRotation - Camera.main.transform.position, width * 1, gizmoColor.Alpha(.5f));
|
||||
@@ -173,7 +184,7 @@ public class EnvironmentObserver{
|
||||
Vector3 labelStartPos = Vector3.zero;
|
||||
switch (labelTextLocation) {
|
||||
case LabelDrawingLocation.PlayerOffset:
|
||||
labelStartPos = player.transform.position;
|
||||
labelStartPos = source.transform.position;
|
||||
break;
|
||||
case LabelDrawingLocation.IntersectingLength:
|
||||
labelStartPos = offsetFromCenter;
|
||||
@@ -203,7 +214,7 @@ public class EnvironmentObserver{
|
||||
// Since the label is already drawn just use the previous startPos
|
||||
switch (labelTextLocation) {
|
||||
case LabelDrawingLocation.PlayerOffset:
|
||||
labelStartPos = player.transform.position;
|
||||
labelStartPos = source.transform.position;
|
||||
break;
|
||||
case LabelDrawingLocation.IntersectingLength:
|
||||
labelStartPos = offsetFromCenter;
|
||||
@@ -228,11 +239,7 @@ public class EnvironmentObserver{
|
||||
gizmoColor
|
||||
);
|
||||
}
|
||||
|
||||
Sirenix.Utilities.Editor.GUIHelper.RequestRepaint();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
static Color GetObserverStatusColorStatic(bool active, RaycastHit hit){
|
||||
@@ -320,7 +327,6 @@ public class PlayerEnvironmentManager : MonoBehaviour{
|
||||
}
|
||||
|
||||
void Update(){
|
||||
Debug.Log(EvaluateFromString("gamedev"));
|
||||
}
|
||||
|
||||
void LateUpdate(){
|
||||
|
||||
Reference in New Issue
Block a user