From cc55520a19043a7b4870858e962fa3e20c46bc39 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Thu, 14 Mar 2024 11:43:40 +0800 Subject: *misc --- AvaragePosition.cs | 26 ------- CameraMovement.cs | 136 ------------------------------------ CameraRecoil.cs | 49 ------------- CameraWobble.cs | 18 ----- CreepyRobots.csproj | 3 + CreepyRobots.sln | 25 +++++++ GameMode.cs | 8 +++ WobbleShake.cs | 50 -------------- _ActiveRagdoll/AvaragePosition.cs | 26 +++++++ _Camera/CameraMovement.cs | 136 ++++++++++++++++++++++++++++++++++++ _Camera/CameraRecoil.cs | 49 +++++++++++++ _Camera/CameraWobble.cs | 18 +++++ _Camera/WobbleShake.cs | 50 ++++++++++++++ _Debug/DebugRigidBody.cs | 140 ++++++++++++++++++++++++++++++++++++++ _Debug/REPL.cs | 124 +++++++++++++++++++++++++++++++++ _Debug/SimpleMoveCamera.cs | 139 +++++++++++++++++++++++++++++++++++++ 16 files changed, 718 insertions(+), 279 deletions(-) delete mode 100644 AvaragePosition.cs delete mode 100644 CameraMovement.cs delete mode 100644 CameraRecoil.cs delete mode 100644 CameraWobble.cs create mode 100644 CreepyRobots.sln delete mode 100644 WobbleShake.cs create mode 100644 _ActiveRagdoll/AvaragePosition.cs create mode 100644 _Camera/CameraMovement.cs create mode 100644 _Camera/CameraRecoil.cs create mode 100644 _Camera/CameraWobble.cs create mode 100644 _Camera/WobbleShake.cs create mode 100644 _Debug/DebugRigidBody.cs create mode 100644 _Debug/REPL.cs create mode 100644 _Debug/SimpleMoveCamera.cs diff --git a/AvaragePosition.cs b/AvaragePosition.cs deleted file mode 100644 index cea74d6..0000000 --- a/AvaragePosition.cs +++ /dev/null @@ -1,26 +0,0 @@ -using UnityEngine; - -public class AvaragePosition : MonoBehaviour -{ - public Transform[] transforms; - - private Transform rotationHelper; - - public Vector3 offset; - - private void Start() - { - rotationHelper = base.transform.root.GetComponentInChildren().transform; - } - - private void LateUpdate() - { - Vector3 zero = Vector3.zero; - for (int i = 0; i < transforms.Length; i++) - { - zero += transforms[i].position; - } - zero /= (float)transforms.Length; - base.transform.position = zero + rotationHelper.TransformDirection(offset); - } -} diff --git a/CameraMovement.cs b/CameraMovement.cs deleted file mode 100644 index a94012a..0000000 --- a/CameraMovement.cs +++ /dev/null @@ -1,136 +0,0 @@ -using UnityEngine; - -public class CameraMovement : MonoBehaviour -{ - public Camera camera; - - public Transform positionTarget; - - public Transform headPosition; - - public Transform rotationTarget; - - public Transform bobberTarget; - - private StandingDataHandler standingData; - - private float fallingValue; - - private float fallingEffectValue; - - private float minBobble = 0.02f; - - public bool ADS; - - public DamageEffects effects; - - private WeaponHandler weaponHandler; - - private Rigidbody hip; - - private HasControl hasControl; - - private HeadCollisionHandler headCollisionHandler; - - private MovementDataHandler movementData; - - private Rigidbody torso; - - private PlayerDeath death; - - private Strength str; - - private Vector3 cameraCurrentRelativeADSPosition = Vector3.zero; - - private Vector3 movementADSVelocity = Vector3.zero; - - private Vector3 ADSMovementPosition = Vector3.zero; - - private void Start() - { - torso = base.transform.root.GetComponentInChildren().GetComponent(); - headCollisionHandler = base.transform.root.GetComponentInChildren(); - standingData = base.transform.GetComponentInParent(); - movementData = base.transform.GetComponentInParent(); - weaponHandler = base.transform.GetComponentInParent(); - camera = GetComponentInChildren(); - hip = base.transform.root.GetComponentInChildren().GetComponent(); - hasControl = base.transform.root.GetComponent(); - death = base.transform.root.GetComponent(); - str = base.transform.root.GetComponent(); - effects = base.transform.root.GetComponent(); - } - - private void LateUpdate() - { - if (hasControl.hasControl) - { - headCollisionHandler.collisionValue = 0f; - if (standingData.sinceLanded > 1f) - { - fallingValue = Mathf.Clamp(standingData.sinceGrounded - 0.5f, 0f, 10f) * 0.5f; - } - if (standingData.sinceGrounded > 0.5f || standingData.sinceLanded < 0.5f) - { - fallingEffectValue = Mathf.Lerp(fallingEffectValue, fallingValue, Time.smoothDeltaTime * 15f); - } - else - { - fallingEffectValue = Mathf.Lerp(fallingEffectValue, minBobble, Time.smoothDeltaTime * 3f); - } - float physicsValue = GetPhysicsValue(); - Vector3 vector = Vector3.Lerp(positionTarget.position, bobberTarget.position, Mathf.Clamp(physicsValue + headCollisionHandler.collisionValue, 0f, 1f)); - Vector3 position = vector; - position.y = base.transform.position.y; - base.transform.position = position; - base.transform.position = vector; - base.transform.rotation = Quaternion.Lerp(rotationTarget.rotation, bobberTarget.rotation, Mathf.Clamp(physicsValue + Mathf.Clamp(headCollisionHandler.collisionValue, 0f, 0.4f), 0f, 1f)); - SetCameraPosition(); - } - } - - private void SetCameraPosition() - { - if (ADS && (bool)weaponHandler.gunADS) - { - cameraCurrentRelativeADSPosition = Vector3.Lerp(cameraCurrentRelativeADSPosition, Vector3.zero, Time.deltaTime * 20f); - camera.transform.position = weaponHandler.gunADS.TransformPoint(cameraCurrentRelativeADSPosition) + ADSMovementPosition; - camera.fieldOfView = Mathf.Lerp(camera.fieldOfView, weaponHandler.ADSFOV, Time.deltaTime * 20f); - return; - } - if ((bool)weaponHandler && (bool)weaponHandler.gunADS) - { - cameraCurrentRelativeADSPosition = weaponHandler.gunADS.InverseTransformPoint(camera.transform.position); - } - camera.transform.localPosition = Vector3.Lerp(camera.transform.localPosition, Vector3.zero, Time.deltaTime * 20f); - camera.fieldOfView = Mathf.Lerp(camera.fieldOfView, 90f, Time.deltaTime * 20f); - } - - private void FixedUpdate() - { - if (hasControl.hasControl && (bool)weaponHandler && (bool)weaponHandler.rightGun) - { - movementADSVelocity += (weaponHandler.rightGun.rig.velocity - hip.velocity) * 0.01f; - movementADSVelocity += -ADSMovementPosition * 3f; - movementADSVelocity *= 0.8f; - } - } - - private void Update() - { - if (hasControl.hasControl) - { - ADSMovementPosition += movementADSVelocity * Time.deltaTime; - } - } - - private float GetPhysicsValue() - { - float result = fallingEffectValue * 0.3f + (1f - str.strength) + effects.damageValue; - if (death.dead) - { - result = 1f; - } - return result; - } -} diff --git a/CameraRecoil.cs b/CameraRecoil.cs deleted file mode 100644 index e82532a..0000000 --- a/CameraRecoil.cs +++ /dev/null @@ -1,49 +0,0 @@ -using UnityEngine; - -public class CameraRecoil : MonoBehaviour -{ - public Transform yRotation; - - public Transform xRotation; - - private float counter; - - private float lastValue; - - private AnimationCurve usedCurve; - - private float deltaValue; - - private float xRecoil; - - private float yRecoil; - - private bool hasCurve; - - private void Start() - { - } - - private void Update() - { - if (hasCurve && counter < usedCurve.keys[usedCurve.length - 1].time) - { - float num = usedCurve.Evaluate(counter); - counter += Time.deltaTime; - deltaValue = num - lastValue; - lastValue = num; - xRotation.Rotate(Vector3.up * Time.deltaTime * xRecoil * deltaValue, Space.World); - yRotation.Rotate(Vector3.right * Time.deltaTime * yRecoil * deltaValue, Space.Self); - } - } - - public void AddRecoil(Vector2 recoil, AnimationCurve curve) - { - counter = 0f; - lastValue = curve.Evaluate(0f); - usedCurve = curve; - xRecoil = recoil.x * 30f; - yRecoil = recoil.y * -30f; - hasCurve = true; - } -} diff --git a/CameraWobble.cs b/CameraWobble.cs deleted file mode 100644 index 2bd1236..0000000 --- a/CameraWobble.cs +++ /dev/null @@ -1,18 +0,0 @@ -using UnityEngine; - -public class CameraWobble : MonoBehaviour -{ - public Transform target; - - private void Start() - { - } - - private void LateUpdate() - { - if ((bool)target) - { - base.transform.localRotation = target.rotation; - } - } -} diff --git a/CreepyRobots.csproj b/CreepyRobots.csproj index 9d5de2a..4b2362c 100644 --- a/CreepyRobots.csproj +++ b/CreepyRobots.csproj @@ -180,4 +180,7 @@ ..\CreepyRobots_Data\Managed\UnityEngine.WindModule.dll + + + \ No newline at end of file diff --git a/CreepyRobots.sln b/CreepyRobots.sln new file mode 100644 index 0000000..7069481 --- /dev/null +++ b/CreepyRobots.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33213.308 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreepyRobots", "CreepyRobots.csproj", "{7A54260D-D4B7-4D9C-A7B2-A32A0DC2C3B1}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7A54260D-D4B7-4D9C-A7B2-A32A0DC2C3B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7A54260D-D4B7-4D9C-A7B2-A32A0DC2C3B1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7A54260D-D4B7-4D9C-A7B2-A32A0DC2C3B1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7A54260D-D4B7-4D9C-A7B2-A32A0DC2C3B1}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {536450D1-037F-4BED-BE36-22A677EAB581} + EndGlobalSection +EndGlobal diff --git a/GameMode.cs b/GameMode.cs index 2d717aa..5b03929 100644 --- a/GameMode.cs +++ b/GameMode.cs @@ -30,6 +30,8 @@ public class GameMode : MonoBehaviour Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; + Invoke("DebugGame", 3); + Init(); while (true) { @@ -39,6 +41,12 @@ public class GameMode : MonoBehaviour } } + // ²âÊÔ + private void DebugGame() + { + REPL.StartREPL(); + } + private IEnumerator WaitForWaveToEnd() { while (enemies.Count > 0) diff --git a/WobbleShake.cs b/WobbleShake.cs deleted file mode 100644 index 4da2d38..0000000 --- a/WobbleShake.cs +++ /dev/null @@ -1,50 +0,0 @@ -using UnityEngine; - -public class WobbleShake : MonoBehaviour -{ - public Vector3 velocity = Vector3.zero; - - public float friction = 0.9f; - - public float movementMultiplier = 10f; - - private Camera mainCam; - - private void Start() - { - mainCam = base.transform.root.GetComponentInChildren(); - } - - private void FixedUpdate() - { - Vector3 forward = Vector3.forward; - Vector3 vector = Vector3.Cross(base.transform.forward, forward).normalized * Vector3.Angle(base.transform.forward, forward); - forward = Vector3.up; - Vector3 vector2 = Vector3.Cross(base.transform.up, forward).normalized * Vector3.Angle(base.transform.up, forward); - velocity += (vector + vector2) * movementMultiplier; - velocity *= friction; - base.transform.Rotate(velocity, Space.World); - friction = Mathf.Lerp(friction, 0.7f, Time.fixedDeltaTime * 1f); - } - - public void AddShake(Vector3 shake, float newFriction) - { - Vector3 vector = new Vector3(0f - shake.y, shake.x, shake.z); - if (Mathf.Abs(newFriction - 0.7f) > Mathf.Abs(friction - 0.7f)) - { - friction = newFriction; - } - velocity += vector; - } - - public void AddShakeWorld(Vector3 shake, float newFriction) - { - if ((bool)mainCam) - { - shake = mainCam.transform.TransformDirection(shake); - Vector3 vector = new Vector3(0f - Mathf.Abs(shake.z + shake.y), 0f - shake.x, 0f); - friction = newFriction; - velocity += vector; - } - } -} diff --git a/_ActiveRagdoll/AvaragePosition.cs b/_ActiveRagdoll/AvaragePosition.cs new file mode 100644 index 0000000..cea74d6 --- /dev/null +++ b/_ActiveRagdoll/AvaragePosition.cs @@ -0,0 +1,26 @@ +using UnityEngine; + +public class AvaragePosition : MonoBehaviour +{ + public Transform[] transforms; + + private Transform rotationHelper; + + public Vector3 offset; + + private void Start() + { + rotationHelper = base.transform.root.GetComponentInChildren().transform; + } + + private void LateUpdate() + { + Vector3 zero = Vector3.zero; + for (int i = 0; i < transforms.Length; i++) + { + zero += transforms[i].position; + } + zero /= (float)transforms.Length; + base.transform.position = zero + rotationHelper.TransformDirection(offset); + } +} diff --git a/_Camera/CameraMovement.cs b/_Camera/CameraMovement.cs new file mode 100644 index 0000000..a94012a --- /dev/null +++ b/_Camera/CameraMovement.cs @@ -0,0 +1,136 @@ +using UnityEngine; + +public class CameraMovement : MonoBehaviour +{ + public Camera camera; + + public Transform positionTarget; + + public Transform headPosition; + + public Transform rotationTarget; + + public Transform bobberTarget; + + private StandingDataHandler standingData; + + private float fallingValue; + + private float fallingEffectValue; + + private float minBobble = 0.02f; + + public bool ADS; + + public DamageEffects effects; + + private WeaponHandler weaponHandler; + + private Rigidbody hip; + + private HasControl hasControl; + + private HeadCollisionHandler headCollisionHandler; + + private MovementDataHandler movementData; + + private Rigidbody torso; + + private PlayerDeath death; + + private Strength str; + + private Vector3 cameraCurrentRelativeADSPosition = Vector3.zero; + + private Vector3 movementADSVelocity = Vector3.zero; + + private Vector3 ADSMovementPosition = Vector3.zero; + + private void Start() + { + torso = base.transform.root.GetComponentInChildren().GetComponent(); + headCollisionHandler = base.transform.root.GetComponentInChildren(); + standingData = base.transform.GetComponentInParent(); + movementData = base.transform.GetComponentInParent(); + weaponHandler = base.transform.GetComponentInParent(); + camera = GetComponentInChildren(); + hip = base.transform.root.GetComponentInChildren().GetComponent(); + hasControl = base.transform.root.GetComponent(); + death = base.transform.root.GetComponent(); + str = base.transform.root.GetComponent(); + effects = base.transform.root.GetComponent(); + } + + private void LateUpdate() + { + if (hasControl.hasControl) + { + headCollisionHandler.collisionValue = 0f; + if (standingData.sinceLanded > 1f) + { + fallingValue = Mathf.Clamp(standingData.sinceGrounded - 0.5f, 0f, 10f) * 0.5f; + } + if (standingData.sinceGrounded > 0.5f || standingData.sinceLanded < 0.5f) + { + fallingEffectValue = Mathf.Lerp(fallingEffectValue, fallingValue, Time.smoothDeltaTime * 15f); + } + else + { + fallingEffectValue = Mathf.Lerp(fallingEffectValue, minBobble, Time.smoothDeltaTime * 3f); + } + float physicsValue = GetPhysicsValue(); + Vector3 vector = Vector3.Lerp(positionTarget.position, bobberTarget.position, Mathf.Clamp(physicsValue + headCollisionHandler.collisionValue, 0f, 1f)); + Vector3 position = vector; + position.y = base.transform.position.y; + base.transform.position = position; + base.transform.position = vector; + base.transform.rotation = Quaternion.Lerp(rotationTarget.rotation, bobberTarget.rotation, Mathf.Clamp(physicsValue + Mathf.Clamp(headCollisionHandler.collisionValue, 0f, 0.4f), 0f, 1f)); + SetCameraPosition(); + } + } + + private void SetCameraPosition() + { + if (ADS && (bool)weaponHandler.gunADS) + { + cameraCurrentRelativeADSPosition = Vector3.Lerp(cameraCurrentRelativeADSPosition, Vector3.zero, Time.deltaTime * 20f); + camera.transform.position = weaponHandler.gunADS.TransformPoint(cameraCurrentRelativeADSPosition) + ADSMovementPosition; + camera.fieldOfView = Mathf.Lerp(camera.fieldOfView, weaponHandler.ADSFOV, Time.deltaTime * 20f); + return; + } + if ((bool)weaponHandler && (bool)weaponHandler.gunADS) + { + cameraCurrentRelativeADSPosition = weaponHandler.gunADS.InverseTransformPoint(camera.transform.position); + } + camera.transform.localPosition = Vector3.Lerp(camera.transform.localPosition, Vector3.zero, Time.deltaTime * 20f); + camera.fieldOfView = Mathf.Lerp(camera.fieldOfView, 90f, Time.deltaTime * 20f); + } + + private void FixedUpdate() + { + if (hasControl.hasControl && (bool)weaponHandler && (bool)weaponHandler.rightGun) + { + movementADSVelocity += (weaponHandler.rightGun.rig.velocity - hip.velocity) * 0.01f; + movementADSVelocity += -ADSMovementPosition * 3f; + movementADSVelocity *= 0.8f; + } + } + + private void Update() + { + if (hasControl.hasControl) + { + ADSMovementPosition += movementADSVelocity * Time.deltaTime; + } + } + + private float GetPhysicsValue() + { + float result = fallingEffectValue * 0.3f + (1f - str.strength) + effects.damageValue; + if (death.dead) + { + result = 1f; + } + return result; + } +} diff --git a/_Camera/CameraRecoil.cs b/_Camera/CameraRecoil.cs new file mode 100644 index 0000000..e82532a --- /dev/null +++ b/_Camera/CameraRecoil.cs @@ -0,0 +1,49 @@ +using UnityEngine; + +public class CameraRecoil : MonoBehaviour +{ + public Transform yRotation; + + public Transform xRotation; + + private float counter; + + private float lastValue; + + private AnimationCurve usedCurve; + + private float deltaValue; + + private float xRecoil; + + private float yRecoil; + + private bool hasCurve; + + private void Start() + { + } + + private void Update() + { + if (hasCurve && counter < usedCurve.keys[usedCurve.length - 1].time) + { + float num = usedCurve.Evaluate(counter); + counter += Time.deltaTime; + deltaValue = num - lastValue; + lastValue = num; + xRotation.Rotate(Vector3.up * Time.deltaTime * xRecoil * deltaValue, Space.World); + yRotation.Rotate(Vector3.right * Time.deltaTime * yRecoil * deltaValue, Space.Self); + } + } + + public void AddRecoil(Vector2 recoil, AnimationCurve curve) + { + counter = 0f; + lastValue = curve.Evaluate(0f); + usedCurve = curve; + xRecoil = recoil.x * 30f; + yRecoil = recoil.y * -30f; + hasCurve = true; + } +} diff --git a/_Camera/CameraWobble.cs b/_Camera/CameraWobble.cs new file mode 100644 index 0000000..2bd1236 --- /dev/null +++ b/_Camera/CameraWobble.cs @@ -0,0 +1,18 @@ +using UnityEngine; + +public class CameraWobble : MonoBehaviour +{ + public Transform target; + + private void Start() + { + } + + private void LateUpdate() + { + if ((bool)target) + { + base.transform.localRotation = target.rotation; + } + } +} diff --git a/_Camera/WobbleShake.cs b/_Camera/WobbleShake.cs new file mode 100644 index 0000000..4da2d38 --- /dev/null +++ b/_Camera/WobbleShake.cs @@ -0,0 +1,50 @@ +using UnityEngine; + +public class WobbleShake : MonoBehaviour +{ + public Vector3 velocity = Vector3.zero; + + public float friction = 0.9f; + + public float movementMultiplier = 10f; + + private Camera mainCam; + + private void Start() + { + mainCam = base.transform.root.GetComponentInChildren(); + } + + private void FixedUpdate() + { + Vector3 forward = Vector3.forward; + Vector3 vector = Vector3.Cross(base.transform.forward, forward).normalized * Vector3.Angle(base.transform.forward, forward); + forward = Vector3.up; + Vector3 vector2 = Vector3.Cross(base.transform.up, forward).normalized * Vector3.Angle(base.transform.up, forward); + velocity += (vector + vector2) * movementMultiplier; + velocity *= friction; + base.transform.Rotate(velocity, Space.World); + friction = Mathf.Lerp(friction, 0.7f, Time.fixedDeltaTime * 1f); + } + + public void AddShake(Vector3 shake, float newFriction) + { + Vector3 vector = new Vector3(0f - shake.y, shake.x, shake.z); + if (Mathf.Abs(newFriction - 0.7f) > Mathf.Abs(friction - 0.7f)) + { + friction = newFriction; + } + velocity += vector; + } + + public void AddShakeWorld(Vector3 shake, float newFriction) + { + if ((bool)mainCam) + { + shake = mainCam.transform.TransformDirection(shake); + Vector3 vector = new Vector3(0f - Mathf.Abs(shake.z + shake.y), 0f - shake.x, 0f); + friction = newFriction; + velocity += vector; + } + } +} diff --git a/_Debug/DebugRigidBody.cs b/_Debug/DebugRigidBody.cs new file mode 100644 index 0000000..8267f50 --- /dev/null +++ b/_Debug/DebugRigidBody.cs @@ -0,0 +1,140 @@ + +using UnityEngine; + +public class DebugRigidBody : MonoBehaviour +{ + + public enum EMode + { + Axis, + Cube, + Axis_Cube, + } + public EMode mode = EMode.Axis; + + public Color color = Color.white; + + // When added to an object, draws colored rays from the + // transform position. + public int lineCount = 100; + public float radius = 3.0f; + + public float cubeLen = 0.05f; + + static Material lineMaterial; + static void CreateLineMaterial() + { + if (!lineMaterial) + { + // Unity has a built-in shader that is useful for drawing + // simple colored things. + Shader shader = Shader.Find("Hidden/Internal-Colored"); + lineMaterial = new Material(shader); + lineMaterial.hideFlags = HideFlags.HideAndDontSave; + // Turn on alpha blending + lineMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha); + lineMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); + // Turn backface culling off + lineMaterial.SetInt("_Cull", (int)UnityEngine.Rendering.CullMode.Off); + // Turn off depth writes + lineMaterial.SetInt("_ZWrite", 0); + } + } + + private void PutVertex(Vector3 vert) + { + GL.Vertex3(vert.x, vert.y, vert.z); + } + + // Will be called after all regular rendering is done + public void OnRenderObject() + { + CreateLineMaterial(); + // Apply the line material + lineMaterial.SetPass(0); + + if (mode == EMode.Axis || mode == EMode.Axis_Cube) + { + GL.PushMatrix(); + // Set transformation matrix for drawing to + // match our transform + GL.MultMatrix(transform.localToWorldMatrix); + + // Draw lines + GL.Begin(GL.LINES); + + float len = 0.3f; + + GL.Color(Color.red); + PutVertex(Vector3.zero); + PutVertex(Vector3.right * len); + + GL.Color(Color.green); + PutVertex(Vector3.zero); + PutVertex(Vector3.up * len); + + GL.Color(Color.blue); + PutVertex(Vector3.zero); + PutVertex(Vector3.forward * len); + + GL.End(); + GL.PopMatrix(); + } + if (mode == EMode.Cube || mode == EMode.Axis_Cube) + { + GL.PushMatrix(); + // Set transformation matrix for drawing to + // match our transform + GL.MultMatrix(transform.localToWorldMatrix); + + float len = cubeLen; + + GL.wireframe = true; + + GL.Begin(GL.QUADS); + + GL.Color(color); + + GL.Vertex3(len, len, -len); + GL.Vertex3(-len, len, -len); + GL.Vertex3(-len, len, len); + GL.Vertex3(len, len, len); + + // Bottom face (y = -len) + GL.Vertex3(len, -len, len); + GL.Vertex3(-len, -len, len); + GL.Vertex3(-len, -len, -len); + GL.Vertex3(len, -len, -len); + + // Front face (z = len) + GL.Vertex3(len, len, len); + GL.Vertex3(-len, len, len); + GL.Vertex3(-len, -len, len); + GL.Vertex3(len, -len, len); + + // Back face (z = -len) + GL.Vertex3(len, -len, -len); + GL.Vertex3(-len, -len, -len); + GL.Vertex3(-len, len, -len); + GL.Vertex3(len, len, -len); + + // Left face (x = -len) + GL.Vertex3(-len, len, len); + GL.Vertex3(-len, len, -len); + GL.Vertex3(-len, -len, -len); + GL.Vertex3(-len, -len, len); + + // Right face (x = len) + GL.Vertex3(len, len, -len); + GL.Vertex3(len, len, len); + GL.Vertex3(len, -len, len); + GL.Vertex3(len, -len, -len); + GL.End(); // End of drawing color-cube + + GL.wireframe = false; + + GL.PopMatrix(); + } + } + +} diff --git a/_Debug/REPL.cs b/_Debug/REPL.cs new file mode 100644 index 0000000..29209ef --- /dev/null +++ b/_Debug/REPL.cs @@ -0,0 +1,124 @@ +using System.Collections.Generic; +using System.Drawing; +using UnityEngine; + +class REPL +{ + public static void StartREPL() + { + AddCamera(); + AddRigidbodyDebug(); + AddCubes(); + } + + public static void AddCamera() + { + GameObject camera = GameObject.Find("WanderCamera"); + if (camera != null) + { + GameObject.DestroyImmediate(camera); + } + + camera = new GameObject(); + camera.name = "WanderCamera"; + camera.AddComponent(); + camera.AddComponent(); + + GameObject wanderCam = GameObject.Find("WanderCamera"); + + GameObject player = GameObject.Find("Player"); + if (player != null) + { + wanderCam.transform.position = player.transform.position; + } + + wanderCam.transform.position = new Vector3(1.21f, 33.92f, -10.4f); + wanderCam.transform.rotation = Quaternion.Euler(25.95f, 75, 0); + } + + public static void AddRigidbodyDebug() + { + string[] targets = { + "Head", + "Neck", + "Torso", + "Arm_Right", + "Arm_Left", + "Hand_Right", + "Hand_Left", + "Hip", + "Leg_Left", + "Leg_Right", + "Foot_Left", + "Foot_Right", + "Knee_Left", + "Knee_Right", + }; + + for(int i = 0; i < targets.Length; ++i) + { + string target = targets[i]; + GameObject go = GameObject.Find(target); + if(go != null) + { + var comps = go.gameObject.GetComponents(); + if (comps != null) + { + for (int j = 0; j < comps.Length; j++) + { + if (comps[j].GetType().Name == "DebugRigidBody" || comps[j].GetType().Name == "DebugRigidBody2") + { + UnityEngine.Object.DestroyImmediate(comps[j]); + } + } + } + Debug.Log(go.name); + var drb = go.AddComponent(); + //drb.mode = DebugRigidBody.EMode.Cube; + //drb.color = Color.green; + } + } + } + + public struct CubeParams + { + public UnityEngine.Color color; + public float size; + public DebugRigidBody.EMode mode; + } + + public static void AddCubes() + { + Dictionary targets = new Dictionary{ + {"CameraPos", new CubeParams(){ color = UnityEngine.Color.red, size = 0.2f, mode = DebugRigidBody.EMode.Cube } }, + {"Main Camera", new CubeParams(){ color = UnityEngine.Color.white, size = 0.05f, mode = DebugRigidBody.EMode.Axis_Cube } }, + {"RotationTarget", new CubeParams(){ color = UnityEngine.Color.green, size = 0.05f, mode = DebugRigidBody.EMode.Axis_Cube } }, + //{"AvaragePosition", new CubeParams(){ color = UnityEngine.Color.blue, size = 0.2f, mode = DebugRigidBody.EMode.Axis_Cube } }, + }; + + foreach(var target in targets) + { + string name = target.Key; + GameObject go = GameObject.Find(name); + if (go != null) + { + var comps = go.gameObject.GetComponents(); + if (comps != null) + { + for (int j = 0; j < comps.Length; j++) + { + if (comps[j].GetType().Name == "DebugRigidBody" || comps[j].GetType().Name == "DebugRigidBody2") + { + UnityEngine.Object.DestroyImmediate(comps[j]); + } + } + } + Debug.Log(go.name); + var drb = go.AddComponent(); + drb.mode = target.Value.mode; + drb.color = target.Value.color; + drb.cubeLen = target.Value.size; + } + } + } +} diff --git a/_Debug/SimpleMoveCamera.cs b/_Debug/SimpleMoveCamera.cs new file mode 100644 index 0000000..35a7360 --- /dev/null +++ b/_Debug/SimpleMoveCamera.cs @@ -0,0 +1,139 @@ + +using UnityEngine; +/// +/// A simple free camera to be added to a Unity game object. +/// +/// Keys: +/// wasd / arrows - movement +/// q/e - up/down (local space) +/// r/f - up/down (world space) +/// pageup/pagedown - up/down (world space) +/// hold shift - enable fast movement mode +/// right mouse - enable free look +/// mouse - free look / rotation +/// +/// +public class SimpleMoveCamera : MonoBehaviour +{ + /// + /// Normal speed of camera movement. + /// + public float movementSpeed = 10f; + + /// + /// Speed of camera movement when shift is held down, + /// + public float fastMovementSpeed = 100f; + + /// + /// Sensitivity for free look. + /// + public float freeLookSensitivity = 3f; + + /// + /// Amount to zoom the camera when using the mouse wheel. + /// + public float zoomSensitivity = 10f; + + /// + /// Amount to zoom the camera when using the mouse wheel (fast mode). + /// + public float fastZoomSensitivity = 50f; + + /// + /// Set to true when free looking (on right mouse button). + /// + private bool looking = false; + + void Update() + { + var fastMode = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift); + var movementSpeed = fastMode ? this.fastMovementSpeed : this.movementSpeed; + + if (Input.GetKey(KeyCode.H) || Input.GetKey(KeyCode.LeftArrow)) + { + transform.position = transform.position + (-transform.right * movementSpeed * Time.deltaTime); + } + + if (Input.GetKey(KeyCode.K) || Input.GetKey(KeyCode.RightArrow)) + { + transform.position = transform.position + (transform.right * movementSpeed * Time.deltaTime); + } + + if (Input.GetKey(KeyCode.U) || Input.GetKey(KeyCode.UpArrow)) + { + transform.position = transform.position + (transform.forward * movementSpeed * Time.deltaTime); + } + + if (Input.GetKey(KeyCode.J) || Input.GetKey(KeyCode.DownArrow)) + { + transform.position = transform.position + (-transform.forward * movementSpeed * Time.deltaTime); + } + if (Input.GetKey(KeyCode.Q)) + { + transform.position = transform.position + (transform.up * movementSpeed * Time.deltaTime); + } + if (Input.GetKey(KeyCode.E)) + { + transform.position = transform.position + (-transform.up * movementSpeed * Time.deltaTime); + } + + if (Input.GetKey(KeyCode.R) || Input.GetKey(KeyCode.PageUp)) + { + transform.position = transform.position + (Vector3.up * movementSpeed * Time.deltaTime); + } + + if (Input.GetKey(KeyCode.F) || Input.GetKey(KeyCode.PageDown)) + { + transform.position = transform.position + (-Vector3.up * movementSpeed * Time.deltaTime); + } + + if (looking) + { + float newRotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * freeLookSensitivity; + float newRotationY = transform.localEulerAngles.x - Input.GetAxis("Mouse Y") * freeLookSensitivity; + transform.localEulerAngles = new Vector3(newRotationY, newRotationX, 0f); + } + + float axis = Input.GetAxis("Mouse ScrollWheel"); + if (axis != 0) + { + var zoomSensitivity = fastMode ? this.fastZoomSensitivity : this.zoomSensitivity; + transform.position = transform.position + transform.forward * axis * zoomSensitivity; + } + + if (Input.GetKeyDown(KeyCode.Mouse1)) + { + StartLooking(); + } + else if (Input.GetKeyUp(KeyCode.Mouse1)) + { + StopLooking(); + } + } + + void OnDisable() + { + StopLooking(); + } + + /// + /// Enable free looking. + /// + public void StartLooking() + { + looking = true; + Cursor.visible = false; + Cursor.lockState = CursorLockMode.Locked; + } + + /// + /// Disable free looking. + /// + public void StopLooking() + { + looking = false; + Cursor.visible = true; + Cursor.lockState = CursorLockMode.None; + } +} \ No newline at end of file -- cgit v1.1-26-g67d0