Merge remote-tracking branch 'origin/main' into HEAD

This commit is contained in:
Hubert Mattusch 2022-12-16 02:29:09 +01:00
commit 1318e8fea4
11 changed files with 321 additions and 1 deletions

View File

@ -16,16 +16,35 @@ namespace NEG.Utils
}
}
public static void ActionAfterFrames(this MonoBehaviour mono, int count, Action action)
{
mono.StartCoroutine(ActionAfterFrames(count, action));
}
public static IEnumerator ActionAfterFrames(int count, Action action)
{
yield return WaitForFrames(count);
action?.Invoke();
}
public static IEnumerator ActionAfterEndOfFrame(Action action)
{
yield return WaitForEndOfFrame;
action?.Invoke();
}
public static void ActionAtNextFrame(this MonoBehaviour mono, Action action) => mono.StartCoroutine(ActionAtNextFrame(action));
public static IEnumerator ActionAtNextFrame(Action action)
{
yield return null;
action?.Invoke();
}
public static void ActionAfterTime(this MonoBehaviour mono, float time, Action action) => mono.StartCoroutine(ActionAfterTime(time, action));
public static IEnumerator ActionAfterTime(float time, Action action)
{
yield return new WaitForSeconds(time);
action?.Invoke();
}
}
}

84
Editor/BuildingUtils.cs Normal file
View File

@ -0,0 +1,84 @@
using System.Diagnostics;
using UnityEngine;
using UnityEditor;
using Debug = UnityEngine.Debug;
public static class BuildingUtils
{
[MenuItem("Tools/Build/Steam/Release")]
public static void SteamRelease()
{
IncreaseBuildNumber();
BuildRelease();
UploadSteam();
}
[MenuItem("Tools/Build/Steam/Development")]
public static void SteamDevelopment()
{
IncreaseBuildNumber();
BuildDevelopment();
UploadSteam();
}
[MenuItem("Tools/Build/All Release")]
public static void BuildRelease()
{
BuildWindowsRelease();
}
[MenuItem("Tools/Build/All Development")]
public static void BuildDevelopment()
{
BuildWindowsDevelopment();
}
[MenuItem("Tools/Build/Platform/Windows/x64-Development")]
public static void BuildWindowsDevelopment() => BuildWindows(false);
[MenuItem("Tools/Build/Platform/Windows/x64-Release")]
public static void BuildWindowsRelease() => BuildWindows(true);
private static void BuildWindows(bool release)
{
var buildPlayerOptions = new BuildPlayerOptions { scenes = new string[EditorBuildSettings.scenes.Length] };
for (int i = 0; i < EditorBuildSettings.scenes.Length; i++)
{
buildPlayerOptions.scenes[i] = EditorBuildSettings.scenes[i].path;
}
buildPlayerOptions.target = BuildTarget.StandaloneWindows64;
buildPlayerOptions.options = release ? BuildOptions.None : BuildOptions.Development;
buildPlayerOptions.locationPathName = Application.dataPath +
$"/../../{Application.productName}-Steam/ContentBuilder/content/windows/{Application.productName}.exe";
BuildPipeline.BuildPlayer(buildPlayerOptions);
}
private static void IncreaseBuildNumber()
{
string[] versionParts = PlayerSettings.bundleVersion.Split('.');
if (versionParts.Length != 3 || !int.TryParse(versionParts[2], out int version)) {
Debug.LogError("IncreaseBuildNumber failed to update version " + PlayerSettings.bundleVersion);
return;
}
versionParts[2] = (version + 1).ToString();
PlayerSettings.bundleVersion = string.Join(".", versionParts);
}
private static void UploadSteam()
{
string command = $"cd {Application.dataPath}/../../{Application.productName}-Steam/ContentBuilder && run_build.bat";
var processInfo = new ProcessStartInfo("cmd.exe", $"/c {command}")
{
CreateNoWindow = true,
UseShellExecute = false
};
var process = Process.Start(processInfo);
process.WaitForExit();
Debug.Log(process.ExitCode);
process.Close();
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1e90ce49e16b4cecb77bf258651f6209
timeCreated: 1669642124

41
Editor/GUIDToAssetPath.cs Normal file
View File

@ -0,0 +1,41 @@
using UnityEditor;
using UnityEngine;
public class GUIDToAssetPath : EditorWindow
{
string guid = "";
string path = "";
[MenuItem("Tools/GUIDToAssetPath")]
static void CreateWindow()
{
GUIDToAssetPath window = (GUIDToAssetPath)EditorWindow.GetWindowWithRect(typeof(GUIDToAssetPath), new Rect(0, 0, 400, 120));
}
void OnGUI()
{
GUILayout.Label("Enter guid");
guid = GUILayout.TextField(guid);
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (GUILayout.Button("Get Asset Path",GUILayout.Width(120)))
path = GetAssetPath(guid);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (GUILayout.Button("Abort", GUILayout.Width(120)))
Close();
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.Label(path);
}
static string GetAssetPath(string guid)
{
guid = guid.Replace("-", "");
string p = AssetDatabase.GUIDToAssetPath(guid);
Debug.Log(p);
if (p.Length == 0) p = "not found";
return p;
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ee5c0a00075140f28ac5e6ff46e9a6b3
timeCreated: 1669777021

8
UiToolkit.meta Normal file
View File

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

View File

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

View File

@ -0,0 +1,127 @@
#if ADDRESSABLES && UI_ELEMENTS
using UnityEngine;
using UnityEngine.UIElements;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using System;
using System.Collections;
using System.ComponentModel;
public class MultiSelectChips : VisualElement
{
public string LabelText
{
get => label.text;
set
{
if (!string.IsNullOrEmpty(value))
{
if (label == null)
{
InitLabel();
}
label.text = value;
}
else if (label != null)
{
label.RemoveFromHierarchy();
label = null;
}
}
}
public IList ItemsSource
{
get => itemsSource;
set
{
itemsSource = value;
UpdateItems();
}
}
private Label label;
private AsyncOperationHandle<VisualTreeAsset> uxmlHandle, itemUxmlHandle;
private VisualTreeAsset itemPrefab;
private IList itemsSource;
public new class UxmlFactory : UxmlFactory<MultiSelectChips, UxmlTraits>
{
}
public new class UxmlTraits : VisualElement.UxmlTraits
{
private readonly UxmlStringAttributeDescription label;
public UxmlTraits()
{
label = new()
{
name = "label"
};
}
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
{
base.Init(ve, bag, cc);
((MultiSelectChips)ve).LabelText = label.GetValueFromBag(bag, cc);
}
}
public MultiSelectChips() : base()
{
uxmlHandle = Addressables.LoadAssetAsync<VisualTreeAsset>("NegUiToolkits/MultiSelectChips.uxml");
itemUxmlHandle = Addressables.LoadAssetAsync<VisualTreeAsset>("NegUiToolkits/MultiSelectChipsItem.uxml");
uxmlHandle.Completed += OnUxmlLoaded;
itemUxmlHandle.Completed += OnItemUxmlLoaded;
}
public void UpdateItems()
{
if (itemPrefab == null)
return;
}
private void InitLabel()
{
label = new Label()
{
pickingMode = PickingMode.Ignore
};
Add(label);
}
private void OnUxmlLoaded(AsyncOperationHandle<VisualTreeAsset> operation)
{
if (operation.Status == AsyncOperationStatus.Succeeded)
{
Add(operation.Result.Instantiate());
Addressables.Release(uxmlHandle);
}
else
{
Debug.LogError($"Asset failed to load.");
}
}
private void OnItemUxmlLoaded(AsyncOperationHandle<VisualTreeAsset> operation)
{
if (operation.Status == AsyncOperationStatus.Succeeded)
{
itemPrefab = operation.Result;
Addressables.Release(itemUxmlHandle);
UpdateItems();
}
else
{
Debug.LogError($"Asset failed to load.");
}
}
}
#endif

View File

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

View File

@ -0,0 +1,6 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
<ui:ListView focusable="true" show-add-remove-footer="false" horizontal-scrolling="true" />
<ui:VisualElement style="flex-direction: row; flex-wrap: wrap;">
<ui:Button text="+" display-tooltip-when-elided="true" name="AddItem" />
</ui:VisualElement>
</ui:UXML>

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 28ecbe3f92afaca4faeec3e9fb3af6a2
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}