| | |
| | | [HideInInspector] |
| | | private string newSceneObjResName = ""; |
| | | |
| | | public override void Save(BinaryWriter bw) |
| | | { |
| | | base.Save(bw); |
| | | bw.Write(sceneObjList.Count); |
| | | foreach (var _sceneObject in sceneObjList) |
| | | { |
| | | _sceneObject.Save(bw); |
| | | } |
| | | } |
| | | |
| | | public override void Export(BinaryWriter bw) |
| | | { |
| | | base.Export(bw); |
| | | bw.Write(sceneObjList.Count); |
| | | foreach (var _sceneObject in sceneObjList) |
| | | { |
| | | _sceneObject.Export(bw); |
| | | } |
| | | } |
| | | |
| | | public override void Load(BinaryReader br) |
| | | { |
| | | base.Load(br); |
| | | int _count = br.ReadInt32(); |
| | | for (int i = 0; i < _count; ++i) |
| | | { |
| | | string _resName = br.ReadString(); |
| | | var _sceneData = CreateSceneObject(_resName); |
| | | _sceneData.transform.SetParent(transform); |
| | | _sceneData.Load(br); |
| | | |
| | | sceneObjList.Add(_sceneData); |
| | | } |
| | | } |
| | | |
| | | public override bool DrawUI(GUISkin guiSkin) |
| | | { |
| | | bool _result = false; |
| | |
| | | newSceneObjResName = EditorGUILayout.TextField(newSceneObjResName, guiSkin.textField, GUILayout.Width(100), GUILayout.Height(20)); |
| | | if (GUILayout.Button("添加", guiSkin.button, GUILayout.Width(60), GUILayout.Height(22))) |
| | | { |
| | | Debug.Log("!!!"); |
| | | var _sceneObject = CreateSceneObject(); |
| | | var _sceneObject = CreateSceneObject(newSceneObjResName); |
| | | if (_sceneObject) |
| | | { |
| | | sceneObjList.Add(_sceneObject); |
| | |
| | | |
| | | if (showSceneObjList) |
| | | { |
| | | for (int i = sceneObjList.Count - 1; i >= 0; --i) |
| | | { |
| | | EditorGUILayout.BeginHorizontal(GUILayout.Height(22)); |
| | | EditorGUILayout.LabelField(string.Format("{0}. ResName", (i + 1)), guiSkin.customStyles[0], GUILayout.Height(22), GUILayout.Width(80)); |
| | | var _npcID = sceneObjList[i].resName; |
| | | EditorGUILayout.TextField(sceneObjList[i].resName, guiSkin.textField, GUILayout.Height(20)); |
| | | sceneObjList[i].isObstacle = GUILayout.Toggle(sceneObjList[i].isObstacle, "障碍", guiSkin.button, GUILayout.Width(50), GUILayout.Height(20)); |
| | | if (GUILayout.Button("定高", guiSkin.button, GUILayout.Width(60), GUILayout.Height(20))) |
| | | { |
| | | Vector3 _pos = sceneObjList[i].transform.position; |
| | | _pos.y = 0; |
| | | RaycastHit _hit; |
| | | |
| | | Ray _ray = new Ray(_pos + Vector3.up * 100, Vector3.down); |
| | | if (Physics.Raycast(_ray, out _hit, 200, LayerUtility.WalkbleMask)) |
| | | { |
| | | sceneObjList[i].transform.position = _hit.point; |
| | | } |
| | | } |
| | | if (GUILayout.Button("查找", guiSkin.button, GUILayout.Width(60), GUILayout.Height(20))) |
| | | { |
| | | Selection.activeGameObject = sceneObjList[i].gameObject; |
| | | if (Selection.activeGameObject) |
| | | { |
| | | SceneView.lastActiveSceneView.LookAt(Selection.activeGameObject.transform.position); |
| | | } |
| | | } |
| | | if (GUILayout.Button("删除", guiSkin.button, GUILayout.Width(60), GUILayout.Height(20))) |
| | | { |
| | | DestroyImmediate(sceneObjList[i].gameObject); |
| | | sceneObjList.RemoveAt(i); |
| | | } |
| | | EditorGUILayout.EndHorizontal(); |
| | | } |
| | | } |
| | | EditorGUILayout.EndVertical(); |
| | | } |
| | |
| | | return _result; |
| | | } |
| | | |
| | | private Bhv_SceneObjectData CreateSceneObject() |
| | | private Bhv_SceneObjectData CreateSceneObject(string sceneName = null) |
| | | { |
| | | if (!string.IsNullOrEmpty(newSceneObjResName)) |
| | | if (!string.IsNullOrEmpty(sceneName)) |
| | | { |
| | | string _path = "Assets/ResourcesOut/Mob/Prefab_Race_" + newSceneObjResName + ".prefab"; |
| | | string _path = "Assets/ResourcesOut/Mob/Prefab_Race_" + sceneName + ".prefab"; |
| | | var _obj = AssetDatabase.LoadAssetAtPath<GameObject>(_path); |
| | | if (!_obj) |
| | | { |
| | |
| | | } |
| | | _obj = Instantiate(_obj); |
| | | var _sceneObjData = _obj.AddComponent<Bhv_SceneObjectData>(); |
| | | _sceneObjData.resName = newSceneObjResName; |
| | | _sceneObjData.resName = sceneName; |
| | | RaycastHit _hit; |
| | | Ray _ray = SceneView.lastActiveSceneView.camera.ViewportPointToRay(new Vector3(.5f, .5f, 0)); |
| | | if (Physics.Raycast(_ray, out _hit, 1000f, LayerUtility.WalkbleMask)) |