init
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using Sirenix.OdinInspector;
|
||||
using Sirenix.OdinInspector.Editor;
|
||||
using Sirenix.OdinInspector.Editor.Validation;
|
||||
using Sirenix.Utilities;
|
||||
using UnityEngine;
|
||||
using VOID.Editor.AttributeValidator.Objects;
|
||||
using VOID.Generic.Objects.Abstract;
|
||||
|
||||
[assembly: RegisterValidator(typeof(AbstractObjectValidator))]
|
||||
|
||||
namespace VOID.Editor.AttributeValidator.Objects
|
||||
{
|
||||
public class AbstractObjectValidator : ValueValidator<AbstractObject>
|
||||
{
|
||||
protected override void Validate(ValidationResult result)
|
||||
{
|
||||
if (Value == null) return;
|
||||
if (OdinPrefabUtility.GetPrefabKind(Value.gameObject) is not PrefabKind.Regular) return;
|
||||
|
||||
IsComponentOrderValid(result);
|
||||
}
|
||||
|
||||
private void IsComponentOrderValid(ValidationResult result)
|
||||
{
|
||||
var components = Value.gameObject.GetComponents<Component>();
|
||||
var abstractObjectIndex = Array.FindIndex(components, component => component is AbstractObject);
|
||||
|
||||
// *Object is first (or right after Transform)
|
||||
if (abstractObjectIndex <= 1) return;
|
||||
|
||||
result.AddError($"{Value.GetType().GetNiceName()} should be first component (right after Transform)")
|
||||
.WithFix(() =>
|
||||
{
|
||||
for (var i = 0; i < abstractObjectIndex - 1; i++)
|
||||
UnityEditorInternal.ComponentUtility.MoveComponentUp(components[abstractObjectIndex]);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d353447115784aa3806a3b1582e00469
|
||||
timeCreated: 1744384089
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Sirenix.OdinInspector;
|
||||
using Sirenix.OdinInspector.Editor;
|
||||
using Sirenix.OdinInspector.Editor.Validation;
|
||||
using Sirenix.Utilities;
|
||||
using UnityEngine;
|
||||
using VOID.Editor.AttributeValidator.Objects;
|
||||
using VOID.Generic.Objects.Item;
|
||||
using VOID.Generic.Objects.Usable;
|
||||
|
||||
[assembly: RegisterValidator(typeof(ItemObjectDataValidator))]
|
||||
|
||||
namespace VOID.Editor.AttributeValidator.Objects
|
||||
{
|
||||
public class ItemObjectDataValidator : ValueValidator<ItemObjectData>
|
||||
{
|
||||
protected override void Validate(ValidationResult result)
|
||||
{
|
||||
if (Value == null) return;
|
||||
if (Property.Parent.ValueEntry.WeakSmartValue is not ItemObject itemObject) return;
|
||||
if (OdinPrefabUtility.GetPrefabKind(itemObject.gameObject) is not PrefabKind.Regular) return;
|
||||
|
||||
IsStackableValid(result);
|
||||
}
|
||||
|
||||
private void IsStackableValid(ValidationResult result)
|
||||
{
|
||||
var allowedTypes = new List<Type> { typeof(ItemObject), typeof(UsableObject) };
|
||||
if (!Value.stackable || allowedTypes.Contains(Property.ParentType)) return;
|
||||
|
||||
var allowedTypeNames = string.Join(", ", allowedTypes.Select(t => t.GetNiceName()).ToList());
|
||||
result.AddError($"Stackable can be TRUE only for objects of type: {allowedTypeNames}")
|
||||
.WithFix(() => Value.stackable = false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 665bab4b4bfc4f829cb3b4738084cdde
|
||||
timeCreated: 1744214861
|
||||
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Sirenix.OdinInspector.Editor.Validation;
|
||||
using VOID.Editor.AttributeValidator.Objects;
|
||||
using VOID.Generic.Dict;
|
||||
using VOID.Generic.Objects.Unit;
|
||||
|
||||
[assembly: RegisterValidator(typeof(UnitObjectEquipmentValidator))]
|
||||
|
||||
namespace VOID.Editor.AttributeValidator.Objects
|
||||
{
|
||||
public class UnitObjectEquipmentValidator : ValueValidator<UnitObjectEquipment>
|
||||
{
|
||||
protected override void Validate(ValidationResult result)
|
||||
{
|
||||
if (Value == null) return;
|
||||
|
||||
AreValidWearablesPlaced(result);
|
||||
}
|
||||
|
||||
private void AreValidWearablesPlaced(ValidationResult result)
|
||||
{
|
||||
foreach (var slotType in Enum.GetValues(typeof(EquipmentSlotType)).Cast<EquipmentSlotType>())
|
||||
{
|
||||
var wearable = Value.GetEquipped(slotType);
|
||||
if (wearable == null) return;
|
||||
|
||||
// Wrong type of wearable placed in this slot
|
||||
if (Value.CanEquipInSlot(slotType, wearable) == false)
|
||||
result.AddError($"<u><b>{wearable.name}</b></u> can't be placed in <u><b>{slotType}</b></u> slot!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: edb7019ba7024f92b3aad84d20f3431b
|
||||
timeCreated: 1718794692
|
||||
Reference in New Issue
Block a user