Additional cleanup

Cleaned up some additional stuff that I found
This commit is contained in:
W2.Wizard
2021-02-21 18:17:35 +01:00
parent 8b3fc9842d
commit 35b687bf3d
21 changed files with 142 additions and 151 deletions

View File

@@ -215,8 +215,7 @@ namespace FlaxEditor.Content.Import
var entries = new List<ImportFileEntry>(_rootNode.ChildrenCount);
for (int i = 0; i < _rootNode.ChildrenCount; i++)
{
var fileEntry = _rootNode.Children[i].Tag as ImportFileEntry;
if (fileEntry != null)
if (_rootNode.Children[i].Tag is ImportFileEntry fileEntry)
entries.Add(fileEntry);
}
Editor.Instance.ContentImporting.LetThemBeImportedxD(entries);

View File

@@ -599,7 +599,7 @@ namespace FlaxEditor.Content
public override bool OnShowTooltip(out string text, out Vector2 location, out Rectangle area)
{
UpdateTooltipText();
var result = base.OnShowTooltip(out text, out location, out area);
var result = base.OnShowTooltip(out text, out _, out area);
location = Size * new Vector2(0.9f, 0.5f);
return result;
}

View File

@@ -74,8 +74,7 @@ namespace FlaxEditor.Content
/// <inheritdoc />
public override void Create(string outputPath, object arg)
{
var actor = arg as Actor;
if (actor == null)
if (!(arg is Actor actor))
{
// Create default prefab root object
actor = new EmptyActor

View File

@@ -59,13 +59,11 @@ namespace FlaxEditor.Content.Thumbnails
}
// We cache previews only for items with 'ID', for now we support only AssetItems
var assetItem = item as AssetItem;
if (assetItem == null)
if (!(item is AssetItem assetItem))
return;
// Ensure that there is valid proxy for that item
var proxy = Editor.ContentDatabase.GetProxy(item) as AssetProxy;
if (proxy == null)
if (!(Editor.ContentDatabase.GetProxy(item) is AssetProxy proxy))
{
Editor.LogWarning($"Cannot generate preview for item {item.Path}. Cannot find proxy for it.");
return;
@@ -105,8 +103,7 @@ namespace FlaxEditor.Content.Thumbnails
throw new ArgumentNullException();
// We cache previews only for items with 'ID', for now we support only AssetItems
var assetItem = item as AssetItem;
if (assetItem == null)
if (!(item is AssetItem assetItem))
return;
lock (_requests)

View File

@@ -1236,8 +1236,7 @@ namespace FlaxEditor
result = IntPtr.Zero;
if (Windows.GameWin != null && (forceGet || Windows.GameWin.ContainsFocus))
{
var win = Windows.GameWin.Root as WindowRootControl;
if (win != null)
if (Windows.GameWin.Root is WindowRootControl win)
result = FlaxEngine.Object.GetUnmanagedPtr(win.Window);
}
}

View File

@@ -242,10 +242,11 @@ namespace FlaxEditor.GUI
MainMenuButton b = null;
foreach (var control in Children)
{
if (b == null && control is MainMenuButton)
b = (MainMenuButton)control;
if (control is MainMenuButton && control.Right > b.Right)
b = (MainMenuButton)control;
if (b == null && control is MainMenuButton button)
b = button;
if (control is MainMenuButton button1 && control.Right > b.Right)
b = button1;
}
return b;
}

View File

@@ -56,104 +56,107 @@ namespace FlaxEditor.Gizmo
_activeAxis = Axis.None;
switch (_activeMode)
{
case Mode.Translate:
{
// Axis boxes collision
if (XAxisBox.Intersects(ref localRay, out intersection) && intersection < closestintersection)
case Mode.Translate:
{
_activeAxis = Axis.X;
closestintersection = intersection;
}
if (YAxisBox.Intersects(ref localRay, out intersection) && intersection < closestintersection)
{
_activeAxis = Axis.Y;
closestintersection = intersection;
}
if (ZAxisBox.Intersects(ref localRay, out intersection) && intersection < closestintersection)
{
_activeAxis = Axis.Z;
closestintersection = intersection;
// Axis boxes collision
if (XAxisBox.Intersects(ref localRay, out intersection) && intersection < closestintersection)
{
_activeAxis = Axis.X;
closestintersection = intersection;
}
if (YAxisBox.Intersects(ref localRay, out intersection) && intersection < closestintersection)
{
_activeAxis = Axis.Y;
closestintersection = intersection;
}
if (ZAxisBox.Intersects(ref localRay, out intersection) && intersection < closestintersection)
{
_activeAxis = Axis.Z;
closestintersection = intersection;
}
// Quad planes collision
if (closestintersection >= float.MaxValue)
closestintersection = float.MinValue;
if (XYBox.Intersects(ref localRay, out intersection) && intersection > closestintersection)
{
_activeAxis = Axis.XY;
closestintersection = intersection;
}
if (XZBox.Intersects(ref localRay, out intersection) && intersection > closestintersection)
{
_activeAxis = Axis.ZX;
closestintersection = intersection;
}
if (YZBox.Intersects(ref localRay, out intersection) && intersection > closestintersection)
{
_activeAxis = Axis.YZ;
closestintersection = intersection;
}
break;
}
// Quad planes collision
if (closestintersection >= float.MaxValue)
closestintersection = float.MinValue;
if (XYBox.Intersects(ref localRay, out intersection) && intersection > closestintersection)
case Mode.Rotate:
{
_activeAxis = Axis.XY;
closestintersection = intersection;
}
if (XZBox.Intersects(ref localRay, out intersection) && intersection > closestintersection)
{
_activeAxis = Axis.ZX;
closestintersection = intersection;
}
if (YZBox.Intersects(ref localRay, out intersection) && intersection > closestintersection)
{
_activeAxis = Axis.YZ;
closestintersection = intersection;
// Circles
if (IntersectsRotateCircle(Vector3.UnitX, ref localRay, out intersection) && intersection < closestintersection)
{
_activeAxis = Axis.X;
closestintersection = intersection;
}
if (IntersectsRotateCircle(Vector3.UnitY, ref localRay, out intersection) && intersection < closestintersection)
{
_activeAxis = Axis.Y;
closestintersection = intersection;
}
if (IntersectsRotateCircle(Vector3.UnitZ, ref localRay, out intersection) && intersection < closestintersection)
{
_activeAxis = Axis.Z;
closestintersection = intersection;
}
// Center
/*if (CenterSphere.Intersects(ref ray, out intersection) && intersection < closestintersection)
{
_activeAxis = Axis.Center;
closestintersection = intersection;
}*/
break;
}
break;
}
case Mode.Scale:
{
// Spheres collision
if (ScaleXSphere.Intersects(ref ray, out intersection) && intersection < closestintersection)
{
_activeAxis = Axis.X;
closestintersection = intersection;
}
if (ScaleYSphere.Intersects(ref ray, out intersection) && intersection < closestintersection)
{
_activeAxis = Axis.Y;
closestintersection = intersection;
}
if (ScaleZSphere.Intersects(ref ray, out intersection) && intersection < closestintersection)
{
_activeAxis = Axis.Z;
closestintersection = intersection;
}
case Mode.Rotate:
{
// Circles
if (IntersectsRotateCircle(Vector3.UnitX, ref localRay, out intersection) && intersection < closestintersection)
{
_activeAxis = Axis.X;
closestintersection = intersection;
}
if (IntersectsRotateCircle(Vector3.UnitY, ref localRay, out intersection) && intersection < closestintersection)
{
_activeAxis = Axis.Y;
closestintersection = intersection;
}
if (IntersectsRotateCircle(Vector3.UnitZ, ref localRay, out intersection) && intersection < closestintersection)
{
_activeAxis = Axis.Z;
closestintersection = intersection;
}
// Center
if (CenterBox.Intersects(ref ray, out intersection) && intersection < closestintersection)
{
_activeAxis = Axis.Center;
closestintersection = intersection;
}
// Center
/*if (CenterSphere.Intersects(ref ray, out intersection) && intersection < closestintersection)
{
_activeAxis = Axis.Center;
closestintersection = intersection;
}*/
break;
}
case Mode.Scale:
{
// Spheres collision
if (ScaleXSphere.Intersects(ref ray, out intersection) && intersection < closestintersection)
{
_activeAxis = Axis.X;
closestintersection = intersection;
break;
}
if (ScaleYSphere.Intersects(ref ray, out intersection) && intersection < closestintersection)
{
_activeAxis = Axis.Y;
closestintersection = intersection;
}
if (ScaleZSphere.Intersects(ref ray, out intersection) && intersection < closestintersection)
{
_activeAxis = Axis.Z;
closestintersection = intersection;
}
// Center
if (CenterBox.Intersects(ref ray, out intersection) && intersection < closestintersection)
{
_activeAxis = Axis.Center;
closestintersection = intersection;
}
break;
}
}
}
}

