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
|
||||
|
||||
Reference in New Issue
Block a user