整合SLSUtilities
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace LunaWolfStudios.ScriptableSheets.Samples.ComponentPresets
|
||||
{
|
||||
public abstract class AbstractComponentPreset<T> : ScriptableObject, IComponentPreset where T : Object
|
||||
{
|
||||
protected abstract void Apply(T obj);
|
||||
|
||||
public void Apply(Object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
Debug.LogWarning($"{typeof(T)} is null. Cannot apply settings.");
|
||||
return;
|
||||
}
|
||||
if (obj.GetType() != typeof(T))
|
||||
{
|
||||
Debug.LogWarning($"Object of type {obj.GetType()} cannot be cast to {typeof(T)}. Cannot apply settings.");
|
||||
return;
|
||||
}
|
||||
Apply((T) obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6a751af09991f6c4c9874747240a06ba
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 284559
|
||||
packageName: Scriptable Sheets
|
||||
packageVersion: 1.8.0
|
||||
assetPath: Packages/com.lunawolfstudios.scriptablesheets/Samples~/ComponentPresets/Scripts/AbstractComponentPreset.cs
|
||||
uploadId: 823456
|
||||
@@ -0,0 +1,40 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace LunaWolfStudios.ScriptableSheets.Samples.ComponentPresets
|
||||
{
|
||||
public class ApplyTransformPreset : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private RigidbodyPreset m_RigidbodyPreset;
|
||||
|
||||
[SerializeField]
|
||||
private TransformPreset m_TransformPreset;
|
||||
|
||||
[SerializeField]
|
||||
private bool m_ApplyOnAwake;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (m_ApplyOnAwake)
|
||||
{
|
||||
Apply();
|
||||
}
|
||||
}
|
||||
|
||||
public void Apply()
|
||||
{
|
||||
if (m_TransformPreset != null)
|
||||
{
|
||||
m_TransformPreset.Apply(transform);
|
||||
}
|
||||
if (m_RigidbodyPreset != null)
|
||||
{
|
||||
var rigidbody = GetComponent<Rigidbody>();
|
||||
if (rigidbody != null)
|
||||
{
|
||||
m_RigidbodyPreset.Apply(rigidbody);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 72c4e21cd4311ef44bcedf0cca7c45b4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 284559
|
||||
packageName: Scriptable Sheets
|
||||
packageVersion: 1.8.0
|
||||
assetPath: Packages/com.lunawolfstudios.scriptablesheets/Samples~/ComponentPresets/Scripts/ApplyPresets.cs
|
||||
uploadId: 823456
|
||||
@@ -0,0 +1,9 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace LunaWolfStudios.ScriptableSheets.Samples.ComponentPresets
|
||||
{
|
||||
public interface IComponentPreset
|
||||
{
|
||||
void Apply(Object obj);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d79add6173b8fa408411f3a0fd1f20f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 284559
|
||||
packageName: Scriptable Sheets
|
||||
packageVersion: 1.8.0
|
||||
assetPath: Packages/com.lunawolfstudios.scriptablesheets/Samples~/ComponentPresets/Scripts/IComponentPreset.cs
|
||||
uploadId: 823456
|
||||
@@ -0,0 +1,103 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace LunaWolfStudios.ScriptableSheets.Samples.ComponentPresets
|
||||
{
|
||||
[System.Serializable]
|
||||
public class RigidbodyPreset : AbstractComponentPreset<Rigidbody>, IComponentPreset
|
||||
{
|
||||
// Remake RigidbodyConstraints enum because Unity's isn't tagged as a System.Flag for serialization.
|
||||
[System.Flags]
|
||||
public enum RigidbodyConstraints
|
||||
{
|
||||
None = 0,
|
||||
FreezePositionX = 2,
|
||||
FreezePositionY = 4,
|
||||
FreezePositionZ = 8,
|
||||
FreezePosition = 14,
|
||||
FreezeRotationX = 16,
|
||||
FreezeRotationY = 32,
|
||||
FreezeRotationZ = 64,
|
||||
FreezeRotation = 112,
|
||||
FreezeAll = 126
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private float m_Mass;
|
||||
public float Mass { get => m_Mass; set => m_Mass = value; }
|
||||
|
||||
[SerializeField]
|
||||
private float m_Drag;
|
||||
public float Drag { get => m_Drag; set => m_Drag = value; }
|
||||
|
||||
[SerializeField]
|
||||
private float m_AngularDrag;
|
||||
public float AngularDrag { get => m_AngularDrag; set => m_AngularDrag = value; }
|
||||
|
||||
[SerializeField]
|
||||
private Vector3 m_CenterOfMass;
|
||||
public Vector3 CenterOfMass { get => m_CenterOfMass; set => m_CenterOfMass = value; }
|
||||
|
||||
[SerializeField]
|
||||
private Vector3 m_InertiaTensor;
|
||||
public Vector3 InertiaTensor { get => m_InertiaTensor; set => m_InertiaTensor = value; }
|
||||
|
||||
[SerializeField]
|
||||
private Quaternion m_InertiaTensorRotation;
|
||||
public Quaternion InertiaTensorRotation { get => m_InertiaTensorRotation; set => m_InertiaTensorRotation = value; }
|
||||
|
||||
[SerializeField]
|
||||
private bool m_UseGravity;
|
||||
public bool UseGravity { get => m_UseGravity; set => m_UseGravity = value; }
|
||||
|
||||
[SerializeField]
|
||||
private bool m_IsKinematic;
|
||||
public bool IsKinematic { get => m_IsKinematic; set => m_IsKinematic = value; }
|
||||
|
||||
[SerializeField]
|
||||
private RigidbodyInterpolation m_Interpolation;
|
||||
public RigidbodyInterpolation Interpolation { get => m_Interpolation; set => m_Interpolation = value; }
|
||||
|
||||
[SerializeField]
|
||||
private CollisionDetectionMode m_CollisionDetectionMode;
|
||||
public CollisionDetectionMode CollisionDetectionMode { get => m_CollisionDetectionMode; set => m_CollisionDetectionMode = value; }
|
||||
|
||||
[SerializeField]
|
||||
private RigidbodyConstraints m_Constraints;
|
||||
public RigidbodyConstraints Constraints { get => m_Constraints; set => m_Constraints = value; }
|
||||
|
||||
#if UNITY_2022_2_OR_NEWER
|
||||
|
||||
[SerializeField]
|
||||
private LayerMask m_IncludeLayers;
|
||||
public LayerMask IncludeLayers { get => m_IncludeLayers; set => m_IncludeLayers = value; }
|
||||
|
||||
[SerializeField]
|
||||
private LayerMask m_ExcludeLayers;
|
||||
public LayerMask ExcludeLayers { get => m_ExcludeLayers; set => m_ExcludeLayers = value; }
|
||||
#endif
|
||||
|
||||
protected override void Apply(Rigidbody obj)
|
||||
{
|
||||
obj.mass = m_Mass;
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
obj.linearDamping = m_Drag;
|
||||
obj.angularDamping = m_AngularDrag;
|
||||
#else
|
||||
obj.drag = m_Drag;
|
||||
obj.angularDrag = m_AngularDrag;
|
||||
#endif
|
||||
obj.centerOfMass = m_CenterOfMass;
|
||||
obj.inertiaTensor = m_InertiaTensor;
|
||||
obj.inertiaTensorRotation = m_InertiaTensorRotation;
|
||||
obj.useGravity = m_UseGravity;
|
||||
obj.isKinematic = m_IsKinematic;
|
||||
obj.interpolation = m_Interpolation;
|
||||
obj.collisionDetectionMode = m_CollisionDetectionMode;
|
||||
obj.constraints = (UnityEngine.RigidbodyConstraints) m_Constraints;
|
||||
#if UNITY_2022_2_OR_NEWER
|
||||
obj.includeLayers = m_IncludeLayers;
|
||||
obj.excludeLayers = m_ExcludeLayers;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 60579ee24071f9f4d97afafacadc6d44
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 284559
|
||||
packageName: Scriptable Sheets
|
||||
packageVersion: 1.8.0
|
||||
assetPath: Packages/com.lunawolfstudios.scriptablesheets/Samples~/ComponentPresets/Scripts/RigidbodyPreset.cs
|
||||
uploadId: 823456
|
||||
@@ -0,0 +1,27 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace LunaWolfStudios.ScriptableSheets.Samples.ComponentPresets
|
||||
{
|
||||
[System.Serializable]
|
||||
public class TransformPreset : AbstractComponentPreset<Transform>, IComponentPreset
|
||||
{
|
||||
[SerializeField]
|
||||
private Vector3 m_Position;
|
||||
public Vector3 Position { get => m_Position; set => m_Position = value; }
|
||||
|
||||
[SerializeField]
|
||||
private Vector3 m_EulerAngles;
|
||||
public Vector3 EulerAngles { get => m_EulerAngles; set => m_EulerAngles = value; }
|
||||
|
||||
[SerializeField]
|
||||
private Vector3 m_LocalScale;
|
||||
public Vector3 LocalScale { get => m_LocalScale; set => m_LocalScale = value; }
|
||||
|
||||
protected override void Apply(Transform obj)
|
||||
{
|
||||
obj.position = m_Position;
|
||||
obj.eulerAngles = m_EulerAngles;
|
||||
obj.localScale = m_LocalScale;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c46de0c47b894474ba990a89e8c585d9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 284559
|
||||
packageName: Scriptable Sheets
|
||||
packageVersion: 1.8.0
|
||||
assetPath: Packages/com.lunawolfstudios.scriptablesheets/Samples~/ComponentPresets/Scripts/TransformPreset.cs
|
||||
uploadId: 823456
|
||||
Reference in New Issue
Block a user