备份CatanBuilding瘦身独立工程

This commit is contained in:
JSD\13999
2026-05-26 16:15:54 +08:00
commit 2d0e6a61b7
12001 changed files with 2431925 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEditor;
namespace HeurekaGames.Utils
{
public static class Heureka_AddDefineSymbols
{
/// <summary>
/// Add define symbols as soon as Unity gets done compiling.
/// </summary>
public static void AddDefineSymbols(string[] Symbols)
{
string definesString = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
List<string> allDefines = definesString.Split(';').ToList();
var newDefines = Symbols.Except(allDefines);
if (newDefines.Count() > 0)
{
Debug.Log($"Adding Compile Symbols {string.Join("; ", newDefines.ToArray())}");
allDefines.AddRange(newDefines);
PlayerSettings.SetScriptingDefineSymbolsForGroup(
EditorUserBuildSettings.selectedBuildTargetGroup,
string.Join(";", allDefines.ToArray()));
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 81ec5bfdbc239094e8832e7ffe32ddab
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,81 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b7cbc456ed952974280520c0443d2c9f, type: 3}
m_Name: Heureka_EditorData
m_EditorClassIdentifier:
HeadlineStyle:
m_Name: Heureka_Header
m_Normal:
m_Background: {fileID: 0}
m_ScaledBackgrounds: []
m_TextColor: {r: 1, g: 1, b: 1, a: 1}
m_Hover:
m_Background: {fileID: 0}
m_ScaledBackgrounds: []
m_TextColor: {r: 0, g: 0, b: 0, a: 1}
m_Active:
m_Background: {fileID: 0}
m_ScaledBackgrounds: []
m_TextColor: {r: 0, g: 0, b: 0, a: 1}
m_Focused:
m_Background: {fileID: 0}
m_ScaledBackgrounds: []
m_TextColor: {r: 0, g: 0, b: 0, a: 1}
m_OnNormal:
m_Background: {fileID: 0}
m_ScaledBackgrounds: []
m_TextColor: {r: 0, g: 0, b: 0, a: 1}
m_OnHover:
m_Background: {fileID: 0}
m_ScaledBackgrounds: []
m_TextColor: {r: 0, g: 0, b: 0, a: 1}
m_OnActive:
m_Background: {fileID: 0}
m_ScaledBackgrounds: []
m_TextColor: {r: 0, g: 0, b: 0, a: 1}
m_OnFocused:
m_Background: {fileID: 0}
m_ScaledBackgrounds: []
m_TextColor: {r: 0, g: 0, b: 0, a: 1}
m_Border:
m_Left: 0
m_Right: 0
m_Top: 0
m_Bottom: 0
m_Margin:
m_Left: 0
m_Right: 0
m_Top: 0
m_Bottom: 0
m_Padding:
m_Left: 0
m_Right: 0
m_Top: 0
m_Bottom: 0
m_Overflow:
m_Left: 0
m_Right: 0
m_Top: 0
m_Bottom: 0
m_Font: {fileID: 12800000, guid: ef8cd11511efcac499ca79b722df7fbe, type: 3}
m_FontSize: 20
m_FontStyle: 0
m_Alignment: 0
m_WordWrap: 0
m_RichText: 1
m_TextClipping: 0
m_ImagePosition: 0
m_ContentOffset: {x: 0, y: 0}
m_FixedWidth: 0
m_FixedHeight: 0
m_StretchWidth: 1
m_StretchHeight: 0

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 84a87a1f0ff862e4fb33fbd10ecb8885
timeCreated: 1498416873
licenseType: Store
NativeFormatImporter:
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,157 @@
using System;
using UnityEditor;
using UnityEngine;
namespace HeurekaGames.Utils
{
public class Heureka_EditorData : ScriptableObject
{
public delegate void EditorDataRefreshDelegate();
public static event EditorDataRefreshDelegate OnEditorDataRefresh;
private static Heureka_EditorData m_instance;
public static Heureka_EditorData Instance
{
get
{
if (!m_instance)
{
m_instance = loadData();
}
return m_instance;
}
}
private static Heureka_EditorData loadData()
{
//LOGO ON WINDOW
string[] configData = AssetDatabase.FindAssets("EditorData t:" + typeof(Heureka_EditorData).ToString(), null);
if (configData.Length >= 1)
{
return AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(configData[0]), typeof(Heureka_EditorData)) as Heureka_EditorData;
}
Debug.LogError("Failed to find config data");
return null;
}
internal void RefreshData()
{
if (OnEditorDataRefresh != null)
OnEditorDataRefresh();
}
public GUIStyle HeadlineStyle;
public static class Links
{
private const string AffiliateID = "1011l4Izm";
private const string SlugSmartBuilder = "206777";
private const string SlugAssetHunter = "135296";
private const string SlugAssetFinder = "97772";
public static string FromAHPToSmartBuilder => GenerateLink("AHPNews", SlugSmartBuilder);
private static string GenerateLink(string pubref, string slug)
{
return $"https://prf.hn/click/camref:{AffiliateID}/pubref:{pubref}/destination:https%3A%2F%2Fassetstore.unity.com%2Fpackages%2Fslug%2F{slug}";
}
}
}
[System.Serializable]
public class ConfigurableIcon
{
[SerializeField] private bool isUsingDarkSkin = false;
[SerializeField] string buildInIconName = "";
[SerializeField] private Texture iconCached = null;
[SerializeField] Texture m_iconNormalOverride = null;
[SerializeField] Texture m_iconProSkinOverride = null;
public ConfigurableIcon()
{
Heureka_EditorData.OnEditorDataRefresh += onEditorDataRefresh;
}
private void onEditorDataRefresh()
{
iconCached = null;
}
public Texture Icon
{
get
{
//TODO A way to make sure we update, if the user have changed skin
if (isUsingDarkSkin != EditorGUIUtility.isProSkin)
{
iconCached = null;
isUsingDarkSkin = EditorGUIUtility.isProSkin;
}
return (iconCached != null) ? iconCached : (iconCached = GetInvertedForProSkin());
}
}
[SerializeField]
bool m_darkSkinInvert = false;
protected Texture GetInvertedForProSkin()
{
Texture imageToUse = (EditorGUIUtility.isProSkin) ? m_iconProSkinOverride : m_iconNormalOverride;
//If we want to use default unity icons and nothing has been setup to override
if (imageToUse == null && !string.IsNullOrEmpty(buildInIconName))
if (EditorGUIUtility.IconContent(buildInIconName) != null)
imageToUse = EditorGUIUtility.IconContent(buildInIconName).image;
//Return current image if we dont have proskin, or dont want to invert
if (!EditorGUIUtility.isProSkin || (EditorGUIUtility.isProSkin && !m_darkSkinInvert))
return imageToUse;
Texture2D readableTexture = getReadableTexture(imageToUse);
Texture2D inverted = new Texture2D(readableTexture.width, readableTexture.height, TextureFormat.ARGB32, false);
for (int x = 0; x < readableTexture.width; x++)
{
for (int y = 0; y < readableTexture.height; y++)
{
Color origColor = readableTexture.GetPixel(x, y);
Color invertedColor = new Color(1 - origColor.r, 1 - origColor.g, 1 - origColor.b, origColor.a);
inverted.SetPixel(x, y, (origColor.a > 0) ? invertedColor : origColor);
}
}
inverted.Apply();
return inverted;
}
private Texture2D getReadableTexture(Texture imageToUse)
{
// Create a temporary RenderTexture of the same size as the texture
RenderTexture tmp = RenderTexture.GetTemporary(
imageToUse.width,
imageToUse.height,
0,
RenderTextureFormat.Default,
RenderTextureReadWrite.Linear);
// Blit the pixels on texture to the RenderTexture
Graphics.Blit(imageToUse, tmp);
// Backup the currently set RenderTexture
RenderTexture previous = RenderTexture.active;
// Set the current RenderTexture to the temporary one we created
RenderTexture.active = tmp;
// Create a new readable Texture2D to copy the pixels to it
Texture2D myTexture2D = new Texture2D(imageToUse.width, imageToUse.height);
// Copy the pixels from the RenderTexture to the new Texture
myTexture2D.ReadPixels(new Rect(0, 0, tmp.width, tmp.height), 0, 0);
myTexture2D.Apply();
// Reset the active RenderTexture
RenderTexture.active = previous;
// Release the temporary RenderTexture
RenderTexture.ReleaseTemporary(tmp);
return myTexture2D;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b7cbc456ed952974280520c0443d2c9f
timeCreated: 1498416726
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,16 @@
{
"name": "HeurekaGames.Utils",
"rootNamespace": "",
"references": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 6b3b893d46a69d5498029e96ff000779
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,102 @@
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace HeurekaGames.Utils
{
public static class Heureka_ResourceLoader
{
private static readonly Dictionary<HeurekaPackage, string> iconPaths = new Dictionary<HeurekaPackage, string>()
{
{HeurekaPackage.SHARED, "com.heurekagames.utils" },
{HeurekaPackage.AHP, "com.heurekagames.assethunterpro" },
{HeurekaPackage.SB, "com.heurekagames.smartbuilder" },
{HeurekaPackage.AFP, "com.heurekagames.assetfinderpro" }
};
public static class Content
{
public static GUIContent Previous = GetInternalContentWithTooltip("tab_prev", "Previous");
public static GUIContent Next = GetInternalContentWithTooltip("tab_next", "Next");
}
public static class Icons
{
public static Texture Pick = EditorGUIUtility.IconContent("pick").image;
public static Texture Clear = EditorGUIUtility.IconContent(Heureka_Utils.IsUnityVersionGreaterThan(2020) ? "clear" : "Toolbar Minus").image;
public static Texture Previous = EditorGUIUtility.IconContent("tab_prev").image;
public static Texture Next= EditorGUIUtility.IconContent("tab_next").image;
}
public static class IconNames
{
public static readonly string TabIconAHP = "tabIcon";
}
public enum HeurekaPackage
{
SHARED,
AHP,
SB,
AFP
}
public static string GetIconPath(HeurekaPackage package, string iconName)
{
var path = $"Packages/{iconPaths[package]}/UI/Icons/{iconName}.png";
var folder = System.IO.Directory.GetCurrentDirectory() + $"/Packages/{iconPaths[package]}/UI/Icons";
bool exists = System.IO.Directory.Exists(folder);
//If this icon resides in "packages"
if (exists)
{
return path;
}
//Else we need to find the directory it lives in
else
{
var targetDir = System.IO.Directory.GetDirectories(System.IO.Directory.GetCurrentDirectory(), $"{iconPaths[package]}", System.IO.SearchOption.AllDirectories);
if (targetDir.Length > 0)
{
var iconPath = string.Join(", ", System.IO.Directory.GetDirectories(targetDir[0], "Icons", System.IO.SearchOption.AllDirectories)) + $"/{iconName}.png";
var relativepath = "Assets" + iconPath.Substring(Application.dataPath.Length);
return relativepath;
}
}
Debug.LogWarning($"Unable to find {iconName} icon, please reinstall Heureka package: {package} in packages");
return string.Empty;
}
public static Texture GetIcon(HeurekaPackage package, string iconName)
{
return EditorGUIUtility.TrIconContent(GetIconPath(package, iconName)).image;
}
public static GUIContent GetContentWithTitle(HeurekaPackage package, string iconName, string title)
{
return EditorGUIUtility.TrTextContentWithIcon(title, GetIconPath(package, iconName));
}
public static GUIContent GetContentWithTooltip(HeurekaPackage package, string iconName, string tooltip)
{
return EditorGUIUtility.TrIconContent(GetIconPath(package, iconName), tooltip);
}
public static GUIContent GetContent(HeurekaPackage package, string iconName, string title, string tooltip)
{
return EditorGUIUtility.TrTextContentWithIcon(title, tooltip, GetIconPath(package, iconName));
}
public static GUIContent GetInternalContentWithTooltip(string iconName, string tooltip)
{
return new GUIContent(EditorGUIUtility.IconContent(iconName).image, tooltip);
}
public static Texture GetInternalIcon(string iconName)
{
return EditorGUIUtility.IconContent(iconName).image;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6096cbae469d125438eb9ff47cbc2022
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using PackageInfo = UnityEditor.PackageManager.PackageInfo;
using UnityEditor;
namespace HeurekaGames.Utils
{
public class Heureka_Serializer
{
public static string Serialize(List<string> items)
{
return JsonUtility.ToJson(new StringList(items));
}
public static List<string> DeserializeStringList(string json)
{
StringList list = JsonUtility.FromJson<StringList>(json);
return (list != null) ? list.Items : new List<string>();
}
public static Type DeSerializeType(string serializedType)
{
return Type.GetType(serializedType);
}
public static string SerializeType(Type type)
{
return type.AssemblyQualifiedName;
}
[SerializeField]
public class StringList
{
public List<string> Items = new List<string>();
public StringList(List<string> items)
{
this.Items = items;
}
}
}
public static class Heureka_Utils
{
public static PackageInfo GetPackageInfo<T>()
{
var assembly = typeof(T).Assembly;
return PackageInfo.FindForAssembly(assembly);
}
public static string GetVersionNumber<T>()
{
return GetPackageInfo<T>()?.version ?? "";
}
public static PackageInfo GetPackageInfoFromObject(UnityEngine.Object asset)
{
return PackageInfo.FindForAssetPath(AssetDatabase.GetAssetPath(asset));
}
public static string GetAssetStoreSearchLink(IEnumerable<string> tags)
{
string tracker = @"https://prf.hn/click/camref:1011l4Izm/pubref:SBSearch/destination:";
string search = string.Join(" ", tags);
return tracker + @"https://assetstore.unity.com/?category=3d%5C2d&q=" + search + @"&orderBy=1";
}
public static bool IsUnityVersionGreaterThan(int major)
{
return System.Int32.Parse(Application.unityVersion.Split('.')[0]) > major;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8cdad70aa85cb144e9299622e104cce6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,111 @@
using System;
using UnityEditor;
using UnityEngine;
namespace HeurekaGames.Utils
{
public static class Heureka_WindowStyler
{
public static float HeaderHeight { get; private set; } = 24f;
public static readonly Color clr_Pink = new Color((226f / 256f), (32f / 256f), (140f / 256f), 1);
public static readonly Color clr_Dark = new Color((48f / 256f), (41f / 256f), (47f / 256f), 1);
public static readonly Color clr_dBlue = new Color((47f / 256f), (102f / 256f), (144f / 256f), 1);
public static readonly Color clr_lBlue = new Color((58f / 256f), (124f / 256f), (165f / 256f), 1);
public static readonly Color clr_White = new Color((217f / 256f), (220f / 256f), (214f / 256f), 1);
public static readonly Color clr_Red = new Color((183f / 256f), (0f / 256f), (0f / 256f));
public static readonly Color clr_middleGreen = new Color((85f / 256f), (133f / 256f), (100f / 256f));
public static void DrawGlobalHeader(Color color, string label, string version = "", Action additionHeaderContent = null)
{
EditorGUI.DrawRect(new Rect(0, 0, EditorGUIUtility.currentViewWidth, HeaderHeight), color);
EditorGUILayout.BeginHorizontal();
GUILayout.Space(4);
if (Heureka_EditorData.Instance.HeadlineStyle != null)
GUILayout.Label(label + " ", Heureka_EditorData.Instance.HeadlineStyle, GUILayout.ExpandWidth(false));
if (version != "")
{
EditorGUILayout.BeginVertical();
EditorGUILayout.Space();
GUILayout.Label(version, EditorStyles.whiteLabel);
EditorGUILayout.EndVertical();
additionHeaderContent?.Invoke();
}
if(additionHeaderContent==null)
GUILayout.FlexibleSpace();
EditorGUILayout.EndHorizontal();
}
public static void DrawCenteredImage(EditorWindow window, Texture image)
{
if (window == null)
return;
GUI.Box(new Rect((window.position.width * .5f) - (image.width * .5f), (window.position.height * .5f) - (image.height * .5f), image.width, image.height), image, GUIStyle.none);
}
public static void DrawCenteredMessage(EditorWindow window, Texture icon, float msgWidth, float msgHeight, string messsage)
{
if (window == null)
return;
Vector2 iconSize = Vector2.zero;
if (icon != null)
iconSize = new Vector2(icon.width, icon.height);
Vector2 outerBoxSize = new Vector2(msgWidth, msgHeight);
float frameWidth = 5;
Vector2 innerBoxSize = new Vector2(outerBoxSize.x - frameWidth * 2, outerBoxSize.y - frameWidth * 2);
Vector2 rectStartPos = new Vector2((window.position.width * .5f) - (outerBoxSize.x * .5f), (window.position.height * .5f) - (outerBoxSize.y * .5f) + (iconSize.y * .5f));
EditorGUI.DrawRect(new Rect(rectStartPos.x, rectStartPos.y, outerBoxSize.x, outerBoxSize.y), Heureka_WindowStyler.clr_White);
EditorGUI.DrawRect(new Rect(rectStartPos.x + frameWidth, rectStartPos.y + frameWidth, innerBoxSize.x, innerBoxSize.y), Heureka_WindowStyler.clr_dBlue);
float bounds = 20;
Vector2 logoStartPos = rectStartPos + new Vector2(bounds, bounds);
GUI.Box(new Rect(logoStartPos.x, logoStartPos.y, iconSize.x, iconSize.y), icon, GUIStyle.none);
Vector2 labelStartPos = logoStartPos + new Vector2(iconSize.x + frameWidth * 2, 0);
float textWidth = innerBoxSize.x - iconSize.x - (bounds * 2);
float textHeight = 30;
string[] lines = messsage.Split(
new[] { Environment.NewLine },
StringSplitOptions.None
);
GUI.Label(new Rect(labelStartPos.x, labelStartPos.y, textWidth, textHeight), lines[0], Heureka_EditorData.Instance.HeadlineStyle);
var whiteStyle = new GUIStyle(EditorStyles.label);
whiteStyle.normal.textColor = Color.white;
labelStartPos.y += 20;
for (int i = 1; i < lines.Length; i++)
{
GUI.Label(new Rect(labelStartPos.x, labelStartPos.y, textWidth, textHeight), lines[i], whiteStyle);
labelStartPos.y += 16;
}
}
private static GUIStyle imageBtnStyle;
public static GUIStyle ImageBtnStyle
{
get
{
if (imageBtnStyle == null)
{
imageBtnStyle = new GUIStyle(GUI.skin.button);
imageBtnStyle.padding = new RectOffset(0, 0, 0, 0);
}
return imageBtnStyle;
}
set => imageBtnStyle = value;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 193aea51eb2e7314387c70be631287b0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 60e6e35b365f2344983f76490854e617
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,42 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace HeurekaGames.Utils
{
[System.Serializable]
public class Heureka_PackageData : ScriptableObject
{
public Texture Icon;
public int PackageShowPrio;
public string AssetName;
public string Subheader;
public string AssetIdentifier;
public string Description;
public List<PackageLinks> Links = new List<PackageLinks>();
}
[System.Serializable]
public struct PackageLinks
{
public bool ActiveLink;
public string Name;
public string Link;
public PackageLinks(string Name, string Link)
{
this.Name = Name;
this.Link = Link;
this.ActiveLink = true;
}
public PackageLinks(string Name, string Link, bool LinkActive)
{
this.Name = Name;
this.Link = Link;
this.ActiveLink = LinkActive;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e2b56c743d6a700428791f460b02a9c7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace HeurekaGames.Utils
{
public class Heureka_PackageDataManager : ScriptableObject
{
public Texture2D icon;
public string title;
public List<PackageLinks> Links = new List<PackageLinks>();
public Heureka_PackageData[] sections;
public bool loadedLayout;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5ad52548211456340bc14f056dd164dd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,267 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Linq;
using System.IO;
using System.Reflection;
using System;
namespace HeurekaGames.Utils
{
[CustomEditor(typeof(Heureka_PackageDataManager))]
[InitializeOnLoad]
public class Heureka_PackageDataManagerEditor : Editor
{
public static readonly string ShowedReadmeProjectStateName = "HeurekaGames.PackageDataManager.ShowedReadme";
static float kSpace = 16f;
static Heureka_PackageDataManagerEditor()
{
EditorApplication.delayCall += SelectReadmeAutomatically;
}
static void SelectReadmeAutomatically()
{
if (!EditorPrefs.GetBool(getUniqueReadMeStatePrefKey(), false))
{
SelectReadme();
EditorPrefs.SetBool(getUniqueReadMeStatePrefKey(), true);
}
}
private static string getUniqueReadMeStatePrefKey()
{
return ShowedReadmeProjectStateName + "." + Application.dataPath;
}
[MenuItem("Window/Heureka/Readme", priority = 10)]
public static Heureka_PackageDataManager SelectReadme()
{
var ids = AssetDatabase.FindAssets("t:" + typeof(Heureka_PackageDataManager).ToString());
if (ids.Length == 1)
{
var readmeObject = AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GUIDToAssetPath(ids[0]));
Selection.objects = new UnityEngine.Object[] { readmeObject };
return (Heureka_PackageDataManager)readmeObject;
}
else
{
Debug.Log("Couldn't find a readme");
return null;
}
}
private void OnEnable()
{
readmeManager = SelectReadme();// (Heureka_PackageDataManager)target;
//populate sections
var guids = AssetDatabase.FindAssets($"t:{nameof(Heureka_PackageData).ToString()}");
List<Heureka_PackageData> tmpList = new List<Heureka_PackageData>();
foreach (var item in guids)
{
string path = AssetDatabase.GUIDToAssetPath(item);
tmpList.Add(AssetDatabase.LoadAssetAtPath<Heureka_PackageData>(path));
}
readmeManager.sections = tmpList.ToArray();
//readmeManager.sections = Resources.FindObjectsOfTypeAll<Heureka_PackageData>();
//Sorted lidt by show Priority
readmeManager.sections = readmeManager.sections.OrderByDescending(val => val.PackageShowPrio).ToArray();
List<Heureka_PackageData> listUniqueEntries = new List<Heureka_PackageData>();
foreach (var item in readmeManager.sections)
{
//If we dont have this asset identifier in list already
if (!listUniqueEntries.Any(val=>val.AssetIdentifier == item.AssetIdentifier))
listUniqueEntries.Add(item);
//If it IS in list already find the one that is NOT a promo, and put that in list
else
{
//If the one we look at right now is a promo, just ignore
if (item.GetType() == typeof(Heureka_PackageDataPromo))
continue;
else
{
//Remove the promo from list and insert the new one with similar identifier (Which should be a readme)
listUniqueEntries.Remove(listUniqueEntries.Find(val=>val.AssetIdentifier == item.AssetIdentifier));
listUniqueEntries.Add(item);
}
}
}
readmeManager.sections = listUniqueEntries.ToArray();
}
protected override void OnHeaderGUI()
{
Init();
//Make sure we have the proper readme's
SelectReadme();
var iconWidth = 96;// Mathf.Min(EditorGUIUtility.currentViewWidth / 3f - 20f, 128f);
GUILayout.BeginHorizontal();
{
GUILayout.Space(10);
EditorGUILayout.BeginVertical();
GUILayout.Space(10);
GUILayout.Label(readmeManager.icon, GUILayout.Width(iconWidth), GUILayout.Height(iconWidth));
EditorGUILayout.EndVertical();
EditorGUILayout.BeginVertical();
GUILayout.BeginHorizontal();
GUILayout.Label(readmeManager.title, TitleStyle);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
foreach (var link in readmeManager.Links.Where(val => val.ActiveLink == true))
{
if (LinkLabel(new GUIContent(link.Name)))
{
Application.OpenURL(link.Link);
}
}
EditorGUILayout.EndVertical();
}
GUILayout.EndHorizontal();
}
public override void OnInspectorGUI()
{
GUILayout.Space(20);
Init();
foreach (var section in readmeManager.sections)
{
drawSeparator();
if (!string.IsNullOrEmpty(section.AssetName))
{
EditorGUILayout.BeginHorizontal();
GUILayout.Box(section.Icon, GUIStyle.none, GUILayout.Width(64), GUILayout.Height(64));
EditorGUILayout.BeginVertical();
GUILayout.Label(section.AssetName, TitleStyle);
GUILayout.Label(section.Subheader, HeadingStyle);
EditorGUILayout.EndVertical();
EditorGUILayout.EndHorizontal();
GUILayout.Space(kSpace);
}
if (!string.IsNullOrEmpty(section.Description))
{
GUILayout.Label(section.Description, BodyStyle);
}
if (section.Links != null)
{
foreach (var link in section.Links.Where(val => val.ActiveLink == true))
{
if (LinkLabel(new GUIContent(link.Name)))
{
Application.OpenURL(link.Link);
}
}
}
GUILayout.Space(10);
//If this is a versioned data package
if (section.GetType() == typeof(Heureka_PackageDataVersioned))
{
Heureka_PackageDataVersioned versionedSection = (Heureka_PackageDataVersioned)section;
if (versionedSection.VersionData != null && versionedSection.VersionData.Count > 0)
{
versionedSection.FoldOutVersionHistory = EditorGUILayout.Foldout(versionedSection.FoldOutVersionHistory, "Version History");
if (versionedSection.FoldOutVersionHistory)
{
for (int i = versionedSection.VersionData.Count() - 1; i >= 0; i--)
{
EditorGUI.indentLevel++;
{
GUILayout.Label(versionedSection.VersionData[i].VersionNum.GetVersionString(), HeadingStyle);
EditorGUI.indentLevel+=2;
foreach (var versionChange in versionedSection.VersionData[i].VersionChanges)
{
EditorGUILayout.LabelField("- " + versionChange, BodyStyle);
}
EditorGUI.indentLevel-=2;
}
EditorGUI.indentLevel--;
GUILayout.Space(4);
}
GUILayout.Space(kSpace);
}
}
}
}
}
private void drawSeparator()
{
var rect = EditorGUILayout.BeginHorizontal();
Handles.color = Color.gray;
Handles.DrawLine(new Vector2(rect.x - 15, rect.y), new Vector2(rect.width + 15, rect.y));
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space();
}
bool m_Initialized;
GUIStyle LinkStyle { get { return m_LinkStyle; } }
[SerializeField] GUIStyle m_LinkStyle;
GUIStyle TitleStyle { get { return m_TitleStyle; } }
[SerializeField] GUIStyle m_TitleStyle;
GUIStyle HeadingStyle { get { return m_HeadingStyle; } }
[SerializeField] GUIStyle m_HeadingStyle;
GUIStyle BodyStyle { get { return m_BodyStyle; } }
[SerializeField] GUIStyle m_BodyStyle;
private Heureka_PackageDataManager readmeManager;
void Init()
{
if (m_Initialized)
return;
m_BodyStyle = new GUIStyle(EditorStyles.label);
m_BodyStyle.wordWrap = true;
m_BodyStyle.fontSize = 12;
m_TitleStyle = new GUIStyle(m_BodyStyle);
m_TitleStyle.wordWrap = false;
m_TitleStyle.fontSize = 18;
m_HeadingStyle = new GUIStyle(m_BodyStyle);
m_HeadingStyle.wordWrap = false;
m_HeadingStyle.fontSize = 14;
m_LinkStyle = new GUIStyle(m_BodyStyle);
m_LinkStyle.wordWrap = false;
// Match selection color which works nicely for both light and dark skins
m_LinkStyle.normal.textColor = new Color(0x00 / 255f, 0x78 / 255f, 0xDA / 255f, 1f);
m_LinkStyle.stretchWidth = false;
m_Initialized = true;
}
bool LinkLabel(GUIContent label, params GUILayoutOption[] options)
{
var position = GUILayoutUtility.GetRect(label, LinkStyle, options);
Handles.BeginGUI();
Handles.color = LinkStyle.normal.textColor;
Handles.DrawLine(new Vector3(position.xMin, position.yMax), new Vector3(position.xMax, position.yMax));
Handles.color = Color.white;
Handles.EndGUI();
EditorGUIUtility.AddCursorRect(position, MouseCursor.Link);
return GUI.Button(position, label, LinkStyle);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a00647402484491499b5fb701efabe22
timeCreated: 1484146680
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace HeurekaGames.Utils
{
public class Heureka_PackageDataPromo : Heureka_PackageData
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 312ef3862be95544daf14a84810fef28
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,196 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
namespace HeurekaGames.Utils
{
public class Heureka_PackageDataVersioned : Heureka_PackageData
{
public List<PackageVersion> VersionData = new List<PackageVersion>();
internal bool FoldOutVersionHistory;
private void Item_OnChanged()
{
EditorUtility.SetDirty(this);
}
public void AddNewVersion(int major, int minor, int patch)
{
PackageVersion newPackageVersion = new PackageVersion(major, minor, patch);
VersionData.Add(newPackageVersion);
}
public void CollapseAll()
{
foreach (var item in VersionData)
{
item.FoldOut = false;
}
}
public void Delete(PackageVersion target)
{
VersionData.Remove(target);
}
}
[System.Serializable]
public class PackageVersion
{
[SerializeField] public PackageVersionNum VersionNum = new PackageVersionNum();
[SerializeField] public List<string> VersionChanges = new List<string>();
internal bool FoldOut = false;
PackageVersionNum newVersionNum = new PackageVersionNum();
private const float btnWidth = 150;
private ReorderableList reorderableList;
private bool initialized = false;
public PackageVersion(int major, int minor, int patch)
{
this.VersionNum = newVersionNum = new PackageVersionNum(major, minor, patch);
this.FoldOut = true;
}
private void initialize()
{
initialized = true;
reorderableList = new ReorderableList(VersionChanges, typeof(string), true, true, true, true);
reorderableList.drawHeaderCallback += DrawHeader;
reorderableList.drawElementCallback += DrawElement;
reorderableList.onAddCallback += AddItem;
reorderableList.onRemoveCallback += RemoveItem;
}
/// <summary>
/// Draws the header of the list
/// </summary>
/// <param name="rect"></param>
private void DrawHeader(Rect rect)
{
GUI.Label(rect, "Version changes");
}
/// <summary>
/// Draws one element of the list (ListItemExample)
/// </summary>
/// <param name="rect"></param>
/// <param name="index"></param>
/// <param name="active"></param>
/// <param name="focused"></param>
private void DrawElement(Rect rect, int index, bool active, bool focused)
{
VersionChanges[index] = EditorGUI.TextField(new Rect(rect.x + 18, rect.y, rect.width - 18, rect.height), VersionChanges[index]);
}
private void AddItem(ReorderableList list)
{
VersionChanges.Add("");
}
private void RemoveItem(ReorderableList list)
{
VersionChanges.RemoveAt(list.index);
}
public void OnGUI(ref bool shouldDelete)
{
if (!initialized || reorderableList == null)
initialize();
GUILayout.Space(10);
FoldOut = EditorGUILayout.Foldout(FoldOut, VersionNum.GetVersionString());
if (GUILayout.Button("Delete Version", GUILayout.Width(btnWidth)))
shouldDelete = true;
if (FoldOut)
{
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Update Version", GUILayout.Width(btnWidth)))
updateVersion();
//Allow for changing version num
newVersionNum.Major = EditorGUILayout.IntField(newVersionNum.Major);
newVersionNum.Minor = EditorGUILayout.IntField(newVersionNum.Minor);
newVersionNum.Patch = EditorGUILayout.IntField(newVersionNum.Patch);
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
//versionDescription = GUILayout.TextArea(versionDescription);
if (reorderableList.count > 0 && (GUILayout.Button("Copy to clipboard")))
{
string clipboardString = "";
foreach (var item in reorderableList.list)
{
clipboardString += item.ToString() + Environment.NewLine;
}
EditorGUIUtility.systemCopyBuffer = clipboardString;
}
EditorGUILayout.EndHorizontal();
{
reorderableList.DoLayoutList();
}
}
}
private void updateVersion()
{
VersionNum = new PackageVersionNum(newVersionNum.Major, newVersionNum.Minor, newVersionNum.Patch);
//TODO SORT Parent list
}
}
[System.Serializable]
public struct PackageVersionNum : IComparable<PackageVersionNum>
{
[SerializeField] public int Major;
[SerializeField] public int Minor;
[SerializeField] public int Patch;
public PackageVersionNum(int major, int minor, int path)
{
this.Major = major;
this.Minor = minor;
this.Patch = path;
}
public int CompareTo(PackageVersionNum other)
{
if (this.Major != other.Major)
return this.Major.CompareTo(other.Major);
else if (this.Minor != other.Minor)
return this.Minor.CompareTo(other.Minor);
else
return this.Patch.CompareTo(other.Patch);
}
public class VersionComparer : IComparer<PackageVersionNum>
{
int IComparer<PackageVersionNum>.Compare(PackageVersionNum objA, PackageVersionNum objB)
{
return objA.CompareTo(objB);
}
}
public string GetVersionString()
{
return string.Format("{0}.{1}.{2}", Major, Minor, Patch);
}
public bool IsEmpty()
{
return (Major == 0 && Minor == 0 && Patch == 0);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7b27603d2be0e81488eb446378c435df
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: