/** * Rigidbody2D Inspector Provider * 2D 刚体检视器 */ import React from 'react'; import { Component } from '@esengine/ecs-framework'; import type { IComponentInspector, ComponentInspectorContext } from '@esengine/editor-core'; import { Rigidbody2DComponent } from '../../components/Rigidbody2DComponent'; import { RigidbodyType2D, CollisionDetectionMode2D } from '../../types/Physics2DTypes'; export class Rigidbody2DInspectorProvider implements IComponentInspector { readonly id = 'rigidbody2d-inspector'; readonly name = 'Rigidbody2D Inspector'; readonly priority = 100; readonly targetComponents = ['Rigidbody2D', 'Rigidbody2DComponent']; canHandle(component: Component): component is Rigidbody2DComponent { return component instanceof Rigidbody2DComponent || component.constructor.name === 'Rigidbody2DComponent'; } render(context: ComponentInspectorContext): React.ReactElement { const component = context.component as Rigidbody2DComponent; const onChange = context.onChange; const handleChange = (prop: string, value: unknown) => { onChange?.(prop, value); }; return (
Rigidbody 2D
{/* Body Type */}
{/* Mass - only for Dynamic */} {component.bodyType === RigidbodyType2D.Dynamic && (
handleChange('mass', parseFloat(e.target.value) || 1)} className="property-input" />
)} {/* Gravity Scale */}
handleChange('gravityScale', parseFloat(e.target.value) || 0)} className="property-input" />
{/* Damping Section */}
Damping
handleChange('linearDamping', parseFloat(e.target.value) || 0)} className="property-input" />
handleChange('angularDamping', parseFloat(e.target.value) || 0)} className="property-input" />
{/* Constraints Section */}
Constraints
handleChange('constraints', { ...component.constraints, freezePositionX: e.target.checked })} className="property-checkbox" />
handleChange('constraints', { ...component.constraints, freezePositionY: e.target.checked })} className="property-checkbox" />
handleChange('constraints', { ...component.constraints, freezeRotation: e.target.checked })} className="property-checkbox" />
{/* Collision Detection */}
Collision
{/* Sleep */}
Sleep
handleChange('canSleep', e.target.checked)} className="property-checkbox" />
{/* Runtime Info (read-only) */}
Runtime Info
({component.velocity.x.toFixed(2)}, {component.velocity.y.toFixed(2)})
{component.angularVelocity.toFixed(2)} rad/s
{component.isAwake ? 'Yes' : 'No'}
); } }