-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,6 @@ sysinfo.txt | |
|
||
# Builds | ||
*.apk | ||
*.unitypackage | ||
|
||
# Crashlytics generated file | ||
crashlytics-build.properties | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace ReadyPlayerMe.AvatarCreator.Editor | ||
{ | ||
[CustomPropertyDrawer(typeof(AssetTypeFilterAttribute))] | ||
public class AssetTypeFilterDrawer : PropertyDrawer | ||
{ | ||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) | ||
{ | ||
var assetTypeAttribute = attribute as AssetTypeFilterAttribute; | ||
|
||
if (property.propertyType == SerializedPropertyType.Enum) | ||
{ | ||
EditorGUI.BeginProperty(position, label, property); | ||
|
||
EditorGUI.BeginChangeCheck(); | ||
|
||
// Get the current enum value | ||
var currentEnumValue = (AssetType) property.enumValueIndex; | ||
|
||
var filteredEnumNames = new List<string>(); | ||
foreach (var enumName in Enum.GetNames(typeof(AssetType))) | ||
{ | ||
var enumFieldInfo = typeof(AssetType).GetField(enumName); | ||
var enumAttribute = (AssetTypeFilterAttribute) Attribute.GetCustomAttribute(enumFieldInfo, typeof(AssetTypeFilterAttribute)); | ||
if (enumAttribute == null) continue; | ||
|
||
var filter = (AssetFilter) Enum.Parse(typeof(AssetFilter), enumAttribute.filter.ToString()); | ||
if (filter == assetTypeAttribute?.filter) | ||
{ | ||
filteredEnumNames.Add(enumName); | ||
} | ||
} | ||
|
||
// Display the dropdown with filtered enum values | ||
var newIndex = EditorGUI.Popup(position, label.text, Array.IndexOf(filteredEnumNames.ToArray(), currentEnumValue.ToString()), filteredEnumNames.ToArray()); | ||
|
||
// Set the new enum value if it has changed | ||
if (EditorGUI.EndChangeCheck()) | ||
{ | ||
property.enumValueIndex = (int) Enum.Parse(typeof(AssetType), filteredEnumNames[newIndex]); | ||
} | ||
|
||
EditorGUI.EndProperty(); | ||
} | ||
else | ||
{ | ||
EditorGUI.LabelField(position, label.text, "Use AssetType with Enum."); | ||
} | ||
} | ||
|
||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace ReadyPlayerMe.Core.Editor | ||
{ | ||
public static class StringExtensions | ||
{ | ||
private const string SHORT_CODE_REGEX = "^[A-Z0-9]{6}$"; | ||
|
||
public static bool IsUrlShortcodeValid(this string urlString) | ||
{ | ||
return !string.IsNullOrEmpty(urlString) && | ||
(Regex.Match(urlString, SHORT_CODE_REGEX).Length > 0 || Uri.IsWellFormedUriString(urlString, UriKind.Absolute) && urlString.EndsWith(".glb")); | ||
} | ||
} | ||
} |