diff options
author | chai <215380520@qq.com> | 2024-03-14 11:43:40 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2024-03-14 11:43:40 +0800 |
commit | cc55520a19043a7b4870858e962fa3e20c46bc39 (patch) | |
tree | b437f788e506a48ec16a215c6965b8170f15d5f6 /_Debug/REPL.cs | |
parent | 54c872fa42b1ba0fdbcfe812b80bb8eb0cfe108f (diff) |
*misc
Diffstat (limited to '_Debug/REPL.cs')
-rw-r--r-- | _Debug/REPL.cs | 124 |
1 files changed, 124 insertions, 0 deletions
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; + } + } + } +} |