183 lines
5.2 KiB
C#
183 lines
5.2 KiB
C#
using Thousandto.Core.Asset;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using UnityEditor;
|
|
using UnityEditor.SceneManagement;
|
|
using UnityEngine;
|
|
|
|
namespace Thousandto.Editor.Test
|
|
{
|
|
public partial class SplitTerrainWindow : UnityEditor.EditorWindow
|
|
{
|
|
#region //私有成员
|
|
private float PosY = 0;
|
|
private TerrainData _curTerrainData = null;
|
|
private string _terrainPath = "";
|
|
private bool _isSelectionChanged = false;
|
|
private UnityEngine.Object _curSelectObj = null;
|
|
private GUIContent _content1;
|
|
private bool _isDisable = false;
|
|
private Vector2 _scrollPos = new Vector2(0, 0);
|
|
private const int WINDOW_WIDTH = 400;
|
|
private bool _bakeStart = false;
|
|
private List<GameObject> _loadedPrefabs;
|
|
#endregion
|
|
|
|
[MenuItem("SplitTerrain/OpenWindow")]
|
|
static void Open()
|
|
{
|
|
SplitTerrainWindow window = UnityEditor.EditorWindow.GetWindowWithRect<SplitTerrainWindow>(new Rect(0, 0, WINDOW_WIDTH, 800), false, "切割地形", true);
|
|
window.maxSize = new Vector2(WINDOW_WIDTH, 800);
|
|
window.Init();
|
|
window.Show();
|
|
}
|
|
|
|
void Init()
|
|
{
|
|
_content1 = new GUIContent("Load all blocks or load the selected one");
|
|
}
|
|
|
|
#region 编辑器自带函数
|
|
void OnInspectorUpdate()
|
|
{
|
|
Repaint();
|
|
|
|
if (_curSelectObj != Selection.activeObject)
|
|
OnSelectionChange();
|
|
|
|
if (_isDisable)
|
|
OnEnable();
|
|
|
|
if(_bakeStart)
|
|
EditorUtility.DisplayProgressBar("Bake", "烘焙lightmap", Lightmapping.buildProgress);
|
|
|
|
}
|
|
|
|
void OnEnable()
|
|
{
|
|
_isDisable = false;
|
|
RegisterSceneRayCastEvent();
|
|
OnSelectionChange();
|
|
|
|
DrawUtils.Initialize();
|
|
}
|
|
|
|
void OnDisable()
|
|
{
|
|
DrawUtils.Uninialize();
|
|
_isDisable = true;
|
|
}
|
|
|
|
void OnDidOpenScene()
|
|
{
|
|
DrawUtils.Uninialize();
|
|
DrawUtils.Initialize();
|
|
}
|
|
|
|
void OnGUI()
|
|
{
|
|
_scrollPos = GUILayout.BeginScrollView(_scrollPos);
|
|
//terrain详细信息以及切割网格的功能
|
|
DrawTerrainInfo();
|
|
DrawSpaceLine(5);
|
|
//loadblock和收集场景上物件
|
|
DrawLoadBlockRegion();
|
|
DrawSpaceLine(5);
|
|
//设置网格材质
|
|
DrawSetMaterialRegion();
|
|
DrawSpaceLine(5);
|
|
//转网格为prefab
|
|
DrawCovertToPrefabRegion();
|
|
DrawSpaceLine(5);
|
|
//场景中辅助划线
|
|
DrawGizmosMeshes();
|
|
DrawSpaceLine(5);
|
|
DrawTexturePreview();
|
|
_isSelectionChanged = false;
|
|
|
|
GUILayout.EndScrollView();
|
|
DrawSpaceLine(5);
|
|
|
|
DrawBakeGUI();
|
|
DrawSpaceLine(5);
|
|
|
|
if (Event.current.type == EventType.MouseDown)
|
|
{
|
|
GUI.FocusControl(null);
|
|
}
|
|
}
|
|
|
|
void OnSelectionChange()
|
|
{
|
|
_curSelectObj = Selection.activeObject;
|
|
|
|
LoadTerrainData();
|
|
ClearPickGos();
|
|
PickTexFromLightmap();
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region 工具函数
|
|
bool IsSelectionInHierarchy()
|
|
{
|
|
string path = AssetDatabase.GetAssetPath(_curSelectObj);
|
|
return !File.Exists(path);
|
|
}
|
|
|
|
void DrawInfo(string tag, ref string member, Action buttonAction = null, string buttonName = "button")
|
|
{
|
|
GUILayout.BeginHorizontal();
|
|
EditorGUI.indentLevel = 1;
|
|
int maxWidth = buttonAction == null ? 200 : 100;
|
|
GUILayout.Label(" " + tag, GUILayout.MaxWidth(maxWidth));
|
|
member = EditorGUILayout.TextField(member);
|
|
|
|
if(buttonAction != null)
|
|
{
|
|
if(GUILayout.Button(buttonName, GUILayout.MaxWidth(100)))
|
|
{
|
|
buttonAction();
|
|
}
|
|
}
|
|
EditorGUI.indentLevel = 0;
|
|
GUILayout.EndHorizontal();
|
|
}
|
|
|
|
public void DrawInfo(string tag, object value)
|
|
{
|
|
GUILayout.BeginHorizontal();
|
|
EditorGUI.indentLevel = 1;
|
|
GUILayout.Label(" " + tag, GUILayout.MaxWidth(200));
|
|
GUILayout.TextField("" + value);
|
|
EditorGUI.indentLevel = 0;
|
|
GUILayout.EndHorizontal();
|
|
}
|
|
|
|
void DrawSplitSetting(string tag, ref int member, string desc)
|
|
{
|
|
GUILayout.BeginHorizontal();
|
|
EditorGUI.indentLevel = 1;
|
|
GUILayout.Label(" " + tag, GUILayout.Width(100));
|
|
member = EditorGUILayout.IntField(member, GUILayout.Width(80));
|
|
GUILayout.Label("x" + member);
|
|
GUILayout.Label(desc);
|
|
EditorGUI.indentLevel = 0;
|
|
GUILayout.EndHorizontal();
|
|
}
|
|
|
|
public void DrawSpaceLine(int num = 3)
|
|
{
|
|
for (int i = 0; i < num; ++i)
|
|
{
|
|
GUILayout.Space(5);
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|