Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

客户顿UniTask版本 #75

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 8 additions & 0 deletions Fantasy.Unity/Fantasy.Unity.UniTask/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Fantasy.Unity/Fantasy.Unity.UniTask/Editor/Runtime.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using UnityEditor;

namespace Fantasy
{
internal static class CheckUnityVersion
{
[InitializeOnLoadMethod]
private static void OnInitializeOnLoad()
{
#if !UNITY_2021_3_OR_NEWER
Debug.LogError("Fantasy支持的最低版本为Unity2021.3.14f1c1");
#endif
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "Fantasy.Editor",
"rootNamespace": "",
"references": [
"GUID:0b7224b83ba514121aa026f3857f820a"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System.IO;
using UnityEditor;
using UnityEngine;

namespace Fantasy
{
[InitializeOnLoad]
public static class FantasyStartup
{
private const string ScriptAssemblies = "Library/ScriptAssemblies/";

static FantasyStartup()
{
if (!FantasySettingsScriptableObject.Instance.autoCopyAssembly)
{
return;
}

var hotUpdatePath = FantasySettingsScriptableObject.Instance.hotUpdatePath;

if (string.IsNullOrEmpty(hotUpdatePath))
{
Debug.LogError("请先在菜单Fantasy-Fantasy Settings里设置HotUpdatePath目录位置");
return;
}

if (!Directory.Exists(hotUpdatePath))
{
Directory.CreateDirectory(hotUpdatePath);
}

// ReSharper disable once StringLastIndexOfIsCultureSpecific.1
if (hotUpdatePath.LastIndexOf("/") != hotUpdatePath.Length - 1)
{
FantasySettingsScriptableObject.Instance.hotUpdatePath += "/";
hotUpdatePath = FantasySettingsScriptableObject.Instance.hotUpdatePath;
}

foreach (var instanceHotUpdateAssemblyDefinition in FantasySettingsScriptableObject.Instance.hotUpdateAssemblyDefinitions)
{
var dll = instanceHotUpdateAssemblyDefinition.name;
File.Copy($"{ScriptAssemblies}{dll}.dll", $"{hotUpdatePath}/{dll}.dll.bytes", true);
File.Copy($"{ScriptAssemblies}{dll}.pdb", $"{hotUpdatePath}/{dll}.pdb.bytes", true);
}

AssetDatabase.Refresh();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.IO;
using UnityEditor;
using UnityEngine;

namespace Fantasy
{
public class LinkXmlGenerator
{
private const string LinkPath = "Assets/link.xml";
// 在Unity编辑器中运行该方法来生成link.xml文件
[UnityEditor.MenuItem("Fantasy/Generate link.xml")]
public static void GenerateLinkXml()
{
using (var writer = new StreamWriter("Assets/link.xml"))
{
writer.WriteLine("<linker>");
GenerateLinkXml(writer, "Assembly-CSharp", LinkPath);
Debug.Log("Assembly-CSharp Link generation completed");
GenerateLinkXml(writer, "Fantasy.Unity", LinkPath);
Debug.Log("Fantasy.Unity Link generation completed");
foreach (var linkAssembly in FantasySettingsScriptableObject.Instance.linkAssemblyDefinitions)
{
GenerateLinkXml(writer, linkAssembly.name, LinkPath);
Debug.Log($"{linkAssembly.name} Link generation completed");
}
writer.WriteLine("</linker>");
}

AssetDatabase.Refresh();
Debug.Log("link.xml generated successfully!");
}

private static void GenerateLinkXml(StreamWriter writer, string assemblyName, string outputPath)
{
var assembly = System.Reflection.Assembly.Load(assemblyName);
var types = assembly.GetTypes();
writer.WriteLine($" <assembly fullname=\"{assembly.GetName().Name}\">");
foreach (var type in types)
{
var typeName = type.FullName.Replace('<', '+').Replace('>', '+');
writer.WriteLine($" <type fullname=\"{typeName}\" preserve=\"all\"/>");
}
writer.WriteLine(" </assembly>");
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using UnityEditor;

namespace Fantasy
{
public class FantasySettings
{
[MenuItem("Fantasy/Fantasy Settings")]
public static void OpenFantasySettings()
{
SettingsService.OpenProjectSettings("Project/Fantasy Settings");
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

namespace Fantasy
{
public class FantasySettingsProvider : SettingsProvider
{
private SerializedObject _serializedObject;
private SerializedProperty _autoCopyAssembly;
private SerializedProperty _hotUpdatePath;
private SerializedProperty _hotUpdateAssemblyDefinitions;
private SerializedProperty _linkAssemblyDefinitions;
public FantasySettingsProvider() : base("Project/Fantasy Settings", SettingsScope.Project) { }

public override void OnActivate(string searchContext, VisualElement rootElement)
{
Init();
base.OnActivate(searchContext, rootElement);
}

public override void OnDeactivate()
{
base.OnDeactivate();
FantasySettingsScriptableObject.Save();
}

private void Init()
{
_serializedObject?.Dispose();
_serializedObject = new SerializedObject(FantasySettingsScriptableObject.Instance);
_autoCopyAssembly = _serializedObject.FindProperty("autoCopyAssembly");
_hotUpdatePath = _serializedObject.FindProperty("hotUpdatePath");
_hotUpdateAssemblyDefinitions = _serializedObject.FindProperty("hotUpdateAssemblyDefinitions");
_linkAssemblyDefinitions = _serializedObject.FindProperty("linkAssemblyDefinitions");
}

public override void OnGUI(string searchContext)
{
if (_serializedObject == null || !_serializedObject.targetObject)
{
Init();
}

using (CreateSettingsWindowGUIScope())
{
_serializedObject!.Update();

EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(_autoCopyAssembly);
EditorGUILayout.PropertyField(_hotUpdatePath);
EditorGUILayout.PropertyField(_hotUpdateAssemblyDefinitions);
EditorGUILayout.PropertyField(_linkAssemblyDefinitions);
EditorGUILayout.HelpBox("默认包括Assembly-CSharp和Fantasy.Unity,所以不需要再次指定。", MessageType.Info);

if (GUILayout.Button("GenerateLinkXml"))
{
LinkXmlGenerator.GenerateLinkXml();
}

if (EditorGUI.EndChangeCheck())
{
_serializedObject.ApplyModifiedProperties();
FantasySettingsScriptableObject.Save();
EditorApplication.RepaintHierarchyWindow();
}

base.OnGUI(searchContext);
}
}

private IDisposable CreateSettingsWindowGUIScope()
{
var unityEditorAssembly = System.Reflection.Assembly.GetAssembly(typeof(EditorWindow));
var type = unityEditorAssembly.GetType("UnityEditor.SettingsWindow+GUIScope");
return Activator.CreateInstance(type) as IDisposable;
}

static FantasySettingsProvider _provider;

[SettingsProvider]
public static SettingsProvider CreateMyCustomSettingsProvider()
{
if (FantasySettingsScriptableObject.Instance && _provider == null)
{
_provider = new FantasySettingsProvider();
using (var so = new SerializedObject(FantasySettingsScriptableObject.Instance))
{
_provider.keywords = GetSearchKeywordsFromSerializedObject(so);
}
}
return _provider;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Serialization;

namespace Fantasy
{
[ScriptableObjectPath("ProjectSettings/FantasySettings.asset")]
public class FantasySettingsScriptableObject : ScriptableObjectSingleton<FantasySettingsScriptableObject>, ISerializationCallbackReceiver
{
[FormerlySerializedAs("AutoCopyAssembly")] [Header("自动拷贝程序集到HotUpdatePath目录中")]
public bool autoCopyAssembly = false;
[FormerlySerializedAs("HotUpdatePath")] [Header("HotUpdate目录(Unity编译后会把所有HotUpdate程序集Copy一份到这个目录下)")]
public string hotUpdatePath;
[FormerlySerializedAs("HotUpdateAssemblyDefinitions")] [Header("HotUpdate程序集")]
public AssemblyDefinitionAsset[] hotUpdateAssemblyDefinitions;
[FormerlySerializedAs("LinkAssemblyDefinitions")] [Header("生成Link.xml的程序集")]
public AssemblyDefinitionAsset[] linkAssemblyDefinitions;
public void OnBeforeSerialize() { }
public void OnAfterDeserialize() { }
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading