当前位置:网站首页>Et5.0 simply transform referencecollectorieditor
Et5.0 simply transform referencecollectorieditor
2022-06-13 00:50:00 【Small fish game development】
Change all at once display to page turning
The reason for the change : I use ReferenceCollector As a resource reference , Some objects reference thousands of objects . I got stuck when I wanted to check .
Why do you reference thousands of objects ? Because each unit in the definition scene has a unique resource ID, All units are unique ID Generating objects
Now that unity is defined ID, Then you need a unified reference . For use in accordance with ID Find actual prefab , Then thousands of objects will be referenced by a single object
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
//Object Is not C# In the foundation Object, It is UnityEngine.Object
using Object = UnityEngine.Object;
// Customize ReferenceCollector Class display and function in the interface
[CustomEditor(typeof(ReferenceCollector))]
// Editors without this attribute will prompt when multiple objects are selected “Multi-object editing not supported”
[CanEditMultipleObjects]
public class ReferenceCollectorEditor : Editor
{
// Enter in textfield String in
private string searchKey
{
get
{
return _searchKey;
}
set
{
if (_searchKey != value)
{
_searchKey = value;
heroPrefab = referenceCollector.Get<Object>(searchKey);
}
}
}
private ReferenceCollector referenceCollector;
private Object heroPrefab;
private string _searchKey = "";
int page;
private void DelNullReference()
{
var dataProperty = serializedObject.FindProperty("data");
for (int i = dataProperty.arraySize - 1; i >= 0; i--)
{
var gameObjectProperty = dataProperty.GetArrayElementAtIndex(i).FindPropertyRelative("gameObject");
if (gameObjectProperty.objectReferenceValue == null)
{
dataProperty.DeleteArrayElementAtIndex(i);
}
}
}
private void OnEnable()
{
// Will be selected gameobject Attached to ReferenceCollector Assigned to... In the editor class ReferenceCollector, Convenient operation
referenceCollector = (ReferenceCollector)target;
}
public override void OnInspectorGUI()
{
var dataProperty = serializedObject.FindProperty("data");
var totalPage = dataProperty.arraySize / 10;
totalPage += dataProperty.arraySize % 10 == 0 ? -1 : 0;
page = Mathf.Max(0, Mathf.Min(page, totalPage));
//page = page % totalPage;
// send ReferenceCollector Supports undo operations , also Redo, But it is not used here
Undo.RecordObject(referenceCollector, "Changed Settings");
// Start horizontal layout , If it is a relatively new version of learning U3D Of , May not know this thing , This is old GUI Systematic knowledge , Except for the editor , It can also be used in generated games
GUILayout.BeginHorizontal();
// Here are some if Click the button to return true Call the things inside
if (GUILayout.Button(" Add reference "))
{
// Add new elements , Specific function comments
// Guid.NewGuid().GetHashCode().ToString() It is the default after creation key
AddReference(dataProperty, Guid.NewGuid().GetHashCode().ToString(), null);
}
if (GUILayout.Button(" Delete all "))
{
dataProperty.ClearArray();
}
if (GUILayout.Button(" Delete empty references "))
{
DelNullReference();
}
if (GUILayout.Button(" Sort "))
{
referenceCollector.Sort();
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
// You can edit searchKey Assign a value , Just enter the corresponding Key value , You can click the delete button to delete the corresponding element
searchKey = EditorGUILayout.TextField(searchKey);
// Added can be used to select Object Box of , there object It's also (UnityEngine.Object
// The third parameter is whether only scene Medium Object
EditorGUILayout.ObjectField(heroPrefab, typeof(Object), false);
if (GUILayout.Button(" Delete "))
{
referenceCollector.Remove(searchKey);
heroPrefab = null;
}
GUILayout.EndHorizontal();
EditorGUILayout.Space();
var delList = new List<int>();
SerializedProperty property;
// Traverse ReferenceCollector in data list All elements of , Display in the editor
GUILayout.Label($"{
page+1}/{
totalPage+1}");
GUILayout.BeginHorizontal();
if (GUILayout.Button(" The previous page "))
{
if (page > 0)
{
page--;
Event.current.Use();
}
}
if (GUILayout.Button(" The next page "))
{
if (page < totalPage)
{
page++;
Event.current.Use();
}
}
GUILayout.EndHorizontal();
for (var i=0;i< 10; i++)
{
var index = page *10+ i;
if (index >= dataProperty.arraySize)
continue;
GUILayout.BeginHorizontal();
// The knowledge here is ReferenceCollector In the said
property = dataProperty.GetArrayElementAtIndex(index).FindPropertyRelative("key");
EditorGUILayout.TextField(property.stringValue, GUILayout.Width(150));
property = dataProperty.GetArrayElementAtIndex(index).FindPropertyRelative("gameObject");
EditorGUILayout.ObjectField(property.objectReferenceValue, typeof(Object), true);
if (GUILayout.Button("X"))
{
// Add elements to delete list
delList.Add(index);
}
GUILayout.EndHorizontal();
}
var eventType = Event.current.type;
// stay Inspector Create an area on the window , Drag the resource object to the area , Get the object dragged to the area
if (eventType == EventType.DragUpdated || eventType == EventType.DragPerform)
{
// Show a copy icon on the drag
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
if (eventType == EventType.DragPerform)
{
DragAndDrop.AcceptDrag();
foreach (var o in DragAndDrop.objectReferences)
{
AddReference(dataProperty, o.name, o);
}
}
Event.current.Use();
}
// Traverse delete list, Delete it
foreach (var i in delList)
{
dataProperty.DeleteArrayElementAtIndex(i);
}
serializedObject.ApplyModifiedProperties();
serializedObject.UpdateIfRequiredOrScript();
}
// Additive elements , The specific knowledge points are ReferenceCollector I said
private void AddReference(SerializedProperty dataProperty, string key, Object obj)
{
int index = dataProperty.arraySize;
dataProperty.InsertArrayElementAtIndex(index);
var element = dataProperty.GetArrayElementAtIndex(index);
element.FindPropertyRelative("key").stringValue = key;
element.FindPropertyRelative("gameObject").objectReferenceValue = obj;
}
}
边栏推荐
- .net core 抛异常对性能影响的求证之路
- Static analysis of malicious code
- kotlin 协程withContext切换线程
- [virtual machine] notes on virtual machine environment problems
- . The way to prove the effect of throwing exceptions on performance in. Net core
- Target recognition gadget
- [JS component] create a custom horizontal and vertical scroll bar following the steam style
- 今日在家休息
- Notes: the 11th and 12th generation mobile versions of Intel support the native thunderbolt4 interface, but the desktop version does not
- How many steps are appropriate for each cycle of deep learning?
猜你喜欢
Aunt learning code sequel: ability to sling a large number of programmers
.net core 抛异常对性能影响的求证之路
Kotlin 协程的四种启动模式
(01).NET MAUI实战 建项目
Static analysis of malicious code
Kotlin 协程的作用域构建器 coroutineScope与runBlocking 与supervisorScope,协程同步运行,协程挂掉的时候其他协程如何不被挂掉。
pytorch和tensorflow有什么区别?
什么是 Meebits?一个简短的解释
Arduino control tm1637 common positive four digit nixie tube
Buuctf's babysql[geek challenge 2019]
随机推荐
Expression tree - medium order printout
What is pytorch? Explain the basic concepts of pytorch
[JS component library] drag sorting component
Download nail live playback through packet capturing
Kotlin collaboration, the life cycle of a job
STM32 USB Basics
Map from getting started to performance optimization
DNS attack surface analysis
人神共愤,唐山“群殴女性事件”细节...
Antdpro - protable realizes the linkage effect of two selection boxes
Android Weather
天津银行周传凯:从 0 到 1,我的分布式数据库落地经验谈
三栏简约typecho主题Lanstar/蓝星typecho主题
What is meebits? A brief explanation
Androi天氣
Three column simple Typecho theme lanstar/ Blue Star Typecho theme
[JS component] calendar
Can GPU acceleration pytorch work?
[JS component] browse progress bar
Dynamic planning - good article link