浏览代码

Fixes for Search Window

/main
Thomas ICHÉ 5 年前
当前提交
f6139776
共有 3 个文件被更改,包括 70 次插入8 次删除
  1. 36
      Editor/FindAndReplace/FindAndReplaceWindow.cs
  2. 31
      Runtime/GameObjectExtensions.cs
  3. 11
      Runtime/GameObjectExtensions.cs.meta

36
Editor/FindAndReplace/FindAndReplaceWindow.cs


Layer,
Mesh,
Material,
Selection
}
private void OnEnable()

Mesh meshSearch;
[SerializeField]
Material materialSearch;
[SerializeField]
bool selectionRecurse = false;
[SerializeField]
bool keepPosition = true;

EditorGUIUtility.labelWidth = 120;
GUILayout.Space(4);
GUILayout.Label("Search Scene Objects", Styles.boldLabel);
searchBy = (SearchBy)EditorGUILayout.EnumPopup(Contents.searchBy, searchBy);
searchBy = (SearchBy)EditorGUILayout.EnumPopup(Contents.criteria, searchBy);
switch (searchBy)
{
case SearchBy.Name:

materialSearch = (Material)EditorGUILayout.ObjectField(Contents.materialSearch, materialSearch, typeof(Material), true);
SearchButtonsGUI(searchBy, materialSearch);
break;
case SearchBy.Selection:
selectionRecurse = EditorGUILayout.Toggle(Contents.selectionRecurse, selectionRecurse);
SearchButtonsGUI(searchBy, selectionRecurse);
break;
}

}
EditorGUI.BeginDisabledGroup(prefabReplacement == null);
GUILayout.Label("Keep Properties:");
GUILayout.Label("Keep Properties from Original:");
using (new GUILayout.HorizontalScope())
{

}
}
break;
case SearchBy.Selection:
foreach(var selected in Selection.gameObjects)
{
bool recurse = (bool)criteria;
if(!recurse)
query.Add(selected);
else
query.AddRange(selected.GetAllChildren());
}
break;
}
switch (op)

{
GUILayout.Label("Search Results", Styles.boldLabel);
GUILayout.FlexibleSpace();
if(GUILayout.Button("From Selection", GUILayout.Height(24)))
if(GUILayout.Button("Select in Scene", GUILayout.Height(24)))
searchResults = Selection.gameObjects.ToList();
Selection.objects = searchResults.ToArray();
if(GUILayout.Button("Select", GUILayout.Height(24)))
if(GUILayout.Button("Clear", GUILayout.Height(24)))
Selection.objects = searchResults.ToArray();
searchResults.Clear();
}
}

static class Contents
{
public static GUIContent title = new GUIContent("Find and Replace", (Texture)EditorGUIUtility.LoadRequired("ViewToolZoom On"));
public static GUIContent searchBy = new GUIContent("Search by");
public static GUIContent criteria = new GUIContent("Criteria");
public static GUIContent nameSearch = new GUIContent("GameObject Name");
public static GUIContent tagSearch = new GUIContent("Tag");
public static GUIContent layerSearch = new GUIContent("Layer");

public static GUIContent selectionRecurse = new GUIContent("Include Children");
public static GUIContent prefabReplacement = new GUIContent("Prefab Replacement");
}

31
Runtime/GameObjectExtensions.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class GameObjectExtensions
{
public static IEnumerable<Transform> GetAllChildren(this Transform transform)
{
var stack = new Stack<Transform>();
stack.Push(transform);
while(stack.Count != 0)
{
var t = stack.Pop();
yield return t;
for (int i = 0; i < t.childCount; i++)
{
stack.Push(t.GetChild(i));
}
}
}
public static IEnumerable<GameObject> GetAllChildren(this GameObject gameObject)
{
var all = gameObject.transform.GetAllChildren();
foreach(Transform t in all)
{
yield return t.gameObject;
}
}
}

11
Runtime/GameObjectExtensions.cs.meta


fileFormatVersion: 2
guid: 043df10a698bef24f85a021cc54479c2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存