Add StickGame Assets

This commit is contained in:
Dzejkobik007
2024-03-24 22:21:16 +01:00
parent 5a5812c0c7
commit 6c8b523d1f
6643 changed files with 596260 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b43a8f6c3cc189c40ae6b248e76e2788
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c197d238762d66b41927449d5c48b3f4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,488 @@
#if UNITY_EDITOR
// Project : UNITY FOLDOUT
// Contacts : Pix - ask@pixeye.games
// https://github.com/PixeyeHQ/InspectorFoldoutGroup
// MIT license https://github.com/PixeyeHQ/InspectorFoldoutGroup/blob/master/LICENSE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
using Object = UnityEngine.Object;
namespace GameKit.Dependencies.Inspectors
{
[CustomEditor(typeof(Object), true, isFallback = true)]
[CanEditMultipleObjects]
public class EditorOverride : Editor
{
public override VisualElement CreateInspectorGUI()
{
return base.CreateInspectorGUI();
}
//===============================//
// Members
//===============================//
Dictionary<string, CacheFoldProp> cacheFolds = new Dictionary<string, CacheFoldProp>();
List<SerializedProperty> props = new List<SerializedProperty>();
List<MethodInfo> methods = new List<MethodInfo>();
bool initialized;
//===============================//
// Logic
//===============================//
void OnEnable()
{
initialized = false;
}
void OnDisable()
{
//if (Application.wantsToQuit)
//if (applicationIsQuitting) return;
// if (Toolbox.isQuittingOrChangingScene()) return;
if (target != null)
foreach (var c in cacheFolds)
{
EditorPrefs.SetBool(string.Format($"{c.Value.atr.name}{c.Value.props[0].name}{target.GetInstanceID()}"), c.Value.expanded);
c.Value.Dispose();
}
}
public override bool RequiresConstantRepaint()
{
return EditorFramework.needToRepaint;
}
public override void OnInspectorGUI()
{
serializedObject.Update();
Setup();
if (props.Count == 0)
{
DrawDefaultInspector();
return;
}
Header();
Body();
serializedObject.ApplyModifiedProperties();
void Header()
{
using (new EditorGUI.DisabledScope("m_Script" == props[0].propertyPath))
{
EditorGUILayout.Space();
EditorGUILayout.PropertyField(props[0], true);
EditorGUILayout.Space();
}
}
void Body()
{
foreach (var pair in cacheFolds)
{
this.UseVerticalLayout(() => Foldout(pair.Value), StyleFramework.box);
EditorGUI.indentLevel = 0;
}
EditorGUILayout.Space();
for (var i = 1; i < props.Count; i++)
{
// if (props[i].isArray)
// {
// DrawPropertySortableArray(props[i]);
// }
// else
// {
EditorGUILayout.PropertyField(props[i], true);
//}
}
EditorGUILayout.Space();
if (methods == null) return;
foreach (MethodInfo memberInfo in methods)
{
this.UseButton(memberInfo);
}
}
void Foldout(CacheFoldProp cache)
{
cache.expanded = EditorGUILayout.Foldout(cache.expanded, cache.atr.name, true,
StyleFramework.foldout);
if (cache.expanded)
{
EditorGUI.indentLevel = 1;
for (int i = 0; i < cache.props.Count; i++)
{
this.UseVerticalLayout(() => Child(i), StyleFramework.boxChild);
}
}
void Child(int i)
{
// if (cache.props[i].isArray)
// {
// DrawPropertySortableArray(cache.props[i]);
// }
// else
// {
EditorGUILayout.PropertyField(cache.props[i], new GUIContent(ObjectNames.NicifyVariableName(cache.props[i].name)), true);
//}
}
}
void Setup()
{
EditorFramework.currentEvent = Event.current;
if (!initialized)
{
// SetupButtons();
List<FieldInfo> objectFields;
GroupAttribute prevFold = default;
var length = EditorTypes.Get(target, out objectFields);
for (var i = 0; i < length; i++)
{
#region FOLDERS
var fold = Attribute.GetCustomAttribute(objectFields[i], typeof(GroupAttribute)) as GroupAttribute;
CacheFoldProp c;
if (fold == null)
{
if (prevFold != null && prevFold.foldEverything)
{
if (!cacheFolds.TryGetValue(prevFold.name, out c))
{
cacheFolds.Add(prevFold.name, new CacheFoldProp { atr = prevFold, types = new HashSet<string> { objectFields[i].Name } });
}
else
{
c.types.Add(objectFields[i].Name);
}
}
continue;
}
prevFold = fold;
if (!cacheFolds.TryGetValue(fold.name, out c))
{
var expanded = EditorPrefs.GetBool(string.Format($"{fold.name}{objectFields[i].Name}{target.GetInstanceID()}"), false);
cacheFolds.Add(fold.name, new CacheFoldProp { atr = fold, types = new HashSet<string> { objectFields[i].Name }, expanded = expanded });
}
else c.types.Add(objectFields[i].Name);
#endregion
}
var property = serializedObject.GetIterator();
var next = property.NextVisible(true);
if (next)
{
do
{
HandleFoldProp(property);
} while (property.NextVisible(false));
}
initialized = true;
}
}
// void SetupButtons()
// {
// var members = GetButtonMembers(target);
//
// foreach (var memberInfo in members)
// {
// var method = memberInfo as MethodInfo;
// if (method == null)
// {
// continue;
// }
//
// if (method.GetParameters().Length > 0)
// {
// continue;
// }
//
// if (methods == null) methods = new List<MethodInfo>();
// methods.Add(method);
// }
// }
}
public void HandleFoldProp(SerializedProperty prop)
{
bool shouldBeFolded = false;
foreach (var pair in cacheFolds)
{
if (pair.Value.types.Contains(prop.name))
{
var pr = prop.Copy();
shouldBeFolded = true;
pair.Value.props.Add(pr);
break;
}
}
if (shouldBeFolded == false)
{
var pr = prop.Copy();
props.Add(pr);
}
}
// IEnumerable<MemberInfo> GetButtonMembers(object target)
// {
// return target.GetType()
// .GetMembers(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.NonPublic)
// .Where(CheckButtonAttribute);
// }
// bool CheckButtonAttribute(MemberInfo memberInfo)
// {
// return Attribute.IsDefined(memberInfo, typeof(ButtonAttribute));
// }
class CacheFoldProp
{
public HashSet<string> types = new HashSet<string>();
public List<SerializedProperty> props = new List<SerializedProperty>();
public GroupAttribute atr;
public bool expanded;
public void Dispose()
{
props.Clear();
types.Clear();
atr = null;
}
}
}
static class EditorUIHelper
{
public static void UseVerticalLayout(this Editor e, Action action, GUIStyle style)
{
EditorGUILayout.BeginVertical(style);
action();
EditorGUILayout.EndVertical();
}
public static void UseButton(this Editor e, MethodInfo m)
{
if (GUILayout.Button(m.Name))
{
m.Invoke(e.target, null);
}
}
}
static class StyleFramework
{
public static GUIStyle box;
public static GUIStyle boxChild;
public static GUIStyle foldout;
public static GUIStyle button;
public static GUIStyle text;
static StyleFramework()
{
bool pro = EditorGUIUtility.isProSkin;
var uiTex_in = UnityEngine.Resources.Load<Texture2D>("IN foldout focus-6510");
var uiTex_in_on = UnityEngine.Resources.Load<Texture2D>("IN foldout focus on-5718");
var c_on = pro ? Color.white : new Color(51 / 255f, 102 / 255f, 204 / 255f, 1);
button = new GUIStyle(EditorStyles.miniButton);
button.font = Font.CreateDynamicFontFromOSFont(new[] { "Terminus (TTF) for Windows", "Calibri" }, 17);
text = new GUIStyle(EditorStyles.label);
text.richText = true;
text.contentOffset = new Vector2(0, 5);
text.font = Font.CreateDynamicFontFromOSFont(new[] { "Terminus (TTF) for Windows", "Calibri" }, 14);
foldout = new GUIStyle(EditorStyles.foldout);
foldout.overflow = new RectOffset(-10, 0, 3, 0);
foldout.padding = new RectOffset(25, 0, -3, 0);
foldout.active.textColor = c_on;
foldout.active.background = uiTex_in;
foldout.onActive.textColor = c_on;
foldout.onActive.background = uiTex_in_on;
foldout.focused.textColor = c_on;
foldout.focused.background = uiTex_in;
foldout.onFocused.textColor = c_on;
foldout.onFocused.background = uiTex_in_on;
foldout.hover.textColor = c_on;
foldout.hover.background = uiTex_in;
foldout.onHover.textColor = c_on;
foldout.onHover.background = uiTex_in_on;
box = new GUIStyle(GUI.skin.box);
box.padding = new RectOffset(10, 0, 10, 0);
boxChild = new GUIStyle(GUI.skin.box);
boxChild.active.textColor = c_on;
boxChild.active.background = uiTex_in;
boxChild.onActive.textColor = c_on;
boxChild.onActive.background = uiTex_in_on;
boxChild.focused.textColor = c_on;
boxChild.focused.background = uiTex_in;
boxChild.onFocused.textColor = c_on;
boxChild.onFocused.background = uiTex_in_on;
EditorStyles.foldout.active.textColor = c_on;
EditorStyles.foldout.active.background = uiTex_in;
EditorStyles.foldout.onActive.textColor = c_on;
EditorStyles.foldout.onActive.background = uiTex_in_on;
EditorStyles.foldout.focused.textColor = c_on;
EditorStyles.foldout.focused.background = uiTex_in;
EditorStyles.foldout.onFocused.textColor = c_on;
EditorStyles.foldout.onFocused.background = uiTex_in_on;
EditorStyles.foldout.hover.textColor = c_on;
EditorStyles.foldout.hover.background = uiTex_in;
EditorStyles.foldout.onHover.textColor = c_on;
EditorStyles.foldout.onHover.background = uiTex_in_on;
}
public static string FirstLetterToUpperCase(this string s)
{
if (string.IsNullOrEmpty(s))
return string.Empty;
var a = s.ToCharArray();
a[0] = char.ToUpper(a[0]);
return new string(a);
}
public static IList<Type> GetTypeTree(this Type t)
{
var types = new List<Type>();
while (t.BaseType != null)
{
types.Add(t);
t = t.BaseType;
}
return types;
}
}
static class EditorTypes
{
public static Dictionary<int, List<FieldInfo>> fields = new Dictionary<int, List<FieldInfo>>(FastComparable.Default);
public static int Get(Object target, out List<FieldInfo> objectFields)
{
var t = target.GetType();
var hash = t.GetHashCode();
if (!fields.TryGetValue(hash, out objectFields))
{
var typeTree = t.GetTypeTree();
objectFields = target.GetType()
.GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.NonPublic)
.OrderByDescending(x => typeTree.IndexOf(x.DeclaringType))
.ToList();
fields.Add(hash, objectFields);
}
return objectFields.Count;
}
}
class FastComparable : IEqualityComparer<int>
{
public static FastComparable Default = new FastComparable();
public bool Equals(int x, int y)
{
return x == y;
}
public int GetHashCode(int obj)
{
return obj.GetHashCode();
}
}
[InitializeOnLoad]
public static class EditorFramework
{
internal static bool needToRepaint;
internal static Event currentEvent;
internal static float t;
static EditorFramework()
{
EditorApplication.update += Updating;
}
static void Updating()
{
CheckMouse();
if (needToRepaint)
{
t += Time.deltaTime;
if (t >= 0.3f)
{
t -= 0.3f;
needToRepaint = false;
}
}
}
static void CheckMouse()
{
var ev = currentEvent;
if (ev == null) return;
if (ev.type == EventType.MouseMove)
needToRepaint = true;
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 428419a625f80f6438c5b74beb2ac763
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bce51828adfc9b540b10914a9ec82c31
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,140 @@
fileFormatVersion: 2
guid: 07896d08487bbb049b494e9e216360ad
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 12
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 0
aniso: 1
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 0
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 1
swizzle: 50462976
cookieLightType: 1
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 1
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 1
- serializedVersion: 3
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 1
- serializedVersion: 3
buildTarget: Server
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 1
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,140 @@
fileFormatVersion: 2
guid: 795626f49ade9024a86e0c1a58aa004b
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 12
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 0
aniso: 1
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 0
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 1
swizzle: 50462976
cookieLightType: 1
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 1
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 1
- serializedVersion: 3
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 1
- serializedVersion: 3
buildTarget: Server
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 1
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,25 @@
// Project : UNITY FOLDOUT
// Contacts : Pix - ask@pixeye.games
// https://github.com/PixeyeHQ/InspectorFoldoutGroup
// MIT license https://github.com/PixeyeHQ/InspectorFoldoutGroup/blob/master/LICENSE
using System;
using UnityEngine;
namespace GameKit.Dependencies.Inspectors
{
public class GroupAttribute : PropertyAttribute
{
public string name;
public bool foldEverything;
/// <summary>Adds the property to the specified foldout group.</summary>
/// <param name="name">Name of the foldout group.</param>
/// <param name="foldEverything">Toggle to put all properties to the specified group</param>
public GroupAttribute(string name, bool foldEverything = false)
{
this.foldEverything = foldEverything;
this.name = name;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e3c02d1d5545ae54687d1a313ebb2fd6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 102b5a2337dae434f989eee1a6a1c571
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a8361a4f779768242840a9c994392e20
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,118 @@
#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace GameKit.Dependencies.Inspectors
{
/// <summary>
/// Based on: https://forum.unity.com/threads/draw-a-field-only-if-a-condition-is-met.448855/
/// </summary>
[CustomPropertyDrawer(typeof(ShowIfAttribute))]
public class ShowIfPropertyDrawer : PropertyDrawer
{
#region Fields
// Reference to the attribute on the property.
ShowIfAttribute drawIf;
// Field that is being compared.
SerializedProperty comparedField;
#endregion
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
if (!ShowMe(property) && drawIf.disablingType == ShowIfAttribute.DisablingType.DontDraw)
{
return -EditorGUIUtility.standardVerticalSpacing;
}
else
{
if (property.propertyType == SerializedPropertyType.Generic)
{
int numChildren = 0;
float totalHeight = 0.0f;
IEnumerator children = property.GetEnumerator();
HashSet<SerializedProperty> drawnprops = new HashSet<SerializedProperty>();
while (children.MoveNext())
{
SerializedProperty child = children.Current as SerializedProperty;
if (drawnprops.Contains(child))
{
continue;
}
drawnprops.Add(child);
GUIContent childLabel = new GUIContent(child.displayName);
totalHeight += EditorGUI.GetPropertyHeight(child, childLabel) + EditorGUIUtility.standardVerticalSpacing;
numChildren++;
}
// Remove extra space at end, (we only want spaces between items)
totalHeight -= EditorGUIUtility.standardVerticalSpacing;
return totalHeight;
}
return EditorGUI.GetPropertyHeight(property, label);
}
}
/// <summary>
/// Errors default to showing the property.
/// </summary>
private bool ShowMe(SerializedProperty property)
{
drawIf = attribute as ShowIfAttribute;
// Replace propertyname to the value from the parameter
string path = property.propertyPath.Contains(".") ? System.IO.Path.ChangeExtension(property.propertyPath, drawIf.comparedPropertyName) : drawIf.comparedPropertyName;
comparedField = property.serializedObject.FindProperty(path);
if (comparedField == null)
{
Debug.LogError("Cannot find property with name: " + path);
return true;
}
// get the value & compare based on types
switch (comparedField.type)
{ // Possible extend cases to support your own type
case "bool":
return comparedField.boolValue.Equals(drawIf.comparedValue);
case "Enum":
return comparedField.enumValueIndex.Equals((int)drawIf.comparedValue);
default:
Debug.LogError("Error: " + comparedField.type + " is not supported of " + path);
return true;
}
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
// If the condition is met, simply draw the field.
if (ShowMe(property))
{
EditorGUI.PropertyField(position, property);
} //...check if the disabling type is read only. If it is, draw it disabled
else if (drawIf.disablingType == ShowIfAttribute.DisablingType.ReadOnly)
{
GUI.enabled = false;
EditorGUI.PropertyField(position, property);
GUI.enabled = true;
}
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1266c8c8d104aeb4faf3f1daaee87479
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,45 @@
using UnityEngine;
using System;
namespace GameKit.Dependencies.Inspectors
{
/// <summary>
/// Draws the field/property ONLY if the compared property compared by the comparison type with the value of comparedValue returns true.
/// Based on: https://forum.unity.com/threads/draw-a-field-only-if-a-condition-is-met.448855/
/// </summary>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true)]
public class ShowIfAttribute : PropertyAttribute
{
#region Fields
public string comparedPropertyName { get; private set; }
public object comparedValue { get; private set; }
public DisablingType disablingType { get; private set; }
/// <summary>
/// Types of comperisons.
/// </summary>
public enum DisablingType
{
ReadOnly = 2,
DontDraw = 3
}
#endregion
/// <summary>
/// Only draws the field only if a condition is met. Supports enum and bools.
/// </summary>
/// <param name="comparedPropertyName">The name of the property that is being compared (case sensitive).</param>
/// <param name="comparedValue">The value the property is being compared to.</param>
/// <param name="disablingType">The type of disabling that should happen if the condition is NOT met. Defaulted to DisablingType.DontDraw.</param>
public ShowIfAttribute(string comparedPropertyName, object comparedValue, DisablingType disablingType = DisablingType.DontDraw)
{
this.comparedPropertyName = comparedPropertyName;
this.comparedValue = comparedValue;
this.disablingType = disablingType;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 203e832301eed08499198358cfd13e7d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: