ios打包修改了部分文件内容
This commit is contained in:
parent
7fcf9a3727
commit
346c5383c7
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2,8 +2,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using TEngine;
|
||||
using UnityEngine;
|
||||
using VoxelBusters.CoreLibrary;
|
||||
using VoxelBusters.EssentialKit;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
@ -19,41 +17,41 @@ namespace GameLogic
|
||||
/// </summary>
|
||||
public static void SaveImageToGallery(string fileName,Texture2D imgTex2D)
|
||||
{
|
||||
MediaContentSaveOptions saveOptions = new MediaContentSaveOptions(directoryName: "EintooAR", fileName: $"{fileName}");
|
||||
MediaServices.SaveMediaContent(imgTex2D.EncodeToPNG(), MimeType.kPNGImage, saveOptions,
|
||||
(bool result, Error error) =>
|
||||
{
|
||||
if (error == null)
|
||||
{
|
||||
SHowDialog($"图片保存成功/EintooAR/{imgTex2D.name}");
|
||||
}
|
||||
else
|
||||
{
|
||||
SHowDialog($"图片保存失败/EintooAR/{imgTex2D.name}");
|
||||
}
|
||||
});
|
||||
// MediaContentSaveOptions saveOptions = new MediaContentSaveOptions(directoryName: "EintooAR", fileName: $"{fileName}");
|
||||
// MediaServices.SaveMediaContent(imgTex2D.EncodeToPNG(), MimeType.kPNGImage, saveOptions,
|
||||
// (bool result, Error error) =>
|
||||
// {
|
||||
// if (error == null)
|
||||
// {
|
||||
// SHowDialog($"图片保存成功/EintooAR/{imgTex2D.name}");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// SHowDialog($"图片保存失败/EintooAR/{imgTex2D.name}");
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
public static void SaveAllImageToGallery(List<Texture2D> texList)
|
||||
{
|
||||
foreach(var tex in texList)
|
||||
{
|
||||
MediaContentSaveOptions saveOptions = new MediaContentSaveOptions(directoryName: "EintooAR", fileName: $"{tex.name}");
|
||||
MediaServices.SaveMediaContent(tex.EncodeToPNG(), MimeType.kPNGImage, saveOptions,null);
|
||||
}
|
||||
SHowDialog($"图片保存成功/EintooAR/{texList.Count}");
|
||||
// foreach(var tex in texList)
|
||||
// {
|
||||
// MediaContentSaveOptions saveOptions = new MediaContentSaveOptions(directoryName: "EintooAR", fileName: $"{tex.name}");
|
||||
// MediaServices.SaveMediaContent(tex.EncodeToPNG(), MimeType.kPNGImage, saveOptions,null);
|
||||
// }
|
||||
// SHowDialog($"图片保存成功/EintooAR/{texList.Count}");
|
||||
}
|
||||
|
||||
private static void SHowDialog(string message)
|
||||
{
|
||||
AlertDialog dialog = AlertDialog.CreateInstance();
|
||||
dialog.Message = message;
|
||||
|
||||
dialog.Show();
|
||||
GameModule.Timer.AddTimer((te)=>
|
||||
{
|
||||
dialog.Dismiss();
|
||||
},1f);
|
||||
// AlertDialog dialog = AlertDialog.CreateInstance();
|
||||
// dialog.Message = message;
|
||||
//
|
||||
// dialog.Show();
|
||||
// GameModule.Timer.AddTimer((te)=>
|
||||
// {
|
||||
// dialog.Dismiss();
|
||||
// },1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,15 +73,6 @@ MonoBehaviour:
|
||||
- UniTask.DOTween
|
||||
- UniTask.Linq
|
||||
- UniTask.TextMeshPro
|
||||
- VoxelBusters.CoreLibrary
|
||||
- VoxelBusters.CoreLibrary.NativePlugins
|
||||
- VoxelBusters.CoreLibrary.NativePlugins.AndroidModule
|
||||
- VoxelBusters.CoreLibrary.NativePlugins.iOSModule
|
||||
- VoxelBusters.CoreLibrary.Parser
|
||||
- VoxelBusters.EssentialKit
|
||||
- VoxelBusters.EssentialKit.AndroidModule
|
||||
- VoxelBusters.EssentialKit.Demo
|
||||
- VoxelBusters.EssentialKit.iOSModule
|
||||
- YooAsset
|
||||
showAdvancedSettings: 0
|
||||
addMgrToSceneAutomatically: 0
|
||||
|
@ -1,12 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5651992cdad94894a3af7dc3f1da9170
|
||||
timeCreated: 1488828285
|
||||
PluginImporter:
|
||||
serializedVersion: 1
|
||||
externalObjects: {}
|
||||
serializedVersion: 3
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
Any:
|
||||
enabled: 0
|
||||
@ -37,30 +40,12 @@ PluginImporter:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
N3DS:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
PS4:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
PSM:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
PSP2:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
SamsungTV:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
Tizen:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
WebGL:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
WiiU:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
WindowsStoreApps:
|
||||
enabled: 1
|
||||
settings:
|
||||
@ -69,7 +54,7 @@ PluginImporter:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
iOS:
|
||||
enabled: 1
|
||||
enabled: 0
|
||||
settings: {}
|
||||
tvOS:
|
||||
enabled: 1
|
||||
|
@ -1,12 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5978f8f3dd274e848fbb7a123bde1fb9
|
||||
timeCreated: 1488828285
|
||||
PluginImporter:
|
||||
serializedVersion: 1
|
||||
externalObjects: {}
|
||||
serializedVersion: 3
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
Any:
|
||||
enabled: 0
|
||||
@ -37,30 +40,12 @@ PluginImporter:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
N3DS:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
PS4:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
PSM:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
PSP2:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
SamsungTV:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
Tizen:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
WebGL:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
WiiU:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
WindowsStoreApps:
|
||||
enabled: 1
|
||||
settings:
|
||||
@ -69,7 +54,7 @@ PluginImporter:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
iOS:
|
||||
enabled: 1
|
||||
enabled: 0
|
||||
settings: {}
|
||||
tvOS:
|
||||
enabled: 1
|
||||
|
@ -1,12 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2a8f0021d6b47c5923d8972dfb81ef1
|
||||
timeCreated: 1488828285
|
||||
PluginImporter:
|
||||
serializedVersion: 1
|
||||
externalObjects: {}
|
||||
serializedVersion: 3
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
Android:
|
||||
enabled: 1
|
||||
@ -40,37 +43,29 @@ PluginImporter:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
Linux:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
Linux64:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
LinuxUniversal:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
OSXIntel:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
OSXIntel64:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
settings:
|
||||
CPU:
|
||||
OSXUniversal:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
PSM:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
settings:
|
||||
CPU:
|
||||
Win:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
settings:
|
||||
CPU:
|
||||
Win64:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
settings:
|
||||
CPU:
|
||||
WindowsStoreApps:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
iOS:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
@ -1,12 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e0a9643dc0d4b46bf2321f72c4e503e
|
||||
timeCreated: 1488828285
|
||||
PluginImporter:
|
||||
serializedVersion: 1
|
||||
externalObjects: {}
|
||||
serializedVersion: 3
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
Android:
|
||||
enabled: 1
|
||||
@ -40,37 +43,29 @@ PluginImporter:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
Linux:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
Linux64:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
LinuxUniversal:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
OSXIntel:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
OSXIntel64:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
settings:
|
||||
CPU:
|
||||
OSXUniversal:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
PSM:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
settings:
|
||||
CPU:
|
||||
Win:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
settings:
|
||||
CPU:
|
||||
Win64:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
settings:
|
||||
CPU:
|
||||
WindowsStoreApps:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
iOS:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d715a94341ea2409e8dc90d116c23ded
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5317c4912d76a48828be99991f62fe81
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2815bd3aec8ef4cdda0dd09e8ad737d2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b00880799a9f24f7b8a4c2e44c84138e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 36aa8feca9d884ed09e68d46a2a8a7b0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,136 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
// Credits: https://github.com/joshcamas/unity-domain-reload-helper
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
public static class DomainReloadManager
|
||||
{
|
||||
#region Static fields
|
||||
|
||||
private const BindingFlags kDefaultBindingAttr = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static methods
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
private static void OnRuntimeLoad()
|
||||
{
|
||||
TypeCache.Rebuild();
|
||||
|
||||
SendReloadMessageToMembers();
|
||||
SendReloadMessageToMethods();
|
||||
}
|
||||
|
||||
private static void SendReloadMessageToMembers()
|
||||
{
|
||||
var members = TypeCache.GetMembersWithAttribute<ClearOnReloadAttribute>(
|
||||
memberTypes: MemberTypes.Field | MemberTypes.Property | MemberTypes.Event,
|
||||
bindingAttr: kDefaultBindingAttr);
|
||||
|
||||
foreach (var item in members)
|
||||
{
|
||||
var member = item.Key;
|
||||
var attribute = item.Value;
|
||||
if (member is FieldInfo)
|
||||
{
|
||||
ClearField(member as FieldInfo, attribute);
|
||||
}
|
||||
else if (member is PropertyInfo)
|
||||
{
|
||||
ClearProperty(member as PropertyInfo, attribute);
|
||||
}
|
||||
else if (member is EventInfo)
|
||||
{
|
||||
ClearEvent(member as EventInfo, attribute);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void SendReloadMessageToMethods()
|
||||
{
|
||||
foreach (var item in TypeCache.GetMethodsWithAttribute<ExecuteOnReloadAttribute>(kDefaultBindingAttr))
|
||||
{
|
||||
var methodInfo = item.Key;
|
||||
if (methodInfo.IsGenericMethod) continue;
|
||||
|
||||
DebugLogger.Log(CoreLibraryDomain.Default, $"Invoking reload method: {methodInfo.Name}.");
|
||||
methodInfo.Invoke(null, new object[] { });
|
||||
}
|
||||
}
|
||||
|
||||
private static void ClearField(FieldInfo fieldInfo, ClearOnReloadAttribute clearAttribute)
|
||||
{
|
||||
var fieldType = fieldInfo.FieldType;
|
||||
if (fieldType.IsGenericParameter || fieldInfo.DeclaringType.ContainsGenericParameters)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Access attribute parameters
|
||||
object resetValue = FindMemberResetValue(fieldType, clearAttribute);
|
||||
|
||||
try
|
||||
{
|
||||
DebugLogger.Log(CoreLibraryDomain.Default, $"Clearing field {fieldInfo.Name} to value {resetValue} for type {fieldType}.");
|
||||
fieldInfo.SetValue(null, resetValue);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
DebugLogger.LogWarning(CoreLibraryDomain.Default, $"Unable to clear field {fieldInfo.Name}." + e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ClearProperty(PropertyInfo propertyInfo, ClearOnReloadAttribute clearAttribute)
|
||||
{
|
||||
if (!propertyInfo.CanWrite) return;
|
||||
|
||||
// Access attribute parameters
|
||||
var propertyType = propertyInfo.PropertyType;
|
||||
object resetValue = FindMemberResetValue(propertyType, clearAttribute);
|
||||
|
||||
try
|
||||
{
|
||||
DebugLogger.Log(CoreLibraryDomain.Default, $"Clearing property {propertyInfo.Name} to value {resetValue}.");
|
||||
propertyInfo.SetValue(null, resetValue);
|
||||
}
|
||||
catch
|
||||
{
|
||||
DebugLogger.LogWarning(CoreLibraryDomain.Default, $"Unable to clear property {propertyInfo.Name}.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void ClearEvent(EventInfo eventInfo, ClearOnReloadAttribute clearAttribute)
|
||||
{
|
||||
var fieldInfo = eventInfo.DeclaringType.GetField(eventInfo.Name, kDefaultBindingAttr);
|
||||
if ((fieldInfo == null) || fieldInfo.FieldType.IsGenericParameter) return;
|
||||
|
||||
DebugLogger.Log(CoreLibraryDomain.Default, $"Clearing event {eventInfo.Name}.");
|
||||
fieldInfo.SetValue(null, null);
|
||||
}
|
||||
|
||||
private static object FindMemberResetValue(Type target, ClearOnReloadAttribute clearAttribute)
|
||||
{
|
||||
object finalValue = null;
|
||||
if (ClearOnReloadOption.Custom == clearAttribute.Option)
|
||||
{
|
||||
finalValue = Convert.ChangeType(clearAttribute.CustomValue, target);
|
||||
if (finalValue == null)
|
||||
{
|
||||
Debug.LogWarning("Unable to assign value of type {valueToAssign.GetType()} to field {field.Name} of type {fieldType}.");
|
||||
}
|
||||
}
|
||||
else if (target.IsValueType || (ClearOnReloadOption.Default == clearAttribute.Option))
|
||||
{
|
||||
finalValue = Activator.CreateInstance(target);
|
||||
}
|
||||
return finalValue;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec2658a60321e44fe81b86a95e54bd8f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,23 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
public class SettingsObjectEditorManager
|
||||
{
|
||||
[InitializeOnLoadMethod]
|
||||
private static void OnEditorReload()
|
||||
{
|
||||
var settingsObjects = AssetDatabaseUtility.FindAssetObjects<SettingsObject>();
|
||||
foreach (var obj in settingsObjects)
|
||||
{
|
||||
if(obj != null)
|
||||
{
|
||||
obj.OnEditorReload();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 668d41341e45a44ed8ea4d6145939d4b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1207f43c46f3944158e30563ec0a499c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,228 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
public static class CustomEditorStyles
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public static Color BorderColor => new Color(0.15f, 0.15f, 0.15f, 1f);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Label styles
|
||||
|
||||
public static GUIStyle Heading1Label()
|
||||
{
|
||||
return CreateLabel(baseStyle: EditorStyles.boldLabel,
|
||||
fontSize: 18,
|
||||
wordWrap: true,
|
||||
richText: true,
|
||||
alignment: TextAnchor.MiddleLeft);
|
||||
}
|
||||
|
||||
public static GUIStyle Heading2Label()
|
||||
{
|
||||
return CreateLabel(baseStyle: EditorStyles.boldLabel,
|
||||
fontSize: 16,
|
||||
wordWrap: true,
|
||||
richText: true,
|
||||
alignment: TextAnchor.MiddleLeft);
|
||||
}
|
||||
|
||||
public static GUIStyle Heading3Label()
|
||||
{
|
||||
return CreateLabel(baseStyle: EditorStyles.boldLabel,
|
||||
fontSize: 14,
|
||||
wordWrap: true,
|
||||
richText: true,
|
||||
alignment: TextAnchor.MiddleLeft);
|
||||
}
|
||||
|
||||
public static GUIStyle NormalLabel()
|
||||
{
|
||||
return CreateLabel(baseStyle: EditorStyles.label,
|
||||
fontSize: 14,
|
||||
wordWrap: true,
|
||||
richText: true);
|
||||
}
|
||||
|
||||
public static GUIStyle OptionsLabel(bool wordWrap = true)
|
||||
{
|
||||
return CreateLabel(baseStyle: EditorStyles.label,
|
||||
fontSize: 12,
|
||||
wordWrap: wordWrap,
|
||||
richText: true,
|
||||
textClipping: TextClipping.Clip);
|
||||
}
|
||||
|
||||
public static GUIStyle LinkLabel()
|
||||
{
|
||||
return CreateLabel(baseStyle: "LinkLabel",
|
||||
fontSize: 12,
|
||||
wordWrap: true,
|
||||
richText: true);
|
||||
}
|
||||
|
||||
public static GUIStyle MiniLabel(bool wordWrap = true)
|
||||
{
|
||||
return CreateLabel(baseStyle: EditorStyles.miniLabel,
|
||||
fontSize: 12,
|
||||
wordWrap: wordWrap,
|
||||
richText: true);
|
||||
}
|
||||
|
||||
|
||||
public static GUIStyle SelectableLabel(FontStyle? fontStyle = null,
|
||||
int? fontSize = null,
|
||||
Color? textColor = null)
|
||||
{
|
||||
var normal = EditorStyles.label;
|
||||
var baseStyle = new GUIStyle()
|
||||
{
|
||||
border = new RectOffset(0, 0, 0, 0),
|
||||
font = normal.font,
|
||||
alignment = normal.alignment,
|
||||
active = normal.active,
|
||||
onActive = normal.onActive,
|
||||
focused = normal.focused,
|
||||
onFocused = normal.onFocused,
|
||||
normal = normal.normal,
|
||||
onNormal = normal.onNormal,
|
||||
hover = normal.hover,
|
||||
onHover = normal.onHover,
|
||||
};
|
||||
return CreateLabel(baseStyle,
|
||||
fontStyle: fontStyle,
|
||||
fontSize: fontSize ?? 14,
|
||||
textColor: textColor);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Button styles
|
||||
|
||||
public static GUIStyle Button()
|
||||
{
|
||||
return CreateButton(baseStyle: "Button",
|
||||
fontSize: 14);
|
||||
}
|
||||
|
||||
public static GUIStyle InvisibleButton()
|
||||
{
|
||||
return CreateButton(baseStyle: "InvisibleButton");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Background styles
|
||||
|
||||
public static GUIStyle ItemBackground()
|
||||
{
|
||||
return CreateBackground(baseStyle: "AnimItemBackground");
|
||||
}
|
||||
|
||||
public static GUIStyle GroupBackground()
|
||||
{
|
||||
GUIStyle baseStyle = "FrameBox";
|
||||
var baseMargin = baseStyle.margin;
|
||||
return CreateBackground(baseStyle: baseStyle,
|
||||
border: new RectOffset(0, 0, 0, 0),
|
||||
margin: new RectOffset(baseMargin.left, baseMargin.right, baseMargin.top, 5));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static methods
|
||||
|
||||
public static GUIStyle CreateLabel(GUIStyle baseStyle,
|
||||
FontStyle? fontStyle = null,
|
||||
int? fontSize = null,
|
||||
Color? textColor = null,
|
||||
bool? wordWrap = null,
|
||||
bool? richText = null,
|
||||
TextAnchor? alignment = null,
|
||||
TextClipping? textClipping = null)
|
||||
{
|
||||
var newStyle = new GUIStyle(baseStyle);
|
||||
if (fontSize != null)
|
||||
{
|
||||
newStyle.fontSize = fontSize.Value;
|
||||
}
|
||||
if (fontStyle != null)
|
||||
{
|
||||
newStyle.fontStyle = fontStyle.Value;
|
||||
}
|
||||
if (textColor != null)
|
||||
{
|
||||
newStyle.normal.textColor = textColor.Value;
|
||||
newStyle.onNormal.textColor = textColor.Value;
|
||||
newStyle.active.textColor = textColor.Value;
|
||||
newStyle.onActive.textColor = textColor.Value;
|
||||
newStyle.focused.textColor = textColor.Value;
|
||||
newStyle.onFocused.textColor = textColor.Value;
|
||||
newStyle.hover.textColor = textColor.Value;
|
||||
newStyle.onHover.textColor = textColor.Value;
|
||||
}
|
||||
if (wordWrap != null)
|
||||
{
|
||||
newStyle.wordWrap = wordWrap.Value;
|
||||
}
|
||||
if (richText != null)
|
||||
{
|
||||
newStyle.richText = richText.Value;
|
||||
}
|
||||
if (alignment != null)
|
||||
{
|
||||
newStyle.alignment = alignment.Value;
|
||||
}
|
||||
if (textClipping != null)
|
||||
{
|
||||
newStyle.clipping = textClipping.Value;
|
||||
}
|
||||
return newStyle;
|
||||
}
|
||||
|
||||
public static GUIStyle CreateButton(GUIStyle baseStyle,
|
||||
int? fontSize = null,
|
||||
int? fixedHeight = null,
|
||||
TextAnchor? alignment = null)
|
||||
{
|
||||
var newStyle = new GUIStyle(baseStyle);
|
||||
if (fontSize != null)
|
||||
{
|
||||
newStyle.fontSize = fontSize.Value;
|
||||
}
|
||||
if (fixedHeight != null)
|
||||
{
|
||||
newStyle.fixedHeight = fixedHeight.Value;
|
||||
}
|
||||
if (alignment != null)
|
||||
{
|
||||
newStyle.alignment = alignment.Value;
|
||||
}
|
||||
return newStyle;
|
||||
}
|
||||
|
||||
public static GUIStyle CreateBackground(GUIStyle baseStyle,
|
||||
RectOffset border = null,
|
||||
RectOffset margin = null)
|
||||
{
|
||||
var newStyle = new GUIStyle(baseStyle);
|
||||
if (border != null)
|
||||
{
|
||||
newStyle.border = border;
|
||||
}
|
||||
if (margin != null)
|
||||
{
|
||||
newStyle.margin = margin;
|
||||
}
|
||||
return newStyle;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e146cad3338c4e56a70c8554ed2901c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,52 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
public class CustomInspector : UnityEditor.Editor
|
||||
{
|
||||
#region Unity methods
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{ }
|
||||
|
||||
protected virtual void OnDisable()
|
||||
{ }
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
DrawCustomInspector();
|
||||
|
||||
bool isDirty = EditorGUI.EndChangeCheck();
|
||||
if (isDirty || UnityEditorUtility.GetIsEditorDirty())
|
||||
{
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
UnityEditorUtility.SetIsEditorDirty(false);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void DrawCustomInspector()
|
||||
{
|
||||
var property = serializedObject.GetIterator();
|
||||
if (property.NextVisible(true))
|
||||
{
|
||||
if (property.name == "m_Script")
|
||||
{
|
||||
GUI.enabled = false;
|
||||
EditorGUILayout.PropertyField(property, true);
|
||||
GUI.enabled = true;
|
||||
}
|
||||
while (property.NextVisible(false))
|
||||
{
|
||||
EditorGUILayout.PropertyField(property, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71ff8e366aef840198f173c1b05160fc
|
||||
timeCreated: 1579541126
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,527 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
public class EditorLayoutBuilder
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private SerializedObject m_serializedObject;
|
||||
|
||||
private string[] m_tabs;
|
||||
|
||||
private GetSectionsCallback m_getSectionsCallback;
|
||||
|
||||
private DrawCallback m_drawTopBarCallback;
|
||||
|
||||
private DrawTabViewCallback m_drawTabViewCallback;
|
||||
|
||||
private DrawCallback m_drawFooterCallback;
|
||||
|
||||
private string m_selectedTab;
|
||||
|
||||
private EditorSectionInfo[] m_selectedTabSections;
|
||||
|
||||
private EditorSectionInfo m_focusSection;
|
||||
|
||||
private Vector2 m_tabBarScrollPosition;
|
||||
|
||||
private Texture2D m_toggleOnIcon;
|
||||
|
||||
private Texture2D m_toggleOffIcon;
|
||||
|
||||
private GUIStyle m_backgroundStyle;
|
||||
|
||||
private GUIStyle m_titleLabelStyle;
|
||||
|
||||
private GUIStyle m_subtitleLabelStyle;
|
||||
|
||||
private GUIStyle m_tabBarLabelNormalStyle;
|
||||
|
||||
private GUIStyle m_tabBarLabelSelectedStyle;
|
||||
|
||||
private GUIStyle m_selectableLabelStyle;
|
||||
|
||||
private GUIStyle m_invisibleButtonStyle;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Delegates
|
||||
|
||||
public delegate EditorSectionInfo[] GetSectionsCallback(string tab);
|
||||
|
||||
public delegate void DrawCallback(string tab);
|
||||
|
||||
public delegate bool DrawTabViewCallback(string tab);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
public event Callback<EditorSectionInfo> OnSectionStatusChange;
|
||||
|
||||
public event Callback<EditorSectionInfo> OnFocusSectionValueChange;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public EditorLayoutBuilder(SerializedObject serializedObject,
|
||||
string[] tabs,
|
||||
GetSectionsCallback getSectionsCallback,
|
||||
DrawCallback drawTopBarCallback,
|
||||
DrawTabViewCallback drawTabViewCallback,
|
||||
DrawCallback drawFooterCallback,
|
||||
Texture2D toggleOnIcon,
|
||||
Texture2D toggleOffIcon)
|
||||
{
|
||||
// Set properties
|
||||
m_serializedObject = serializedObject;
|
||||
m_tabs = tabs;
|
||||
m_getSectionsCallback = getSectionsCallback;
|
||||
m_drawTopBarCallback = drawTopBarCallback;
|
||||
m_drawTabViewCallback = drawTabViewCallback;
|
||||
m_drawFooterCallback = drawFooterCallback;
|
||||
m_toggleOnIcon = toggleOnIcon;
|
||||
m_toggleOffIcon = toggleOffIcon;
|
||||
|
||||
LoadStyles();
|
||||
SetSelectedTab(m_tabs[0]);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static methods
|
||||
|
||||
public static void DrawChildProperties(SerializedProperty property,
|
||||
string prefix = null,
|
||||
bool indent = true,
|
||||
params string[] ignoreProperties)
|
||||
{
|
||||
EditorGUILayout.BeginVertical(CustomEditorStyles.GroupBackground());
|
||||
try
|
||||
{
|
||||
float maxWidth = 0;
|
||||
//Calculate max label width first
|
||||
IterateThroughValidChildren(property, ignoreProperties, (eachChildProperty) =>
|
||||
{
|
||||
var currentDisplayName = (prefix != null) ? $"{prefix} {eachChildProperty.displayName}" : eachChildProperty.displayName;
|
||||
float currentLabelWidth = GUI.skin.label.CalcSize(new GUIContent(currentDisplayName)).x;
|
||||
|
||||
if(maxWidth < currentLabelWidth)
|
||||
{
|
||||
maxWidth = currentLabelWidth;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
if (indent)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
}
|
||||
|
||||
var oldLabelWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = ((maxWidth / 128) + 1) * 128; //Adding some extra 128 pixels buffer.
|
||||
IterateThroughValidChildren(property, ignoreProperties, (eachChildProperty) =>
|
||||
{
|
||||
// Display the property
|
||||
if (prefix != null)
|
||||
{
|
||||
EditorGUILayout.PropertyField(eachChildProperty, new GUIContent($"{prefix} {eachChildProperty.displayName}", eachChildProperty.tooltip), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.PropertyField(eachChildProperty, true);
|
||||
}
|
||||
});
|
||||
EditorGUIUtility.labelWidth = oldLabelWidth;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (indent)
|
||||
{
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
|
||||
private static void IterateThroughValidChildren(SerializedProperty property, string[] ignoreProperties, Action<SerializedProperty> callbackOnEachChild)
|
||||
{
|
||||
// Move pointer to first element
|
||||
var currentProperty = property.Copy();
|
||||
var endProperty = default(SerializedProperty);
|
||||
|
||||
// Start iterating through the properties
|
||||
bool firstTime = true;
|
||||
while (currentProperty.NextVisible(enterChildren: firstTime))
|
||||
{
|
||||
if (firstTime)
|
||||
{
|
||||
endProperty = property.GetEndProperty();
|
||||
firstTime = false;
|
||||
}
|
||||
if (SerializedProperty.EqualContents(currentProperty, endProperty))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// Exclude specified properties
|
||||
if ((ignoreProperties != null) && System.Array.Exists(ignoreProperties, (item) => string.Equals(item, currentProperty.name)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
callbackOnEachChild(currentProperty);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public methods
|
||||
|
||||
public void DoLayout()
|
||||
{
|
||||
if (CanShowFocusSection())
|
||||
{
|
||||
DrawFocusSection();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_drawTopBarCallback?.Invoke(m_selectedTab);
|
||||
DrawTabBar();
|
||||
DrawTabView();
|
||||
m_drawFooterCallback?.Invoke(m_selectedTab);
|
||||
}
|
||||
m_serializedObject.ApplyModifiedProperties();
|
||||
m_serializedObject.Update();
|
||||
}
|
||||
|
||||
public void DrawSection(EditorSectionInfo section,
|
||||
bool showDetails = true,
|
||||
bool selectable = true)
|
||||
{
|
||||
EditorGUILayout.BeginVertical(m_backgroundStyle);
|
||||
bool expanded = DrawSectionHeader(section,
|
||||
selectable);
|
||||
bool endGroup = true;
|
||||
if (showDetails || expanded)
|
||||
{
|
||||
if (section.DrawStyle == EditorSectionDrawStyle.Default)
|
||||
{
|
||||
endGroup = false;
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
|
||||
if (section.DrawDetailsCallback != null)
|
||||
{
|
||||
section.DrawDetailsCallback(section);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (section.DrawStyle == EditorSectionDrawStyle.Default)
|
||||
{
|
||||
endGroup = true;
|
||||
EditorGUILayout.BeginVertical(m_backgroundStyle);
|
||||
}
|
||||
DrawSectionDetails(section);
|
||||
}
|
||||
}
|
||||
if (endGroup)
|
||||
{
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawSectionDetails(EditorSectionInfo section)
|
||||
{
|
||||
bool originalGUIState = GUI.enabled;
|
||||
try
|
||||
{
|
||||
// Update edit capability
|
||||
GUI.enabled = section.IsEnabled;
|
||||
|
||||
// Draw section properties
|
||||
DrawChildProperties(property: section.Property,
|
||||
ignoreProperties: section.IgnoreProperties);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Reset gui state
|
||||
GUI.enabled = originalGUIState;
|
||||
}
|
||||
}
|
||||
|
||||
public void BeginVertical()
|
||||
{
|
||||
EditorGUILayout.BeginVertical(m_backgroundStyle);
|
||||
}
|
||||
|
||||
public void EndVertical()
|
||||
{
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
|
||||
private void LoadStyles()
|
||||
{
|
||||
m_backgroundStyle = CustomEditorStyles.GroupBackground();
|
||||
m_titleLabelStyle = CustomEditorStyles.Heading2Label();
|
||||
m_subtitleLabelStyle = CustomEditorStyles.OptionsLabel(wordWrap: false);
|
||||
m_tabBarLabelNormalStyle = CustomEditorStyles.SelectableLabel(fontSize: 16, textColor: Color.gray);
|
||||
m_tabBarLabelSelectedStyle = CustomEditorStyles.SelectableLabel(fontSize: 16, fontStyle: FontStyle.Bold);
|
||||
m_selectableLabelStyle = CustomEditorStyles.SelectableLabel();
|
||||
m_invisibleButtonStyle = CustomEditorStyles.InvisibleButton();
|
||||
}
|
||||
|
||||
private bool CanShowFocusSection()
|
||||
{
|
||||
return (m_focusSection != null) && (m_focusSection.DrawStyle == EditorSectionDrawStyle.Default);
|
||||
}
|
||||
|
||||
private void DrawTabBar()
|
||||
{
|
||||
if (m_tabs.Length > 1)
|
||||
{
|
||||
m_tabBarScrollPosition = GUILayout.BeginScrollView(m_tabBarScrollPosition, m_backgroundStyle, GUILayout.Height(30f));
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.FlexibleSpace();
|
||||
for (int iter = 0; iter < m_tabs.Length; iter++)
|
||||
{
|
||||
var current = m_tabs[iter];
|
||||
var labelStyle = (current == m_selectedTab) ? m_tabBarLabelSelectedStyle : m_tabBarLabelNormalStyle;
|
||||
if (GUILayout.Button(current, labelStyle, GUILayout.Width(80f)))
|
||||
{
|
||||
SetSelectedTab(current);
|
||||
}
|
||||
}
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.EndScrollView();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawTabView()
|
||||
{
|
||||
if ((m_drawTabViewCallback == null) || !m_drawTabViewCallback(m_selectedTab))
|
||||
{
|
||||
for (int iter = 0; iter < m_selectedTabSections.Length; iter++)
|
||||
{
|
||||
var current = m_selectedTabSections[iter];
|
||||
DrawSection(section: current,
|
||||
showDetails: (current.DrawStyle == EditorSectionDrawStyle.Expand) && (current == m_focusSection));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool DrawSectionHeader(EditorSectionInfo section,
|
||||
bool selectable = true)
|
||||
{
|
||||
bool isSelected = (section == m_focusSection);
|
||||
bool hasSubtitle = (section.Description != null);
|
||||
float headerHeight = hasSubtitle ? 52f : 30f;
|
||||
|
||||
// Draw rect
|
||||
var rect = EditorGUILayout.GetControlRect(false, headerHeight);
|
||||
//GUI.Box(rect, GUIContent.none, HeaderButtonStyle);
|
||||
|
||||
/*
|
||||
// Draw expand control
|
||||
if (drawStyle == PropertyGroupDrawStyle.Expand)
|
||||
{
|
||||
var foldOutRect = new Rect(rect.x + 5f, rect.y, 50f, rect.height);
|
||||
EditorGUI.LabelField(foldOutRect, isSelected ? "-" : "+", CustomEditorStyles.Heading3);
|
||||
}
|
||||
*/
|
||||
|
||||
// Draw text
|
||||
var titleRect = new Rect(rect.x + 5f,
|
||||
rect.y + 4f,
|
||||
rect.width * 0.8f,
|
||||
22f);
|
||||
EditorGUI.LabelField(titleRect, section.DisplayName, m_titleLabelStyle);
|
||||
if (hasSubtitle)
|
||||
{
|
||||
var subtitleRect = new Rect(rect.x + 5f,
|
||||
rect.y + 25f,
|
||||
rect.width * 0.8f,
|
||||
18f);
|
||||
EditorGUI.LabelField(subtitleRect, section.Description, m_subtitleLabelStyle);
|
||||
}
|
||||
|
||||
// Draw selectable rect
|
||||
var selectableRect = new Rect(rect.x,
|
||||
rect.y,
|
||||
rect.width * 0.8f,
|
||||
rect.height);
|
||||
if (selectable && EditorLayoutUtility.TransparentButton(selectableRect))
|
||||
{
|
||||
isSelected = SetFocusSection(section);
|
||||
}
|
||||
|
||||
// Draw toggle button
|
||||
var enabledProperty = section.EnabledProperty;
|
||||
if (enabledProperty != null)
|
||||
{
|
||||
var toggleIcon = enabledProperty.boolValue ? m_toggleOnIcon : m_toggleOffIcon;
|
||||
var iconSize = new Vector2(64f, 32f);
|
||||
var toggleRect = new Rect(rect.xMax - (iconSize.x * 1.2f),
|
||||
titleRect.yMin + ((titleRect.height - iconSize.y/2)),
|
||||
iconSize.x,
|
||||
iconSize.y);
|
||||
if (GUI.Button(toggleRect, toggleIcon, m_invisibleButtonStyle))
|
||||
{
|
||||
enabledProperty.boolValue = !enabledProperty.boolValue;
|
||||
|
||||
// Raise an event to notify others, delay is added to ensure that modified properties are serialized
|
||||
EditorApplication.delayCall += () => { OnSectionStatusChange?.Invoke(section); };
|
||||
}
|
||||
}
|
||||
return isSelected;
|
||||
}
|
||||
|
||||
private void DrawFocusSection()
|
||||
{
|
||||
var property = m_focusSection.Property;
|
||||
EditorGUILayout.BeginHorizontal(m_backgroundStyle);
|
||||
if (GUILayout.Button($"{'\u2190'} Back To Main Menu", m_titleLabelStyle))
|
||||
{
|
||||
SetFocusSection(null);
|
||||
return;
|
||||
}
|
||||
GUILayout.FlexibleSpace();
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
property.isExpanded = true;
|
||||
DrawSection(section: m_focusSection,
|
||||
selectable: false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Getter methods
|
||||
|
||||
private EditorSectionInfo[] GetSections(string tab)
|
||||
{
|
||||
return m_getSectionsCallback(tab) ?? new EditorSectionInfo[0];
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Setter methods
|
||||
|
||||
private void SetSelectedTab(string tab)
|
||||
{
|
||||
// Update cached data
|
||||
m_selectedTab = tab;
|
||||
m_selectedTabSections = GetSections(tab);
|
||||
}
|
||||
|
||||
private bool SetFocusSection(EditorSectionInfo section)
|
||||
{
|
||||
var oldFocusSection = m_focusSection;
|
||||
|
||||
// Set new value
|
||||
m_focusSection = section;
|
||||
|
||||
// Update selection state
|
||||
if ((section != null) && (section == oldFocusSection))
|
||||
{
|
||||
section.Property.isExpanded = !section.Property.isExpanded;
|
||||
m_focusSection = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (oldFocusSection != null)
|
||||
{
|
||||
oldFocusSection.Property.isExpanded = false;
|
||||
}
|
||||
if (section != null)
|
||||
{
|
||||
section.Property.isExpanded = true;
|
||||
}
|
||||
}
|
||||
bool hasChanged = (oldFocusSection != m_focusSection);
|
||||
if (hasChanged)
|
||||
{
|
||||
OnFocusSectionValueChange?.Invoke(m_focusSection);
|
||||
}
|
||||
return hasChanged;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class EditorSectionInfo
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public string DisplayName { get; private set; }
|
||||
|
||||
public string Description { get; private set; }
|
||||
|
||||
public bool IsEnabled => (EnabledProperty == null) || EnabledProperty.boolValue;
|
||||
|
||||
public SerializedProperty Property { get; private set; }
|
||||
|
||||
public SerializedProperty EnabledProperty { get; private set; }
|
||||
|
||||
public EditorSectionDrawStyle DrawStyle { get; private set; }
|
||||
|
||||
public DrawCallback DrawDetailsCallback { get; private set; }
|
||||
|
||||
public string[] IgnoreProperties { get; private set; }
|
||||
|
||||
public object Tag { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Delegates
|
||||
|
||||
public delegate void DrawCallback(EditorSectionInfo section);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public EditorSectionInfo(string displayName,
|
||||
SerializedProperty property,
|
||||
SerializedProperty enabledProperty = null,
|
||||
string description = null,
|
||||
EditorSectionDrawStyle drawStyle = EditorSectionDrawStyle.Default,
|
||||
DrawCallback drawDetailsCallback = null,
|
||||
object tag = null,
|
||||
params string[] ignoreProperties)
|
||||
{
|
||||
Assert.IsArgNotNull(displayName, nameof(displayName));
|
||||
Assert.IsArgNotNull(property, nameof(property));
|
||||
|
||||
// set properties
|
||||
DisplayName = displayName;
|
||||
Description = description;
|
||||
Property = property;
|
||||
EnabledProperty = enabledProperty ?? property.FindPropertyRelative("m_isEnabled");
|
||||
DrawStyle = drawStyle;
|
||||
DrawDetailsCallback = drawDetailsCallback;
|
||||
IgnoreProperties = ignoreProperties ?? new string[] { "m_isEnabled" };
|
||||
Tag = tag;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public enum EditorSectionDrawStyle
|
||||
{
|
||||
Default,
|
||||
|
||||
Expand,
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4019dad4610704cb38751061068b7fa8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,117 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
public static class EditorLayoutUtility
|
||||
{
|
||||
#region Static methods
|
||||
|
||||
public static void DisableGUI()
|
||||
{
|
||||
GUI.enabled = false;
|
||||
}
|
||||
|
||||
public static void EnableGUI()
|
||||
{
|
||||
GUI.enabled = true;
|
||||
}
|
||||
|
||||
public static bool TransparentButton(Rect rect,
|
||||
string label = "")
|
||||
{
|
||||
var originalColor = GUI.color;
|
||||
try
|
||||
{
|
||||
GUI.color = Color.clear;
|
||||
return GUI.Button(rect, label);
|
||||
}
|
||||
finally
|
||||
{
|
||||
GUI.color = originalColor;
|
||||
}
|
||||
}
|
||||
|
||||
public static void StringPopup(int selectedIndex,
|
||||
string[] options,
|
||||
Callback<int> onValueChange,
|
||||
params GUILayoutOption[] layoutOptions)
|
||||
{
|
||||
int newValue = EditorGUILayout.Popup(selectedIndex, options, layoutOptions);
|
||||
if (newValue != selectedIndex)
|
||||
{
|
||||
onValueChange?.Invoke(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
public static void StringPopup(SerializedProperty stringProperty,
|
||||
ref int selectedIndex,
|
||||
string[] displayedOptions,
|
||||
Callback<int> onValueChange = null,
|
||||
params GUILayoutOption[] layoutOptions)
|
||||
{
|
||||
int newValue = EditorGUILayout.Popup(new GUIContent(stringProperty.displayName, stringProperty.tooltip),
|
||||
selectedIndex,
|
||||
displayedOptions,
|
||||
layoutOptions);
|
||||
if (newValue != selectedIndex)
|
||||
{
|
||||
selectedIndex = newValue;
|
||||
stringProperty.stringValue = displayedOptions[newValue];
|
||||
|
||||
onValueChange?.Invoke(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Helpbox(string title,
|
||||
string description,
|
||||
System.Action drawFunc,
|
||||
GUIStyle style)
|
||||
{
|
||||
GUILayout.BeginVertical(style);
|
||||
GUILayout.Label(title, EditorStyles.boldLabel);
|
||||
GUILayout.Label(description, EditorStyles.wordWrappedLabel);
|
||||
drawFunc();
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
public static void Helpbox(string title,
|
||||
string description,
|
||||
string actionLabel,
|
||||
System.Action onClick,
|
||||
GUIStyle style)
|
||||
{
|
||||
Helpbox(
|
||||
title: title,
|
||||
description: description,
|
||||
drawFunc: () =>
|
||||
{
|
||||
if (GUILayout.Button(actionLabel))
|
||||
{
|
||||
onClick?.Invoke();
|
||||
}
|
||||
},
|
||||
style: style);
|
||||
}
|
||||
|
||||
public static void BeginBottomBar(Color? borderColor = null,
|
||||
params GUILayoutOption[] options)
|
||||
{
|
||||
var bottomBarRect = EditorGUILayout.BeginHorizontal(options);
|
||||
bottomBarRect.height = 1f;
|
||||
if (borderColor != null)
|
||||
{
|
||||
EditorGUI.DrawRect(bottomBarRect, borderColor.Value);
|
||||
}
|
||||
}
|
||||
|
||||
public static void EndBottomBar()
|
||||
{
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c40767cd6fb464f3b83f7e68d5e47449
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,185 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
public class EditorSplitView
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private SplitDirection m_direction;
|
||||
|
||||
private float m_splitRatio;
|
||||
|
||||
private bool m_resize;
|
||||
|
||||
private Vector2 m_firstContainerScrollPos;
|
||||
|
||||
private Rect m_availableRect;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
private EditorSplitView(SplitDirection direction, float splitRatio)
|
||||
{
|
||||
m_splitRatio = splitRatio;
|
||||
m_direction = direction;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static methods
|
||||
|
||||
public static EditorSplitView CreateHorizontalSplitView(float splitRatio = 0.3f)
|
||||
{
|
||||
return new EditorSplitView(SplitDirection.Horizontal, splitRatio);
|
||||
}
|
||||
|
||||
public static EditorSplitView CreateVerticalSplitView(float splitRatio = 0.3f)
|
||||
{
|
||||
return new EditorSplitView(SplitDirection.Vertical, splitRatio);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
|
||||
public void BeginArea()
|
||||
{
|
||||
Rect tempRect = Rect.zero;
|
||||
if (m_direction == SplitDirection.Horizontal)
|
||||
{
|
||||
tempRect = EditorGUILayout.BeginHorizontal();
|
||||
}
|
||||
else if (m_direction == SplitDirection.Vertical)
|
||||
{
|
||||
tempRect = EditorGUILayout.BeginVertical();
|
||||
}
|
||||
if (tempRect.width > 0.0f)
|
||||
{
|
||||
m_availableRect = tempRect;
|
||||
}
|
||||
|
||||
BeginContainer();
|
||||
if (m_direction == SplitDirection.Horizontal)
|
||||
{
|
||||
m_firstContainerScrollPos = EditorGUILayout.BeginScrollView(m_firstContainerScrollPos, GUILayout.Width(m_availableRect.width * m_splitRatio));
|
||||
}
|
||||
else if (m_direction == SplitDirection.Vertical)
|
||||
{
|
||||
m_firstContainerScrollPos = EditorGUILayout.BeginScrollView(m_firstContainerScrollPos, GUILayout.Height(m_availableRect.height * m_splitRatio));
|
||||
}
|
||||
}
|
||||
|
||||
public void Split()
|
||||
{
|
||||
// firstly mark that first container has ended
|
||||
EditorGUILayout.EndScrollView();
|
||||
EndContainer();
|
||||
ResizeFirstContainer();
|
||||
|
||||
// initiate rendering second container
|
||||
BeginContainer();
|
||||
}
|
||||
|
||||
public void EndArea()
|
||||
{
|
||||
EndContainer();
|
||||
|
||||
if (m_direction == SplitDirection.Horizontal)
|
||||
{
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
else if (m_direction == SplitDirection.Vertical)
|
||||
{
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
}
|
||||
|
||||
private Rect BeginContainer()
|
||||
{
|
||||
if (m_direction == SplitDirection.Horizontal)
|
||||
{
|
||||
return EditorGUILayout.BeginVertical();
|
||||
}
|
||||
else if (m_direction == SplitDirection.Vertical)
|
||||
{
|
||||
return EditorGUILayout.BeginHorizontal();
|
||||
}
|
||||
else
|
||||
{
|
||||
return Rect.zero;
|
||||
}
|
||||
}
|
||||
|
||||
private void EndContainer()
|
||||
{
|
||||
if (m_direction == SplitDirection.Horizontal)
|
||||
{
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
else if (m_direction == SplitDirection.Vertical)
|
||||
{
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
|
||||
private void ResizeFirstContainer()
|
||||
{
|
||||
Rect resizeHandleRect;
|
||||
if (m_direction == SplitDirection.Horizontal)
|
||||
{
|
||||
resizeHandleRect = new Rect(m_availableRect.width * m_splitRatio, m_availableRect.y, 1f, m_availableRect.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
resizeHandleRect = new Rect(m_availableRect.x, m_availableRect.height * m_splitRatio, m_availableRect.width, 1f);
|
||||
}
|
||||
EditorGUI.DrawRect(resizeHandleRect, CustomEditorStyles.BorderColor);
|
||||
if (m_direction == SplitDirection.Horizontal)
|
||||
{
|
||||
EditorGUIUtility.AddCursorRect(resizeHandleRect, MouseCursor.ResizeHorizontal);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUIUtility.AddCursorRect(resizeHandleRect, MouseCursor.ResizeVertical);
|
||||
}
|
||||
|
||||
if (Event.current.type == EventType.MouseDown && resizeHandleRect.Contains(Event.current.mousePosition))
|
||||
{
|
||||
m_resize = true;
|
||||
}
|
||||
if (m_resize)
|
||||
{
|
||||
if (m_direction == SplitDirection.Horizontal)
|
||||
{
|
||||
m_splitRatio = Event.current.mousePosition.x / m_availableRect.width;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_splitRatio = Event.current.mousePosition.y / m_availableRect.height;
|
||||
}
|
||||
}
|
||||
if (Event.current.type == EventType.MouseUp)
|
||||
{
|
||||
m_resize = false;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Nested types
|
||||
|
||||
private enum SplitDirection
|
||||
{
|
||||
Horizontal,
|
||||
|
||||
Vertical
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a20197bdbee5a44b196d137503bca990
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,41 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
public class EditorWindowZ : EditorWindow
|
||||
{
|
||||
#region Fields
|
||||
|
||||
[System.NonSerialized]
|
||||
private bool m_isInitialized;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Unity methods
|
||||
|
||||
protected virtual void OnGUI()
|
||||
{
|
||||
EnsureInitialized();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
|
||||
protected virtual void Init()
|
||||
{ }
|
||||
|
||||
protected void EnsureInitialized()
|
||||
{
|
||||
if (m_isInitialized) return;
|
||||
|
||||
m_isInitialized = true;
|
||||
Init();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0757cac8d21f499e80db0e955801000
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,49 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using VoxelBusters.CoreLibrary;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(EnumMaskFieldAttribute))]
|
||||
public class EnumMaskFieldDrawer : PropertyDrawer
|
||||
{
|
||||
#region Drawer Methods
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
label = EditorGUI.BeginProperty(position, label, property);
|
||||
if (IsEnum())
|
||||
{
|
||||
UnityEditorUtility.EnumFlagsField(position, label, property, GetEnumType());
|
||||
}
|
||||
else
|
||||
{
|
||||
base.OnGUI(position, property, label);
|
||||
}
|
||||
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
|
||||
private Type GetEnumType()
|
||||
{
|
||||
return ((EnumMaskFieldAttribute)attribute).EnumType;
|
||||
}
|
||||
|
||||
private bool IsEnum()
|
||||
{
|
||||
Type type = GetEnumType();
|
||||
#if NETFX_CORE
|
||||
return type.GetTypeInfo().IsEnum;
|
||||
#else
|
||||
return type.IsEnum;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11e33d767c33a4a10bc1e378ed17ef72
|
||||
timeCreated: 1579074419
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,52 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using VoxelBusters.CoreLibrary;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(FileBrowserAttribute))]
|
||||
public class FileBrowserAttributeDrawer : PropertyDrawer
|
||||
{
|
||||
#region Base class methods
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
// draw property
|
||||
var valueRect = new Rect(position.x, position.y, position.width - 50, position.height);
|
||||
var buttonRect = new Rect(position.xMax - 45, position.y, 45, position.height);
|
||||
|
||||
EditorGUI.PropertyField(valueRect, property, label);
|
||||
if (GUI.Button(buttonRect, new GUIContent("Select")))
|
||||
{
|
||||
EditorApplication.delayCall += () =>
|
||||
{
|
||||
OpenFileBrowser(property);
|
||||
};
|
||||
}
|
||||
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
|
||||
private void OpenFileBrowser(SerializedProperty property)
|
||||
{
|
||||
var value = EditorUtility.OpenFilePanel("Select file", IOServices.GetAbsolutePath(property.stringValue), ((FileBrowserAttribute)attribute).Extension);
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
property.stringValue = ((FileBrowserAttribute)attribute).UsesRelativePath ? IOServices.GetRelativePath(IOServices.GetAbsolutePath(""), value) : value;
|
||||
UnityEditorUtility.SetIsEditorDirty(true);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f924f934566204936b517248f5f8f4bd
|
||||
timeCreated: 1576323713
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,51 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using VoxelBusters.CoreLibrary;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(FolderBrowserAttribute))]
|
||||
public class FolderBrowserAttributeDrawer : PropertyDrawer
|
||||
{
|
||||
#region Base class methods
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
// draw property
|
||||
var valueRect = new Rect(position.x, position.y, position.width - 50, position.height);
|
||||
var buttonRect = new Rect(position.xMax - 45, position.y, 45, position.height);
|
||||
|
||||
EditorGUI.PropertyField(valueRect, property, label);
|
||||
if (GUI.Button(buttonRect, new GUIContent("Select")))
|
||||
{
|
||||
EditorApplication.delayCall += () =>
|
||||
{
|
||||
OpenFolderBrowser(property);
|
||||
};
|
||||
}
|
||||
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
|
||||
private void OpenFolderBrowser(SerializedProperty property)
|
||||
{
|
||||
var value = EditorUtility.OpenFolderPanel("Select folder", IOServices.GetAbsolutePath(property.stringValue), string.Empty);
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
property.stringValue = ((FolderBrowserAttribute)attribute).UsesRelativePath ? IOServices.GetRelativePath(IOServices.GetAbsolutePath(""), value) : value;
|
||||
UnityEditorUtility.SetIsEditorDirty(true);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cafbc9653f53348559d4e088e2014b44
|
||||
timeCreated: 1576323712
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,38 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using VoxelBusters.CoreLibrary;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(InterfaceFieldAttribute))]
|
||||
public class InterfaceFieldAttributeDrawer : PropertyDrawer
|
||||
{
|
||||
#region Base class methods
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
// draw property
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.PropertyField(position, property, label);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
var reference = property.objectReferenceValue;
|
||||
var interfaceType = ((InterfaceFieldAttribute)attribute).InterfaceType;
|
||||
if (reference && !interfaceType.IsAssignableFrom(reference.GetType()))
|
||||
{
|
||||
DebugLogger.LogError(CoreLibraryDomain.Default, $"Object does not implement interface of type: {interfaceType}.");
|
||||
property.objectReferenceValue = null;
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9c5bbe7cdfcd444908de802817480fbf
|
||||
timeCreated: 1577514657
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,66 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(ReadOnlyAttribute), true)]
|
||||
public class ReadOnlyAttributeDrawer : PropertyDrawer
|
||||
{
|
||||
private const float m_padding = 10f;
|
||||
|
||||
#region Base class methods
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
var offset = GetMessageHeight();
|
||||
var fieldHeight = EditorGUI.GetPropertyHeight(property, label, true);
|
||||
var fieldRect = new Rect(position.x, position.y + m_padding, position.width, fieldHeight);
|
||||
var messageRect = new Rect(position.x, position.y + fieldHeight + m_padding + 2f, position.width, offset);
|
||||
|
||||
GUI.enabled = false;
|
||||
EditorGUI.PropertyField(fieldRect, property, label, true);
|
||||
if (HasMessage())
|
||||
{
|
||||
EditorGUI.LabelField(messageRect, GetMessage(), GetMessageStyle());
|
||||
}
|
||||
GUI.enabled = true;
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return EditorGUI.GetPropertyHeight(property, label, true) + GetMessageHeight() + m_padding * 2f;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Utility methods
|
||||
|
||||
private GUIStyle GetMessageStyle()
|
||||
{
|
||||
return CustomEditorStyles.MiniLabel(wordWrap: false); //TODO: Using false as calcSize is not working properly with wordwrap on.
|
||||
}
|
||||
|
||||
private bool HasMessage()
|
||||
{
|
||||
return !string.IsNullOrEmpty(GetMessage());
|
||||
}
|
||||
|
||||
private string GetMessage()
|
||||
{
|
||||
var message = ((ReadOnlyAttribute)attribute).Message;
|
||||
return message;
|
||||
}
|
||||
|
||||
private float GetMessageHeight()
|
||||
{
|
||||
var message = GetMessage();
|
||||
|
||||
if (string.IsNullOrEmpty(message))
|
||||
return 0f;
|
||||
|
||||
return GetMessageStyle().CalcSize(new GUIContent(message)).y;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fb5b59ba618cd4d3a97f3f6a1f7ec0c6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,38 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using VoxelBusters.CoreLibrary;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(RuntimePlatformConstant))]
|
||||
public class RuntimePlatformConstantDrawer : PropertyDrawer
|
||||
{
|
||||
#region Unity methods
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight;
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
// show property name label
|
||||
label = EditorGUI.BeginProperty(position, label, property);
|
||||
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
|
||||
|
||||
// show property attributes
|
||||
Rect platformRect = new Rect(position.x, position.y, 60f, position.height);
|
||||
Rect idRect = new Rect(position.x + 65f, position.y, position.width - 65f, position.height);
|
||||
int indentLevel = EditorGUI.indentLevel;
|
||||
|
||||
EditorGUI.indentLevel = 0;
|
||||
EditorGUI.PropertyField(platformRect, property.FindPropertyRelative("m_platform"), GUIContent.none);
|
||||
EditorGUI.PropertyField(idRect, property.FindPropertyRelative("m_value"), GUIContent.none);
|
||||
EditorGUI.indentLevel = indentLevel;
|
||||
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8345dac92c6c4d8e813c3a6cc3bd585
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,244 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
public abstract class SettingsObjectInspector : UnityEditor.Editor
|
||||
{
|
||||
#region Constants
|
||||
|
||||
private static readonly ButtonMeta[] s_emptyButtonArray = new ButtonMeta[0];
|
||||
|
||||
private static readonly string[] s_ignoredProperties = new string[] { "m_Script" };
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
|
||||
private string m_productName;
|
||||
|
||||
private string m_productVersion;
|
||||
|
||||
// Assets
|
||||
private Texture2D m_logoIcon;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public EditorLayoutBuilder LayoutBuilder { get; private set; }
|
||||
|
||||
protected GUIStyle CustomMarginStyle { get; private set; }
|
||||
|
||||
protected GUIStyle GroupBackgroundStyle { get; private set; }
|
||||
|
||||
protected GUIStyle ProductNameStyle { get; private set; }
|
||||
|
||||
protected GUIStyle NormalLabelStyle { get; private set; }
|
||||
|
||||
protected GUIStyle OptionsLabelStyle { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Abstract methods
|
||||
|
||||
protected abstract UnityPackageDefinition GetOwner();
|
||||
|
||||
protected abstract string[] GetTabNames();
|
||||
|
||||
protected abstract EditorSectionInfo[] GetSectionsForTab(string tab);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Unity methods
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{ }
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
EnsurePropertiesAreSet();
|
||||
|
||||
EditorGUILayout.BeginVertical(CustomMarginStyle);
|
||||
LayoutBuilder.DoLayout();
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
|
||||
public override bool UseDefaultMargins()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Draw methods
|
||||
|
||||
protected virtual void DrawTopBar(string tab)
|
||||
{
|
||||
GUILayout.BeginHorizontal(GroupBackgroundStyle);
|
||||
|
||||
// logo section
|
||||
GUILayout.BeginVertical();
|
||||
GUILayout.Space(2f);
|
||||
GUILayout.Label(m_logoIcon, GUILayout.Height(64f), GUILayout.Width(64f));
|
||||
GUILayout.Space(2f);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
// product info
|
||||
GUILayout.BeginVertical();
|
||||
GUILayout.Label(m_productName, ProductNameStyle);
|
||||
GUILayout.Label(m_productVersion, NormalLabelStyle);
|
||||
GUILayout.Label("Copyright © 2024 Voxel Busters Interactive LLP.", OptionsLabelStyle);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
protected virtual bool DrawTabView(string tab)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
protected virtual void DrawFooter(string tab)
|
||||
{ }
|
||||
|
||||
protected virtual void DrawButtonList(ButtonMeta[] buttons)
|
||||
{
|
||||
GUILayout.BeginVertical();
|
||||
foreach (var item in buttons)
|
||||
{
|
||||
if (GUILayout.Button(item.Label, GUILayout.MinHeight(80f)))
|
||||
{
|
||||
item?.OnClick();
|
||||
}
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
|
||||
private void EnsurePropertiesAreSet()
|
||||
{
|
||||
if (LayoutBuilder != null) return;
|
||||
|
||||
LoadCustomStyles();
|
||||
LoadAssets();
|
||||
|
||||
// Set properties
|
||||
var commonResourcePath = CoreLibrarySettings.Package.GetEditorResourcesPath();
|
||||
var ownerPackage = GetOwner();
|
||||
m_productName = ownerPackage.DisplayName;
|
||||
m_productVersion = $"v{ownerPackage.Version}";
|
||||
LayoutBuilder = new EditorLayoutBuilder(serializedObject: serializedObject,
|
||||
tabs: GetTabNames(),
|
||||
getSectionsCallback: GetSectionsForTab,
|
||||
drawTopBarCallback: DrawTopBar,
|
||||
drawTabViewCallback: DrawTabView,
|
||||
drawFooterCallback: DrawFooter,
|
||||
toggleOnIcon: AssetDatabase.LoadAssetAtPath<Texture2D>(commonResourcePath + "/Textures/toggle-on.png"),
|
||||
toggleOffIcon: AssetDatabase.LoadAssetAtPath<Texture2D>(commonResourcePath + "/Textures/toggle-off.png"));
|
||||
LayoutBuilder.OnSectionStatusChange += OnSectionStatusChange;
|
||||
LayoutBuilder.OnFocusSectionValueChange += OnFocusSectionValueChange;
|
||||
}
|
||||
|
||||
private void LoadCustomStyles()
|
||||
{
|
||||
CustomMarginStyle = new GUIStyle(EditorStyles.inspectorFullWidthMargins)
|
||||
{
|
||||
margin = new RectOffset(2, 2, 0, 0),
|
||||
};
|
||||
GroupBackgroundStyle = CustomEditorStyles.GroupBackground();
|
||||
ProductNameStyle = CustomEditorStyles.Heading1Label();
|
||||
NormalLabelStyle = CustomEditorStyles.NormalLabel();
|
||||
OptionsLabelStyle = CustomEditorStyles.OptionsLabel();
|
||||
}
|
||||
|
||||
private void LoadAssets()
|
||||
{
|
||||
// load custom assets
|
||||
var ownerResourcePath = GetOwner().GetEditorResourcesPath();
|
||||
m_logoIcon = AssetDatabase.LoadAssetAtPath<Texture2D>(ownerResourcePath + "/Textures/logo.png");
|
||||
}
|
||||
|
||||
protected void EnsureChangesAreSerialized()
|
||||
{
|
||||
EditorUtility.SetDirty(target);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
serializedObject.Update();
|
||||
}
|
||||
|
||||
protected void TryApplyModifiedProperties()
|
||||
{
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
serializedObject.Update();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Misc methods
|
||||
#if NATIVE_PLUGINS_SHOW_UPM_MIGRATION
|
||||
protected void ShowMigrateToUpmOption()
|
||||
{
|
||||
EditorLayoutUtility.Helpbox(title: "UPM Support",
|
||||
description: "You can install the package on UPM.",
|
||||
actionLabel: "Migrate To UPM",
|
||||
onClick: GetOwner().MigrateToUpm,
|
||||
style: GroupBackgroundStyle);
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
|
||||
#region Event handler methods
|
||||
|
||||
protected virtual void OnSectionStatusChange(EditorSectionInfo section)
|
||||
{ }
|
||||
|
||||
protected virtual void OnFocusSectionValueChange(EditorSectionInfo section)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Nested types
|
||||
|
||||
protected class ButtonMeta
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public string Label { get; private set; }
|
||||
|
||||
public System.Action OnClick { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public ButtonMeta(string label, System.Action onClick)
|
||||
{
|
||||
// set properties
|
||||
Label = label;
|
||||
OnClick = onClick;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
protected class DefaultTabs
|
||||
{
|
||||
public const string kGeneral = "General";
|
||||
|
||||
public const string kServices = "Services";
|
||||
|
||||
public const string kMisc = "Help";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b40748a9ae9854787b64a0c8ccc993a9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,89 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
#if UNITY_2019_1_OR_NEWER
|
||||
using UnityEngine.UIElements;
|
||||
#else
|
||||
using UnityEngine.Experimental.UIElements;
|
||||
#endif
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
public class SettingsProviderZ : SettingsProvider
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private SettingsObject m_settingsObject;
|
||||
|
||||
private SettingsObjectInspector m_settingsObjectInspector;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
private SettingsProviderZ(SettingsObject settingsObject, string path, SettingsScope scopes)
|
||||
: base(path, scopes)
|
||||
{
|
||||
// set properties
|
||||
keywords = GetSearchKeywordsFromSerializedObject(new SerializedObject(settingsObject));
|
||||
m_settingsObject = settingsObject;
|
||||
m_settingsObjectInspector = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Create methods
|
||||
|
||||
public static SettingsProviderZ Create(SettingsObject settingsObject, string path, SettingsScope scopes)
|
||||
{
|
||||
return new SettingsProviderZ(settingsObject, path, scopes);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Base class methods
|
||||
|
||||
public override void OnActivate(string searchContext, VisualElement rootElement)
|
||||
{
|
||||
base.OnActivate(searchContext, rootElement);
|
||||
|
||||
m_settingsObjectInspector = UnityEditor.Editor.CreateEditor(m_settingsObject) as SettingsObjectInspector;
|
||||
}
|
||||
|
||||
public override void OnTitleBarGUI()
|
||||
{
|
||||
EditorGUILayout.InspectorTitlebar(false, m_settingsObject);
|
||||
}
|
||||
|
||||
public override void OnGUI(string searchContext)
|
||||
{
|
||||
if (m_settingsObjectInspector == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
GUILayout.Space(10f);
|
||||
EditorGUILayout.BeginVertical();
|
||||
m_settingsObjectInspector.OnInspectorGUI();
|
||||
EditorGUILayout.EndVertical();
|
||||
GUILayout.Space(10f);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
public override void OnDeactivate()
|
||||
{
|
||||
base.OnDeactivate();
|
||||
|
||||
if (m_settingsObjectInspector)
|
||||
{
|
||||
Object.DestroyImmediate(m_settingsObjectInspector);
|
||||
m_settingsObjectInspector = null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 82c92451806c941888c94130f02c1a18
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,49 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using VoxelBusters.CoreLibrary;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(StringPopupAttribute), true)]
|
||||
public class StringPopupAttributeDrawer : PropertyDrawer
|
||||
{
|
||||
#region Base class methods
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
label = EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
// determine whether popup is required
|
||||
bool canShowPopup = true;
|
||||
var popupAttribute = (StringPopupAttribute)attribute;
|
||||
if (popupAttribute.PreferencePropertyName != null)
|
||||
{
|
||||
var preferencePropertyPath = property.propertyPath.Replace(property.name, popupAttribute.PreferencePropertyName);
|
||||
var preferenceProperty = property.serializedObject.FindProperty(preferencePropertyPath);
|
||||
canShowPopup = (preferenceProperty != null) && (preferenceProperty.boolValue == popupAttribute.PreferencePropertyValue);
|
||||
}
|
||||
|
||||
// draw property as per preference
|
||||
if (canShowPopup)
|
||||
{
|
||||
var options = popupAttribute.Options;
|
||||
int selectedIndex = Array.FindIndex(options, (item) => string.Equals(item, property.stringValue));
|
||||
selectedIndex = EditorGUI.Popup(position, label.text, selectedIndex, options);
|
||||
|
||||
// assign value
|
||||
property.stringValue = (selectedIndex == -1) ? string.Empty : options[selectedIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUI.PropertyField(position, property);
|
||||
}
|
||||
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a787cc0f93bc1438c845ec658e1ce1d5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,105 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
public static class UnityEditorUtility
|
||||
{
|
||||
#region Static methods
|
||||
|
||||
public static bool ShowFoldableHeader(string prefKeyName, string content, string tooltip = null)
|
||||
{
|
||||
bool isExpanded = EditorGUILayout.Foldout(EditorPrefs.GetBool(prefKeyName, false), new GUIContent(content, tooltip));
|
||||
EditorPrefs.SetBool(prefKeyName, isExpanded);
|
||||
|
||||
return isExpanded;
|
||||
}
|
||||
|
||||
public static bool ShowFoldableHeader(SerializedProperty property, string displayName = null)
|
||||
{
|
||||
bool isExpanded = EditorGUILayout.Foldout(property.isExpanded, new GUIContent(displayName ?? property.displayName, property.tooltip));
|
||||
property.isExpanded = isExpanded;
|
||||
|
||||
return isExpanded;
|
||||
}
|
||||
|
||||
public static void SetIsEditorDirty(bool value)
|
||||
{
|
||||
EditorPrefs.SetBool("editor-is-dirty", value);
|
||||
}
|
||||
|
||||
public static bool GetIsEditorDirty()
|
||||
{
|
||||
return EditorPrefs.GetBool("editor-is-dirty", false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Mask field methods
|
||||
|
||||
public static void EnumFlagsField(Rect position, GUIContent label, SerializedProperty property, Type type)
|
||||
{
|
||||
property.intValue = EnumFlagsField(position, label, property.intValue, type);
|
||||
}
|
||||
|
||||
public static int EnumFlagsField(Rect position, GUIContent label, int value, Type type)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
Enum newValue = EditorGUI.EnumFlagsField(position, label, GetValueAsEnum(value, type));
|
||||
#else
|
||||
Enum newValue = EditorGUI.EnumMaskField(position, label, GetValueAsEnum(value, type));
|
||||
#endif
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
return GetEnumAsInt(newValue, type);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static T EnumFlagsField<T>(Rect position, string label, T value)
|
||||
{
|
||||
return (T)(object)EnumFlagsField(position, new GUIContent(label), (int)(object)value, typeof(T));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private static methods
|
||||
|
||||
private static Array GetEnumValues(Type type)
|
||||
{
|
||||
return Enum.GetValues(type);
|
||||
}
|
||||
|
||||
private static Enum GetValueAsEnum(int value, Type type)
|
||||
{
|
||||
return (Enum)Enum.ToObject(type, value);
|
||||
}
|
||||
|
||||
private static int GetEnumAsInt(Enum value, Type type)
|
||||
{
|
||||
int newValueInt = Convert.ToInt32(value);
|
||||
|
||||
// if "Everything" is set, force Unity to unset the extra bits by iterating through them
|
||||
if (newValueInt < 0)
|
||||
{
|
||||
int bits = 0;
|
||||
foreach (var enumValue in GetEnumValues(type))
|
||||
{
|
||||
int checkBit = newValueInt & (int)enumValue;
|
||||
if (checkBit != 0)
|
||||
{
|
||||
bits |= (int)enumValue;
|
||||
}
|
||||
}
|
||||
newValueInt = bits;
|
||||
}
|
||||
return newValueInt;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8a74bb08ae57c4ca79d5d452cffa4c63
|
||||
timeCreated: 1576323712
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1aed5f1786094c25bd1a7e0d9ebaffb
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,115 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.PackageManager;
|
||||
using UnityEditor.PackageManager.Requests;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
public class AddUnityPackageOperation
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private string m_package;
|
||||
|
||||
private Action m_callback;
|
||||
|
||||
private AddRequest m_addPackageRequest;
|
||||
|
||||
private ListRequest m_getPackagesRequest;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public AddUnityPackageOperation(string package, System.Action callback)
|
||||
{
|
||||
// set properties
|
||||
m_package = package;
|
||||
m_callback = callback;
|
||||
m_getPackagesRequest = null;
|
||||
m_addPackageRequest = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public methods
|
||||
|
||||
public void Start()
|
||||
{
|
||||
m_getPackagesRequest = Client.List();
|
||||
|
||||
// register for routine callbacks
|
||||
EditorApplication.update += EditorUpdate;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
|
||||
private void EditorUpdate()
|
||||
{
|
||||
// check whether dependency packages are already installed
|
||||
if (m_getPackagesRequest != null)
|
||||
{
|
||||
if (m_getPackagesRequest.IsCompleted)
|
||||
{
|
||||
bool packageInstalled = false;
|
||||
foreach (var item in m_getPackagesRequest.Result)
|
||||
{
|
||||
if (string.Equals(item.name, m_package))
|
||||
{
|
||||
packageInstalled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// reset state
|
||||
m_getPackagesRequest = null;
|
||||
|
||||
// create add request, incase if package is not installed
|
||||
if (!packageInstalled)
|
||||
{
|
||||
Debug.LogFormat("[VoxelBusters] Creating request to add package {0}", m_package);
|
||||
m_addPackageRequest = Client.Add(m_package);
|
||||
}
|
||||
else
|
||||
{
|
||||
SendCompletionCallback();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// import resources after required packages are installed
|
||||
if (m_addPackageRequest != null)
|
||||
{
|
||||
if (m_addPackageRequest.IsCompleted)
|
||||
{
|
||||
SendCompletionCallback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SendCompletionCallback()
|
||||
{
|
||||
try
|
||||
{
|
||||
m_callback();
|
||||
}
|
||||
finally
|
||||
{
|
||||
// reset state
|
||||
m_package = null;
|
||||
m_callback = null;
|
||||
m_addPackageRequest = null;
|
||||
m_getPackagesRequest = null;
|
||||
EditorApplication.update -= EditorUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a35410a8a14c41b3ae3d22ba17a44fe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,152 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
using UnityEngine;
|
||||
using VoxelBusters.CoreLibrary;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
public static class ScriptingDefinesManager
|
||||
{
|
||||
#region Static fields
|
||||
|
||||
private static Dictionary<BuildTargetGroup, List<string>> s_addDefinesCollection;
|
||||
|
||||
private static Dictionary<BuildTargetGroup, List<string>> s_removeDefinesCollection;
|
||||
|
||||
private static BuildTargetGroup[] s_supportedTargetGroups;
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static methods
|
||||
|
||||
public static void AddDefine(string define, params BuildTargetGroup[] targetGroups)
|
||||
{
|
||||
EnsureInitialized();
|
||||
|
||||
AddDefineToCollection(
|
||||
definesCollection: s_addDefinesCollection,
|
||||
define: define,
|
||||
targetGroups: GetBuildTargetGroupsOrDefault(targetGroups));
|
||||
UpdateDefineSymbolsDelayed();
|
||||
}
|
||||
|
||||
public static void RemoveDefine(string define, params BuildTargetGroup[] targetGroups)
|
||||
{
|
||||
EnsureInitialized();
|
||||
|
||||
AddDefineToCollection(
|
||||
definesCollection: s_removeDefinesCollection,
|
||||
define: define,
|
||||
targetGroups: GetBuildTargetGroupsOrDefault(targetGroups));
|
||||
UpdateDefineSymbolsDelayed();
|
||||
}
|
||||
|
||||
private static void EnsureInitialized()
|
||||
{
|
||||
if (s_addDefinesCollection != null) return;
|
||||
|
||||
// set properties
|
||||
s_addDefinesCollection = new Dictionary<BuildTargetGroup, List<string>>();
|
||||
s_removeDefinesCollection = new Dictionary<BuildTargetGroup, List<string>>();
|
||||
s_supportedTargetGroups = GetSupportedBuildTargetGroups();
|
||||
}
|
||||
|
||||
private static BuildTargetGroup[] GetSupportedBuildTargetGroups()
|
||||
{
|
||||
var newList = new List<BuildTargetGroup>();
|
||||
foreach (BuildTarget buildTarget in System.Enum.GetValues(typeof(BuildTarget)))
|
||||
{
|
||||
var buildTargetGroup = BuildPipeline.GetBuildTargetGroup(buildTarget);
|
||||
if (BuildPipeline.IsBuildTargetSupported(buildTargetGroup, buildTarget))
|
||||
{
|
||||
newList.AddUnique(buildTargetGroup);
|
||||
}
|
||||
}
|
||||
return newList.ToArray();
|
||||
}
|
||||
|
||||
private static BuildTargetGroup[] GetBuildTargetGroupsOrDefault(BuildTargetGroup[] targetGroups)
|
||||
{
|
||||
return ((targetGroups == null) || (targetGroups.Length == 0))
|
||||
? s_supportedTargetGroups
|
||||
: targetGroups;
|
||||
}
|
||||
|
||||
private static void AddDefineToCollection(Dictionary<BuildTargetGroup, List<string>> definesCollection, string define, BuildTargetGroup[] targetGroups)
|
||||
{
|
||||
// add define symbol for all the specified target groups
|
||||
foreach (var group in targetGroups)
|
||||
{
|
||||
if (!System.Array.Exists(s_supportedTargetGroups, (item) => (item == group)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!definesCollection.TryGetValue(group, out List<string> groupDefines))
|
||||
{
|
||||
var newDefines = new List<string>();
|
||||
definesCollection.Add(group, newDefines);
|
||||
|
||||
groupDefines = newDefines;
|
||||
}
|
||||
|
||||
groupDefines.AddUnique(define);
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdateDefineSymbolsDelayed()
|
||||
{
|
||||
EditorApplication.delayCall -= UpdateDefineSymbols;
|
||||
EditorApplication.delayCall += UpdateDefineSymbols;
|
||||
}
|
||||
|
||||
private static void UpdateDefineSymbols()
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureInitialized();
|
||||
AssetDatabase.StartAssetEditing();
|
||||
|
||||
foreach (var targetGroup in s_supportedTargetGroups)
|
||||
{
|
||||
var existingDefines = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(targetGroup)).Split(';');
|
||||
var updatedDefines = new List<string>(existingDefines);
|
||||
bool isModified = false;
|
||||
if (s_addDefinesCollection.TryGetValue(targetGroup, out List<string> addDefines))
|
||||
{
|
||||
foreach (var define in addDefines)
|
||||
{
|
||||
isModified |= updatedDefines.AddUnique(define);
|
||||
}
|
||||
}
|
||||
if (s_removeDefinesCollection.TryGetValue(targetGroup, out List<string> removeDefines))
|
||||
{
|
||||
foreach (var define in removeDefines)
|
||||
{
|
||||
isModified |= updatedDefines.Remove(define);
|
||||
}
|
||||
}
|
||||
|
||||
// set values if there are modifications
|
||||
if (isModified)
|
||||
{
|
||||
PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(targetGroup), string.Join(";", updatedDefines.ToArray()));
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
AssetDatabase.StopAssetEditing();
|
||||
|
||||
// reset properties
|
||||
s_addDefinesCollection.Clear();
|
||||
s_removeDefinesCollection.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ef477a8c89c614881ab6594601f54f4b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3046d47b6921d4f5e8210ffad4508e17
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,60 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEditor.PackageManager;
|
||||
using UnityEditor.PackageManager.Requests;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
public class AddUpmPackageRequest : AsyncOperation<StatusCode>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private AddRequest m_request;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public string Identifier { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public AddUpmPackageRequest(string identifier)
|
||||
{
|
||||
// Set properties
|
||||
Identifier = identifier;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Base class methods
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
m_request = Client.Add(Identifier);
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
if (!m_request.IsCompleted) return;
|
||||
|
||||
// Process response
|
||||
if (m_request.Status == StatusCode.Success)
|
||||
{
|
||||
Debug.Log($"Installed package: {m_request.Result.packageId} successfully.");
|
||||
SetIsCompleted(StatusCode.Success);
|
||||
}
|
||||
else if (m_request.Status == StatusCode.Failure)
|
||||
{
|
||||
Debug.Log($"Failed to install package: {m_request.Result.packageId}. Error {m_request.Error.message}.");
|
||||
SetIsCompleted(error: new Error(m_request.Error.message));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a87b7bce048e1424984e245b62107603
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,61 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
|
||||
public partial class AssemblyDefinitionProxy
|
||||
{
|
||||
private struct AssemblyDefinitionData
|
||||
{
|
||||
#region Properties
|
||||
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[JsonProperty("references")]
|
||||
public string[] References { get; set; }
|
||||
|
||||
[JsonProperty("optionalUnityReferences")]
|
||||
public string[] OptionalUnityReferences { get; set; }
|
||||
|
||||
[JsonProperty("includePlatforms")]
|
||||
public string[] IncludePlatforms { get; set; }
|
||||
|
||||
[JsonProperty("excludePlatforms")]
|
||||
public string[] ExcludePlatforms { get; set; }
|
||||
|
||||
[JsonProperty("allowUnsafeCode")]
|
||||
public bool AllowUnsafeCode { get; set; }
|
||||
|
||||
[JsonProperty("overrideReferences")]
|
||||
public bool OverrideReferences { get; set; }
|
||||
|
||||
[JsonProperty("precompiledReferences")]
|
||||
public string[] PrecompiledReferences { get; set; }
|
||||
|
||||
[JsonProperty("autoReferenced")]
|
||||
public bool AutoReferenced { get; set; }
|
||||
|
||||
[JsonProperty("defineConstraints")]
|
||||
public string[] DefineConstraints { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public methods
|
||||
|
||||
public static AssemblyDefinitionData Load(string dataString)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<AssemblyDefinitionData>(dataString);
|
||||
}
|
||||
|
||||
public string ToJson()
|
||||
{
|
||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f335c720b36b4411b4d54550b2e94d8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,52 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Compilation;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
|
||||
public partial class AssemblyDefinitionProxy
|
||||
{
|
||||
|
||||
private AssemblyDefinitionData m_data;
|
||||
private string m_directoryPath;
|
||||
|
||||
public AssemblyDefinitionProxy(string assemblyDirectoryPath)
|
||||
{
|
||||
string asmdefFile = Directory.GetFiles(assemblyDirectoryPath, "*.asmdef").FirstOrDefault();
|
||||
|
||||
if (string.IsNullOrEmpty(asmdefFile))
|
||||
{
|
||||
throw new VBException($"No .asmdef file found in {assemblyDirectoryPath} directory.");
|
||||
}
|
||||
|
||||
m_directoryPath = assemblyDirectoryPath;
|
||||
string contents = IOServices.ReadFile(asmdefFile);
|
||||
m_data = AssemblyDefinitionData.Load(contents);
|
||||
}
|
||||
|
||||
public void IncludeAllPlatforms()
|
||||
{
|
||||
m_data.ExcludePlatforms = new string[0];
|
||||
m_data.IncludePlatforms = new string[0];
|
||||
}
|
||||
|
||||
public void ExcludeAllPlatforms()
|
||||
{
|
||||
AssemblyDefinitionPlatform[] platforms = CompilationPipeline.GetAssemblyDefinitionPlatforms();
|
||||
m_data.ExcludePlatforms = platforms.Select(platform => platform.Name).ToArray();
|
||||
m_data.IncludePlatforms = new string[0];
|
||||
}
|
||||
|
||||
|
||||
public void Save()
|
||||
{
|
||||
IOServices.CreateFile(IOServices.CombinePath(m_directoryPath, $"{m_data.Name}.asmdef"), m_data.ToJson());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5c04f18545af4d43bfe1034aa18a54e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,39 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
public static class AssemblyDefinitionServices
|
||||
{
|
||||
#region Static methods
|
||||
|
||||
public static void CreateDefinition(string path,
|
||||
string name,
|
||||
string[] includePlatforms = null,
|
||||
string[] references = null)
|
||||
{
|
||||
string json = $"{{" +
|
||||
$"\n\t\"name\":\"{name}\"," +
|
||||
$"\n\t\"includePlatforms\":{Jsonify(includePlatforms)}," +
|
||||
$"\n\t\"references\":{Jsonify(references)}" +
|
||||
$"\n}}";
|
||||
|
||||
if (!IOServices.DirectoryExists(path))
|
||||
{
|
||||
IOServices.CreateDirectory(path);
|
||||
}
|
||||
|
||||
IOServices.CreateFile(IOServices.CombinePath(path, $"{name}.asmdef"), json);
|
||||
}
|
||||
|
||||
private static string Jsonify(string[] array)
|
||||
{
|
||||
if (array == null) return "[]";
|
||||
|
||||
return $"[{string.Join(",", System.Array.ConvertAll(array, (item) => $"\"{item}\""))}]";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f85adcf2acaf49838d6c77837b24ca1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,90 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
public static class AssetDatabaseUtility
|
||||
{
|
||||
#region Resources methods
|
||||
|
||||
public static void CreateFolder(string folder)
|
||||
{
|
||||
var pathComponents = folder.Split('/');
|
||||
|
||||
string currentPath = string.Empty;
|
||||
for (int iter = 0; iter < pathComponents.Length; iter++)
|
||||
{
|
||||
string component = pathComponents[iter];
|
||||
string newPath = Path.Combine(currentPath, component);
|
||||
if (!AssetDatabase.IsValidFolder(newPath))
|
||||
{
|
||||
AssetDatabase.CreateFolder(currentPath, component);
|
||||
}
|
||||
|
||||
// update path
|
||||
currentPath = newPath;
|
||||
}
|
||||
}
|
||||
|
||||
public static void CreateAssetAtPath(Object asset,
|
||||
string assetPath)
|
||||
{
|
||||
// create container folder
|
||||
string parentFolder = assetPath.Substring(0, assetPath.LastIndexOf('/'));
|
||||
CreateFolder(parentFolder);
|
||||
|
||||
// create asset
|
||||
AssetDatabase.CreateAsset(asset, assetPath);
|
||||
}
|
||||
|
||||
public static T CreateScriptableObject<T>(string assetPath,
|
||||
System.Func<T> createFunc = null,
|
||||
System.Action<T> onInit = null) where T : ScriptableObject
|
||||
{
|
||||
var instance = (createFunc != null)
|
||||
? createFunc()
|
||||
: ScriptableObject.CreateInstance<T>();
|
||||
onInit?.Invoke(instance);
|
||||
|
||||
// create file
|
||||
CreateAssetAtPath(instance, assetPath);
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static T LoadScriptableObject<T>(string assetPath,
|
||||
System.Action<T> onLoad = null,
|
||||
System.Func<System.Exception> throwErrorFunc = null) where T : ScriptableObject
|
||||
{
|
||||
var instance = AssetDatabase.LoadAssetAtPath<T>(assetPath);
|
||||
if (instance)
|
||||
{
|
||||
onLoad?.Invoke(instance);
|
||||
return instance;
|
||||
}
|
||||
|
||||
if (throwErrorFunc != null)
|
||||
{
|
||||
throw throwErrorFunc();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static T[] FindAssetObjects<T>() where T : ScriptableObject
|
||||
{
|
||||
var guids = AssetDatabase.FindAssets($"t:{typeof(T).Name}");
|
||||
return System.Array.ConvertAll(guids, (item) =>
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(item);
|
||||
return AssetDatabase.LoadAssetAtPath<T>(path);
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab0d5c5a093844a80ae39b5d66ab9164
|
||||
timeCreated: 1576669974
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,39 +0,0 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
public class DeleteAssetRequest : AsyncOperation<bool>
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public string Path { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public DeleteAssetRequest(string path)
|
||||
{
|
||||
Path = path;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Base class methods
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
if (!AssetDatabase.DeleteAsset(Path))
|
||||
{
|
||||
SetIsCompleted(new Error("File not found."));
|
||||
return;
|
||||
}
|
||||
SetIsCompleted(true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2204697bc932f4f28b4dad14e5c29724
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,31 +0,0 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using VoxelBusters.CoreLibrary;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
public static class EditorApplicationUtility
|
||||
{
|
||||
#region Platform methods
|
||||
|
||||
public static RuntimePlatform ConvertBuildTargetToRuntimePlatform(BuildTarget buildTarget)
|
||||
{
|
||||
switch (buildTarget)
|
||||
{
|
||||
case BuildTarget.iOS:
|
||||
return RuntimePlatform.IPhonePlayer;
|
||||
|
||||
case BuildTarget.tvOS:
|
||||
return RuntimePlatform.tvOS;
|
||||
|
||||
case BuildTarget.Android:
|
||||
return RuntimePlatform.Android;
|
||||
|
||||
default:
|
||||
return (RuntimePlatform)(-1);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f0eb0657c7f942c6a847903ed852752
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,40 +0,0 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
public class ImportPackageRequest : VoxelBusters.CoreLibrary.AsyncOperation<bool>
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public string Path { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public ImportPackageRequest(string path)
|
||||
{
|
||||
Path = path;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Base class methods
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
if (!IOServices.FileExists(Path))
|
||||
{
|
||||
SetIsCompleted(new Error("File not found."));
|
||||
return;
|
||||
}
|
||||
|
||||
AssetDatabase.ImportPackage(Path, interactive: false);
|
||||
SetIsCompleted(true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a33d068e4b51149e08021407780741d2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,60 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEditor.PackageManager;
|
||||
using UnityEditor.PackageManager.Requests;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
public class RemoveUpmPackageRequest : AsyncOperation<StatusCode>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private RemoveRequest m_request;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public string Identifier { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public RemoveUpmPackageRequest(string identifier)
|
||||
{
|
||||
// Set properties
|
||||
Identifier = identifier;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Base class methods
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
m_request = Client.Remove(Identifier);
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
if (!m_request.IsCompleted) return;
|
||||
|
||||
// Process response
|
||||
if (m_request.Status == StatusCode.Success)
|
||||
{
|
||||
Debug.Log($"Installed package: {m_request.PackageIdOrName} successfully.");
|
||||
SetIsCompleted(m_request.Status);
|
||||
}
|
||||
else if (m_request.Status >= StatusCode.Failure)
|
||||
{
|
||||
Debug.Log($"Failed to install package: {m_request.PackageIdOrName}. Error {m_request.Error.message}.");
|
||||
SetIsCompleted(error: new Error(m_request.Error.message));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5ea45e566aa3452aa8db2aa084333c4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,122 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
public class TypeCache
|
||||
{
|
||||
#region Static fields
|
||||
|
||||
private static Dictionary<Type, string> s_typeMap;
|
||||
|
||||
private static bool s_isDirty;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static methods
|
||||
|
||||
public static void Rebuild()
|
||||
{
|
||||
// Reset properties
|
||||
s_isDirty = true;
|
||||
s_typeMap?.Clear();
|
||||
|
||||
EnsureCacheIsUpdated();
|
||||
}
|
||||
|
||||
public static Dictionary<MemberInfo, TAttribute> GetMembersWithAttribute<TAttribute>(MemberTypes memberTypes, BindingFlags bindingAttr)
|
||||
where TAttribute : Attribute
|
||||
{
|
||||
return GetMembersWithAttribute<MemberInfo, TAttribute>(memberTypes, bindingAttr);
|
||||
}
|
||||
|
||||
public static Dictionary<FieldInfo, TAttribute> GetFieldsWithAttribute<TAttribute>(BindingFlags bindingAttr) where TAttribute : Attribute
|
||||
{
|
||||
return GetMembersWithAttribute<FieldInfo, TAttribute>(MemberTypes.Field, bindingAttr);
|
||||
}
|
||||
|
||||
public static Dictionary<PropertyInfo, TAttribute> GetPropertiesWithAttribute<TAttribute>(BindingFlags bindingAttr) where TAttribute : Attribute
|
||||
{
|
||||
return GetMembersWithAttribute<PropertyInfo, TAttribute>(MemberTypes.Property, bindingAttr);
|
||||
}
|
||||
|
||||
public static Dictionary<EventInfo, TAttribute> GetEventsWithAttribute<TAttribute>(BindingFlags bindingAttr) where TAttribute : Attribute
|
||||
{
|
||||
return GetMembersWithAttribute<EventInfo, TAttribute>(MemberTypes.Event, bindingAttr);
|
||||
}
|
||||
|
||||
public static Dictionary<MethodInfo, TAttribute> GetMethodsWithAttribute<TAttribute>(BindingFlags bindingAttr) where TAttribute : Attribute
|
||||
{
|
||||
return GetMembersWithAttribute<MethodInfo, TAttribute>(MemberTypes.Method, bindingAttr);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
|
||||
private static void EnsureCacheIsUpdated()
|
||||
{
|
||||
if (!s_isDirty) return;
|
||||
|
||||
// Initialize object
|
||||
s_isDirty = false;
|
||||
if (s_typeMap == null)
|
||||
{
|
||||
s_typeMap = new Dictionary<Type, string>(capacity: 1024);
|
||||
}
|
||||
|
||||
// Add types to the cache
|
||||
foreach (var type in ReflectionUtility.FindAllTypes())
|
||||
{
|
||||
s_typeMap.Add(type, type.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<TMemberInfo, TAttribute> GetMembersWithAttribute<TMemberInfo, TAttribute>(MemberTypes memberTypes, BindingFlags bindingAttr)
|
||||
where TMemberInfo : MemberInfo
|
||||
where TAttribute : Attribute
|
||||
{
|
||||
EnsureCacheIsUpdated();
|
||||
|
||||
// Find all the methods with specified attribute
|
||||
var attributeType = typeof(TAttribute);
|
||||
var collection = new Dictionary<TMemberInfo, TAttribute>();
|
||||
foreach (var mapItem in s_typeMap)
|
||||
{
|
||||
var currentType = mapItem.Key;
|
||||
|
||||
AddMembersWithRequiredAttributes(currentType);
|
||||
|
||||
//When we create a "concrete" class derived from a generic class, it will internally constructs a new class (replacing generic parameters with actual types). We need to query this type for required attributes as well.
|
||||
if (IsConstructedClosedGenericType(currentType.BaseType))
|
||||
{
|
||||
AddMembersWithRequiredAttributes(currentType.BaseType);
|
||||
}
|
||||
}
|
||||
return collection;
|
||||
|
||||
void AddMembersWithRequiredAttributes(Type type)
|
||||
{
|
||||
var members = type.FindMembers(memberTypes, bindingAttr, null, null);
|
||||
foreach (var memberInfo in members)
|
||||
{
|
||||
var attributes = memberInfo.GetCustomAttributes(attributeType, false);
|
||||
if (attributes.IsNullOrEmpty()) continue;
|
||||
|
||||
collection.Add(memberInfo as TMemberInfo, attributes[0] as TAttribute);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static bool IsConstructedClosedGenericType(Type type)
|
||||
{
|
||||
return type != null && type.IsConstructedGenericType && !type.ContainsGenericParameters;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d14cdf5aeeb847f0ac54ffd5c03ae1d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,89 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor
|
||||
{
|
||||
public static class UnityPackageServices
|
||||
{
|
||||
#region Constants
|
||||
|
||||
private static readonly string[] s_staticFolders =
|
||||
{
|
||||
"Essentials",
|
||||
"Examples",
|
||||
"Extras",
|
||||
"Plugins",
|
||||
"Scripts"
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static methods
|
||||
|
||||
[System.Obsolete("This method is deprecated. Use MigrateToUpm instead.")]
|
||||
public static void MigrateToUPM(this UnityPackageDefinition package)
|
||||
{
|
||||
MovePackageToUpmRecursively(package, refreshOnFinish: true);
|
||||
}
|
||||
|
||||
public static void MigrateToUpm(this UnityPackageDefinition package)
|
||||
{
|
||||
MovePackageToUpmRecursively(package, refreshOnFinish: true);
|
||||
}
|
||||
|
||||
private static void MovePackageToUpmRecursively(this UnityPackageDefinition package, bool refreshOnFinish)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Move dependencies
|
||||
foreach (var dependency in package.Dependencies)
|
||||
{
|
||||
MovePackageToUpmRecursively(dependency, refreshOnFinish: false);
|
||||
}
|
||||
|
||||
// Move main package
|
||||
MovePackageToUpm(package);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (refreshOnFinish)
|
||||
{
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void MovePackageToUpm(UnityPackageDefinition package)
|
||||
{
|
||||
// Confirm that package exists in default install path
|
||||
if (!package.IsInstalledWithinAssets()) return;
|
||||
|
||||
// Move files and folders to new path
|
||||
var sourceDirectory = new DirectoryInfo(package.DefaultInstallPath);
|
||||
IOServices.CreateDirectory(package.UpmInstallPath);
|
||||
foreach (var file in sourceDirectory.GetFiles())
|
||||
{
|
||||
var fileName = file.Name;
|
||||
if (System.Array.Exists(s_staticFolders, (item) => string.Equals(fileName, $"{item}.meta")))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
IOServices.MoveFile(file.FullName, $"{package.UpmInstallPath}/{fileName}");
|
||||
}
|
||||
foreach (var subDirectory in sourceDirectory.GetDirectories())
|
||||
{
|
||||
var subDirectoryName = subDirectory.Name;
|
||||
if (System.Array.Exists(s_staticFolders, (item) => string.Equals(subDirectoryName, item)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
IOServices.MoveDirectory(subDirectory.FullName, $"{package.UpmInstallPath}/{subDirectoryName}");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4667b4f0e71ec4791afd9f9d887a0c96
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,16 +0,0 @@
|
||||
{
|
||||
"name": "VoxelBusters.CoreLibrary.Editor",
|
||||
"references": [
|
||||
"VoxelBusters.CoreLibrary"
|
||||
],
|
||||
"optionalUnityReferences": [],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": []
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2e305d2a5092a465db2a72838d17a500
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e4381b029b7441f28679a1978aee2bf
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d402a199f95044159bdc2107cdcd3334
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,25 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor.Experimental
|
||||
{
|
||||
public static class InstallPath
|
||||
{
|
||||
#region Static properties
|
||||
|
||||
public static string EssentialKit { get; private set; } = "https://link.voxelbusters.com/essential-kit";
|
||||
|
||||
public static string ScreenRecorderKit { get; private set; } = "https://link.voxelbusters.com/screen-recorder-kit";
|
||||
|
||||
public static string SocialKit { get; private set; } = "https://link.voxelbusters.com/social-kit";
|
||||
|
||||
public static string MLKit { get; private set; } = "https://link.voxelbusters.com/easy-ml-kit";
|
||||
|
||||
public static string ReportingKit { get; private set; } = "https://link.voxelbusters.com/reporting-kit";
|
||||
|
||||
public static string AdsKit { get; private set; } = "https://link.voxelbusters.com/ads-kit";
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ccdff37e3ee3d41f794ef3d1b107b01d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,65 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor.Experimental
|
||||
{
|
||||
public static class ProxyMenuManager
|
||||
{
|
||||
#region Constants
|
||||
|
||||
private const string kMenuItemPath = "Window/Voxel Busters";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static methods
|
||||
|
||||
#if !ENABLE_VOXELBUSTERS_ESSENTIAL_KIT
|
||||
[MenuItem(kMenuItemPath + "/Essential Kit/Learn More", priority = 0)]
|
||||
public static void InstallEssentialKit()
|
||||
{
|
||||
OpenInstallPath(InstallPath.EssentialKit);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !ENABLE_VOXELBUSTERS_SCREEN_RECORDER_KIT
|
||||
[MenuItem(kMenuItemPath + "/Screen Recorder Kit/Learn More", priority = 0)]
|
||||
public static void InstallScreenRecorderKit()
|
||||
{
|
||||
OpenInstallPath(InstallPath.ScreenRecorderKit);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !ENABLE_VOXELBUSTERS_SOCIAL_KIT
|
||||
[MenuItem(kMenuItemPath + "/Social Kit/Learn More", priority = 0)]
|
||||
public static void InstallSocialKit()
|
||||
{
|
||||
OpenInstallPath(InstallPath.SocialKit);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !ENABLE_VOXELBUSTERS_ML_KIT
|
||||
[MenuItem(kMenuItemPath + "/ML Kit/Learn More", priority = 0)]
|
||||
public static void InstallMLKit()
|
||||
{
|
||||
OpenInstallPath(InstallPath.MLKit);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !ENABLE_VOXELBUSTERS_REPORTING_KIT
|
||||
[MenuItem(kMenuItemPath + "/Reporting Kit/Learn More", priority = 0)]
|
||||
public static void InstallReportingKit()
|
||||
{
|
||||
OpenInstallPath(InstallPath.ReportingKit);
|
||||
}
|
||||
#endif
|
||||
|
||||
private static void OpenInstallPath(string path)
|
||||
{
|
||||
Application.OpenURL(path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d5313a9f9e1b4bcdb89c991f700da78
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,115 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor.Experimental
|
||||
{
|
||||
public class ProxySettingsProvider : SettingsProvider
|
||||
{
|
||||
#region Constants
|
||||
|
||||
private const string kDefaultInstallMessageFormat = "In order to use {0} system you need to install the {0} package. Clicking the button below will install {0} package and allow you to configure.";
|
||||
|
||||
private const string kDefaultProjectSettingsPathFormat = "Project/Voxel Busters/{0}";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
|
||||
private string m_installMessage;
|
||||
|
||||
private string m_installButtonLabel;
|
||||
|
||||
private string m_installUrl;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public ProxySettingsProvider(string name,
|
||||
string installUrl,
|
||||
string path = null,
|
||||
SettingsScope scopes = SettingsScope.Project)
|
||||
: base(path ?? string.Format(kDefaultProjectSettingsPathFormat, name), scopes)
|
||||
{
|
||||
// set properties
|
||||
m_installMessage = string.Format(kDefaultInstallMessageFormat, name);
|
||||
m_installButtonLabel = $"Install {name}";
|
||||
m_installUrl = installUrl;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Create methods
|
||||
|
||||
#if !ENABLE_VOXELBUSTERS_ESSENTIAL_KIT
|
||||
[SettingsProvider]
|
||||
private static SettingsProvider CreateEssentialKitSettingsProvider()
|
||||
{
|
||||
return new ProxySettingsProvider(name: "Essential Kit",
|
||||
installUrl: InstallPath.EssentialKit);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !ENABLE_VOXELBUSTERS_SCREEN_RECORDER_KIT
|
||||
[SettingsProvider]
|
||||
private static SettingsProvider CreateScreenRecorderKitSettingsProvider()
|
||||
{
|
||||
return new ProxySettingsProvider(name: "Screen Recorder Kit",
|
||||
installUrl: InstallPath.ScreenRecorderKit);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !ENABLE_VOXELBUSTERS_SOCIAL_KIT
|
||||
[SettingsProvider]
|
||||
private static SettingsProvider CreateSocialKitSettingsProvider()
|
||||
{
|
||||
return new ProxySettingsProvider(name: "Social Kit",
|
||||
installUrl: InstallPath.SocialKit);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !ENABLE_VOXELBUSTERS_ML_KIT
|
||||
[SettingsProvider]
|
||||
private static SettingsProvider CreateMLKitSettingsProvider()
|
||||
{
|
||||
return new ProxySettingsProvider(name: "ML Kit",
|
||||
installUrl: InstallPath.MLKit);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !ENABLE_VOXELBUSTERS_REPORTING_KIT
|
||||
[SettingsProvider]
|
||||
private static SettingsProvider CreateReportingKitSettingsProvider()
|
||||
{
|
||||
return new ProxySettingsProvider(name: "Reporting Kit",
|
||||
installUrl: InstallPath.ReportingKit);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !ENABLE_VOXELBUSTERS_ADS_KIT
|
||||
[SettingsProvider]
|
||||
private static SettingsProvider CreateAdsKitSettingsProvider()
|
||||
{
|
||||
return new ProxySettingsProvider(name: "Ads Kit",
|
||||
installUrl: InstallPath.AdsKit);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
#region Base class methods
|
||||
|
||||
public override void OnGUI(string searchContext)
|
||||
{
|
||||
EditorGUILayout.HelpBox(m_installMessage, MessageType.Info);
|
||||
if (GUILayout.Button(m_installButtonLabel))
|
||||
{
|
||||
Application.OpenURL(m_installUrl);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c3cf9ccd372c74ed1a07c9da30675268
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb5fe327595d0453e96752fdceb6dced
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,163 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Compilation;
|
||||
using System.IO;
|
||||
using System;
|
||||
|
||||
using JsonUtility = VoxelBusters.CoreLibrary.Parser.JsonUtility;
|
||||
|
||||
namespace VoxelBusters.CoreLibrary.Editor.Experimental
|
||||
{
|
||||
/*
|
||||
public class UnityPackageManifestKey
|
||||
{
|
||||
public const string kDependencies = "dependencies";
|
||||
}
|
||||
|
||||
public class AssetPackageDependencyResolver : AssetPostprocessor
|
||||
{
|
||||
#region Constants
|
||||
|
||||
private const string kMainManifestPath = "Packages/manifest.json";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
|
||||
private static Dictionary<string, object> s_mainManifestDict;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static methods
|
||||
|
||||
[MenuItem("Window/Voxel Busters/Asset Packages/Resolve Dependency")]
|
||||
public static void Resolve()
|
||||
{
|
||||
var assetManifestFiles = Array.FindAll(
|
||||
Array.ConvertAll(AssetDatabase.FindAssets("package"), (guid) => AssetDatabase.GUIDToAssetPath(guid)),
|
||||
(assetPath) => IsPackageManifest(assetPath));
|
||||
if (assetManifestFiles.Length > 0)
|
||||
{
|
||||
AddMissingDependencies(assetManifestFiles);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private static methods
|
||||
|
||||
private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
|
||||
{
|
||||
var assetManifestFiles = Array.FindAll(
|
||||
importedAssets,
|
||||
(assetPath) => IsPackageManifest(assetPath));
|
||||
AddMissingDependencies(assetManifestFiles);
|
||||
}
|
||||
|
||||
private static bool IsPackageManifest(string assetPath)
|
||||
{
|
||||
return assetPath.StartsWith("Assets") && string.Equals(Path.GetFileName(assetPath), "package.json");
|
||||
}
|
||||
|
||||
private static void AddMissingDependencies(string[] assetManifestFiles)
|
||||
{
|
||||
// Gather all the dependencies from the packages installed in Assets
|
||||
// Manually add them to project manifest file
|
||||
var registeredDependencies = GetOrCreateMainManifestObject()[UnityPackageManifestKey.kDependencies] as Dictionary<string, object>;
|
||||
var newDependencies = new List<KeyValuePair<string, string>>();
|
||||
foreach (var file in assetManifestFiles)
|
||||
{
|
||||
var assetManifestDict = OpenManifestAsObject(file);
|
||||
if (assetManifestDict.TryGetValue(UnityPackageManifestKey.kDependencies, out object assetDependencies))
|
||||
{
|
||||
var assetDependenciesDict = assetDependencies as Dictionary<string, object>;
|
||||
foreach (var dependency in assetDependenciesDict)
|
||||
{
|
||||
if (registeredDependencies.ContainsKey(dependency.Key)) continue;
|
||||
|
||||
AddDependencyToList(ref newDependencies, dependency.Key, (string)dependency.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check whether we have any unregisted dependecies
|
||||
if (newDependencies.Count > 0)
|
||||
{
|
||||
EditorApplication.delayCall += () =>
|
||||
{
|
||||
PromptUserToMergeDependency(newDependencies);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddDependencyToList(ref List<KeyValuePair<string, string>> list, string name, string versionOrPath)
|
||||
{
|
||||
int existingItemIndex;
|
||||
if ((existingItemIndex = list.FindIndex((item) => string.Equals(item.Key, name))) == -1)
|
||||
{
|
||||
list.Add(new KeyValuePair<string, string>(name, versionOrPath));
|
||||
}
|
||||
else if (string.Compare(list[existingItemIndex].Value, versionOrPath) >= 0)
|
||||
{
|
||||
list[existingItemIndex] = new KeyValuePair<string, string>(name, versionOrPath);
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<string, object> OpenManifestAsObject(string path)
|
||||
{
|
||||
var contents = File.ReadAllText(path);
|
||||
return JsonUtility.FromJson(contents) as Dictionary<string, object>;
|
||||
}
|
||||
|
||||
private static Dictionary<string, object> GetOrCreateMainManifestObject()
|
||||
{
|
||||
if (s_mainManifestDict == null)
|
||||
{
|
||||
s_mainManifestDict = OpenManifestAsObject(kMainManifestPath);
|
||||
}
|
||||
return s_mainManifestDict;
|
||||
}
|
||||
|
||||
private static void PromptUserToMergeDependency(List<KeyValuePair<string, string>> dependencies)
|
||||
{
|
||||
if (EditorUtility.DisplayDialog(
|
||||
title: "Resolve Dependencies",
|
||||
message: "System has detected that there are one or more dependecies used by the Asset-Packages that are missing from the Package-Manifest file. Do you approve adding it to the Package-Manifest file?",
|
||||
ok: "Ok",
|
||||
cancel: "Cancel"))
|
||||
{
|
||||
PerformMergeDependency(dependencies);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static void PerformMergeDependency(List<KeyValuePair<string, string>> values)
|
||||
{
|
||||
// Update dependency collection
|
||||
var contentDict = GetOrCreateMainManifestObject();
|
||||
var dependenciesDict = contentDict[UnityPackageManifestKey.kDependencies]as Dictionary<string, object>;
|
||||
bool isDirty = false;
|
||||
foreach (var newValue in values)
|
||||
{
|
||||
if (!dependenciesDict.ContainsKey(newValue.Key))
|
||||
{
|
||||
dependenciesDict.Add(newValue.Key, newValue.Value);
|
||||
isDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Save changes
|
||||
if (isDirty)
|
||||
{
|
||||
string jsonStr = JsonUtility.ToJson(contentDict);
|
||||
File.WriteAllText(kMainManifestPath, jsonStr);
|
||||
|
||||
CompilationPipeline.RequestScriptCompilation();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}*/
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5aafeb5c45eb14356b966fa280363556
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,17 +0,0 @@
|
||||
{
|
||||
"name": "VoxelBusters.CoreLibrary.Editor.Experimental",
|
||||
"references": [
|
||||
"VoxelBusters.CoreLibrary.Parser"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user