BITFALL/Assets/BITKit/UnityEditor/SceneBasedEnvironmentCatego...

56 lines
1.3 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UIElements;
namespace BITKit.GameEditor
{
//This is a helper can make scene uncategory assets to be categorized
public sealed class SceneBasedEnvironmentCategoryWindow : EditorWindow
{
[MenuItem("Tools/Scene/Category Window")]
public static void Open()
{
var window = GetWindow<SceneBasedEnvironmentCategoryWindow>();
window.Show();
}
private Label reportLabel;
private void OnEnable()
{
Rebuild();
}
private void Rebuild()
{
var button = rootVisualElement.Create<Button>();
reportLabel = rootVisualElement.Create<Label>();
reportLabel.text = "0";
button.text = "Execute";
button.clicked += Execute;
}
private void Execute()
{
var stringBuilder = new System.Text.StringBuilder();
//Get All Root GameObject in editor
var objects = UnityEditor.SceneManagement.StageUtility.GetCurrentStageHandle().FindComponentsOfType<Transform>()
.Where(PrefabUtility.IsPartOfPrefabAsset).ToArray();
stringBuilder.AppendLine($"Total: {objects.Length}");
foreach (var VARIABLE in objects)
{
}
reportLabel.text = stringBuilder.ToString();
}
}
}