diff options
Diffstat (limited to 'Docs')
-rw-r--r-- | Docs/TAB_AddCamera.txt | 11 | ||||
-rw-r--r-- | Docs/TAB_AddDebugRigidBody.txt | 143 | ||||
-rw-r--r-- | Docs/TAB_Camera.txt | 140 | ||||
-rw-r--r-- | Docs/TAB_DebugRigidBody.txt | 135 | ||||
-rw-r--r-- | Docs/TAB_UnityExploerer.txt | 28 | ||||
-rw-r--r-- | Docs/资料.xlsx | bin | 4611242 -> 5842601 bytes |
6 files changed, 457 insertions, 0 deletions
diff --git a/Docs/TAB_AddCamera.txt b/Docs/TAB_AddCamera.txt new file mode 100644 index 0000000..d456f6d --- /dev/null +++ b/Docs/TAB_AddCamera.txt @@ -0,0 +1,11 @@ + + GameObject camera = GameObject.Find("WanderCamera"); + if(camera != null) + { + GameObject.DestroyImmediate(camera); + } + + camera = new GameObject(); + camera.name = "WanderCamera"; + camera.AddComponent<Camera>(); + camera.AddComponent<SimpleMoveCamera>(); diff --git a/Docs/TAB_AddDebugRigidBody.txt b/Docs/TAB_AddDebugRigidBody.txt new file mode 100644 index 0000000..0af5869 --- /dev/null +++ b/Docs/TAB_AddDebugRigidBody.txt @@ -0,0 +1,143 @@ + +GameObject go = GameObject.Find("Player_Target"); +if (go != null) +{ + + Rigidbody[] rigs = go.transform.GetComponentsInChildren<Rigidbody>(); + for (int i = 0; i < rigs.Length; i++) + { + var rig = rigs[i]; + var comps = rig.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(rig.gameObject.name); + rig.gameObject.AddComponent<DebugRigidBody>(); + } +} + + +GameObject mainCam = GameObject.Find("Main Camera"); +if (mainCam != null) +{ + var comps = mainCam.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(mainCam.name); + mainCam.AddComponent<DebugRigidBody>(); +} + + +string name = "RotationTarget"; +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); + go.AddComponent<DebugRigidBody>(); +} + +string name = "AvaragePosition"; +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); + go.AddComponent<DebugRigidBody>(); +} + +string name = "CameraRotationY"; +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); + go.AddComponent<DebugRigidBody>(); +} + + +string name = "CameraRotationX"; +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); + go.AddComponent<DebugRigidBody>(); +} + + + +string name = "CameraMovement"; +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 = DebugRigidBody.EMode.Cube; +}
\ No newline at end of file diff --git a/Docs/TAB_Camera.txt b/Docs/TAB_Camera.txt new file mode 100644 index 0000000..aa09665 --- /dev/null +++ b/Docs/TAB_Camera.txt @@ -0,0 +1,140 @@ + +/// <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 diff --git a/Docs/TAB_DebugRigidBody.txt b/Docs/TAB_DebugRigidBody.txt new file mode 100644 index 0000000..095c105 --- /dev/null +++ b/Docs/TAB_DebugRigidBody.txt @@ -0,0 +1,135 @@ + +using UnityEngine; + +public class DebugRigidBody : MonoBehaviour +{ + + public enum EMode + { + Axis, + Cube, + } + public EMode mode = EMode.Axis; + + // When added to an object, draws colored rays from the + // transform position. + public int lineCount = 100; + public float radius = 3.0f; + + 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) + { + 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(); + } + else if (mode == EMode.Cube) + { + GL.PushMatrix(); + // Set transformation matrix for drawing to + // match our transform + GL.MultMatrix(transform.localToWorldMatrix); + + float len = 0.05f; + + GL.wireframe = true; + + GL.Begin(GL.QUADS); + + GL.Color(Color.white); + + 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/Docs/TAB_UnityExploerer.txt b/Docs/TAB_UnityExploerer.txt new file mode 100644 index 0000000..ed028a6 --- /dev/null +++ b/Docs/TAB_UnityExploerer.txt @@ -0,0 +1,28 @@ +// To start a Coroutine directly, use "Start(SomeCoroutine());" in REPL mode. + +// To declare a coroutine, you will need to compile it separately. For example: +public class MyCoro +{ + public static IEnumerator Main() + { + while(true){ + GameObject go = GameObject.Find("Player_Target"); + if(go != null ) { + Rigidbody[] rigs = go.transform.GetComponentsInChildren<Rigidbody>(); + for(int i = 0; i < rigs.Length; i++) { + var rig = rigs[i]; + //Debug.Log(rig.gameObject.name); + Debug.DrawLine(rig.transform.position, rig.transform.position + 10*rig.transform.forward); + } + } + yield return null; + } + } +} +// To run this Coroutine in REPL, it would look like "Start(MyCoro.Main());" + + + + + +Start(MyCoro.Main());
\ No newline at end of file diff --git a/Docs/资料.xlsx b/Docs/资料.xlsx Binary files differindex 0d25766..cd5fd1f 100644 --- a/Docs/资料.xlsx +++ b/Docs/资料.xlsx |