-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor refactor changes; implement NotPrefabObjectOnlyAttribute & Drawer
- Loading branch information
Showing
12 changed files
with
88 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
Assets/Editor Toolbox/Editor/Drawers/Regular/NotPrefabObjectOnlyAttributeDrawer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Toolbox.Editor.Drawers | ||
{ | ||
[CustomPropertyDrawer(typeof(NotPrefabObjectOnlyAttribute))] | ||
public class NotPrefabObjectOnlyAttributeDrawer : ObjectValidationDrawer | ||
{ | ||
protected override string GetWarningMessage() | ||
{ | ||
return "Assigned object can't be a Prefab."; | ||
} | ||
|
||
protected override bool IsObjectValid(Object objectValue, SerializedProperty property) | ||
{ | ||
if (objectValue == null) | ||
{ | ||
return false; | ||
} | ||
|
||
var attribute = Attribute; | ||
if (PrefabUtility.GetPrefabAssetType(objectValue) == PrefabAssetType.NotAPrefab) | ||
{ | ||
return true; | ||
} | ||
|
||
if (PrefabUtility.GetPrefabInstanceStatus(objectValue) == PrefabInstanceStatus.Connected && | ||
attribute.AllowInstancedPrefabs) | ||
{ | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private NotPrefabObjectOnlyAttribute Attribute => attribute as NotPrefabObjectOnlyAttribute; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Editor Toolbox/Editor/Drawers/Regular/NotPrefabObjectOnlyAttributeDrawer.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
Assets/Editor Toolbox/Runtime/Attributes/Property/Regular/NotPrefabObjectOnlyAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace UnityEngine | ||
{ | ||
/// <summary> | ||
/// Validates input values and accepts only objects that are not Prefabs. | ||
/// | ||
/// <para>Supported types: <see cref="GameObject"/> and any <see cref="Component"/>.</para> | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] | ||
[Conditional("UNITY_EDITOR")] | ||
public class NotPrefabObjectOnlyAttribute : PropertyAttribute | ||
{ | ||
public bool AllowInstancedPrefabs { get; set; } | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...s/Editor Toolbox/Runtime/Attributes/Property/Regular/NotPrefabObjectOnlyAttribute.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters