forked from Shardstone/trail-into-darkness
Added a bit of character selection UI
This commit is contained in:
@@ -1,54 +1,46 @@
|
||||
#if UNITY_EDITOR
|
||||
namespace Jovian.InspectorTools.Internal
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
[InitializeOnLoad]
|
||||
public class RequireLayerOrTagAttributeHandler
|
||||
{
|
||||
static RequireLayerOrTagAttributeHandler()
|
||||
{
|
||||
EditorApplication.playModeStateChanged += AutoSaveWhenPlaymodeStarts;
|
||||
}
|
||||
namespace Jovian.InspectorTools.Internal {
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
private static void AutoSaveWhenPlaymodeStarts(PlayModeStateChange obj)
|
||||
{
|
||||
if (EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying)
|
||||
{
|
||||
var components = Object.FindObjectsOfType<Component>();
|
||||
foreach (var component in components)
|
||||
{
|
||||
foreach (var attribute in component.GetType().GetCustomAttributes(true))
|
||||
{
|
||||
var layerAttribute = attribute as RequireLayerAttribute;
|
||||
if (layerAttribute != null)
|
||||
{
|
||||
var requiredLayer = layerAttribute.LayerName != null ?
|
||||
LayerMask.NameToLayer(layerAttribute.LayerName) :
|
||||
layerAttribute.LayerIndex;
|
||||
if (component.gameObject.layer == requiredLayer) continue;
|
||||
[InitializeOnLoad]
|
||||
public class RequireLayerOrTagAttributeHandler {
|
||||
static RequireLayerOrTagAttributeHandler() {
|
||||
EditorApplication.playModeStateChanged += AutoSaveWhenPlaymodeStarts;
|
||||
}
|
||||
|
||||
Debug.LogWarning("Layer of " + component.name + " changed by RequireLayerAttribute to " + layerAttribute.LayerName);
|
||||
component.gameObject.layer = requiredLayer;
|
||||
EditorUtility.SetDirty(component);
|
||||
|
||||
continue;
|
||||
}
|
||||
private static void AutoSaveWhenPlaymodeStarts(PlayModeStateChange obj) {
|
||||
if(!EditorApplication.isPlayingOrWillChangePlaymode || EditorApplication.isPlaying) {
|
||||
return;
|
||||
}
|
||||
var components = Object.FindObjectsByType<Component>(FindObjectsInactive.Include, FindObjectsSortMode.None);
|
||||
foreach(var component in components) {
|
||||
foreach(var attribute in component.GetType().GetCustomAttributes(true)) {
|
||||
switch(attribute) {
|
||||
case RequireLayerAttribute layerAttribute: {
|
||||
var requiredLayer = layerAttribute.LayerName != null ? LayerMask.NameToLayer(layerAttribute.LayerName) : layerAttribute.LayerIndex;
|
||||
if(component.gameObject.layer == requiredLayer) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var tagAttribute = attribute as RequireTagAttribute;
|
||||
if (tagAttribute != null)
|
||||
{
|
||||
if (component.CompareTag(tagAttribute.Tag)) continue;
|
||||
Debug.LogWarning("Layer of " + component.name + " changed by RequireLayerAttribute to " + layerAttribute.LayerName);
|
||||
component.gameObject.layer = requiredLayer;
|
||||
EditorUtility.SetDirty(component);
|
||||
|
||||
Debug.LogWarning("Tag of " + component.name + " changed by RequireTagAttribute to " + tagAttribute.Tag);
|
||||
component.gameObject.tag = tagAttribute.Tag;
|
||||
EditorUtility.SetDirty(component);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
case RequireTagAttribute tagAttribute when component.CompareTag(tagAttribute.Tag):
|
||||
continue;
|
||||
case RequireTagAttribute tagAttribute:
|
||||
Debug.LogWarning("Tag of " + component.name + " changed by RequireTagAttribute to " + tagAttribute.Tag);
|
||||
component.gameObject.tag = tagAttribute.Tag;
|
||||
EditorUtility.SetDirty(component);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Jovian.InspectorTools.Internal {
|
||||
|
||||
if (previewButtonMethods == null && target is Component component) {
|
||||
previewScroll = Vector2.zero;
|
||||
Component[] objectComponents = component.gameObject.GetComponents<Component>();
|
||||
var objectComponents = component.gameObject.GetComponents<Component>();
|
||||
previewButtonMethods = new ButtonMethodHandler[objectComponents.Length];
|
||||
for (int i = 0; i < objectComponents.Length; i++) {
|
||||
previewButtonMethods[i] = new ButtonMethodHandler(objectComponents[i]);
|
||||
@@ -95,7 +95,10 @@ namespace Jovian.InspectorTools.Internal {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (ButtonMethodHandler previewButtonMethod in previewButtonMethods) {
|
||||
foreach (var previewButtonMethod in previewButtonMethods) {
|
||||
if(previewButtonMethod == null) {
|
||||
continue;
|
||||
}
|
||||
if (previewButtonMethod.HasAnyVisibleMethods()) {
|
||||
return true;
|
||||
}
|
||||
@@ -114,7 +117,7 @@ namespace Jovian.InspectorTools.Internal {
|
||||
GUILayout.BeginArea(previewRect);
|
||||
previewScroll = GUILayout.BeginScrollView(previewScroll);
|
||||
|
||||
foreach (ButtonMethodHandler previewButtonMethod in previewButtonMethods) {
|
||||
foreach (var previewButtonMethod in previewButtonMethods) {
|
||||
if (previewButtonMethod.HasAnyVisibleMethods()) {
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Label(ObjectNames.NicifyVariableName(previewButtonMethod.Target.GetType().Name), EditorStyles.boldLabel);
|
||||
|
||||
Reference in New Issue
Block a user