diff --git a/Prowl.Editor/Assets/AssetDatabase.Core.cs b/Prowl.Editor/Assets/AssetDatabase.Core.cs
index 1cca34a7..ef83566b 100644
--- a/Prowl.Editor/Assets/AssetDatabase.Core.cs
+++ b/Prowl.Editor/Assets/AssetDatabase.Core.cs
@@ -80,6 +80,7 @@ public static AssetDirectoryCache GetRootFolderCache(int index)
public static void AddRootFolder(string rootFolder)
{
ArgumentException.ThrowIfNullOrEmpty(rootFolder);
+ ArgumentNullException.ThrowIfNull(Project.Active);
var rootPath = Path.Combine(Project.Active.ProjectPath, rootFolder);
var info = new DirectoryInfo(rootPath);
@@ -139,7 +140,7 @@ public static void Update(bool doUnload = true, bool forceCacheUpdate = false)
if (ProcessFile(file, out _))
toReimport.Add(file);
}
- else if (!assetPathToMeta.TryGetValue(file, out var meta))
+ else if (!assetPathToMeta.TryGetValue(file, out _))
{
// File hasent changed but we dont have it in the cache, process it but dont reimport
Debug.Log("Asset Found: " + file);
@@ -168,7 +169,7 @@ public static void Update(bool doUnload = true, bool forceCacheUpdate = false)
cacheModified = true;
bool hasMeta = assetPathToMeta.TryGetValue(file, out var meta);
- if (hasMeta)
+ if (hasMeta && meta is not null)
{
assetPathToMeta.Remove(file);
@@ -248,7 +249,7 @@ static bool ProcessFile(string file, out bool metaOutdated)
{
// No meta file, create and import
var newMeta = new MetaFile(fileInfo);
- if (newMeta.importer == null)
+ if (newMeta.Importer == null)
{
Debug.LogError($"No importer found for file:\n{fileInfo.FullName}");
return false;
@@ -351,17 +352,18 @@ public static bool Reimport(FileInfo assetFile, bool disposeExisting = true)
Debug.LogError($"No valid meta file found for asset: {ToRelativePath(assetFile)}");
return false;
}
- if (meta.importer == null)
- {
- Debug.LogError($"No valid importer found for asset: {ToRelativePath(assetFile)}");
- return false;
- }
+ // TODO: FIXME: its always not null
+ // if (meta.Importer == null)
+ // {
+ // Debug.LogError($"No valid importer found for asset: {ToRelativePath(assetFile)}");
+ // return false;
+ // }
// Import the asset
SerializedAsset ctx = new(meta.guid);
try
{
- meta.importer.Import(ctx, assetFile);
+ meta.Importer.Import(ctx, assetFile);
}
catch (Exception e)
{
@@ -494,8 +496,11 @@ public static bool Reimport(FileInfo assetFile, bool disposeExisting = true)
{
var serializedAsset = SerializedAsset.FromSerializedAsset(serializedAssetPath.FullName);
serializedAsset.Guid = assetGuid;
- serializedAsset.Main.AssetID = assetGuid;
- serializedAsset.Main.FileID = 0;
+ if (serializedAsset.Main is not null)
+ {
+ serializedAsset.Main.AssetID = assetGuid;
+ serializedAsset.Main.FileID = 0;
+ }
for (int i = 0; i < serializedAsset.SubAssets.Count; i++)
{
serializedAsset.SubAssets[i].AssetID = assetGuid;
diff --git a/Prowl.Editor/Assets/AssetDatabase.FileOperations.cs b/Prowl.Editor/Assets/AssetDatabase.FileOperations.cs
index 744d77ac..63572a6c 100644
--- a/Prowl.Editor/Assets/AssetDatabase.FileOperations.cs
+++ b/Prowl.Editor/Assets/AssetDatabase.FileOperations.cs
@@ -100,7 +100,7 @@ public static bool Rename(FileInfo file, string newName)
///
/// Renames a folder.
///
- /// The folder to rename.
+ /// The folder to rename.
/// The new name of the folder.
/// True if the folder was renamed successfully, false otherwise.
public static bool Rename(DirectoryInfo source, string newName)
@@ -143,7 +143,7 @@ public static bool Delete(FileInfo file)
///
/// Deletes a folder.
///
- /// The folder to delete.
+ /// The folder to delete.
/// True if the folder was deleted successfully, false otherwise.
public static bool Delete(DirectoryInfo source)
{
diff --git a/Prowl.Editor/Assets/AssetDatabase.Packages.cs b/Prowl.Editor/Assets/AssetDatabase.Packages.cs
index 56cdb183..234616a3 100644
--- a/Prowl.Editor/Assets/AssetDatabase.Packages.cs
+++ b/Prowl.Editor/Assets/AssetDatabase.Packages.cs
@@ -325,7 +325,7 @@ public static async Task InstallPackage(string packageId, string version)
Update();
}
- public static async Task UninstallPackage(string packageId, string version)
+ public static void UninstallPackage(string packageId, string version)
{
ArgumentNullException.ThrowIfNull(packageId, nameof(packageId));
ArgumentNullException.ThrowIfNull(version, nameof(version));
diff --git a/Prowl.Editor/Assets/AssetDatabase.Utilities.cs b/Prowl.Editor/Assets/AssetDatabase.Utilities.cs
index e3348343..2850ce23 100644
--- a/Prowl.Editor/Assets/AssetDatabase.Utilities.cs
+++ b/Prowl.Editor/Assets/AssetDatabase.Utilities.cs
@@ -12,7 +12,7 @@ public static partial class AssetDatabase
#region Public Methods
- public static bool PathToCachedNode(string path, out AssetDirectoryCache.DirNode node)
+ public static bool PathToCachedNode(string path, out AssetDirectoryCache.DirNode? node)
{
node = null;
foreach (var tuple in rootFolders)
@@ -239,7 +239,7 @@ public static void GenerateUniqueAssetPath(ref FileInfo file)
return result;
}
- public static Type GetTypeOfAsset(Guid guid, ushort fileID)
+ public static Type? GetTypeOfAsset(Guid guid, ushort fileID)
{
if (assetGuidToMeta.TryGetValue(guid, out var meta))
if (meta.assetTypes.Length > fileID)
diff --git a/Prowl.Editor/Assets/AssetDirectoryCache.cs b/Prowl.Editor/Assets/AssetDirectoryCache.cs
index f34ce24e..84838d91 100644
--- a/Prowl.Editor/Assets/AssetDirectoryCache.cs
+++ b/Prowl.Editor/Assets/AssetDirectoryCache.cs
@@ -5,10 +5,10 @@ namespace Prowl.Editor.Assets;
public class AssetDirectoryCache(DirectoryInfo root)
{
- public class DirNode(DirectoryInfo directory, DirNode parent)
+ public class DirNode(DirectoryInfo directory, DirNode? parent)
{
public DirectoryInfo Directory = directory;
- public DirNode Parent = parent;
+ public DirNode? Parent = parent;
public List SubDirectories = [];
public List Files = [];
}
@@ -90,7 +90,7 @@ public void Refresh()
_rootNode = BuildDirectoryTree(_rootDir, null);
}
- private DirNode BuildDirectoryTree(DirectoryInfo directory, DirNode parent)
+ private DirNode BuildDirectoryTree(DirectoryInfo directory, DirNode? parent)
{
DirNode node = new(directory, parent);
try
diff --git a/Prowl.Editor/Assets/ImporterAttribute.cs b/Prowl.Editor/Assets/ImporterAttribute.cs
index 9139f204..c88fda27 100644
--- a/Prowl.Editor/Assets/ImporterAttribute.cs
+++ b/Prowl.Editor/Assets/ImporterAttribute.cs
@@ -31,26 +31,25 @@ public static void GenerateLookUp()
extToIcon.Clear();
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
foreach (var type in assembly.GetTypes())
- if (type != null)
+ {
+ var attribute = type.GetCustomAttribute();
+ if (attribute == null) continue;
+
+ foreach (var extRW in attribute.Extensions)
{
- var attribute = type.GetCustomAttribute();
- if (attribute == null) continue;
-
- foreach (var extRW in attribute.Extensions)
- {
- var ext = extRW.ToLower();
- // Make sure the Extension is formatted correctly '.png' 1 dot at start
- if (ext[0] != '.') ext = '.' + ext;
- // Check if has more then 1 '.'
- if (ext.Count(x => x == '.') > 1) throw new Exception($"Extension {ext} is formatted incorrectly on importer: {type.Name}");
-
- if (extToImporter.TryGetValue(ext, out var oldType))
- Debug.LogError($"Asset Importer Overwritten. {ext} extension already in use by: {oldType.Name}, being overwritten by: {type.Name}");
- extToImporter[ext] = type;
- extToIcon[ext] = attribute.FileIcon;
- extToGeneralType[ext] = attribute.GeneralType;
- }
+ var ext = extRW.ToLower();
+ // Make sure the Extension is formatted correctly '.png' 1 dot at start
+ if (ext[0] != '.') ext = '.' + ext;
+ // Check if has more then 1 '.'
+ if (ext.Count(x => x == '.') > 1) throw new Exception($"Extension {ext} is formatted incorrectly on importer: {type.Name}");
+
+ if (extToImporter.TryGetValue(ext, out var oldType))
+ Debug.LogError($"Asset Importer Overwritten. {ext} extension already in use by: {oldType.Name}, being overwritten by: {type.Name}");
+ extToImporter[ext] = type;
+ extToIcon[ext] = attribute.FileIcon;
+ extToGeneralType[ext] = attribute.GeneralType;
}
+ }
}
[OnAssemblyUnload]
@@ -104,15 +103,14 @@ public static void GenerateLookUp()
{
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
foreach (var type in assembly.GetTypes())
- if (type != null)
- {
- var attribute = type.GetCustomAttribute();
- if (attribute == null) continue;
-
- if (typeToEditor.TryGetValue(attribute.Type, out var oldType))
- Debug.LogError($"Custom Editor Overwritten. {attribute.Type.Name} already has a custom Editor: {oldType.Name}, being overwritten by: {type.Name}");
- typeToEditor[attribute.Type] = type;
- }
+ {
+ var attribute = type.GetCustomAttribute();
+ if (attribute == null) continue;
+
+ if (typeToEditor.TryGetValue(attribute.Type, out var oldType))
+ Debug.LogError($"Custom Editor Overwritten. {attribute.Type.Name} already has a custom Editor: {oldType.Name}, being overwritten by: {type.Name}");
+ typeToEditor[attribute.Type] = type;
+ }
}
[OnAssemblyUnload]
diff --git a/Prowl.Editor/Assets/Importers/AudioClipImporter.cs b/Prowl.Editor/Assets/Importers/AudioClipImporter.cs
index e078b223..dd6f38fc 100644
--- a/Prowl.Editor/Assets/Importers/AudioClipImporter.cs
+++ b/Prowl.Editor/Assets/Importers/AudioClipImporter.cs
@@ -124,7 +124,8 @@ public class AudioClipEditor : ScriptedEditor
public override void OnEnable()
{
- serialized = AssetDatabase.LoadAsset((target as MetaFile).AssetPath);
+ var metaFile = target as MetaFile ?? throw new Exception();
+ serialized = AssetDatabase.LoadAsset(metaFile.AssetPath) ?? throw new Exception();
}
public override void OnDisable()
@@ -140,7 +141,7 @@ public override void OnInspectorGUI()
{
double ItemSize = EditorStylePrefs.Instance.ItemSize;
- var importer = (AudioClipImporter)(target as MetaFile).importer;
+ var importer = (AudioClipImporter)(target as MetaFile).Importer;
try
{
diff --git a/Prowl.Editor/Assets/Importers/FontImporter.cs b/Prowl.Editor/Assets/Importers/FontImporter.cs
index f3072d17..6306e3d2 100644
--- a/Prowl.Editor/Assets/Importers/FontImporter.cs
+++ b/Prowl.Editor/Assets/Importers/FontImporter.cs
@@ -27,7 +27,7 @@ public override void Import(SerializedAsset ctx, FileInfo assetPath)
[CustomEditor(typeof(FontImporter))]
public class FontEditor : ScriptedEditor
{
- static int start, end;
+ // static int start, end;
private readonly int numberOfProperties = 0;
public void InputFloat(string name, ref float val)
{
@@ -101,7 +101,7 @@ public override void OnInspectorGUI()
{
double ItemSize = EditorStylePrefs.Instance.ItemSize;
- var importer = (FontImporter)(target as MetaFile).importer;
+ var importer = (FontImporter)(target as MetaFile).Importer;
gui.CurrentNode.Layout(LayoutType.Column);
diff --git a/Prowl.Editor/Assets/Importers/MaterialImporter.cs b/Prowl.Editor/Assets/Importers/MaterialImporter.cs
index 420219bd..28115f55 100644
--- a/Prowl.Editor/Assets/Importers/MaterialImporter.cs
+++ b/Prowl.Editor/Assets/Importers/MaterialImporter.cs
@@ -38,7 +38,7 @@ public class MaterialImporterEditor : ScriptedEditor
{
public override void OnInspectorGUI()
{
- var importer = (MaterialImporter)(target as MetaFile).importer;
+ var importer = (MaterialImporter)(target as MetaFile).Importer;
try
{
diff --git a/Prowl.Editor/Assets/Importers/ModelImporter.cs b/Prowl.Editor/Assets/Importers/ModelImporter.cs
index 86947ed4..22978f18 100644
--- a/Prowl.Editor/Assets/Importers/ModelImporter.cs
+++ b/Prowl.Editor/Assets/Importers/ModelImporter.cs
@@ -667,7 +667,7 @@ public override void OnInspectorGUI()
{
double ItemSize = EditorStylePrefs.Instance.ItemSize;
- var importer = (ModelImporter)(target as MetaFile).importer;
+ var importer = (ModelImporter)(target as MetaFile).Importer;
var serialized = AssetDatabase.LoadAsset((target as MetaFile).AssetPath);
gui.CurrentNode.Layout(LayoutType.Column);
diff --git a/Prowl.Editor/Assets/Importers/TextureImporter.cs b/Prowl.Editor/Assets/Importers/TextureImporter.cs
index 7d0bf576..8a60277c 100644
--- a/Prowl.Editor/Assets/Importers/TextureImporter.cs
+++ b/Prowl.Editor/Assets/Importers/TextureImporter.cs
@@ -53,7 +53,7 @@ public class TextureEditor : ScriptedEditor
{
public override void OnInspectorGUI()
{
- var importer = (TextureImporter)(target as MetaFile).importer;
+ var importer = (TextureImporter)(target as MetaFile).Importer;
gui.CurrentNode.Layout(LayoutType.Column);
diff --git a/Prowl.Editor/Assets/MetaFile.cs b/Prowl.Editor/Assets/MetaFile.cs
index 3415d51d..886549ec 100644
--- a/Prowl.Editor/Assets/MetaFile.cs
+++ b/Prowl.Editor/Assets/MetaFile.cs
@@ -18,7 +18,7 @@ public class MetaFile
public string[] assetTypes = [];
public DateTime lastModified;
- public ScriptedImporter importer;
+ public readonly ScriptedImporter Importer;
public List dependencies;
/// Default constructor for MetaFile.
@@ -35,7 +35,8 @@ public MetaFile(FileInfo assetFile)
AssetPath = assetFile;
guid = Guid.NewGuid();
lastModified = assetFile.LastWriteTimeUtc;
- importer = Activator.CreateInstance(importerType) as ScriptedImporter;
+ var importer = Activator.CreateInstance(importerType) as ScriptedImporter;
+ Importer = importer ?? throw new Exception();
}
/// Save the MetaFile to a specified file or default to the associated asset file with a ".meta" extension.
diff --git a/Prowl.Editor/Editor/AssetsBrowserWindow.cs b/Prowl.Editor/Editor/AssetsBrowserWindow.cs
index f2889852..406d4bc3 100644
--- a/Prowl.Editor/Editor/AssetsBrowserWindow.cs
+++ b/Prowl.Editor/Editor/AssetsBrowserWindow.cs
@@ -334,20 +334,20 @@ public void RenderEntry(ref int index, AssetDirectoryCache.FileNode entry)
var interact = gui.GetInteractable();
AssetsTreeWindow.HandleFileClick(-1, interact, entry, i, true);
- DrawFileEntry(index++, entry.File, interact, true, subAssets[i]);
+ DrawFileEntry(index++, entry.File, interact, subAssets[i]);
}
}
}
}
- private void DrawFileEntry(int index, FileSystemInfo entry, Interactable interact, bool hasSubAsset = false, AssetDatabase.SubAssetCache? subAsset = null)
+ private void DrawFileEntry(int index, FileSystemInfo entry, Interactable interact, AssetDatabase.SubAssetCache? subAsset = null)
{
var rect = gui.CurrentNode.LayoutData.Rect;
//if (hasSubAsset)
// rect.Expand(-10);
var entrySize = rect.width;
- gui.Tooltip(hasSubAsset ? subAsset.Value.name : entry.FullName);
+ gui.Tooltip(subAsset is not null ? subAsset.Value.name : entry.FullName);
var color = EditorStylePrefs.Instance.Borders;
if (entry is FileInfo f)
diff --git a/Prowl.Editor/Editor/AssetsTreeWindow.cs b/Prowl.Editor/Editor/AssetsTreeWindow.cs
index 407171ff..5513a0b8 100644
--- a/Prowl.Editor/Editor/AssetsTreeWindow.cs
+++ b/Prowl.Editor/Editor/AssetsTreeWindow.cs
@@ -129,7 +129,7 @@ protected override void Draw()
}
}
- public static void DrawContextMenu(FileSystemInfo? fileInfo, DirectoryInfo? directory = null, bool fromAssetBrowser = false, LayoutNode popupHolder = null)
+ public static void DrawContextMenu(FileSystemInfo? fileInfo, DirectoryInfo? directory = null, bool fromAssetBrowser = false, LayoutNode? popupHolder = null)
{
bool closePopup = false;
diff --git a/Prowl.Editor/Editor/Docking/DockContainer.cs b/Prowl.Editor/Editor/Docking/DockContainer.cs
index 696f384e..bd2c18ac 100644
--- a/Prowl.Editor/Editor/Docking/DockContainer.cs
+++ b/Prowl.Editor/Editor/Docking/DockContainer.cs
@@ -9,15 +9,15 @@ namespace Prowl.Editor.Docking;
public class DockContainer
{
- public DockNode Root = new DockNode();
- private Vector2 PaddedMins => new Vector2(0, 0);
+ public DockNode Root = new();
+ private Vector2 PaddedMins => new(0, 0);
public void Update(Rect root)
{
Root.UpdateRecursive(root.Min, root.Max);
}
- public DockNode TraceLeaf(double x, double y)
+ public DockNode? TraceLeaf(double x, double y)
{
x -= PaddedMins.x;
y -= PaddedMins.y;
@@ -25,7 +25,7 @@ public DockNode TraceLeaf(double x, double y)
return Root.TraceLeaf(x, y);
}
- public DockPlacement GetPlacement(double x, double y, out List possibleAreas, out Rect hovered)
+ public DockPlacement GetPlacement(double x, double y, out List? possibleAreas, out Rect hovered)
{
possibleAreas = null;
hovered = Rect.Zero;
@@ -38,21 +38,23 @@ public DockPlacement GetPlacement(double x, double y, out List possibleAre
return default;
Vector2 cen = (leaf.Mins + leaf.Maxs) * 0.5f;
- Vector2 size = new Vector2(100, 100);
+ Vector2 size = new(100, 100);
// TODO: Why do we need to remove half of the size? Shouldn't ((min + max) / 2) be the center already?
cen.x -= size.x / 2;
cen.y -= size.y / 2;
- Rect main = new Rect(cen, size);
+ Rect main = new(cen, size);
- Rect left = new Rect(cen - new Vector2(size.x + 5, 0), size);
- Rect right = new Rect(cen + new Vector2(size.x + 5, 0), size);
- Rect top = new Rect(cen - new Vector2(0, size.y + 5), size);
- Rect bottom = new Rect(cen + new Vector2(0, size.y + 5), size);
+ Rect left = new(cen - new Vector2(size.x + 5, 0), size);
+ Rect right = new(cen + new Vector2(size.x + 5, 0), size);
+ Rect top = new(cen - new Vector2(0, size.y + 5), size);
+ Rect bottom = new(cen + new Vector2(0, size.y + 5), size);
possibleAreas = [main, left, right, top, bottom];
- DockPlacement placement = new DockPlacement();
- placement.Leaf = leaf;
- placement.PolygonVerts = new Vector2[4];
+ DockPlacement placement = new()
+ {
+ Leaf = leaf,
+ PolygonVerts = new Vector2[4]
+ };
while (true)
{
@@ -318,7 +320,7 @@ public bool DetachWindow(EditorWindow window)
if (leaf.LeafWindows.Count == 0)
{
- DockNode parent = FindParent(leaf);
+ DockNode? parent = FindParent(leaf);
if (parent != null)
{
DockNode neighborNode;
diff --git a/Prowl.Editor/Editor/Docking/DockNode.cs b/Prowl.Editor/Editor/Docking/DockNode.cs
index 4b69997c..5c110837 100644
--- a/Prowl.Editor/Editor/Docking/DockNode.cs
+++ b/Prowl.Editor/Editor/Docking/DockNode.cs
@@ -52,7 +52,7 @@ public enum NodeType
for (int i = 0; i < 2; ++i)
{
- DockNode leaf = Child[i].TraceLeaf(x, y);
+ DockNode? leaf = Child[i].TraceLeaf(x, y);
if (leaf != null)
return leaf;
}
@@ -82,7 +82,7 @@ public enum NodeType
return this;
}
- DockNode node = Child[0].TraceSeparator(x, y);
+ DockNode? node = Child[0].TraceSeparator(x, y);
if (node != null)
return node;
@@ -138,7 +138,7 @@ public void UpdateRecursive(double x, double y, double w, double h)
}
}
- public DockNode FindParent(DockNode node)
+ public DockNode? FindParent(DockNode node)
{
if (Type == NodeType.Leaf)
return null;
@@ -147,7 +147,7 @@ public DockNode FindParent(DockNode node)
if (Child[i] == node)
return this;
- DockNode n = Child[0].FindParent(node);
+ DockNode? n = Child[0].FindParent(node);
if (n != null)
return n;
diff --git a/Prowl.Editor/Editor/DragnDrop.cs b/Prowl.Editor/Editor/DragnDrop.cs
index 6b64a3e9..3bce1dc6 100644
--- a/Prowl.Editor/Editor/DragnDrop.cs
+++ b/Prowl.Editor/Editor/DragnDrop.cs
@@ -11,7 +11,7 @@ namespace Prowl.Editor;
public static class DragnDrop
{
- private static object[] draggedObject;
+ private static object[]? draggedObject;
private static string payloadTag = "";
diff --git a/Prowl.Editor/Editor/EditorGUI.cs b/Prowl.Editor/Editor/EditorGUI.cs
index 94a8b2cc..ffadbbf3 100644
--- a/Prowl.Editor/Editor/EditorGUI.cs
+++ b/Prowl.Editor/Editor/EditorGUI.cs
@@ -357,7 +357,7 @@ static bool HandleBeginGUIAttributes(string id, object target, IEnumerable m_Leaf != null;
- private DockNode m_Leaf;
- private Vector2 m_DockPosition;
+ private DockNode? m_Leaf;
+ // private Vector2 m_DockPosition;
- public DockNode Leaf
+ public DockNode? Leaf
{
get => m_Leaf;
internal set => m_Leaf = value;
@@ -128,7 +128,7 @@ public void ProcessFrame()
{
HandleTitleBarInteraction();
- if (IsDocked && Leaf.LeafWindows.Count > 0)
+ if (IsDocked && Leaf?.LeafWindows.Count > 0)
{
double[] tabWidths = new double[Leaf.LeafWindows.Count];
double total = 0;
@@ -310,7 +310,7 @@ private void HandleTitleBarInteraction()
if (gui.IsPointerMoving && IsDocked)
{
- EditorGuiManager.Container.DetachWindow(this);
+ EditorGuiManager.Container?.DetachWindow(this);
// Position the window so the mouse is over the title bar
_x = gui.PointerPos.x - (_width / 2);
_y = gui.PointerPos.y - 10;
@@ -359,4 +359,4 @@ protected virtual void Draw() { }
protected virtual void Update() { }
protected virtual void Close() { }
-}
\ No newline at end of file
+}
diff --git a/Prowl.Editor/Editor/GameWindow.cs b/Prowl.Editor/Editor/GameWindow.cs
index a845a7f7..8b630aa1 100644
--- a/Prowl.Editor/Editor/GameWindow.cs
+++ b/Prowl.Editor/Editor/GameWindow.cs
@@ -34,7 +34,7 @@ public enum Resolutions
const int HeaderHeight = 27;
RenderTexture RenderTarget;
- bool previouslyPlaying = false;
+ // bool previouslyPlaying = false;
bool hasFrame;
public static WeakReference LastFocused;
diff --git a/Prowl.Editor/Editor/HierarchyWindow.cs b/Prowl.Editor/Editor/HierarchyWindow.cs
index e7037759..ff96d767 100644
--- a/Prowl.Editor/Editor/HierarchyWindow.cs
+++ b/Prowl.Editor/Editor/HierarchyWindow.cs
@@ -21,7 +21,7 @@ public class HierarchyWindow : EditorWindow
private const float PingDuration = 3f;
private static float pingTimer;
- private static WeakReference pingedGO;
+ private static WeakReference? pingedGO;
private bool justStartedRename;
public HierarchyWindow() : base()
diff --git a/Prowl.Editor/Editor/InspectorWindow.cs b/Prowl.Editor/Editor/InspectorWindow.cs
index 43688723..f58038a9 100644
--- a/Prowl.Editor/Editor/InspectorWindow.cs
+++ b/Prowl.Editor/Editor/InspectorWindow.cs
@@ -8,6 +8,7 @@
using Prowl.Icons;
using Prowl.Runtime;
using Prowl.Runtime.GUI;
+using EditorCustom = (object parent, Prowl.Editor.Assets.ScriptedEditor? editor);
namespace Prowl.Editor;
@@ -20,7 +21,7 @@ public class InspectorWindow : EditorWindow
private object? Selected;
private bool lockSelection;
- (object, ScriptedEditor)? customEditor;
+ (object parent, ScriptedEditor scriptedEditor)? customEditor;
public InspectorWindow() : base()
{
@@ -111,12 +112,10 @@ protected override void Draw()
var meta = MetaFile.Load(path);
if (meta != null)
{
- Type? editorType = CustomEditorAttribute.GetEditor(meta.importer.GetType());
+ Type? editorType = CustomEditorAttribute.GetEditor(meta.Importer.GetType());
if (editorType != null)
{
- customEditor = (path, (ScriptedEditor)Activator.CreateInstance(editorType));
- customEditor.Value.Item2.target = meta;
- customEditor.Value.Item2.OnEnable();
+ CreateInstanceCustomEditor(path, editorType, meta);
destroyCustomEditor = false;
}
else
@@ -143,7 +142,7 @@ protected override void Draw()
else if (customEditor.Value.Item1.Equals(path))
{
// We are still editing the same asset path
- customEditor.Value.Item2.OnInspectorGUI();
+ customEditor.Value.scriptedEditor?.OnInspectorGUI();
destroyCustomEditor = false;
}
}
@@ -155,9 +154,7 @@ protected override void Draw()
Type? editorType = CustomEditorAttribute.GetEditor(Selected.GetType());
if (editorType != null)
{
- customEditor = (Selected, (ScriptedEditor)Activator.CreateInstance(editorType));
- customEditor.Value.Item2.target = Selected;
- customEditor.Value.Item2.OnEnable();
+ customEditor = CreateInstanceCustomEditor(Selected, editorType, Selected);
destroyCustomEditor = false;
}
else
@@ -177,19 +174,31 @@ protected override void Draw()
else if (customEditor.Value.Item1 == Selected)
{
// We are still editing the same object
- customEditor.Value.Item2.OnInspectorGUI();
+ customEditor.Value.scriptedEditor?.OnInspectorGUI();
destroyCustomEditor = false;
}
}
if (destroyCustomEditor)
{
- customEditor?.Item2.OnDisable();
+ customEditor?.scriptedEditor?.OnDisable();
customEditor = null;
}
}
}
+ private (object parent, ScriptedEditor scriptedEditor)? CreateInstanceCustomEditor(object path, Type editorType, object meta)
+ {
+ var scriptedEditor = Activator.CreateInstance(editorType) as ScriptedEditor;
+ customEditor = (path, scriptedEditor);
+ if (customEditor.Value.scriptedEditor is not null)
+ {
+ customEditor.Value.scriptedEditor.target = meta;
+ customEditor.Value.scriptedEditor.OnEnable();
+ }
+ return customEditor;
+ }
+
private void DrawInspectorLabel(string message)
{
double ItemSize = EditorStylePrefs.Instance.ItemSize;
diff --git a/Prowl.Editor/Editor/NodeEditor/NodeEditor.cs b/Prowl.Editor/Editor/NodeEditor/NodeEditor.cs
index 969abe55..c84c0064 100644
--- a/Prowl.Editor/Editor/NodeEditor/NodeEditor.cs
+++ b/Prowl.Editor/Editor/NodeEditor/NodeEditor.cs
@@ -444,9 +444,13 @@ protected bool DrawBackingField(Gui g, Node node, int fieldIndex, NodePort port)
bool changed = false;
var fieldInfo = GetFieldInfo(port.node.GetType(), port.fieldName);
- InputAttribute field = fieldInfo.GetCustomAttributes(true).FirstOrDefault();
+ if (fieldInfo is null)
+ {
+ return changed;
+ }
+ InputAttribute? field = fieldInfo.GetCustomAttributes(true).FirstOrDefault();
bool showBacking = false;
- if (field.backingValue != ShowBackingValue.Never)
+ if (field is not null && field.backingValue != ShowBackingValue.Never)
showBacking = field.backingValue == ShowBackingValue.Always || (field.backingValue == ShowBackingValue.Unconnected && !port.IsConnected);
if (showBacking)
@@ -462,12 +466,12 @@ protected bool DrawBackingField(Gui g, Node node, int fieldIndex, NodePort port)
return changed;
}
- protected static FieldInfo GetFieldInfo(Type type, string fieldName)
+ protected static FieldInfo? GetFieldInfo(Type type, string fieldName)
{
// If we can't find field in the first run, it's probably a private field in a base class.
- FieldInfo field = type.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
+ FieldInfo? field = type.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
// Search base classes for private fields only. Public fields are found above
- while (field == null && (type = type.BaseType) != typeof(Node)) field = type.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
+ while (field is not null && type.BaseType is not null && (type = type.BaseType) != typeof(Node)) field = type.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
return field;
}
@@ -578,7 +582,7 @@ public class NodeEditor
internal Rect dragSelection;
private string _searchText = string.Empty;
- private static NodeMenuItemInfo rootMenuItem;
+ private static NodeMenuItemInfo? rootMenuItem;
private readonly SelectHandler SelectHandler = new((item) => !item.IsAlive, (a, b) => ReferenceEquals(a.Target, b.Target));
@@ -1034,7 +1038,7 @@ public bool DrawBlackBoard(Gui gui)
{
object? obj = graph;
// Get graph.parameters field
- FieldInfo props = graph.GetType().GetField("parameters", BindingFlags.Instance | BindingFlags.Public);
+ FieldInfo props = graph.GetType().GetField("parameters", BindingFlags.Instance | BindingFlags.Public) ?? throw new Exception();
return EditorGUI.PropertyGrid("BlackBoard", ref obj, [props], EditorGUI.PropertyGridConfig.NoHeader);
}
}
@@ -1086,15 +1090,16 @@ public void Release()
private void DrawMenuItems(NodeMenuItemInfo menuItem, Gui g)
{
- bool foundName = false;
+ // bool foundName = false;
bool hasSearch = string.IsNullOrEmpty(_searchText) == false;
foreach (var item in menuItem.Children)
{
if (hasSearch && (item.Name.Contains(_searchText, StringComparison.CurrentCultureIgnoreCase) == false || item.Type == null))
{
DrawMenuItems(item, g);
- if (hasSearch && item.Name.Equals(_searchText, StringComparison.CurrentCultureIgnoreCase))
- foundName = true;
+ // TODO: `foundName` is not used anywhere
+ // if (hasSearch && item.Name.Equals(_searchText, StringComparison.CurrentCultureIgnoreCase))
+ // foundName = true;
continue;
}
@@ -1229,12 +1234,12 @@ private class NodeMenuItemInfo
{
public string Name;
public Type Type;
- public readonly MethodInfo Method;
+ public readonly MethodInfo? Method;
public readonly List Children = [];
public NodeMenuItemInfo() { }
- public NodeMenuItemInfo(Type type, MethodInfo method = null)
+ public NodeMenuItemInfo(Type type, MethodInfo? method = null)
{
Type = type;
Method = method;
@@ -1244,7 +1249,7 @@ public NodeMenuItemInfo(Type type, MethodInfo method = null)
Name = addToMenuAttribute.catagory;
}
- public void AddChild(string path, Type type, MethodInfo method = null)
+ public void AddChild(string path, Type type, MethodInfo? method = null)
{
string[] parts = path.Split('/');
NodeMenuItemInfo currentNode = this;
diff --git a/Prowl.Editor/Editor/PackageManager.cs b/Prowl.Editor/Editor/PackageManager.cs
index 25d2cf08..12d97d5a 100644
--- a/Prowl.Editor/Editor/PackageManager.cs
+++ b/Prowl.Editor/Editor/PackageManager.cs
@@ -170,7 +170,7 @@ private void DrawPackageList()
}
}
- private void DrawPackageDetails()
+ private async void DrawPackageDetails()
{
if (loadingDetails)
{
@@ -211,7 +211,7 @@ private void DrawPackageDetails()
if (canUpdate && EditorGUI.StyledButton("Update", installWidth / 2, itemSize))
{
AssetDatabase.UninstallPackage(_metadata.Identity.Id, installedPackage.Identity.Version.ToString());
- AssetDatabase.InstallPackage(_metadata.Identity.Id, _projectVersions[_selectedVersionIndex]);
+ await AssetDatabase.InstallPackage(_metadata.Identity.Id, _projectVersions[_selectedVersionIndex]);
}
if (EditorGUI.StyledButton("Uninstall", canUpdate ? installWidth / 2 : installWidth, itemSize))
@@ -226,7 +226,7 @@ private void DrawPackageDetails()
if (gui.Combo("Version", "VersionPopup", ref _selectedVersionIndex, _projectVersions, 0, 0, 75, itemSize))
PopulateDetails(_projectVersions[_selectedVersionIndex]);
if (EditorGUI.StyledButton("Install", installWidth, itemSize))
- AssetDatabase.InstallPackage(_metadata.Identity.Id, _projectVersions[_selectedVersionIndex]);
+ await AssetDatabase.InstallPackage(_metadata.Identity.Id, _projectVersions[_selectedVersionIndex]);
}
}
diff --git a/Prowl.Editor/Editor/ProjectSettingsWindow.cs b/Prowl.Editor/Editor/ProjectSettingsWindow.cs
index 9e4ab3e3..c27093f2 100644
--- a/Prowl.Editor/Editor/ProjectSettingsWindow.cs
+++ b/Prowl.Editor/Editor/ProjectSettingsWindow.cs
@@ -107,8 +107,8 @@ private void RenderBody()
if (currentType == null) return;
// Draw Settings
- object setting = currentSingleton;
-
+ object? setting = currentSingleton ?? throw new Exception();
+
string name = currentType.Name.Replace("Preferences", "");
if (PropertyGrid(name, ref setting, TargetFields.Serializable | TargetFields.Properties, PropertyGridConfig.NoBorder | PropertyGridConfig.NoBackground))
{
diff --git a/Prowl.Editor/Editor/PropertyDrawer/Drawers/Bool_PropertyDrawer.cs b/Prowl.Editor/Editor/PropertyDrawer/Drawers/Bool_PropertyDrawer.cs
index a613d951..d8484c7c 100644
--- a/Prowl.Editor/Editor/PropertyDrawer/Drawers/Bool_PropertyDrawer.cs
+++ b/Prowl.Editor/Editor/PropertyDrawer/Drawers/Bool_PropertyDrawer.cs
@@ -13,7 +13,7 @@ public class Bool_PropertyDrawer : PropertyDrawer
public override bool OnValueGUI(Gui gui, string ID, Type targetType, ref object? value)
{
- bool val = (bool)value;
+ bool val = value is bool v ? v : Convert.ToBoolean(value);
bool changed = Gui.ActiveGUI.Checkbox(ID + "Val", ref val, 0, 0, out _, EditorGUI.GetInputStyle());
value = val;
return changed;
diff --git a/Prowl.Editor/Editor/PropertyDrawer/Drawers/Color_PropertyDrawer.cs b/Prowl.Editor/Editor/PropertyDrawer/Drawers/Color_PropertyDrawer.cs
index 40bf52b6..2e799443 100644
--- a/Prowl.Editor/Editor/PropertyDrawer/Drawers/Color_PropertyDrawer.cs
+++ b/Prowl.Editor/Editor/PropertyDrawer/Drawers/Color_PropertyDrawer.cs
@@ -13,7 +13,7 @@ public override bool OnValueGUI(Gui gui, string ID, Type targetType, ref object?
{
gui.CurrentNode.Layout(LayoutType.Row).ScaleChildren();
- Color val = (Color)value;
+ Color val = value is Color v ? v : throw new Exception();
var style = EditorGUI.InputFieldStyle;
style.TextColor = val with { a = 1 };
diff --git a/Prowl.Editor/Editor/PropertyDrawer/Drawers/Double_PropertyDrawer.cs b/Prowl.Editor/Editor/PropertyDrawer/Drawers/Double_PropertyDrawer.cs
index 3809b71d..a32bf473 100644
--- a/Prowl.Editor/Editor/PropertyDrawer/Drawers/Double_PropertyDrawer.cs
+++ b/Prowl.Editor/Editor/PropertyDrawer/Drawers/Double_PropertyDrawer.cs
@@ -12,9 +12,9 @@ public class Double_PropertyDrawer : PropertyDrawer
public override double MinWidth => EditorStylePrefs.Instance.ItemSize * 2;
public override bool OnValueGUI(Gui gui, string ID, Type targetType, ref object? value)
{
- double val = (double)value;
+ double val = value is double v ? v : double.NaN;
bool changed = EditorGUI.InputDouble(ID + "Val", ref val, 0, 0, Size.Percentage(1f), EditorGUI.InputFieldStyle);
value = val;
return changed;
}
-}
\ No newline at end of file
+}
diff --git a/Prowl.Editor/Editor/PropertyDrawer/Drawers/Float_PropertyDrawer.cs b/Prowl.Editor/Editor/PropertyDrawer/Drawers/Float_PropertyDrawer.cs
index 367cc4e3..d1ef8579 100644
--- a/Prowl.Editor/Editor/PropertyDrawer/Drawers/Float_PropertyDrawer.cs
+++ b/Prowl.Editor/Editor/PropertyDrawer/Drawers/Float_PropertyDrawer.cs
@@ -13,7 +13,7 @@ public class Float_PropertyDrawer : PropertyDrawer
public override bool OnValueGUI(Gui gui, string ID, Type targetType, ref object? value)
{
- float val = (float)value;
+ float val = value is float v ? v : Convert.ToSingle(value);
bool changed = EditorGUI.InputFloat(ID + "Val", ref val, 0, 0, Size.Percentage(1f), EditorGUI.InputFieldStyle);
value = val;
return changed;
diff --git a/Prowl.Editor/Editor/PropertyDrawer/Drawers/PropertyDrawerEnumerable.cs b/Prowl.Editor/Editor/PropertyDrawer/Drawers/PropertyDrawerEnumerable.cs
index 0091cf7c..a20e5109 100644
--- a/Prowl.Editor/Editor/PropertyDrawer/Drawers/PropertyDrawerEnumerable.cs
+++ b/Prowl.Editor/Editor/PropertyDrawer/Drawers/PropertyDrawerEnumerable.cs
@@ -1,6 +1,8 @@
// This file is part of the Prowl Game Engine
// Licensed under the MIT License. See the LICENSE file in the project root for details.
+using DotRecast.Core;
+
using Prowl.Editor.Preferences;
using Prowl.Icons;
using Prowl.Runtime;
@@ -104,12 +106,12 @@ public override bool PropertyLayout(Gui gui, string label, int index, Type prope
// See if Element has a field called "Name" or "name" and use that as the label
var nameField = ElementType(list).GetField("Name") ?? ElementType(list).GetField("name");
- string elementName = ((string)nameField?.GetValue(element)) ?? "Element " + i;
+ string elementName = nameField?.GetValue(element) as string ?? "Element " + i;
config |= EditorGUI.PropertyGridConfig.NoBackground;
changed |= DrawerAttribute.DrawProperty(gui, elementName, i, ElementType(list), ref element, config);
if (changed)
- SetElement(list, i, element);
+ SetElement(list, i, element!);
if (drawerID == selectedDrawer && i == selectedElement)
@@ -222,14 +224,14 @@ public override bool PropertyLayout(Gui gui, string label, int index, Type prope
[Drawer(typeof(Array))]
public class PropertyDrawerArray : PropertyDrawerEnumerable
{
- protected override Type ElementType(Array value) => value.GetType().GetElementType();
+ protected override Type ElementType(Array value) => value.GetType().GetElementType()!;
protected override int GetCount(Array value) => value.Length;
- protected override object GetElement(Array value, int index) => value.GetValue(index);
+ protected override object GetElement(Array value, int index) => value.GetValue(index)!;
protected override void SetElement(Array value, int index, object element) => value.SetValue(element, index);
protected override void RemoveElement(ref Array value, int index)
{
var elementType = value.GetType().GetElementType();
- var newArray = Array.CreateInstance(elementType, value.Length - 1);
+ var newArray = Array.CreateInstance(elementType!, value.Length - 1);
Array.Copy(value, 0, newArray, 0, index);
Array.Copy(value, index + 1, newArray, index, value.Length - index - 1);
value = newArray;
@@ -237,7 +239,7 @@ protected override void RemoveElement(ref Array value, int index)
protected override void AddElement(ref Array value)
{
var elementType = value.GetType().GetElementType();
- var newArray = Array.CreateInstance(elementType, value.Length + 1);
+ var newArray = Array.CreateInstance(elementType!, value.Length + 1);
Array.Copy(value, newArray, value.Length);
value = newArray;
}
@@ -248,7 +250,7 @@ public class PropertyDrawerList : PropertyDrawerEnumerable value.GetType().GetGenericArguments()[0];
protected override int GetCount(System.Collections.IList value) => value.Count;
- protected override object GetElement(System.Collections.IList value, int index) => value[index];
+ protected override object GetElement(System.Collections.IList value, int index) => value[index] ?? throw new Exception();
protected override void SetElement(System.Collections.IList value, int index, object element) => value[index] = element;
protected override void RemoveElement(ref System.Collections.IList value, int index) => value.RemoveAt(index);
protected override void AddElement(ref System.Collections.IList value)
diff --git a/Prowl.Editor/Editor/PropertyDrawer/Drawers/Vector2_PropertyDrawer.cs b/Prowl.Editor/Editor/PropertyDrawer/Drawers/Vector2_PropertyDrawer.cs
index 5c9fb0f9..ac520f07 100644
--- a/Prowl.Editor/Editor/PropertyDrawer/Drawers/Vector2_PropertyDrawer.cs
+++ b/Prowl.Editor/Editor/PropertyDrawer/Drawers/Vector2_PropertyDrawer.cs
@@ -15,7 +15,7 @@ public override bool OnValueGUI(Gui gui, string ID, Type targetType, ref object?
{
gui.CurrentNode.Layout(LayoutType.Row).ScaleChildren();
- Vector2 val = (Vector2)value;
+ Vector2 val = value is Vector2 v ? v : throw new Exception();
bool changed = EditorGUI.InputDouble(ID + "X", ref val.x, 0, 0, 0, EditorGUI.VectorXStyle);
changed |= EditorGUI.InputDouble(ID + "Y", ref val.y, 0, 0, 0, EditorGUI.VectorYStyle);
value = val;
diff --git a/Prowl.Editor/Editor/PropertyDrawer/Drawers/Vector3_PropertyDrawer.cs b/Prowl.Editor/Editor/PropertyDrawer/Drawers/Vector3_PropertyDrawer.cs
index 678e24b5..81cb7d67 100644
--- a/Prowl.Editor/Editor/PropertyDrawer/Drawers/Vector3_PropertyDrawer.cs
+++ b/Prowl.Editor/Editor/PropertyDrawer/Drawers/Vector3_PropertyDrawer.cs
@@ -15,7 +15,7 @@ public override bool OnValueGUI(Gui gui, string ID, Type targetType, ref object?
{
gui.CurrentNode.Layout(LayoutType.Row).ScaleChildren();
- Vector3 val = (Vector3)value;
+ Vector3 val = value is Vector3 v ? v : throw new Exception();
bool changed = EditorGUI.InputDouble(ID + "X", ref val.x, 0, 0, 0, EditorGUI.VectorXStyle);
changed |= EditorGUI.InputDouble(ID + "Y", ref val.y, 0, 0, 0, EditorGUI.VectorYStyle);
changed |= EditorGUI.InputDouble(ID + "Z", ref val.z, 0, 0, 0, EditorGUI.VectorZStyle);
diff --git a/Prowl.Editor/Editor/PropertyDrawer/Drawers/Vector4_PropertyDrawer.cs b/Prowl.Editor/Editor/PropertyDrawer/Drawers/Vector4_PropertyDrawer.cs
index 72091e90..cf4cf33f 100644
--- a/Prowl.Editor/Editor/PropertyDrawer/Drawers/Vector4_PropertyDrawer.cs
+++ b/Prowl.Editor/Editor/PropertyDrawer/Drawers/Vector4_PropertyDrawer.cs
@@ -14,7 +14,7 @@ public override bool OnValueGUI(Gui gui, string ID, Type targetType, ref object?
{
gui.CurrentNode.Layout(LayoutType.Row).ScaleChildren();
- Vector4 val = (Vector4)value;
+ Vector4 val = value is Vector4 v ? v : throw new Exception();
bool changed = EditorGUI.InputDouble(ID + "X", ref val.x, 0, 0, 0, EditorGUI.VectorXStyle);
changed |= EditorGUI.InputDouble(ID + "Y", ref val.y, 0, 0, 0, EditorGUI.VectorYStyle);
changed |= EditorGUI.InputDouble(ID + "Z", ref val.z, 0, 0, 0, EditorGUI.VectorZStyle);
diff --git a/Prowl.Editor/Editor/SceneViewWindow.cs b/Prowl.Editor/Editor/SceneViewWindow.cs
index 6155ed5c..0b3211ea 100644
--- a/Prowl.Editor/Editor/SceneViewWindow.cs
+++ b/Prowl.Editor/Editor/SceneViewWindow.cs
@@ -17,8 +17,8 @@ public class SceneViewWindow : EditorWindow
private static bool LastFocusedCameraChanged;
readonly Camera Cam;
- Material gridMat;
- Mesh gridMesh;
+ // Material gridMat;
+ // Mesh gridMesh;
RenderTexture RenderTarget;
Vector2 WindowCenter;
Vector2 mouseUV;
@@ -26,7 +26,7 @@ public class SceneViewWindow : EditorWindow
double fpsTimer;
double fps;
double moveSpeed = 1;
- bool hasStarted = false;
+ // bool hasStarted = false;
double camX, camY;
readonly TransformGizmo gizmo;
@@ -123,6 +123,7 @@ protected override void Draw()
Matrix4x4.CreateTranslation(new Vector3(gX, gY, 0)),
GridType.YZ => Matrix4x4.CreateLookToLeftHanded(Vector3.zero, Vector3.up, Vector3.right) *
Matrix4x4.CreateTranslation(new Vector3(0, gY, gZ)),
+ _ => throw new NotImplementedException(),
};
}
diff --git a/Prowl.Editor/Editor/ScriptedEditors/GameObjectEditor.cs b/Prowl.Editor/Editor/ScriptedEditors/GameObjectEditor.cs
index 63284feb..1feb782b 100644
--- a/Prowl.Editor/Editor/ScriptedEditors/GameObjectEditor.cs
+++ b/Prowl.Editor/Editor/ScriptedEditors/GameObjectEditor.cs
@@ -24,7 +24,7 @@ namespace Prowl.Editor.EditorWindows.CustomEditors;
public class GameObjectEditor : ScriptedEditor
{
private string _searchText = string.Empty;
- private static MenuItemInfo rootMenuItem;
+ private static MenuItemInfo? rootMenuItem;
private readonly Dictionary compEditors = new();
[OnAssemblyUnload]
diff --git a/Prowl.Editor/Editor/ScriptedEditors/ScriptableObjectEditor.cs b/Prowl.Editor/Editor/ScriptedEditors/ScriptableObjectEditor.cs
index 8f3da8b7..ea48c407 100644
--- a/Prowl.Editor/Editor/ScriptedEditors/ScriptableObjectEditor.cs
+++ b/Prowl.Editor/Editor/ScriptedEditors/ScriptableObjectEditor.cs
@@ -12,19 +12,20 @@ namespace Prowl.Editor.ScriptedEditors;
[CustomEditor(typeof(ScriptableObjectImporter))]
public class ScriptableObjectEditor : ScriptedEditor
{
- ScriptableObject? scriptObject;
+ ScriptableObject? _scriptObject;
public override void OnInspectorGUI()
{
- var importer = (ScriptableObjectImporter)(target as MetaFile).importer;
+ var metaFile = target as MetaFile ?? throw new Exception();
+ // var importer = (ScriptableObjectImporter)metaFile.importer;
try
{
bool changed = false;
- scriptObject ??= Serializer.Deserialize(StringTagConverter.ReadFromFile((target as MetaFile).AssetPath));
+ _scriptObject ??= Serializer.Deserialize(StringTagConverter.ReadFromFile(metaFile.AssetPath));
- object t = scriptObject;
+ object t = _scriptObject ?? throw new Exception();
changed |= PropertyGrid("CompPropertyGrid", ref t, TargetFields.Serializable | TargetFields.Properties, PropertyGridConfig.NoHeader | PropertyGridConfig.NoBorder | PropertyGridConfig.NoBackground);
// Draw any Buttons
@@ -32,15 +33,15 @@ public override void OnInspectorGUI()
if (changed)
{
- scriptObject.OnValidate();
- StringTagConverter.WriteToFile(Serializer.Serialize(scriptObject), (target as MetaFile).AssetPath);
- AssetDatabase.Reimport((target as MetaFile).AssetPath);
+ _scriptObject.OnValidate();
+ StringTagConverter.WriteToFile(Serializer.Serialize(_scriptObject), metaFile.AssetPath);
+ AssetDatabase.Reimport(metaFile.AssetPath);
}
}
catch (Exception e)
{
- double ItemSize = EditorStylePrefs.Instance.ItemSize;
- gui.Node("DummyForText").ExpandWidth().Height(ItemSize * 10);
+ double itemSize = EditorStylePrefs.Instance.ItemSize;
+ gui.Node("DummyForText").ExpandWidth().Height(itemSize * 10);
gui.Draw2D.DrawText("Failed to Deserialize ScriptableObject, The ScriptableObject file is invalid. Error: " + e.ToString(), gui.CurrentNode.LayoutData.Rect);
}
}
diff --git a/Prowl.Editor/EditorGuiManager.cs b/Prowl.Editor/EditorGuiManager.cs
index 846df24a..e86048c0 100644
--- a/Prowl.Editor/EditorGuiManager.cs
+++ b/Prowl.Editor/EditorGuiManager.cs
@@ -19,9 +19,9 @@ public static class EditorGuiManager
public static System.Numerics.Vector4 SelectedColor => new System.Numerics.Vector4(0.06f, 0.53f, 0.98f, 1.00f);
public static Gui Gui;
- public static DockContainer? Container;
- public static EditorWindow DraggingWindow;
- public static DockNode DragSplitter;
+ public static DockContainer Container;
+ public static EditorWindow? DraggingWindow;
+ public static DockNode? DragSplitter;
private static Vector2 m_DragPos;
private static double m_StartSplitPos;
@@ -49,7 +49,7 @@ public static void FocusWindow(EditorWindow editorWindow)
Windows.Add(editorWindow);
FocusedWindow = new WeakReference(editorWindow);
- if (editorWindow.IsDocked)
+ if (editorWindow.IsDocked && editorWindow.Leaf is not null)
editorWindow.Leaf.WindowNum = editorWindow.Leaf.LeafWindows.IndexOf(editorWindow);
}
@@ -69,8 +69,8 @@ internal static void Remove(EditorWindow editorWindow)
public static void Update()
{
- if (FocusedWindow != null && FocusedWindow.Target != null)
- FocusWindow(FocusedWindow.Target as EditorWindow); // Ensure focused window is always on top (But below floating windows if docked)
+ if (FocusedWindow != null && FocusedWindow.Target != null && FocusedWindow.Target is EditorWindow editorWindow)
+ FocusWindow(editorWindow); // Ensure focused window is always on top (But below floating windows if docked)
// Sort by docking as well, Docked windows are guranteed to come first
Windows.Sort((a, b) => b.IsDocked.CompareTo(a.IsDocked));
@@ -84,7 +84,6 @@ public static void Update()
Veldrid.CommandList commandList = Graphics.GetCommandList();
commandList.Name = "GUI Command Buffer";
-
commandList.SetFramebuffer(Graphics.ScreenTarget);
commandList.ClearColorTarget(0, Veldrid.RgbaFloat.Black);
commandList.ClearDepthStencil(1.0f, 0);
@@ -208,7 +207,7 @@ private static void DrawContent(Gui g)
{
if (!Gui.IsBlockedByInteractable(cursorPos))
{
- DockNode node = Container.Root.TraceSeparator(cursorPos.x, cursorPos.y);
+ DockNode? node = Container.Root.TraceSeparator(cursorPos.x, cursorPos.y);
if (node != null)
{
node.GetSplitterBounds(out var bmins, out var bmaxs, 4);
@@ -273,7 +272,7 @@ private static void DrawContent(Gui g)
for (int i = 0; i < windowList.Count; i++)
{
EditorWindow window = windowList[i];
- if (!window.IsDocked || window.Leaf.LeafWindows[window.Leaf.WindowNum] == window)
+ if (!window.IsDocked || window.Leaf?.LeafWindows[window.Leaf.WindowNum] == window)
{
g.SetZIndex(i * 100);
g.PushID((ulong)window._id);
@@ -308,7 +307,7 @@ public static void SaveScene()
return;
}
- if (AssetDatabase.TryGetFile(scene.AssetID, out var file))
+ if (AssetDatabase.TryGetFile(scene.AssetID, out var file) && file is not null)
{
AssetDatabase.Delete(file);
@@ -464,7 +463,7 @@ public static void CreateScript()
FileInfo file = new FileInfo(Path.Combine(Directory.FullName, $"New Script.cs"));
AssetDatabase.GenerateUniqueAssetPath(ref file);
- using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"Prowl.Editor.EmbeddedResources.NewScript.txt");
+ using Stream? stream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"Prowl.Editor.EmbeddedResources.NewScript.txt") ?? throw new Exception();
using StreamReader reader = new StreamReader(stream);
string script = reader.ReadToEnd();
script = script.Replace("%SCRIPTNAME%", EditorUtils.FilterAlpha(Path.GetFileNameWithoutExtension(file.Name)));
diff --git a/Prowl.Editor/SelectHandler.cs b/Prowl.Editor/SelectHandler.cs
index 1cbcb763..b45158d4 100644
--- a/Prowl.Editor/SelectHandler.cs
+++ b/Prowl.Editor/SelectHandler.cs
@@ -23,7 +23,7 @@ public class SelectHandler where T : class
{
bool selectedThisFrame;
readonly List selected = new();
- SortedList previousFrameSelectables;
+ SortedList previousFrameSelectables = [];
SortedList selectables = new();
int lastSelectedIndex = -1;
@@ -35,12 +35,12 @@ public class SelectHandler where T : class
public event Action? OnDeselectObject;
private readonly Func CheckIsDestroyed;
- private readonly Func Equals;
+ private readonly Func EqualsFunc;
public SelectHandler(Func checkIsDestroyed, Func equals)
{
CheckIsDestroyed = checkIsDestroyed;
- Equals = equals;
+ EqualsFunc = equals;
}
public void StartFrame()
@@ -61,7 +61,7 @@ public void StartFrame()
if (lastSelectedIndex == -1 && selected.Count > 0)
{
- SetSelectedIndex((T)selected[0]);
+ SetSelectedIndex(Selected[0]);
}
}
@@ -94,7 +94,7 @@ public bool IsSelected(T obj)
{
for (int i = 0; i < selected.Count; i++)
{
- if (Equals.Invoke(selected[i], obj))
+ if (EqualsFunc.Invoke(selected[i], obj))
return true;
}
return false;
@@ -105,7 +105,7 @@ public void Foreach(Action value)
var copy = new List(selected);
copy.ForEach((weak) =>
{
- value?.Invoke((T)weak);
+ value.Invoke((T)weak);
});
}
@@ -155,7 +155,7 @@ public void Select(T obj, bool additively = false)
{
for (int i = 0; i < selected.Count; i++)
{
- if (Equals.Invoke(selected[i], obj))
+ if (EqualsFunc.Invoke(selected[i], obj))
{
selected.RemoveAt(i);
break;
@@ -178,11 +178,10 @@ public void Select(T obj, bool additively = false)
private void SetSelectedIndex(T entity)
{
- if (previousFrameSelectables == null) return;
// if sorted has this value using reference equals, set lastSelectedIndex to the index of it
for (int i = 0; i < previousFrameSelectables.Count; i++)
{
- if (Equals.Invoke(previousFrameSelectables.Values[i], entity))
+ if (EqualsFunc.Invoke(previousFrameSelectables.Values[i], entity))
{
lastSelectedIndex = previousFrameSelectables.Keys[i];
break;
diff --git a/Prowl.Editor/Utilities/CreateAssetMenu.cs b/Prowl.Editor/Utilities/CreateAssetMenu.cs
index 16d13f0e..04c40ab6 100644
--- a/Prowl.Editor/Utilities/CreateAssetMenu.cs
+++ b/Prowl.Editor/Utilities/CreateAssetMenu.cs
@@ -20,19 +20,21 @@ public static void FindAllMenus()
List<(string, Type)> values = new();
foreach (var assembly in assemblies)
{
- Type[] types = null;
try
{
- types = assembly.GetTypes();
+ Type[] types = assembly.GetTypes();
foreach (var type in types)
- if (type != null && type.IsAssignableTo(typeof(ScriptableObject)))
+ if (type.IsAssignableTo(typeof(ScriptableObject)))
{
var attribute = type.GetCustomAttribute();
if (attribute != null)
values.Add(("Assets/" + attribute.Name, type));
}
}
- catch { }
+ catch
+ {
+ // ignored
+ }
}
foreach (var value in values)
diff --git a/Prowl.Editor/Utilities/EditorUtils.cs b/Prowl.Editor/Utilities/EditorUtils.cs
index 482ca994..77653af0 100644
--- a/Prowl.Editor/Utilities/EditorUtils.cs
+++ b/Prowl.Editor/Utilities/EditorUtils.cs
@@ -29,7 +29,7 @@ public static List GetDerivedTypes(Type baseType, Assembly assembly)
return derivedTypes;
}
- public static bool IsSubclassOf(Type type, Type baseType)
+ public static bool IsSubclassOf(Type? type, Type? baseType)
{
if (type == null || baseType == null || type == baseType)
return false;
diff --git a/Prowl.Editor/Utilities/MenuItem.cs b/Prowl.Editor/Utilities/MenuItem.cs
index 174d3b53..71279452 100644
--- a/Prowl.Editor/Utilities/MenuItem.cs
+++ b/Prowl.Editor/Utilities/MenuItem.cs
@@ -57,20 +57,21 @@ public static void FindAllMenus()
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (var assembly in assemblies)
{
- Type[] types = null;
try
{
- types = assembly.GetTypes();
+ Type[] types = assembly.GetTypes();
foreach (var type in types)
- if (type != null)
- foreach (MethodInfo method in type.GetMethods())
- {
- var attribute = method.GetCustomAttribute