Add files via upload

This commit is contained in:
celisej567
2021-08-05 17:54:51 +03:00
committed by GitHub
parent d58ad89d11
commit 76b55e2a87
57 changed files with 5632 additions and 0 deletions

92
code/Tool.Preview.cs Normal file
View File

@@ -0,0 +1,92 @@
using System.Collections.Generic;
namespace Sandbox.Tools
{
public partial class BaseTool
{
internal List<PreviewEntity> Previews;
protected virtual bool IsPreviewTraceValid( TraceResult tr )
{
if ( !tr.Hit )
return false;
if ( !tr.Entity.IsValid() )
return false;
return true;
}
public virtual void CreatePreviews()
{
// Nothing
}
public virtual void DeletePreviews()
{
if ( Previews == null || Previews.Count == 0 )
return;
foreach ( var preview in Previews )
{
preview.Delete();
}
Previews.Clear();
}
public virtual bool TryCreatePreview( ref PreviewEntity ent, string model )
{
if ( !ent.IsValid() )
{
ent = new PreviewEntity();
ent.SetModel( model );
}
if ( Previews == null )
{
Previews = new List<PreviewEntity>();
}
if ( !Previews.Contains( ent ) )
{
Previews.Add( ent );
}
return ent.IsValid();
}
private void UpdatePreviews()
{
if ( Previews == null || Previews.Count == 0 )
return;
if ( !Owner.IsValid() )
return;
var startPos = Owner.EyePos;
var dir = Owner.EyeRot.Forward;
var tr = Trace.Ray( startPos, startPos + dir * 10000.0f )
.Ignore( Owner )
.Run();
foreach ( var preview in Previews )
{
if ( !preview.IsValid() )
continue;
if ( IsPreviewTraceValid( tr ) && preview.UpdateFromTrace( tr ) )
{
preview.RenderAlpha = 0.5f;
}
else
{
preview.RenderAlpha = 0.0f;
}
}
}
}
}