浏览代码

State Machine Icon + Find and Replace

/main
Thomas ICHÉ 5 年前
当前提交
102cbdd5
共有 2 个文件被更改,包括 62 次插入11 次删除
  1. 67
      Editor/FindAndReplace/FindAndReplaceWindow.cs
  2. 6
      Icons/ic-StateMachine.png.meta

67
Editor/FindAndReplace/FindAndReplaceWindow.cs


private void OnEnable()
{
titleContent = Contents.title;
minSize = new Vector2(640, 280);
}
private void OnGUI()

void SearchControlsGUI()
{
EditorGUIUtility.labelWidth = 120;
GUILayout.Space(8);
GUILayout.Label("Search and Filter", EditorStyles.boldLabel);
GUILayout.Label("Search and Filter", Styles.boldLabel);
searchBy = (SearchBy)EditorGUILayout.EnumPopup(Contents.searchBy, searchBy);
switch(searchBy)
{

GUILayout.FlexibleSpace();
GUILayout.Label("Replace By", EditorStyles.boldLabel);
GUILayout.Label("Replace By", Styles.boldLabel);
GUILayout.Button("Replace All", GUILayout.Height(32));
if (GUILayout.Button("Replace All", GUILayout.Height(32)) && prefabReplacement != null)
{
Undo.RecordObjects(searchResults.ToArray(), "Replace Objects");
for(int i = 0; i < searchResults.Count; i++)
{
var obj = searchResults[i];
var newObj = SwapObject(obj, prefabReplacement, searchResults);
searchResults[i] = newObj;
}
}
GameObject SwapObject(GameObject toReplace, GameObject replacement, List<GameObject> others)
{
var newObj = Instantiate<GameObject>(replacement);
newObj.name = replacement.name;
newObj.transform.position = toReplace.transform.position;
newObj.transform.rotation = toReplace.transform.rotation;
newObj.transform.parent = toReplace.transform.parent;
newObj.transform.localScale = toReplace.transform.localScale;
newObj.tag = toReplace.tag;
newObj.layer = toReplace.layer;
newObj.isStatic = toReplace.isStatic;
foreach(var other in others)
{
if(other.transform.parent == toReplace.transform)
{
other.transform.parent = newObj.transform;
}
}
DestroyImmediate(toReplace);
return newObj;
}
void SearchButtonsGUI(SearchBy by, object criteria)
{
using (new GUILayout.HorizontalScope())

void SearchResultsGUI()
{
GUILayout.Space(8);
GUILayout.Label("Search Results", EditorStyles.boldLabel);
GUILayout.Label("Search Results", Styles.boldLabel);
if(GUILayout.Button("From Selection"))
if(GUILayout.Button("From Selection", GUILayout.Height(24)))
if(GUILayout.Button("Select"))
if(GUILayout.Button("Select", GUILayout.Height(24)))
{
Selection.objects = searchResults.ToArray();
}

{
GameObject toRemove = null;
// Trim all nulls
searchResults = searchResults.Where(o => o != null).ToList();
foreach(var obj in searchResults)
{

public static GUIContent materialSearch = new GUIContent("Material");
public static GUIContent prefabReplacement = new GUIContent("Prefab Replacement");
}
static class Styles
{
public static readonly GUIStyle boldLabel = GetBoldLabel();
static GUIStyle GetBoldLabel()
{
var style = new GUIStyle(EditorStyles.boldLabel);
style.fontSize = 14;
return style;
}
}
}
}

6
Icons/ic-StateMachine.png.meta


maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
filterMode: 0
aniso: 1
mipBias: -100
wrapU: 1

maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0

maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0

正在加载...
取消
保存