diff --git a/Assets/Fungus/EditorResources/FungusEditorResources.asset b/Assets/Fungus/EditorResources/FungusEditorResources.asset index 05ea3abc..0e6ef67d 100644 --- a/Assets/Fungus/EditorResources/FungusEditorResources.asset +++ b/Assets/Fungus/EditorResources/FungusEditorResources.asset @@ -27,6 +27,9 @@ MonoBehaviour: duplicate: free: {fileID: 2800000, guid: c97f334c466215a4f93eff31de3c1591, type: 3} pro: {fileID: 2800000, guid: 2f17490d993c84bd7872ef6588ffba47, type: 3} + fungus_mushroom: + free: {fileID: 2800000, guid: 1c99c9bf7557e23469ed5dfce00504c0, type: 3} + pro: {fileID: 2800000, guid: 6368c1c16ebb1694091262337e4f8c44, type: 3} up: free: {fileID: 2800000, guid: 8f1242ad894201f43b2b6d52fd990f77, type: 3} pro: {fileID: 2800000, guid: 2a76a781db2994b33b83cd84b8835da7, type: 3} diff --git a/Assets/Fungus/EditorResources/Icons/Pro/fungus_mushroom.png b/Assets/Fungus/EditorResources/Icons/Pro/fungus_mushroom.png new file mode 100644 index 00000000..ab22ce9c Binary files /dev/null and b/Assets/Fungus/EditorResources/Icons/Pro/fungus_mushroom.png differ diff --git a/Assets/Fungus/EditorResources/Icons/Pro/fungus_mushroom.png.meta b/Assets/Fungus/EditorResources/Icons/Pro/fungus_mushroom.png.meta new file mode 100644 index 00000000..360d5b0d --- /dev/null +++ b/Assets/Fungus/EditorResources/Icons/Pro/fungus_mushroom.png.meta @@ -0,0 +1,92 @@ +fileFormatVersion: 2 +guid: 6368c1c16ebb1694091262337e4f8c44 +timeCreated: 1500456217 +licenseType: Free +TextureImporter: + fileIDToRecycleName: {} + serializedVersion: 4 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 0 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + filterMode: 1 + aniso: -1 + mipBias: -1 + wrapMode: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spritePixelsToUnits: 100 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 2 + textureShape: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - buildTarget: DefaultTexturePlatform + maxTextureSize: 1024 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + - buildTarget: Standalone + maxTextureSize: 1024 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + - buildTarget: Android + maxTextureSize: 1024 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + - buildTarget: WebGL + maxTextureSize: 1024 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + spritePackingTag: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/EditorResources/Icons/fungus_mushroom.png b/Assets/Fungus/EditorResources/Icons/fungus_mushroom.png new file mode 100644 index 00000000..ab22ce9c Binary files /dev/null and b/Assets/Fungus/EditorResources/Icons/fungus_mushroom.png differ diff --git a/Assets/Fungus/EditorResources/Icons/fungus_mushroom.png.meta b/Assets/Fungus/EditorResources/Icons/fungus_mushroom.png.meta new file mode 100644 index 00000000..6433d929 --- /dev/null +++ b/Assets/Fungus/EditorResources/Icons/fungus_mushroom.png.meta @@ -0,0 +1,92 @@ +fileFormatVersion: 2 +guid: 1c99c9bf7557e23469ed5dfce00504c0 +timeCreated: 1500455974 +licenseType: Free +TextureImporter: + fileIDToRecycleName: {} + serializedVersion: 4 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 0 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + filterMode: 1 + aniso: -1 + mipBias: -1 + wrapMode: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spritePixelsToUnits: 100 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 2 + textureShape: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - buildTarget: DefaultTexturePlatform + maxTextureSize: 1024 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + - buildTarget: Standalone + maxTextureSize: 1024 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + - buildTarget: Android + maxTextureSize: 1024 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + - buildTarget: WebGL + maxTextureSize: 1024 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + spritePackingTag: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Editor/FungusEditorPreferences.cs b/Assets/Fungus/Scripts/Editor/FungusEditorPreferences.cs new file mode 100644 index 00000000..50a0a881 --- /dev/null +++ b/Assets/Fungus/Scripts/Editor/FungusEditorPreferences.cs @@ -0,0 +1,43 @@ +using UnityEngine; +using UnityEditor; + +namespace Fungus +{ + namespace EditorUtils + { + /// + /// Shows Fungus section in the Edit->Preferences in unity allows you to configure Fungus behaviour + /// + /// ref https://docs.unity3d.com/ScriptReference/PreferenceItem.html + /// + public class FungusEditorPreferences + { + // Have we loaded the prefs yet + private static bool prefsLoaded = false; + + public static bool hideMushroomInHierarchy = false; + + // Add preferences section named "My Preferences" to the Preferences Window + [PreferenceItem("Fungus")] + + public static void PreferencesGUI() + { + // Load the preferences + if (!prefsLoaded) + { + hideMushroomInHierarchy = EditorPrefs.GetBool("hideMushroomInHierarchy", false); + prefsLoaded = true; + } + + // Preferences GUI + hideMushroomInHierarchy = EditorGUILayout.Toggle("Hide Mushroom Flowchart Icon", hideMushroomInHierarchy); + + // Save the preferences + if (GUI.changed) + { + EditorPrefs.SetBool("hideMushroomInHierarchy", hideMushroomInHierarchy); + } + } + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Editor/FungusEditorPreferences.cs.meta b/Assets/Fungus/Scripts/Editor/FungusEditorPreferences.cs.meta new file mode 100644 index 00000000..8d0eedb8 --- /dev/null +++ b/Assets/Fungus/Scripts/Editor/FungusEditorPreferences.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: cde6865c94505574e8ccf958a03f8463 +timeCreated: 1500456646 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Editor/FungusEditorResourcesGenerated.cs b/Assets/Fungus/Scripts/Editor/FungusEditorResourcesGenerated.cs index f7a0641b..1bfd555a 100644 --- a/Assets/Fungus/Scripts/Editor/FungusEditorResourcesGenerated.cs +++ b/Assets/Fungus/Scripts/Editor/FungusEditorResourcesGenerated.cs @@ -12,6 +12,7 @@ namespace Fungus.EditorUtils [SerializeField] private EditorTexture delete; [SerializeField] private EditorTexture down; [SerializeField] private EditorTexture duplicate; + [SerializeField] private EditorTexture fungus_mushroom; [SerializeField] private EditorTexture up; [SerializeField] private EditorTexture bullet_point; [SerializeField] private EditorTexture choice_node_off; @@ -30,6 +31,7 @@ namespace Fungus.EditorUtils public static Texture2D Delete { get { return Instance.delete.Texture2D; } } public static Texture2D Down { get { return Instance.down.Texture2D; } } public static Texture2D Duplicate { get { return Instance.duplicate.Texture2D; } } + public static Texture2D FungusMushroom { get { return Instance.fungus_mushroom.Texture2D; } } public static Texture2D Up { get { return Instance.up.Texture2D; } } public static Texture2D BulletPoint { get { return Instance.bullet_point.Texture2D; } } public static Texture2D ChoiceNodeOff { get { return Instance.choice_node_off.Texture2D; } } diff --git a/Assets/Fungus/Scripts/Editor/HierarchyIcons.cs b/Assets/Fungus/Scripts/Editor/HierarchyIcons.cs new file mode 100644 index 00000000..60171bbb --- /dev/null +++ b/Assets/Fungus/Scripts/Editor/HierarchyIcons.cs @@ -0,0 +1,67 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; +using System.Linq; + +namespace Fungus +{ + /// + /// Static class that hooks into the hierachy changed and item gui callbacks to put + /// a fungus icon infront of all GOs that have a flowchart on them + /// + /// Reference; http://answers.unity3d.com/questions/431952/how-to-show-an-icon-in-hierarchy-view.html + /// + /// TODO + /// There is what appears like a bug but is currently out of our control. When Unity reloads the built scripts it fires + /// InitializeOnLoad but doesn't then fire HierarchyChanged so icons disappear until a change occurs + /// + [InitializeOnLoad] + public class HierarchyIcons + { + // the fungus mushroom icon + static Texture2D TextureIcon { get { return Fungus.EditorUtils.FungusEditorResources.FungusMushroom; } } + + //sorted list of the GO instance IDs that have flowcharts on them + static List flowchartIDs = new List(); + + static HierarchyIcons() + { + EditorApplication.hierarchyWindowItemOnGUI += HierarchyIconCallback; + EditorApplication.hierarchyWindowChanged += HierarchyChanged; + } + + //track all gameobjectIds that have flowcharts on them + static void HierarchyChanged() + { + flowchartIDs.Clear(); + + if (EditorUtils.FungusEditorPreferences.hideMushroomInHierarchy) + return; + + var flowcharts = GameObject.FindObjectsOfType(); + + flowchartIDs = flowcharts.Select(x => x.gameObject.GetInstanceID()).Distinct().ToList(); + flowchartIDs.Sort(); + } + + //Draw icon if the isntance id is in our cached list + static void HierarchyIconCallback(int instanceID, Rect selectionRect) + { + if (EditorUtils.FungusEditorPreferences.hideMushroomInHierarchy) + return; + + // place the icon to the left of the element + Rect r = new Rect(selectionRect); + r.x = 0; + r.width = r.height; + + //GameObject go = EditorUtility.InstanceIDToObject(instanceID) as GameObject; + + //binary search as it is much faster to cache and int bin search than GetComponent + // should be less GC too + if (flowchartIDs.BinarySearch(instanceID) >= 0) + GUI.Label(r, TextureIcon); + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Editor/HierarchyIcons.cs.meta b/Assets/Fungus/Scripts/Editor/HierarchyIcons.cs.meta new file mode 100644 index 00000000..ed0611fa --- /dev/null +++ b/Assets/Fungus/Scripts/Editor/HierarchyIcons.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: a347e274da09aa44dbb68f1375508d11 +timeCreated: 1500115754 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: