summaryrefslogtreecommitdiff
path: root/_Debug
diff options
context:
space:
mode:
Diffstat (limited to '_Debug')
-rw-r--r--_Debug/DebugRigidBody.cs140
-rw-r--r--_Debug/REPL.cs124
-rw-r--r--_Debug/SimpleMoveCamera.cs139
3 files changed, 403 insertions, 0 deletions
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>();
+ camera.AddComponent<SimpleMoveCamera>();
+
+ 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<MonoBehaviour>();
+ 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<DebugRigidBody>();
+ //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<string, CubeParams> targets = new Dictionary<string, CubeParams>{
+ {"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<MonoBehaviour>();
+ 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<DebugRigidBody>();
+ 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;
+/// <summary>
+/// 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
+///
+/// </summary>
+public class SimpleMoveCamera : MonoBehaviour
+{
+ /// <summary>
+ /// Normal speed of camera movement.
+ /// </summary>
+ public float movementSpeed = 10f;
+
+ /// <summary>
+ /// Speed of camera movement when shift is held down,
+ /// </summary>
+ public float fastMovementSpeed = 100f;
+
+ /// <summary>
+ /// Sensitivity for free look.
+ /// </summary>
+ public float freeLookSensitivity = 3f;
+
+ /// <summary>
+ /// Amount to zoom the camera when using the mouse wheel.
+ /// </summary>
+ public float zoomSensitivity = 10f;
+
+ /// <summary>
+ /// Amount to zoom the camera when using the mouse wheel (fast mode).
+ /// </summary>
+ public float fastZoomSensitivity = 50f;
+
+ /// <summary>
+ /// Set to true when free looking (on right mouse button).
+ /// </summary>
+ 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();
+ }
+
+ /// <summary>
+ /// Enable free looking.
+ /// </summary>
+ public void StartLooking()
+ {
+ looking = true;
+ Cursor.visible = false;
+ Cursor.lockState = CursorLockMode.Locked;
+ }
+
+ /// <summary>
+ /// Disable free looking.
+ /// </summary>
+ public void StopLooking()
+ {
+ looking = false;
+ Cursor.visible = true;
+ Cursor.lockState = CursorLockMode.None;
+ }
+} \ No newline at end of file