77 lines
2.2 KiB
C#
77 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace Thousandto.Editor.Test
|
|
{
|
|
public partial class SplitTerrainWindow : UnityEditor.EditorWindow
|
|
{
|
|
void LoadTerrainData()
|
|
{
|
|
TerrainData td = null;
|
|
|
|
if (!IsSelectionInHierarchy())
|
|
{
|
|
td = LoadSelectedObject<TerrainData>();
|
|
|
|
}
|
|
|
|
if (td == null)
|
|
{
|
|
var terrain = LoadSelectedObject<Terrain>(true);
|
|
if (terrain != null)
|
|
td = terrain.terrainData;
|
|
}
|
|
|
|
if (td != null)
|
|
_curTerrainData = td;
|
|
}
|
|
|
|
T LoadSelectedObject<T>(bool useGetComponent = false) where T : UnityEngine.Object
|
|
{
|
|
T ret = null;
|
|
if (ret == null)
|
|
{
|
|
if (!IsSelectionInHierarchy())
|
|
{
|
|
if (useGetComponent && typeof(T).IsSubclassOf(typeof(Component)))
|
|
{
|
|
if (_curSelectObj is Component)
|
|
ret = ((Component)_curSelectObj).GetComponentInChildren<T>();
|
|
else if (_curSelectObj is GameObject)
|
|
ret = ((GameObject)_curSelectObj).GetComponentInChildren<T>();
|
|
}
|
|
|
|
if (ret == null)
|
|
ret = _curSelectObj as T;
|
|
|
|
}
|
|
else
|
|
{
|
|
if (useGetComponent)
|
|
{
|
|
if (_curSelectObj is GameObject)
|
|
{
|
|
GameObject go = _curSelectObj as GameObject;
|
|
ret = go.GetComponentInChildren<T>();
|
|
}
|
|
else if (_curSelectObj is Behaviour)
|
|
{
|
|
Behaviour bh = _curSelectObj as Behaviour;
|
|
ret = bh.GetComponentInChildren<T>();
|
|
}
|
|
}
|
|
else
|
|
ret = _curSelectObj as T;
|
|
}
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
}
|
|
}
|