Skip to content

Commit

Permalink
Update to latest modkit
Browse files Browse the repository at this point in the history
  • Loading branch information
CaitSith2 committed Mar 28, 2018
1 parent 21906c5 commit d8e38e9
Show file tree
Hide file tree
Showing 18 changed files with 890 additions and 366 deletions.
47 changes: 39 additions & 8 deletions Assets/Editor/Scripts/AssetBundler.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using UnityEngine;
using System;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using System.Linq;
using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;

/// <summary>
///
Expand Down Expand Up @@ -64,7 +64,7 @@ public class AssetBundler
private List<string> scriptPathsToRestore = new List<string>();
#endregion

[MenuItem("Keep Talking ModKit/Build AssetBundle", priority = 10)]
[MenuItem("Keep Talking ModKit/Build AssetBundle _F6", priority = 10)]
public static void BuildAllAssetBundles_WithEditorUtility()
{
BuildModBundle(false);
Expand Down Expand Up @@ -123,7 +123,7 @@ protected static void BuildModBundle(bool useMSBuild)
//Copy any other non-Editor managed assemblies to the output folder
bundler.CopyManagedAssemblies();

//Create the modInfo.json file
//Create the modInfo.json file and copy the preview image if available
bundler.CreateModInfo();

//Copy the modSettings.json file from Assets into the build
Expand Down Expand Up @@ -243,7 +243,7 @@ void CompileAssemblyWithEditor()
{
case PlatformID.MacOSX:
case PlatformID.Unix:
unityAssembliesLocation = EditorApplication.applicationPath.Replace("Unity.app", "Unity.app/Contents/Frameworks/Managed/");
unityAssembliesLocation = EditorApplication.applicationPath.Replace("Unity.app", "Unity.app/Contents/Managed/");
break;
case PlatformID.Win32NT:
default:
Expand All @@ -262,10 +262,10 @@ void CompileAssemblyWithEditor()
string[] defineArray = allDefines.Split(';');

//MonoIsland to compile
string classlib_profile = "2.0";
int apiCompatibilityLevel = 1; //NET_2_0 compatibility level is enum value 1
Assembly assembly = Assembly.GetAssembly(typeof(MonoScript));
var monoIslandType = assembly.GetType("UnityEditor.Scripting.MonoIsland");
object monoIsland = Activator.CreateInstance(monoIslandType, BuildTarget.StandaloneWindows, classlib_profile, scriptArray, referenceArray, defineArray, outputFilename);
object monoIsland = Activator.CreateInstance(monoIslandType, BuildTarget.StandaloneWindows, apiCompatibilityLevel, scriptArray, referenceArray, defineArray, outputFilename);

//MonoCompiler itself
var monoCompilerType = assembly.GetType("UnityEditor.Scripting.Compilers.MonoCSharpCompiler");
Expand Down Expand Up @@ -439,6 +439,26 @@ protected void CreateAssetBundle()
protected void CreateModInfo()
{
File.WriteAllText(outputFolder + "/modInfo.json", ModConfig.Instance.ToJson());

if(ModConfig.PreviewImage != null)
{
string previewImageAssetPath = AssetDatabase.GetAssetPath(ModConfig.PreviewImage);

if (!string.IsNullOrEmpty(previewImageAssetPath))
{
TextureImporter importer = AssetImporter.GetAtPath(previewImageAssetPath) as TextureImporter;

if (!importer.isReadable || importer.textureCompression != TextureImporterCompression.Uncompressed)
{
importer.isReadable = true;
importer.textureCompression = TextureImporterCompression.Uncompressed;
importer.SaveAndReimport();
}

byte[] bytes = ModConfig.PreviewImage.EncodeToPNG();
File.WriteAllBytes(outputFolder + "/previewImage.png", bytes);
}
}
}

/// <summary>
Expand Down Expand Up @@ -613,6 +633,17 @@ protected void UpdateMaterialInfo()
materialInfo.ShaderNames = new List<string>();
foreach(Material material in renderer.sharedMaterials)
{
if (material == null)
{
var obj = renderer.transform;
var str = new List<string>();
while (obj != null)
{
str.Add(obj.gameObject.name);
obj = obj.parent;
}
Debug.LogErrorFormat("There is an unassigned material on the following object: {0}", string.Join(" > ", str.ToArray()));
}
materialInfo.ShaderNames.Add(material.shader.name);

if(material.shader.name == "Standard")
Expand Down
7 changes: 3 additions & 4 deletions Assets/Editor/Scripts/Missions/KMMissionEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(serializedObject.FindProperty("GeneratorSetting.NumStrikes"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("GeneratorSetting.TimeBeforeNeedyActivation"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("GeneratorSetting.FrontFaceOnly"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("GeneratorSetting.OptionalWidgetCount"));

//Component Pools
EditorGUILayout.Separator();
Expand Down Expand Up @@ -141,10 +142,8 @@ private void DrawComponentPoolEntry(int poolIndex, SerializedProperty componentP
EditorGUILayout.BeginHorizontal();

//Count
componentPoolProperty.FindPropertyRelative("Count").intValue = EditorGUILayout.IntPopup(
componentPoolProperty.FindPropertyRelative("Count").intValue,
new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11" },
new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }, GUILayout.Width(60));
componentPoolProperty.FindPropertyRelative("Count").intValue = Math.Min(EditorGUILayout.IntField(
componentPoolProperty.FindPropertyRelative("Count").intValue, GUILayout.Width(60)), 1);


//Summary of types in this pool
Expand Down
18 changes: 18 additions & 0 deletions Assets/Editor/Scripts/ModConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public static string Title
set { Instance.title = value; }
}

public static string Description
{
get { return Instance.description; }
set { Instance.description = value; }
}

public static string Version
{
get { return Instance.version; }
Expand All @@ -32,14 +38,25 @@ public static string OutputFolder
set { Instance.outputFolder = value; }
}

public static Texture2D PreviewImage
{
get { return Instance.previewImage; }
set { Instance.previewImage = value; }
}

[SerializeField]
private string id = "";
[SerializeField]
private string title = "";
[SerializeField]
[TextArea(5, 10)]
private string description = "";
[SerializeField]
private string version = "";
[SerializeField]
private string outputFolder = "build";
[SerializeField]
private Texture2D previewImage = null;


private static ModConfig instance;
Expand All @@ -65,6 +82,7 @@ public string ToJson()
Dictionary<string, object> dict = new Dictionary<string, object>();
dict.Add("id", id);
dict.Add("title", title);
dict.Add("description", description);
dict.Add("version", version);
dict.Add("unityVersion", Application.unityVersion);

Expand Down
69 changes: 29 additions & 40 deletions Assets/Editor/Scripts/ModKitSettingsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,49 +34,38 @@ public static void ConfigureMod()

public override void OnInspectorGUI()
{
EditorGUILayout.Separator();
EditorGUILayout.BeginHorizontal();

GUIContent idLabel = new GUIContent("Mod ID", "Identifier for the mod. Affects assembly name and output name.");
GUI.changed = false;
ModConfig.ID = EditorGUILayout.TextField(idLabel, ModConfig.ID);
SetDirtyOnGUIChange();
EditorGUILayout.EndHorizontal();

EditorGUILayout.Separator();
EditorGUILayout.BeginHorizontal();
GUIContent titleLabel = new GUIContent("Mod Title", "Name of the mod as it appears in game.");
GUI.changed = false;
ModConfig.Title = EditorGUILayout.TextField(titleLabel, ModConfig.Title);
SetDirtyOnGUIChange();
EditorGUILayout.EndHorizontal();
//Basic Info
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
EditorGUILayout.PropertyField(serializedObject.FindProperty("id"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("title"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("description"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("version"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("outputFolder"));
EditorGUILayout.EndVertical();

EditorGUILayout.Separator();
EditorGUILayout.BeginHorizontal();
GUIContent versionLabel = new GUIContent("Mod Version", "Current version of the mod.");
GUI.changed = false;
ModConfig.Version = EditorGUILayout.TextField(versionLabel, ModConfig.Version);
SetDirtyOnGUIChange();
EditorGUILayout.EndHorizontal();

EditorGUILayout.Separator();
EditorGUILayout.BeginHorizontal();
GUIContent outputFolderLabel = new GUIContent("Mod Output Folder", "Folder relative to the project where the built mod bundle will be placed.");
GUI.changed = false;
ModConfig.OutputFolder = EditorGUILayout.TextField(outputFolderLabel, ModConfig.OutputFolder);
SetDirtyOnGUIChange();
EditorGUILayout.EndHorizontal();
EditorGUILayout.HelpBox("This folder will be cleaned with each build.", MessageType.Warning);
//Preview Image
EditorGUILayout.BeginHorizontal(EditorStyles.helpBox);
using (new EditorGUILayout.VerticalScope())
{
EditorGUILayout.LabelField("Preview Image:");
EditorGUILayout.PropertyField(serializedObject.FindProperty("previewImage"), new GUIContent());

GUI.enabled = true;
}
if (ModConfig.PreviewImage != null)
{
FileInfo f = new FileInfo(AssetDatabase.GetAssetPath(ModConfig.PreviewImage));
if (f.Exists)
{
EditorGUILayout.LabelField(string.Format("File Size: {0}", WorkshopEditorWindow.FormatFileSize(f.Length)));

private void SetDirtyOnGUIChange()
{
if (GUI.changed)
{
EditorUtility.SetDirty(ModConfig.Instance);
GUI.changed = false;
if (f.Length > 1024 * 1024)
{
EditorGUILayout.HelpBox("Max allowed size is 1MB", MessageType.Error);
}
}
}
}
GUILayout.Label(ModConfig.PreviewImage, GUILayout.MaxWidth(128), GUILayout.MaxHeight(128));
EditorGUILayout.EndHorizontal();
serializedObject.ApplyModifiedProperties();
}
}
12 changes: 8 additions & 4 deletions Assets/Editor/Scripts/Workshop/WorkshopEditorWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

public class WorkshopEditorWindow : EditorWindow
{
private Vector2 scrollPosition;

protected static readonly AppId_t KTANE_APP_ID = new AppId_t(341800);
protected static readonly AppId_t EDITOR_APP_ID = new AppId_t(341800); //For now, the same AppID

Expand All @@ -32,7 +34,7 @@ private static void SteamAPIDebugTextHook(int nSeverity, System.Text.StringBuild
Debug.LogWarning(pchDebugText);
}

[MenuItem("Keep Talking ModKit/Steam Workshop Tool", priority = 20)]
[MenuItem("Keep Talking ModKit/Steam Workshop Tool _#F6", priority = 20)]
protected static void ShowWindow()
{
WorkshopEditorWindow window = EditorWindow.GetWindow<WorkshopEditorWindow>("Workshop");
Expand Down Expand Up @@ -85,6 +87,7 @@ protected void OnGUI()
}
}

scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
workshopItemEditor.OnInspectorGUI();

//Publishing Tools
Expand Down Expand Up @@ -168,6 +171,7 @@ protected void OnGUI()
GUI.enabled = true;
}
EditorGUILayout.EndVertical();
EditorGUILayout.EndScrollView();
}
}

Expand Down Expand Up @@ -196,17 +200,17 @@ protected void PublishWorkshopChanges()
ugcUpdateHandle = SteamUGC.StartItemUpdate(KTANE_APP_ID, new PublishedFileId_t(currentWorkshopItem.WorkshopPublishedFileID));

SteamUGC.SetItemTitle(ugcUpdateHandle, currentWorkshopItem.Title);
SteamUGC.SetItemDescription(ugcUpdateHandle, currentWorkshopItem.Description);
SteamUGC.SetItemDescription(ugcUpdateHandle, ModConfig.Description);

string[] tags = GetTags();
if (tags != null && tags.Length > 0)
{
SteamUGC.SetItemTags(ugcUpdateHandle, GetTags());
}

if (currentWorkshopItem.PreviewImage != null)
if (ModConfig.PreviewImage != null)
{
string previewImagePath = AssetDatabase.GetAssetPath(currentWorkshopItem.PreviewImage);
string previewImagePath = AssetDatabase.GetAssetPath(ModConfig.PreviewImage);
previewImagePath = Path.GetFullPath(previewImagePath);
Debug.LogFormat("Setting preview image path to: {0}", previewImagePath);
SteamUGC.SetItemPreview(ugcUpdateHandle, previewImagePath);
Expand Down
6 changes: 1 addition & 5 deletions Assets/Editor/Scripts/Workshop/WorkshopItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ public class WorkshopItem : ScriptableObject
{
public ulong WorkshopPublishedFileID;
public string Title;

[TextArea(5, 10)]
public string Description;

public Texture2D PreviewImage;

public List<string> Tags;
}
13 changes: 8 additions & 5 deletions Assets/Editor/Scripts/Workshop/WorkshopItemEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class WorkshopItemEditor : Editor

public override void OnInspectorGUI()
{
var modConfigSO = new UnityEditor.SerializedObject(ModConfig.Instance);
modConfigSO.Update();
serializedObject.Update();

WorkshopItem item = (WorkshopItem)target;
Expand All @@ -18,19 +20,19 @@ public override void OnInspectorGUI()
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
EditorGUILayout.PropertyField(serializedObject.FindProperty("WorkshopPublishedFileID"), new GUIContent("Workshop File ID"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("Title"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("Description"));
EditorGUILayout.PropertyField(modConfigSO.FindProperty("description"));
EditorGUILayout.EndVertical();

//Preview Image
EditorGUILayout.BeginHorizontal(EditorStyles.helpBox);
using (new EditorGUILayout.VerticalScope())
{
EditorGUILayout.LabelField("Preview Image:");
EditorGUILayout.PropertyField(serializedObject.FindProperty("PreviewImage"), new GUIContent());
EditorGUILayout.PropertyField(modConfigSO.FindProperty("previewImage"), new GUIContent());

if (item.PreviewImage != null)
if (ModConfig.PreviewImage != null)
{
FileInfo f = new FileInfo(AssetDatabase.GetAssetPath(item.PreviewImage));
FileInfo f = new FileInfo(AssetDatabase.GetAssetPath(ModConfig.PreviewImage));
if (f.Exists)
{
EditorGUILayout.LabelField(string.Format("File Size: {0}", WorkshopEditorWindow.FormatFileSize(f.Length)));
Expand All @@ -42,7 +44,7 @@ public override void OnInspectorGUI()
}
}
}
GUILayout.Label(item.PreviewImage, GUILayout.MaxWidth(128), GUILayout.MaxHeight(128));
GUILayout.Label(ModConfig.PreviewImage, GUILayout.MaxWidth(128), GUILayout.MaxHeight(128));
EditorGUILayout.EndHorizontal();

//Tags
Expand Down Expand Up @@ -71,5 +73,6 @@ public override void OnInspectorGUI()
EditorGUILayout.EndVertical();

serializedObject.ApplyModifiedProperties();
modConfigSO.ApplyModifiedProperties();
}
}
2 changes: 1 addition & 1 deletion Assets/Editor/Steamworks.NET/CallbackDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#if UNITY_3_5 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5
#error Unsupported Unity platform. Steamworks.NET requires Unity 4.6 or higher.
#elif UNITY_4_6 || UNITY_5
#elif UNITY_4_6 || UNITY_5 || UNITY_2017
#if UNITY_EDITOR_WIN || (UNITY_STANDALONE_WIN && !UNITY_EDITOR)
#define WINDOWS_BUILD
#endif
Expand Down
Loading

0 comments on commit d8e38e9

Please sign in to comment.