void CreatePath() { if (pm == null) { pm = GameObject.Find("PathManager"); } if (pm == null) { pm = new GameObject("PathManager"); } BezierPath path = new GameObject("Path" + pm.transform.childCount.ToString()).AddComponent <BezierPath>(); path.transform.SetParent(pm.transform); path.transform.localPosition = Vector3.zero; path.transform.localRotation = Quaternion.identity; Selection.activeGameObject = path.gameObject; GameObject bonePrefab = Resources.Load <GameObject>("BoneGenerator"); GameObject bone = Instantiate(bonePrefab); BoneGenerator boneGenerator = bone.GetComponent <BoneGenerator>(); boneGenerator.transform.SetParent(path.transform); string fpath = EditorUtility.OpenFilePanel("BVH Import", Application.dataPath, "bvh"); if (string.IsNullOrEmpty(fpath)) { EditorUtility.DisplayDialog("Editor", "讀取BVH檔案失敗", "OK"); return; } path.fpath = fpath; }
private void Awake() { _boneGenerator = FindObjectOfType <BoneGenerator>(); foreach (Transform border in transform) { if (border.TryGetComponent(out BoxCollider boxCollider)) { _borderColliders.Add(boxCollider); } } }
void ImportBVH() { string fpath = EditorUtility.OpenFilePanel("BVH Import", Application.dataPath, "bvh"); if (string.IsNullOrEmpty(fpath)) { EditorUtility.DisplayDialog("Editor", "讀取BVH檔案失敗", "OK"); return; } BoneGenerator boneGenerator = _Path.GetComponentInChildren <BoneGenerator>(); _Path.fpath = fpath; }
// Start is called before the first frame update void Start() { boneGenerator = GetComponentInChildren <BoneGenerator>(); if (boneGenerator.Parse(fpath) == 0) { boneGenerator.SetPath(simulateBezierPath); boneGenerator.GenerateJointBone(); boneGenerator.Play(); } else { Debug.Log("Bvh Data Error!"); } }
void ImportPath() { string path = EditorUtility.OpenFilePanel("File Import", Application.dataPath, "json"); if (string.IsNullOrEmpty(path)) { EditorUtility.DisplayDialog("Editor", "讀取路徑檔案失敗", "OK"); return; } string jsonContent; using (StreamReader reader = new StreamReader(path)) { jsonContent = reader.ReadToEnd(); } PathData data = JsonUtility.FromJson <PathData>(jsonContent); if (data == null) { EditorUtility.DisplayDialog("Editor", "讀取檔案失敗", "OK"); return; } while (_Path.transform.childCount > 0) { DestroyImmediate(_Path.transform.GetChild(0).gameObject); } _Path._ctrlPoint.Clear(); _Path._ctrlPoint = data._ctrlPoint; _Path.nodes = new Transform[_Path._ctrlPoint.Count]; GameObject bonePrefab = Resources.Load <GameObject>("BoneGenerator"); GameObject bone = Instantiate(bonePrefab); BoneGenerator boneGenerator = bone.GetComponent <BoneGenerator>(); boneGenerator.transform.SetParent(_Path.transform); _Path.fpath = data._fpath; // Create Path for (int i = 0; i < _Path._ctrlPoint.Count; i++) { // Create obj GameObject node = new GameObject("Node (" + i + ")"); GameObject up = new GameObject("Slope_Up"); GameObject down = new GameObject("Slope_Down"); // Bind node.transform.SetParent(_Path.transform); up.transform.SetParent(node.transform); down.transform.SetParent(node.transform); // Set pos node.transform.position = _Path._ctrlPoint[i].ori; up.transform.position = _Path._ctrlPoint[i].up; down.transform.position = _Path._ctrlPoint[i].down; _Path.nodes[i] = node.transform; } }
void PausePath() { BoneGenerator bg = _Path.GetComponentInChildren <BoneGenerator>(); bg.isPaused = true; }
void PlayPath() { BoneGenerator bg = _Path.GetComponentInChildren <BoneGenerator>(); bg.isPaused = false; }
void DrawPathGUI() { if (_Path == null) { return; } // Edit Area EditorGUILayout.LabelField("Edit", EditorUtils.titleStyle); EditorGUILayout.BeginVertical("box"); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button(_contentCreate, GUILayout.Width(Button_Size), GUILayout.Height(Button_Size))) { CreatePath(); } if (GUILayout.Button(_contentDestroy, GUILayout.Width(Button_Size), GUILayout.Height(Button_Size))) { if (EditorUtility.DisplayDialog("Path", "你確定要刪除路徑", "Yes", "No")) { DestroyImmediate(_Path.gameObject); } } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); EditorGUILayout.LabelField("Node Modify", EditorUtils.titleStyle); EditorGUILayout.BeginVertical("box"); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button(_contentAdd, GUILayout.Width(Button_Size), GUILayout.Height(Button_Size))) { AddNode(); } if (GUILayout.Button(_contentRemove, GUILayout.Width(Button_Size), GUILayout.Height(Button_Size))) { RemoveNode(); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); //Play Pause EditorGUILayout.LabelField("Action", EditorUtils.titleStyle); EditorGUILayout.BeginVertical("box"); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button(_contentPlay, GUILayout.Width(Button_Size), GUILayout.Height(Button_Size))) { PlayPath(); } BoneGenerator bg = _Path.GetComponentInChildren <BoneGenerator>(); GUI.backgroundColor = bg.isPaused ? EditorUtils.guiBlackColor : EditorUtils.guiDefaultColor; if (GUILayout.Button(_contentPause, GUILayout.Width(Button_Size), GUILayout.Height(Button_Size))) { PausePath(); } GUI.backgroundColor = EditorUtils.guiDefaultColor; GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); _Path.moveSpeed = EditorGUILayout.Slider("移動速度", _Path.moveSpeed, 0.5f, 4f); EditorGUILayout.EndVertical(); // Camera Control EditorGUILayout.LabelField("Camera Control", EditorUtils.titleStyle); EditorGUILayout.BeginVertical("box"); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button(_contentFixed, GUILayout.Width(Button_Size), GUILayout.Height(Button_Size))) { SetCamera(0); } if (GUILayout.Button(_contentBack, GUILayout.Width(Button_Size), GUILayout.Height(Button_Size))) { SetCamera(1); } if (GUILayout.Button(_contentTop, GUILayout.Width(Button_Size), GUILayout.Height(Button_Size))) { SetCamera(2); } if (GUILayout.Button(_contentSide, GUILayout.Width(Button_Size), GUILayout.Height(Button_Size))) { if (_cameraMode == 4) { SetCamera(3); } else { SetCamera(4); } } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); // File Area EditorGUILayout.LabelField("File", EditorUtils.titleStyle); EditorGUILayout.BeginVertical("box"); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button(_contentImportPath, GUILayout.Width(100), GUILayout.Height(Button_Size))) { ImportPath(); } if (GUILayout.Button(_contentBVH, GUILayout.Width(100), GUILayout.Height(Button_Size))) { ImportBVH(); } if (GUILayout.Button(_contentExportPath, GUILayout.Width(100), GUILayout.Height(Button_Size))) { ExportPath(); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); }
void ImportLevel() { string path = EditorUtility.OpenFilePanel("Level Import", Application.dataPath, "json"); if (string.IsNullOrEmpty(path)) { EditorUtility.DisplayDialog("Level", "讀取Level檔案失敗", "OK"); return; } string jsonContent; using (StreamReader reader = new StreamReader(path)) { jsonContent = reader.ReadToEnd(); } LevelData loadLevel = JsonUtility.FromJson <LevelData>(jsonContent); if (loadLevel == null) { EditorUtility.DisplayDialog("LevelEditor", "解析路徑檔案失敗", "OK"); return; } if (pm == null) { pm = GameObject.Find("PathManager"); } if (pm == null) { pm = new GameObject("PathManager"); } while (pm.transform.childCount > 0) { DestroyImmediate(pm.transform.GetChild(0).gameObject); } PathData[] paths = loadLevel._paths; for (int i = 0; i < paths.Length; i++) { BezierPath bp = new GameObject("Path" + i.ToString()).AddComponent <BezierPath>(); bp.transform.SetParent(pm.transform); bp.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity); bp._ctrlPoint = paths[i]._ctrlPoint; bp.nodes = new Transform[paths[i]._pointLength]; GameObject bonePrefab = Resources.Load <GameObject>("BoneGenerator"); GameObject bone = Instantiate(bonePrefab); BoneGenerator boneGenerator = bone.GetComponent <BoneGenerator>(); boneGenerator.transform.SetParent(bp.transform); bp.fpath = paths[i]._fpath; for (int j = 0; j < paths[i]._pointLength; j++) { // Create obj GameObject node = new GameObject("Node (" + j + ")"); GameObject up = new GameObject("Slope_Up"); GameObject down = new GameObject("Slope_Down"); // Bind node.transform.SetParent(bp.transform); up.transform.SetParent(node.transform); down.transform.SetParent(node.transform); // Set pos node.transform.position = paths[i]._ctrlPoint[j].ori; up.transform.position = paths[i]._ctrlPoint[j].up; down.transform.position = paths[i]._ctrlPoint[j].down; bp.nodes[j] = node.transform; } } }
private void Awake() { _boneGenerator = FindObjectOfType <BoneGenerator>(); }