Browse Source

Bugfix: Make sure managed code compiler checks if the built assemblies are missing, and starts the recompilation process

BearishSun 6 years ago
parent
commit
db62ad3258

+ 2 - 1
Source/EditorManaged/General/EditorApplication.cs

@@ -305,7 +305,6 @@ namespace bs.Editor
         internal EditorApplication()
         {
             instance = this;
-            codeManager = new ScriptCodeManager();
 
             const string soName = "EditorPersistentData";
             SceneObject so = Scene.Root.FindChild(soName);
@@ -316,6 +315,8 @@ namespace bs.Editor
             if (persistentData == null)
                 persistentData = so.AddComponent<EditorPersistentData>();
 
+            codeManager = new ScriptCodeManager();
+
             // Register controls
             InputConfiguration inputConfig = VirtualInput.KeyConfig;
 

+ 3 - 0
Source/EditorManaged/General/EditorPersistentData.cs

@@ -19,6 +19,9 @@ namespace bs.Editor
 
         [SerializeField]
         internal Dictionary<UUID, EditorAnimClipInfo> dirtyAnimClips = new Dictionary<UUID, EditorAnimClipInfo>();
+
+        [SerializeField]
+        internal long lastCompileTime;
     }
 
     /** @} */

+ 1 - 4
Source/EditorManaged/Inspectors/MeshInspector.cs

@@ -41,10 +41,7 @@ namespace bs.Editor
         /// <inheritdoc/>
         protected internal override InspectableState Refresh()
         {
-            MeshImportOptions newImportOptions = GetImportOptions();
-
-
-            importOptions = newImportOptions;
+            importOptions = GetImportOptions();
 
             return InspectableState.NotModified;
         }

+ 46 - 0
Source/EditorManaged/Script/ScriptCodeManager.cs

@@ -1,5 +1,8 @@
 //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
 //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+
+using System;
+using System.IO;
 using System.Text;
 using System.Text.RegularExpressions;
 using bs;
@@ -27,6 +30,47 @@ namespace bs.Editor
             ProjectLibrary.OnEntryAdded += OnEntryAdded;
             ProjectLibrary.OnEntryRemoved += OnEntryRemoved;
             ProjectLibrary.OnEntryImported += OnEntryImported;
+
+            // Check for missing or out of date assemblies
+            DateTime lastModifiedGameScript = DateTime.MinValue;
+            DateTime lastModifiedEditorScript = DateTime.MinValue;
+
+            LibraryEntry[] scriptEntries = ProjectLibrary.Search("*.cs", new ResourceType[] { ResourceType.ScriptCode });
+            for (int i = 0; i < scriptEntries.Length; i++)
+            {
+                if(scriptEntries[i].Type != LibraryEntryType.File)
+                    continue;
+
+                FileEntry fileEntry = (FileEntry)scriptEntries[i];
+
+                string absPath = Path.Combine(ProjectLibrary.ResourceFolder, fileEntry.Path);
+                ScriptCodeImportOptions io = (ScriptCodeImportOptions) fileEntry.Options;
+                if (io.EditorScript)
+                    lastModifiedEditorScript = File.GetLastWriteTime(absPath);
+                else
+                    lastModifiedGameScript = File.GetLastWriteTime(absPath);
+            }
+
+            DateTime lastCompileTime = new DateTime(EditorApplication.PersistentData.lastCompileTime);
+            if (lastModifiedGameScript != DateTime.MinValue)
+            {
+                string gameAssemblyPath = Path.Combine(EditorApplication.ScriptAssemblyPath,
+                    EditorApplication.ScriptGameAssemblyName);
+
+                isGameAssemblyDirty = (!File.Exists(gameAssemblyPath) || 
+                                      File.GetLastWriteTime(gameAssemblyPath) < lastModifiedGameScript) && 
+                                      (lastModifiedGameScript > lastCompileTime);
+            }
+
+            if (lastModifiedEditorScript != DateTime.MinValue)
+            {
+                string editorAssemblyPath = Path.Combine(EditorApplication.ScriptAssemblyPath,
+                    EditorApplication.ScriptEditorAssemblyName);
+
+                isEditorAssemblyDirty = (!File.Exists(editorAssemblyPath) || 
+                                         File.GetLastWriteTime(editorAssemblyPath) < lastModifiedEditorScript) && 
+                                        (lastModifiedEditorScript > lastCompileTime);
+            }
         }
 
         /// <summary>
@@ -51,6 +95,7 @@ namespace bs.Editor
                                 ScriptAssemblyType.Game, BuildManager.ActivePlatform, true, outputDir);
 
                             EditorApplication.SetStatusCompiling(true);
+                            EditorApplication.PersistentData.lastCompileTime = DateTime.Now.Ticks;
                             isGameAssemblyDirty = false;
                         }
                         else if (isEditorAssemblyDirty)
@@ -59,6 +104,7 @@ namespace bs.Editor
                                 ScriptAssemblyType.Editor, BuildManager.ActivePlatform, true, outputDir);
 
                             EditorApplication.SetStatusCompiling(true);
+                            EditorApplication.PersistentData.lastCompileTime = DateTime.Now.Ticks;
                             isEditorAssemblyDirty = false;
                         }
                     }