diff --git a/Source/Editor/Content/Thumbnails/ThumbnailsModule.cs b/Source/Editor/Content/Thumbnails/ThumbnailsModule.cs index 1b1329318..d234eb91e 100644 --- a/Source/Editor/Content/Thumbnails/ThumbnailsModule.cs +++ b/Source/Editor/Content/Thumbnails/ThumbnailsModule.cs @@ -59,11 +59,13 @@ namespace FlaxEditor.Content.Thumbnails } // We cache previews only for items with 'ID', for now we support only AssetItems - if (!(item is AssetItem assetItem)) + var assetItem = item as AssetItem; + if (assetItem == null) return; // Ensure that there is valid proxy for that item - if (!(Editor.ContentDatabase.GetProxy(item) is AssetProxy proxy)) + var proxy = Editor.ContentDatabase.GetProxy(item) as AssetProxy; + if (proxy == null) { Editor.LogWarning($"Cannot generate preview for item {item.Path}. Cannot find proxy for it."); return; @@ -103,7 +105,8 @@ namespace FlaxEditor.Content.Thumbnails throw new ArgumentNullException(); // We cache previews only for items with 'ID', for now we support only AssetItems - if (!(item is AssetItem assetItem)) + var assetItem = item as AssetItem; + if (assetItem == null) return; lock (_requests) diff --git a/Source/Editor/Editor.cs b/Source/Editor/Editor.cs index 0c91a4f66..f81f81ddd 100644 --- a/Source/Editor/Editor.cs +++ b/Source/Editor/Editor.cs @@ -1236,7 +1236,8 @@ namespace FlaxEditor result = IntPtr.Zero; if (Windows.GameWin != null && (forceGet || Windows.GameWin.ContainsFocus)) { - if (Windows.GameWin.Root is WindowRootControl win) + var win = Windows.GameWin.Root as WindowRootControl; + if (win != null) result = FlaxEngine.Object.GetUnmanagedPtr(win.Window); } } diff --git a/Source/Editor/GUI/MainMenu.cs b/Source/Editor/GUI/MainMenu.cs index 620542ce4..81579b253 100644 --- a/Source/Editor/GUI/MainMenu.cs +++ b/Source/Editor/GUI/MainMenu.cs @@ -242,11 +242,11 @@ namespace FlaxEditor.GUI MainMenuButton b = null; foreach (var control in Children) { - if (b == null && control is MainMenuButton button) - b = button; + if (b == null && control is MainMenuButton) + b = (MainMenuButton)control; - if (control is MainMenuButton button1 && control.Right > b.Right) - b = button1; + if (control is MainMenuButton && control.Right > b.Right) + b = (MainMenuButton)control; } return b; } diff --git a/Source/Editor/Gizmo/TransformGizmoBase.Selection.cs b/Source/Editor/Gizmo/TransformGizmoBase.Selection.cs index fb526cd10..c1f7d1d0d 100644 --- a/Source/Editor/Gizmo/TransformGizmoBase.Selection.cs +++ b/Source/Editor/Gizmo/TransformGizmoBase.Selection.cs @@ -56,107 +56,107 @@ namespace FlaxEditor.Gizmo _activeAxis = Axis.None; switch (_activeMode) { - case Mode.Translate: + case Mode.Translate: + { + // Axis boxes collision + if (XAxisBox.Intersects(ref localRay, out intersection) && intersection < closestintersection) { - // 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; + _activeAxis = Axis.X; + closestintersection = intersection; } - case Mode.Rotate: + if (YAxisBox.Intersects(ref localRay, out intersection) && intersection < closestintersection) { - // 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; + _activeAxis = Axis.Y; + closestintersection = intersection; } - case Mode.Scale: + if (ZAxisBox.Intersects(ref localRay, out intersection) && intersection < closestintersection) { - // 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; - } - - // Center - if (CenterBox.Intersects(ref ray, out intersection) && intersection < closestintersection) - { - _activeAxis = Axis.Center; - closestintersection = intersection; - } - - break; + _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; + } + + 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 (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; + } + 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; + } } } } diff --git a/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs b/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs index 048244701..7b4b35ed1 100644 --- a/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs +++ b/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs @@ -690,7 +690,8 @@ namespace FlaxEditor.SceneGraph.GUI var item = _dragActorType.Objects[i]; // Create actor - if (!(item.CreateInstance() is Actor actor)) + var actor = item.CreateInstance() as Actor; + if (actor == null) { Editor.LogWarning("Failed to spawn actor of type " + item.TypeName); continue; diff --git a/Source/Editor/Surface/Archetypes/Animation.StateMachine.cs b/Source/Editor/Surface/Archetypes/Animation.StateMachine.cs index dfeea5774..1d04ae187 100644 --- a/Source/Editor/Surface/Archetypes/Animation.StateMachine.cs +++ b/Source/Editor/Surface/Archetypes/Animation.StateMachine.cs @@ -547,10 +547,12 @@ namespace FlaxEditor.Surface.Archetypes { var context = _context.Get(_surface); - if (!(context.FindNode(_srcStateId) is StateMachineState src)) + var src = context.FindNode(_srcStateId) as StateMachineState; + if (src == null) throw new Exception("Missing source state."); - if (!(context.FindNode(_dstStateId) is StateMachineState dst)) + var dst = context.FindNode(_dstStateId) as StateMachineState; + if (dst == null) throw new Exception("Missing destination state."); var transition = new StateMachineTransition(src, dst, ref _data); @@ -870,7 +872,8 @@ namespace FlaxEditor.Surface.Archetypes if (ruleSize != 0) rule = reader.ReadBytes(ruleSize); - if (!(Context.FindNode(data.Destination) is StateMachineState destination)) + var destination = Context.FindNode(data.Destination) as StateMachineState; + if (destination == null) { Editor.LogWarning("Missing state machine state destination node."); continue; diff --git a/Source/Editor/Surface/Archetypes/Function.cs b/Source/Editor/Surface/Archetypes/Function.cs index e568d3867..0b2bef3b4 100644 --- a/Source/Editor/Surface/Archetypes/Function.cs +++ b/Source/Editor/Surface/Archetypes/Function.cs @@ -766,7 +766,8 @@ namespace FlaxEditor.Surface.Archetypes { var signature = new SignatureInfo(); - if (!(Values[4] is byte[] data) || data.Length == 0) + var data = Values[4] as byte[]; + if (data == null || data.Length == 0) return signature; if (data[0] == 4) diff --git a/Source/Editor/Surface/Elements/Box.cs b/Source/Editor/Surface/Elements/Box.cs index ee0687ef4..2a460013c 100644 --- a/Source/Editor/Surface/Elements/Box.cs +++ b/Source/Editor/Surface/Elements/Box.cs @@ -686,9 +686,10 @@ namespace FlaxEditor.Surface.Elements public bool CanConnectWith(IConnectionInstigator other) { var start = this; + var end = other as Box; // Allow only box with box connection - if (!(other is Box end)) + if (end == null) { // Cannot return false; diff --git a/Source/Editor/Surface/VisjectSurface.cs b/Source/Editor/Surface/VisjectSurface.cs index 1db1f06d1..33786c935 100644 --- a/Source/Editor/Surface/VisjectSurface.cs +++ b/Source/Editor/Surface/VisjectSurface.cs @@ -744,7 +744,8 @@ namespace FlaxEditor.Surface if (!CanEdit) return; - if (!(control is SurfaceNode node)) + var node = control as SurfaceNode; + if (node == null) { Context.OnControlDeleted(control); MarkAsEdited(); diff --git a/Source/Editor/Viewport/MainEditorGizmoViewport.cs b/Source/Editor/Viewport/MainEditorGizmoViewport.cs index aaf75a21c..fc6a50a34 100644 --- a/Source/Editor/Viewport/MainEditorGizmoViewport.cs +++ b/Source/Editor/Viewport/MainEditorGizmoViewport.cs @@ -968,7 +968,8 @@ namespace FlaxEditor.Viewport private void Spawn(ScriptType item, SceneGraphNode hit, ref Vector2 location, ref Vector3 hitLocation) { - if (!(item.CreateInstance() is Actor actor)) + var actor = item.CreateInstance() as Actor; + if (actor == null) { Editor.LogWarning("Failed to spawn actor of type " + item.TypeName); return; diff --git a/Source/Editor/Viewport/PrefabWindowViewport.cs b/Source/Editor/Viewport/PrefabWindowViewport.cs index 08202427b..08b40c912 100644 --- a/Source/Editor/Viewport/PrefabWindowViewport.cs +++ b/Source/Editor/Viewport/PrefabWindowViewport.cs @@ -749,7 +749,8 @@ namespace FlaxEditor.Viewport private void Spawn(ScriptType item, SceneGraphNode hit, ref Vector3 hitLocation) { - if (!(item.CreateInstance() is Actor actor)) + var actor = item.CreateInstance() as Actor; + if (actor == null) { Editor.LogWarning("Failed to spawn actor of type " + item.TypeName); return;