upd
This commit is contained in:
@@ -13,18 +13,9 @@ public sealed partial class Dedugan : Component
|
||||
[Sync] public bool CameraTraceIsHit { get; set; }
|
||||
public Vector3 TracedHitNormal { get; set; }
|
||||
|
||||
// private TimeSince HoldTime = 0;
|
||||
// private bool Holding = false;
|
||||
// private bool HoldingInteractionHappened = false;
|
||||
|
||||
void InteractionsUpdate()
|
||||
{
|
||||
if ( !EnablePressing )
|
||||
{
|
||||
// Holding = false;
|
||||
// HoldingInteractionHappened = false;
|
||||
return;
|
||||
}
|
||||
if ( !EnablePressing ) return;
|
||||
|
||||
if ( Pressed.IsValid() )
|
||||
{
|
||||
@@ -66,6 +57,8 @@ public sealed partial class Dedugan : Component
|
||||
|
||||
private void UpdateHovered()
|
||||
{
|
||||
if ( Pressed.IsValid() ) return;
|
||||
|
||||
SwitchHovered( TryGetLookedAt() );
|
||||
|
||||
if ( Hovered is IPressable pressable )
|
||||
@@ -76,15 +69,19 @@ public sealed partial class Dedugan : Component
|
||||
} );
|
||||
}
|
||||
|
||||
if ( Input.Down( "use" ) )
|
||||
if ( Input.Pressed( "use" ) )
|
||||
{
|
||||
StartPressing( Hovered );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void StartPressing( Component obj )
|
||||
{
|
||||
if ( Pressed == obj ) return;
|
||||
|
||||
StopPressing();
|
||||
|
||||
if ( !obj.IsValid() )
|
||||
{
|
||||
ISceneEvent<PlayerController.IEvents>.PostToGameObject( GameObject, x => x.FailPressing() );
|
||||
@@ -162,37 +159,30 @@ public sealed partial class Dedugan : Component
|
||||
|
||||
private Component TryGetLookedAt()
|
||||
{
|
||||
for ( float num = 0f; num <= 4f; num += 2f )
|
||||
var from = Scene.Camera.WorldPosition + Scene.Camera.WorldRotation.Forward;
|
||||
var to = from + Scene.Camera.WorldRotation.Forward * InteractDistance;
|
||||
|
||||
var trace = Scene.Trace
|
||||
.Ray( from, to )
|
||||
.IgnoreGameObjectHierarchy( GameObject )
|
||||
.Run();
|
||||
|
||||
TracedHitPos = trace.Hit ? trace.HitPosition : trace.EndPosition;
|
||||
CameraTraceIsHit = trace.Hit;
|
||||
TracedHitNormal = trace.Normal;
|
||||
|
||||
if ( !trace.Hit || !trace.GameObject.IsValid() ) return null;
|
||||
|
||||
var go = trace.GameObject;
|
||||
|
||||
var pressable = go.Components.Get<IPressable>( FindMode.EnabledInSelfAndDescendants );
|
||||
|
||||
if ( pressable != null && pressable.CanPress( new IPressable.Event
|
||||
{
|
||||
Ray = new Ray( Camera.WorldPosition, EyeAngles.ToRotation().Forward ), Source = this
|
||||
} ) )
|
||||
{
|
||||
var from = Scene.Camera.WorldPosition + Scene.Camera.WorldRotation.Forward;
|
||||
var to = from + Scene.Camera.WorldRotation.Forward * (InteractDistance - num);
|
||||
var trace = Scene.Trace.Ray( from, to ).IgnoreGameObjectHierarchy( GameObject ).Radius( num ).Run();
|
||||
|
||||
TracedHitPos = trace.Hit ? trace.HitPosition : trace.EndPosition;
|
||||
CameraTraceIsHit = trace.Hit;
|
||||
TracedHitNormal = trace.Normal;
|
||||
|
||||
if ( !trace.Hit || !trace.GameObject.IsValid() ) continue;
|
||||
|
||||
Component foundComponent = null;
|
||||
|
||||
ISceneEvent<PlayerController.IEvents>.PostToGameObject( GameObject, x =>
|
||||
{
|
||||
foundComponent = x.GetUsableComponent( trace.GameObject ) ?? foundComponent;
|
||||
} );
|
||||
|
||||
if ( foundComponent.IsValid() ) return foundComponent;
|
||||
|
||||
foreach ( var component in trace.GameObject.Components.GetAll<IPressable>() )
|
||||
{
|
||||
if ( component.CanPress( new IPressable.Event
|
||||
{
|
||||
Ray = new Ray( Camera.WorldPosition, EyeAngles.ToRotation().Forward ), Source = this
|
||||
} ) )
|
||||
{
|
||||
return component as Component;
|
||||
}
|
||||
}
|
||||
return pressable as Component;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -16,29 +16,29 @@ public sealed partial class Dedugan : Component
|
||||
|
||||
_resolver = new AttachmentSlotResolver( Renderer.GetAttachmentObject );
|
||||
|
||||
Inventory.AddItem( new InventoryItem
|
||||
{
|
||||
Definition = ResourceLibrary.Get<ClothingItemDefinition>( "Items/cloth_pijama.clitem" )
|
||||
} );
|
||||
|
||||
// Inventory.AddItem( new InventoryItem
|
||||
// {
|
||||
// Definition = ResourceLibrary.Get<BaseItemDefinition>( "Items/shorts_1.inv" )
|
||||
// Definition = ResourceLibrary.Get<ClothingItemDefinition>( "Items/cloth_pijama.clitem" )
|
||||
// } );
|
||||
|
||||
Inventory.AddItem( new InventoryItem
|
||||
{
|
||||
Definition = ResourceLibrary.Get<WeaponItemDefinition>( "Items/pistol_test.weapon" )
|
||||
} );
|
||||
|
||||
var ammo = new InventoryItem
|
||||
{
|
||||
Definition = ResourceLibrary.Get<BaseItemDefinition>( "Items/pistol_ammo.inv" )
|
||||
};
|
||||
ammo.Count = 30;
|
||||
ammo.MaxCount = 130;
|
||||
|
||||
Inventory.AddItem( ammo );
|
||||
//
|
||||
// Inventory.AddItem( new InventoryItem
|
||||
// {
|
||||
// Definition = ResourceLibrary.Get<ClothingItemDefinition>( "Items/cloth_pijama_bottom.clitem" )
|
||||
// } );
|
||||
//
|
||||
// Inventory.AddItem( new InventoryItem
|
||||
// {
|
||||
// Definition = ResourceLibrary.Get<WeaponItemDefinition>( "Items/pistol_test.weapon" )
|
||||
// } );
|
||||
//
|
||||
// var ammo = new InventoryItem
|
||||
// {
|
||||
// Definition = ResourceLibrary.Get<BaseItemDefinition>( "Items/pistol_ammo.inv" )
|
||||
// };
|
||||
// ammo.Count = 30;
|
||||
// ammo.MaxCount = 130;
|
||||
//
|
||||
// Inventory.AddItem( ammo );
|
||||
|
||||
Inventory.OnEquipped += OnItemEquipped;
|
||||
Inventory.OnUnEquipped += OnItemUnEquipped;
|
||||
@@ -70,6 +70,8 @@ public sealed partial class Dedugan : Component
|
||||
go.LocalPosition = weaponDef.WeaponDefinition.Position;
|
||||
go.LocalRotation = weaponDef.WeaponDefinition.Rotation;
|
||||
|
||||
go.Components.Get<UseableBase>().Equipped = true;
|
||||
|
||||
go.NetworkSpawn();
|
||||
|
||||
var hand = weaponDef.Slot switch
|
||||
@@ -145,8 +147,10 @@ public sealed partial class Dedugan : Component
|
||||
|
||||
if ( Input.Pressed( "Attack1" ) )
|
||||
{
|
||||
UseSystem.TryUse( this );
|
||||
Attack();
|
||||
if ( UseSystem.TryUse( this ) )
|
||||
{
|
||||
Attack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user