using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEditor;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
public class SelectionEditor : EditorWindow
|
|
{
|
|
|
|
public class Data
|
|
{
|
|
public bool isKinematic = false;
|
|
}
|
|
|
|
Vector2 m_selectionScroll;
|
|
GameObject[] selectedGameObjects => m_selecteData.Keys.ToArray();
|
|
Scene[] activeScenes;
|
|
string[] activeSceneNames;
|
|
|
|
#region Settings
|
|
bool m_SettingsFoldout = true;
|
|
float simulationTime = 5;
|
|
bool showSimulation;
|
|
bool m_CollisionBetweenScenes = true;
|
|
bool m_CollideWithNonSelected;
|
|
#endregion Settings
|
|
|
|
Dictionary<GameObject, Data> m_selecteData = new Dictionary<GameObject, Data>();
|
|
|
|
|
|
[MenuItem("Tools/Selection Test")]
|
|
public static void OpenEditor()
|
|
{
|
|
SelectionEditor window = (SelectionEditor)EditorWindow.GetWindow(typeof(SelectionEditor));
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
OnSelectionChange();
|
|
}
|
|
|
|
void OnGUI()
|
|
{
|
|
SettingsGUI();
|
|
EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
|
|
SelectionGUI();
|
|
ButtonGUI();
|
|
}
|
|
|
|
public void SettingsGUI()
|
|
{
|
|
|
|
m_SettingsFoldout = EditorGUILayout.BeginFoldoutHeaderGroup(m_SettingsFoldout,"Base Settings", EditorStyles.foldoutHeader);
|
|
if (m_SettingsFoldout)
|
|
{
|
|
EditorGUI.indentLevel++;
|
|
EditorGUILayout.BeginHorizontal();
|
|
simulationTime = EditorGUILayout.FloatField("Simulation Time", simulationTime);
|
|
showSimulation = EditorGUILayout.Toggle("Show Simulation", showSimulation);
|
|
EditorGUILayout.EndHorizontal();
|
|
|
|
m_CollisionBetweenScenes = EditorGUILayout.Toggle(new GUIContent("Multi-Scene Collision", "Allow objects from different scenes to collide"), m_CollisionBetweenScenes);
|
|
m_CollideWithNonSelected = EditorGUILayout.Toggle(new GUIContent("Non-selected Collision", "Allow selected objects to collide with existing colliders"), m_CollideWithNonSelected);
|
|
}
|
|
EditorGUI.EndFoldoutHeaderGroup();
|
|
|
|
EditorGUI.indentLevel--;
|
|
}
|
|
|
|
public void SelectionGUI()
|
|
{
|
|
GUILayout.BeginHorizontal();
|
|
GUILayout.Label("Selection -", EditorStyles.boldLabel);
|
|
if (activeSceneNames.Length > 0)
|
|
GUILayout.Label($"({string.Join(", ", activeSceneNames)})");
|
|
GUILayout.FlexibleSpace();
|
|
GUILayout.EndHorizontal();
|
|
|
|
//Rect _scrollRect = GUILayoutUtility.GetRect(position.width - 20, 50);
|
|
//GUI.Box(_scrollRect,"");
|
|
m_selectionScroll = EditorGUILayout.BeginScrollView(m_selectionScroll);
|
|
EditorGUI.indentLevel++;
|
|
foreach (GameObject selected in selectedGameObjects)
|
|
{
|
|
if (m_selecteData[selected].isKinematic)
|
|
GUI.color = Color.red;
|
|
|
|
EditorGUILayout.BeginHorizontal();
|
|
EditorGUILayout.LabelField(new GUIContent(selected.name, PrefabUtility.GetIconForGameObject(selected)));
|
|
GUILayout.FlexibleSpace();
|
|
|
|
if (GUILayout.Button(m_selecteData[selected].isKinematic ? "Simulate" : "Kinematic"))
|
|
{
|
|
m_selecteData[selected].isKinematic = !m_selecteData[selected].isKinematic;
|
|
}
|
|
|
|
GUI.color = Color.white;
|
|
|
|
EditorGUILayout.EndHorizontal();
|
|
}
|
|
EditorGUI.indentLevel--;
|
|
EditorGUILayout.EndScrollView();
|
|
}
|
|
|
|
public void ButtonGUI()
|
|
{
|
|
GUILayout.FlexibleSpace();
|
|
EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
|
|
GUILayout.BeginHorizontal();
|
|
GUILayout.FlexibleSpace();
|
|
GUILayout.Button("Start", GUILayout.Width(position.width / 2));
|
|
GUILayout.FlexibleSpace();
|
|
GUILayout.EndHorizontal();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnSelectionChange()
|
|
{
|
|
GameObject[] _objectsToRemove = selectedGameObjects.Except(Selection.gameObjects).ToArray();
|
|
GameObject[] _objectsToAdd = Selection.gameObjects.Except(selectedGameObjects).ToArray();
|
|
|
|
foreach (GameObject gameObject in _objectsToRemove)
|
|
m_selecteData.Remove(gameObject);
|
|
|
|
foreach (GameObject gameObject in _objectsToAdd)
|
|
m_selecteData.Add(gameObject, new Data());
|
|
|
|
m_selecteData.OrderBy(p => p.Key.transform.GetGlobalIndex());
|
|
|
|
activeScenes = selectedGameObjects.Select(p => p.scene).Distinct().ToArray();
|
|
activeSceneNames = activeScenes.Select(p => !string.IsNullOrEmpty(p.name) ? p.name : "Untitled").ToArray();
|
|
Repaint();
|
|
|
|
}
|
|
}
|