This commit is contained in:
Gerard Gascón 2025-04-24 17:37:25 +02:00
commit 341a877b4a
2338 changed files with 1346408 additions and 0 deletions

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 798c42d0f311cc64f866979e82c1f3ba
folderAsset: yes
timeCreated: 1441032760
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 1039ef92232abf64d92fd50cfc3cdb07
folderAsset: yes
timeCreated: 1441032760
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,179 @@
using UnityEngine;
using UnityEditor;
using System.Collections;
[CustomPropertyDrawer(typeof(MinMaxCustomSlider))]
public class MinMaxCustomSliderDrawer : PropertyDrawer
{
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
SerializedProperty showGroup = property.FindPropertyRelative("ShowGroup");
if (!showGroup.boolValue)
return 16;
SerializedProperty CompareMethod = property.FindPropertyRelative("CompareMethod");
if (CompareMethod.enumValueIndex != 2) //!= ExactAngle
{
MinMaxCustomSlider slider = (MinMaxCustomSlider)attribute;
if (slider.PropertyWidth<250)
return 130;
else
return 150;
}
else
return 64f;
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
int indent = EditorGUI.indentLevel;
//positions
Rect groupPos = new Rect(position.x, position.y, position.width, 16);
//Rect namePos = new Rect(position.x, position.y + 16, position.width, 16);
Rect comparePos = new Rect(position.x, position.y + 20, position.width, 20);
//variables
SerializedProperty PropertyName = property.FindPropertyRelative("Name");
SerializedProperty MinValue = property.FindPropertyRelative("MinValue");
SerializedProperty MaxValue = property.FindPropertyRelative("MaxValue");
SerializedProperty MinLimit = property.FindPropertyRelative("MinLimit");
SerializedProperty MaxLimit = property.FindPropertyRelative("MaxLimit");
SerializedProperty ExactValue = property.FindPropertyRelative("ExactValue");
SerializedProperty CompareMethod = property.FindPropertyRelative("CompareMethod");
SerializedProperty showGroup = property.FindPropertyRelative("ShowGroup");
MinMaxCustomSlider slider = (MinMaxCustomSlider)attribute;
slider.PropertyWidth = position.width;
//default values
SetupDefaultValues(MinValue, MaxValue, MinLimit, MaxLimit, PropertyName, ExactValue, showGroup);
//controls
showGroup.boolValue = EditorGUI.Foldout(groupPos, showGroup.boolValue, PropertyName.stringValue);
//works good
// if(property.isExpanded)
// showGroup.boolValue = EditorGUI.Foldout(groupPos, showGroup.boolValue, PropertyName.stringValue);
// else
// EditorGUI.LabelField(groupPos, PropertyName.stringValue);
if (showGroup.boolValue)
{
EditorGUI.indentLevel++;
//PropertyName.stringValue = EditorGUI.TextField(namePos, "Name", PropertyName.stringValue);
// EditorGUI.HandlePrefixLabel(new Rect(comparePos.x, comparePos.y, 92, comparePos.height),
// new Rect(comparePos.x, comparePos.y, 92, comparePos.height),
// new GUIContent("Custom Range:"));
// EditorGUI.PropertyField(new Rect(comparePos.x + 95, comparePos.y, comparePos.width, comparePos.height), CompareMethod, GUIContent.none);
EditorGUI.PropertyField(comparePos, CompareMethod);
if (CompareMethod.enumValueIndex == 0 //ValueRangeCompareMethod.ValueInsideRange)
|| CompareMethod.enumValueIndex == 1)//ValueRangeCompareMethod.ValueOutsideRange)
{
if (position.width < 250)
{
//positions
Rect slidePos = new Rect(position.x, position.y + 40, position.width, 16);
Rect minPos = new Rect(position.x, position.y + 60, position.width, 16);
Rect maxPos = new Rect(position.x, position.y + 78, position.width, 16);
Rect minLimitPos = new Rect(position.x, position.y + 104, position.width, 16);
Rect maxLimitPos = new Rect(position.x, position.y + 122, position.width, 16);
//controls
MinValue.floatValue = EditorGUI.FloatField(minPos, new GUIContent("MinValue"), MinValue.floatValue);
MaxValue.floatValue = EditorGUI.FloatField(maxPos, new GUIContent("MaxValue"), MaxValue.floatValue);
MinLimit.floatValue = EditorGUI.FloatField(minLimitPos, new GUIContent("MinLimit"), MinLimit.floatValue);
MaxLimit.floatValue = EditorGUI.FloatField(maxLimitPos, new GUIContent("MaxLimit"), MaxLimit.floatValue);
float minVal = MinValue.floatValue;
float maxVal = MaxValue.floatValue;
EditorGUI.MinMaxSlider(new GUIContent("Range"),
slidePos,
ref minVal, ref maxVal,
MinLimit.floatValue, MaxLimit.floatValue);
MinValue.floatValue = minVal;
MaxValue.floatValue = maxVal;
}
else
{
Rect slidePos = new Rect(position.x + 48, position.y + 48, position.width - 106, 16);
//positions
Rect minLimitPos = new Rect(position.x, position.y + 48, 72, 16);
Rect maxLimitPos = new Rect(position.x + position.width - 72, position.y + 48, 72, 16);
Rect minPos = new Rect(position.x, position.y + 74, position.width, 16);
Rect maxPos = new Rect(position.x, position.y + 92, position.width, 16);
if (EditorGUI.indentLevel < 2)
{
minLimitPos = new Rect(position.x, position.y + 48, 57, 16);
maxLimitPos = new Rect(position.x + position.width - 57, position.y + 48, 57, 16);
}
//controls
MinValue.floatValue = EditorGUI.FloatField(minPos, new GUIContent("MinValue"), MinValue.floatValue);
MaxValue.floatValue = EditorGUI.FloatField(maxPos, new GUIContent("MaxValue"), MaxValue.floatValue);
MinLimit.floatValue = EditorGUI.FloatField(minLimitPos, GUIContent.none, MinLimit.floatValue);
MaxLimit.floatValue = EditorGUI.FloatField(maxLimitPos, GUIContent.none, MaxLimit.floatValue);
float minVal = MinValue.floatValue;
float maxVal = MaxValue.floatValue;
EditorGUI.MinMaxSlider(GUIContent.none,
slidePos,
ref minVal, ref maxVal,
MinLimit.floatValue, MaxLimit.floatValue);
MinValue.floatValue = minVal;
MaxValue.floatValue = maxVal;
}
}
else //ExactAngle
{
Rect exactValPos = new Rect(position.x, position.y + 44, position.width, 16);
EditorGUI.PropertyField(exactValPos, ExactValue);
}
}
EditorGUI.indentLevel = indent;
EditorGUI.EndProperty();
}
void SetupDefaultValues(SerializedProperty MinValue, SerializedProperty MaxValue, SerializedProperty MinLimit, SerializedProperty MaxLimit,
SerializedProperty PropertyName, SerializedProperty ExactValue, SerializedProperty showGroup)
{
if (MinValue.floatValue == 0 && MaxValue.floatValue == 0
&& MinLimit.floatValue == 0 && MaxLimit.floatValue == 0)
{
MinValue.floatValue = -45;
MaxValue.floatValue = 45;
MinLimit.floatValue = -90;
MaxLimit.floatValue = 90;
ExactValue.floatValue = 45;
PropertyName.stringValue = "Value Range";
showGroup.boolValue = true;
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: dfdd32516482b164c9b1a0ecfaf5880b
timeCreated: 1439388012
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 6a815c5a4a443104c86f1354ff165d82
folderAsset: yes
timeCreated: 1441032771
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,68 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ValueRangeExamples : MonoBehaviour
{
//different usage examples
[Header("Visibility example")]
public float currentViewAngleOffset = 0;
[MinMaxCustomSlider]
public ValueRange VisibilityZone;
[Header("Valid attack angle example")]
public float currentTargetAngleOffset = 0;
[MinMaxCustomSlider]
public List<ValueRange> ValidAttackAngles;
[Header("Change Gear Zones example")]
public float currentSpeed = 120;
[MinMaxCustomSlider]
public ValueRange[] GearChangeThresholds;
void OnEnable()
{
bool validRange = false;
//visibility zone example
if(VisibilityZone.IsValidAngle(currentViewAngleOffset))
Debug.Log("Character can see the target!");
else
Debug.Log("Character cannot see the target.");
//angle range example
foreach (ValueRange valueRange in ValidAttackAngles)
{
if(valueRange.IsValidAngle(currentTargetAngleOffset))
{
Debug.Log("Valid character attack angle to target!");
validRange = true;
break;
}
}
if(validRange == false)
Debug.Log("Character is not in valid attack angle to target.");
validRange = false;
//min max range example
foreach (ValueRange valueRange in GearChangeThresholds)
{
if(valueRange.IsValid(currentSpeed))
{
Debug.Log("Perfect Gear change!");
validRange = true;
break;
}
}
if(validRange == false)
Debug.Log("Gear change was made outside perfect zone.");
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 70787bdd26a0cb74695e459cdc5240e1
timeCreated: 1441032859
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: b45a23b1b981b9e49b0530ac7a1943c6
folderAsset: yes
timeCreated: 1441032760
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,8 @@
using UnityEngine;
using System.Collections;
[System.Serializable]
public class MinMaxCustomSlider : PropertyAttribute
{
public float PropertyWidth = 300;
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 882d7c6c31d763d46a433183a7b9be38
timeCreated: 1439388171
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,69 @@
using UnityEngine;
using System.Collections;
public enum ValueRangeCompareMethod
{
ValueInsideRange,
ValueOutsideRange,
ExactValue
}
[System.Serializable]
public class ValueRange : System.Object
{
public ValueRange(string _name)
{
Name = _name;
}
public string Name = "Value Range";
public float MinValue = -45;
public float MaxValue = 45;
public float MinLimit = -90;
public float MaxLimit = 90;
public float ExactValue = 45;
public ValueRangeCompareMethod CompareMethod;
//We need to keep individual track of expanded groups since attributes holds it for the entire list
[HideInInspector]
public bool ShowGroup = true;
public bool IsValid(float value)
{
if(CompareMethod == ValueRangeCompareMethod.ValueInsideRange)
{
return MinValue <= value && value <= MaxValue;
}
else if(CompareMethod == ValueRangeCompareMethod.ValueOutsideRange)
{
return value < MinValue || MaxValue < value;
}
else
{
return value == ExactValue;
}
}
public bool IsValidAngle(float value)
{
if(CompareMethod == ValueRangeCompareMethod.ValueInsideRange)
{
value = Mathf.DeltaAngle(0, value);
return MinValue <= value && value <= MaxValue;
}
else if(CompareMethod == ValueRangeCompareMethod.ValueOutsideRange)
{
value = Mathf.DeltaAngle(0, value);
return value < MinValue || MaxValue < value;
}
else
{
return value == ExactValue;
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: bb7d93a4be37e124fbe3fef16ad84114
timeCreated: 1439388887
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: