static public float GetCornerDistanceExt(this Cover cover, bool rightSide, float testedCollisionDistance) { float testedCornerDistanceLeftRight = 1.2f; float testedCornerDistanceForward = 1.0f; // TODO : we can compute this calue using distance to the wall Vector3 fromPos, forward, rightPos, leftPos, right; cover.GetMetricsExt(out fromPos, out right, out forward, out rightPos, out leftPos); // new approach Vector3 fromPosRFrom = rightPos + right * testedCornerDistanceLeftRight; Vector3 fromPosRTo = fromPosRFrom + forward * testedCornerDistanceForward; Vector3 fromPosLFrom = leftPos - right * testedCornerDistanceLeftRight; Vector3 fromPosLTo = fromPosLFrom + forward * testedCornerDistanceForward; MinMaxPair tmp = new MinMaxPair(); tmp.Reset(); if (rightSide) { CoverUtils.LineDistanceCast(fromPosRFrom, fromPosRTo, -right, testedCollisionDistance, ref tmp, testedCornerDistanceLeftRight); } else // left { CoverUtils.LineDistanceCast(fromPosLFrom, fromPosLTo, right, testedCollisionDistance, ref tmp, testedCornerDistanceLeftRight); } return(tmp.m_MaxValue); }
private void OnGUISelectCoversButton(string title, System.Predicate <Cover> match = null) { if (GUILayout.Button(title, GUILayout.Width(m_ButtonSize)) == true) { CoverUtils.SelectCovers(title, match); } }
private static void ExecuteCommandOnSelectedCovers(CoverCommand command, float param, string undoName) { List <Cover> covers = CoverUtils.GrabSelectedCovers(); if (covers.Count > 0) { GUIEditorUtils.RegisterSceneUndo(undoName); foreach (Cover cover in covers) { command(cover, param); } } }
static public MinMaxPair GetWallDistanceExt(this Cover cover, float testedWallDistance) { float testedDistance = testedWallDistance + 0.05f; Vector3 fromPos, forward, rightPos, leftPos, right; cover.GetMetricsExt(out fromPos, out right, out forward, out rightPos, out leftPos); MinMaxPair tmp = new MinMaxPair(); tmp.Reset(); CoverUtils.LineDistanceCast(rightPos, leftPos, forward, testedDistance, ref tmp); return(tmp); }
static public void SetGroundDistanceExt(this Cover cover, float desiredDistance, float testedCollisionDistance) { MinMaxPair tmp = new MinMaxPair(); tmp.Reset(); Vector3 from = cover.transform.position + Vector3.up * testedCollisionDistance * 0.5f; Vector3 right = cover.transform.right; CoverUtils.LineDistanceCast(from + right, from - right, Vector3.down, testedCollisionDistance, ref tmp); if (tmp.IsValid()) { float dist = (desiredDistance - (tmp.m_MinValue - testedCollisionDistance * 0.5f)); cover.transform.position += dist * Vector3.up; } }
private void OnGUILine(string name, CoverCommand command, ref float floatValue, float maxValue) { GUILayout.BeginHorizontal(); { floatValue = EditorGUILayout.FloatField(name, floatValue); floatValue = Mathf.Clamp(floatValue, 0, maxValue); GUI.enabled = CoverUtils.IsGameObjectSelected(); if (GUILayout.Button("Modify selection", GUILayout.Width(m_ButtonSize)) == true) { ExecuteCommandOnSelectedCovers(command, floatValue, "CoverUtils: " + name); } GUI.enabled = true; } GUILayout.EndHorizontal(); }
private void ScanSelection() { Reset(); ScanArray(CoverUtils.GrabSelectedCovers().ToArray()); }
void OnGUI() { GUILayout.BeginVertical(); { GUILayout.Space(8); int buttonSize = 110; GUILayout.BeginHorizontal(""); { if (GUILayout.Button("Scan scene", GUILayout.Width(buttonSize)) == true) { Scan(); } GUI.enabled = CoverUtils.IsGameObjectSelected(); if (GUILayout.Button("Scan selection", GUILayout.Width(buttonSize)) == true) { ScanSelection(); } GUI.enabled = true; } GUILayout.EndHorizontal(); m_VisualizeTests = GUILayout.Toggle(m_VisualizeTests, "Visualize tests"); GUILayout.Space(8); if (m_Covers >= 0) { GUILayout.BeginVertical(""); { GUILayout.Label("Statistics"); OnGUIBreak(true); OnGUILine("Covers count", m_Covers); if (m_Covers > 0) { OnGUILine("Left crouch", m_FlagCrouchLeft); OnGUILine("Right crouch", m_FlagCrouchRight); OnGUILine("Up crouch", m_FlagCrouchUp); OnGUILine("Left stand", m_FlagStandLeft); OnGUILine("Right stand", m_FlagStandRight); OnGUILine("Jump up", m_FlagJumpUp); if (m_DistanceToWallCrouch.IsValid()) { OnGUIBreak(false); OnGUILine("Min dist to wall (crouch)", m_DistanceToWallCrouch.m_MinValue); OnGUILine("Max dist to wall (crouch)", m_DistanceToWallCrouch.m_MaxValue); } if (m_DistanceToWallStand.IsValid()) { OnGUIBreak(false); OnGUILine("Min dist to wall (stand)", m_DistanceToWallStand.m_MinValue); OnGUILine("Max dist to wall (stand)", m_DistanceToWallStand.m_MaxValue); } if (m_DistanceCrouchCorner.IsValid()) { OnGUIBreak(false); OnGUILine("Min dist to corner (crouch)", m_DistanceCrouchCorner.m_MinValue); OnGUILine("Max dist to corner (crouch)", m_DistanceCrouchCorner.m_MaxValue); } if (m_DistanceStandCorner.IsValid()) { OnGUIBreak(false); OnGUILine("Min dist to corner (stand)", m_DistanceStandCorner.m_MinValue); OnGUILine("Max dist to corner (stand)", m_DistanceStandCorner.m_MaxValue); } } OnGUIBreak(true); } GUILayout.EndVertical(); } } GUILayout.EndVertical(); }