54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
using UnityEngine;
|
|
|
|
namespace Needle.Engine
|
|
{
|
|
public enum PhysicsEngine
|
|
{
|
|
None = 0,
|
|
Auto = 1,
|
|
Rapier = 2,
|
|
}
|
|
|
|
/** Deprecated. The physics module is loaded asynchronously at runtime, so this component is no longer needed. */
|
|
[AddComponentMenu("")]
|
|
public class NeedleEngineModules : MonoBehaviour
|
|
{
|
|
public PhysicsEngine PhysicsEngine = PhysicsEngine.Auto;
|
|
}
|
|
|
|
internal class PhysicsConfig : IBuildConfigProperty
|
|
{
|
|
public string Key => "useRapier";
|
|
|
|
public object GetValue(string projectDirectory)
|
|
{
|
|
var mod = Object.FindAnyObjectByType<NeedleEngineModules>();
|
|
if (mod)
|
|
{
|
|
if (mod.PhysicsEngine == PhysicsEngine.Auto)
|
|
{
|
|
if(UsePhysicsAuto()) return true;
|
|
Debug.LogWarning("Needle Engine: Physics module is disabled because it is set to \"Auto\" and no Collider or Rigidbody component was found in the scene", mod);
|
|
return false;
|
|
}
|
|
|
|
var physicsEnabled = mod.PhysicsEngine == PhysicsEngine.Rapier;
|
|
if (!physicsEnabled)
|
|
{
|
|
Debug.LogWarning("Needle Engine: Physics module is disabled.", mod);
|
|
}
|
|
return physicsEnabled;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public static bool UsePhysicsAuto()
|
|
{
|
|
// This doesnt check if any referenced prefab or scene has a Collider or RigidBody.
|
|
// It could also fail when physical objects are disabled in the scene and expected to later be enabled.
|
|
if (Object.FindAnyObjectByType<Collider>()) return true;
|
|
if (Object.FindAnyObjectByType<Rigidbody>()) return true;
|
|
return false;
|
|
}
|
|
}
|
|
} |