View File

@@ -690,8 +690,7 @@ namespace FlaxEditor.SceneGraph.GUI
var item = _dragActorType.Objects[i];
// Create actor
var actor = item.CreateInstance() as Actor;
if (actor == null)
if (!(item.CreateInstance() is Actor actor))
{
Editor.LogWarning("Failed to spawn actor of type " + item.TypeName);
continue;

View File

@@ -255,8 +255,7 @@ namespace FlaxEditor.Surface.Archetypes
private void OnSurfaceLoaded(VisjectSurfaceContext context)
{
// Ensure that loaded surface has entry node for state machine
var entryNode = context.FindNode(9, 19);
if (entryNode == null)
if (context.FindNode(9, 19) == null)
{
var wasEnabled = true;
if (Surface.Undo != null)
@@ -265,7 +264,7 @@ namespace FlaxEditor.Surface.Archetypes
Surface.Undo.Enabled = false;
}
entryNode = context.SpawnNode(9, 19, new Vector2(100.0f));
context.SpawnNode(9, 19, new Vector2(100.0f));
if (Surface.Undo != null)
{
@@ -547,11 +546,11 @@ namespace FlaxEditor.Surface.Archetypes
private void Add()
{
var context = _context.Get(_surface);
var src = context.FindNode(_srcStateId) as StateMachineState;
if (src == null)
if (!(context.FindNode(_srcStateId) is StateMachineState src))
throw new Exception("Missing source state.");
var dst = context.FindNode(_dstStateId) as StateMachineState;
if (dst == null)
if (!(context.FindNode(_dstStateId) is StateMachineState dst))
throw new Exception("Missing destination state.");
var transition = new StateMachineTransition(src, dst, ref _data);
@@ -567,12 +566,13 @@ namespace FlaxEditor.Surface.Archetypes
private void Remove()
{
var context = _context.Get(_surface);
var src = context.FindNode(_srcStateId) as StateMachineState;
if (src == null)
if (!(context.FindNode(_srcStateId) is StateMachineState src))
throw new Exception("Missing source state.");
var dst = context.FindNode(_dstStateId) as StateMachineState;
if (dst == null)
if (!(context.FindNode(_dstStateId) is StateMachineState dst))
throw new Exception("Missing destination state.");
var transition = src.Transitions.Find(x => x.DestinationState == dst);
if (transition == null)
throw new Exception("Missing transition.");
@@ -870,8 +870,7 @@ namespace FlaxEditor.Surface.Archetypes
if (ruleSize != 0)
rule = reader.ReadBytes(ruleSize);
var destination = Context.FindNode(data.Destination) as StateMachineState;
if (destination == null)
if (!(Context.FindNode(data.Destination) is StateMachineState destination))
{
Editor.LogWarning("Missing state machine state destination node.");
continue;
@@ -1310,8 +1309,7 @@ namespace FlaxEditor.Surface.Archetypes
private void OnSurfaceLoaded(VisjectSurfaceContext context)
{
// Ensure that loaded surface has output node for state
var entryNode = context.FindNode(9, 21);
if (entryNode == null)
if (context.FindNode(9, 21) == null)
{
var wasEnabled = true;
if (Surface.Undo != null)
@@ -1320,7 +1318,7 @@ namespace FlaxEditor.Surface.Archetypes
Surface.Undo.Enabled = false;
}
entryNode = context.SpawnNode(9, 21, new Vector2(100.0f));
context.SpawnNode(9, 21, new Vector2(100.0f));
if (Surface.Undo != null)
{
@@ -1678,8 +1676,7 @@ namespace FlaxEditor.Surface.Archetypes
private void OnSurfaceLoaded(VisjectSurfaceContext context)
{
// Ensure that loaded surface has rule output node
var ruleOutputNode = context.FindNode(9, 22);
if (ruleOutputNode == null)
if (context.FindNode(9, 22) == null)
{
var wasEnabled = true;
var undo = SourceState.Surface.Undo;
@@ -1689,7 +1686,7 @@ namespace FlaxEditor.Surface.Archetypes
undo.Enabled = false;
}
ruleOutputNode = context.SpawnNode(9, 22, new Vector2(100.0f));
context.SpawnNode(9, 22, new Vector2(100.0f));
// TODO: add default rule nodes for easier usage

View File

@@ -765,9 +765,10 @@ namespace FlaxEditor.Surface.Archetypes
private SignatureInfo LoadSignature()
{
var signature = new SignatureInfo();
var data = Values[4] as byte[];
if (data == null || data.Length == 0)
if (!(Values[4] is byte[] data) || data.Length == 0)
return signature;
if (data[0] == 4)
{
using (var stream = new MemoryStream(data))

View File

@@ -686,10 +686,9 @@ namespace FlaxEditor.Surface.Elements
public bool CanConnectWith(IConnectionInstigator other)
{
var start = this;
var end = other as Box;
// Allow only box with box connection
if (end == null)
if (!(other is Box end))
{
// Cannot
return false;

View File

@@ -156,7 +156,6 @@ namespace FlaxEditor.Surface
/// <param name="height">The height.</param>
protected void Resize(float width, float height)
{
var prevSize = Size;
Size = CalculateNodeSize(width, height);
// Update boxes on width change
@@ -791,7 +790,7 @@ namespace FlaxEditor.Surface
/// <inheritdoc />
public override bool OnShowTooltip(out string text, out Vector2 location, out Rectangle area)
{
var result = base.OnShowTooltip(out text, out location, out area);
var result = base.OnShowTooltip(out text, out _, out area);
// Change the position
location = new Vector2(_headerRect.Width * 0.5f, _headerRect.Bottom);

View File

@@ -743,13 +743,14 @@ namespace FlaxEditor.Surface
{
if (!CanEdit)
return;
var node = control as SurfaceNode;
if (node == null)
if (!(control is SurfaceNode node))
{
Context.OnControlDeleted(control);
MarkAsEdited();
return;
}
if ((node.Archetype.Flags & NodeFlags.NoRemove) != 0)
return;

View File

@@ -577,7 +577,7 @@ namespace FlaxEditor.Surface
// Store node typename in values container
node.Values[0] = typeName;
}
if (node is MissingNode missingNode)
if (node is MissingNode)
{
// Read all values
Array.Resize(ref node.Values, valuesCnt);
@@ -749,7 +749,7 @@ namespace FlaxEditor.Surface
// Store node typename in values container
node.Values[0] = typeName;
}
if (node is MissingNode missingNode)
if (node is MissingNode)
{
// Read all values
Array.Resize(ref node.Values, valuesCnt);
@@ -769,7 +769,7 @@ namespace FlaxEditor.Surface
{
Editor.LogWarning(string.Format("Invalid node values. Loaded: {0}, expected: {1}. Type: {2}, {3}", valuesCnt, nodeValuesCnt, node.Archetype.Title, node.Archetype.TypeID));
object dummy = null;
object dummy;
for (int j = firstValueReadIdx; j < valuesCnt; j++)
{
dummy = stream.ReadVariant();
@@ -789,7 +789,7 @@ namespace FlaxEditor.Surface
for (int j = 0; j < boxesCount; j++)
{
var id = stream.ReadByte();
var type = stream.ReadVariantType();
stream.ReadVariantType(); // Skip type
var connectionsCnt = stream.ReadUInt16();
ConnectionHint hint;

View File

@@ -833,7 +833,7 @@ namespace FlaxEditor.Viewport
private Vector3 PostProcessSpawnedActorLocation(Actor actor, ref Vector3 hitLocation)
{
Editor.GetActorEditorBox(actor, out BoundingBox box);
Editor.GetActorEditorBox(actor, out _);
// Place the object
//var location = hitLocation - (box.Size.Length * 0.5f) * ViewDirection;
@@ -968,8 +968,7 @@ namespace FlaxEditor.Viewport
private void Spawn(ScriptType item, SceneGraphNode hit, ref Vector2 location, ref Vector3 hitLocation)
{
var actor = item.CreateInstance() as Actor;
if (actor == null)
if (!(item.CreateInstance() is Actor actor))
{
Editor.LogWarning("Failed to spawn actor of type " + item.TypeName);
return;

View File

@@ -749,8 +749,7 @@ namespace FlaxEditor.Viewport
private void Spawn(ScriptType item, SceneGraphNode hit, ref Vector3 hitLocation)
{
var actor = item.CreateInstance() as Actor;
if (actor == null)
if (!(item.CreateInstance() is Actor actor))
{
Editor.LogWarning("Failed to spawn actor of type " + item.TypeName);
return;

View File

@@ -157,7 +157,7 @@ namespace FlaxEditor.Windows.Profiler
float width = (float)(e.Time * scale);
string name = new string(e.Name);
var control = new Timeline.Event(x, e.Depth, width)
new Timeline.Event(x, e.Depth, width)
{
Name = name,
TooltipText = string.Format("{0}, {1} ms", name, ((int)(e.Time * 10000.0) / 10000.0f)),

View File

@@ -149,7 +149,7 @@ namespace FlaxEngine
/// <returns>Whether the two objects intersected.</returns>
public bool Intersects(ref Ray ray)
{
return CollisionsHelper.RayIntersectsBox(ref ray, ref this, out float distance);
return CollisionsHelper.RayIntersectsBox(ref ray, ref this, out float _);
}
/// <summary>

View File

@@ -81,7 +81,7 @@ namespace FlaxEngine
/// <returns>Whether the two objects intersected.</returns>
public bool Intersects(ref Ray ray)
{
return CollisionsHelper.RayIntersectsSphere(ref ray, ref this, out float distance);
return CollisionsHelper.RayIntersectsSphere(ref ray, ref this, out float _);
}
/// <summary>

View File

@@ -756,7 +756,7 @@ namespace FlaxEngine
/// <returns>Whether the two objects intersected.</returns>
public bool Intersects(ref Ray ray)
{
return Intersects(ref ray, out Vector3 point);
return Intersects(ref ray, out Vector3 _);
}
private Vector3[] GetLocalCorners()

View File

@@ -254,7 +254,7 @@ namespace FlaxEngine
/// <returns>Whether the two objects intersected.</returns>
public bool Intersects(ref Ray ray)
{
return CollisionsHelper.RayIntersectsPlane(ref ray, ref this, out float distance);
return CollisionsHelper.RayIntersectsPlane(ref ray, ref this, out float _);
}
/// <summary>
@@ -488,7 +488,6 @@ namespace FlaxEngine
float x = -plane.Normal.X;
float y = -plane.Normal.Y;
float z = -plane.Normal.Z;
float d = -plane.D;
result.M11 = x * light.X + dot;
result.M21 = y * light.X;
@@ -802,7 +801,7 @@ namespace FlaxEngine
if (planes == null)
throw new ArgumentNullException(nameof(planes));
Matrix.Invert(ref transformation, out Matrix inverse);
Matrix.Invert(ref transformation, out _);
for (var i = 0; i < planes.Length; ++i)
Transform(ref planes[i], ref transformation, out planes[i]);