VirtualFramework/Assets/Scripts/Editor/FixedMainEditor.cs
2025-04-23 11:45:50 +08:00

82 lines
2.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using QFramework;
using System;
using System.IO;
using UnityEditor;
using UnityEngine;
#if UNITY_EDITOR
public class FixedMainEditor
{
private const string FixedMainKey = "IsFixedMain";
public static bool isFixedMain
{
get
{
return PlayerPrefs.GetInt(FixedMainKey, 0) == 1;
}
set
{
PlayerPrefs.SetInt(FixedMainKey, value ? 1 : 0);
PlayerPrefs.Save();
}
}
[MenuItem("Tools/强制Main场景启动 %#x", false, 10)]
private static void ToggleOption()
{
isFixedMain = !isFixedMain;
EditorUtility.DisplayDialog("Option Status", "Option is now " + (isFixedMain ? "enabled" : "disabled"), "OK");
}
[MenuItem("Tools/强制Main场景启动 %#x", true, 10)]
private static bool ValidateToggleOption()
{
Menu.SetChecked("Tools/强制Main场景启动", isFixedMain);
return true;
}
[MenuItem("Tools/创建时间锁")]
private static void TimerLock()
{
//创建数据资源文件
//泛型是继承自ScriptableObject的类
TimerLock asset = ScriptableObject.CreateInstance<TimerLock>();
//前一步创建的资源只是存在内存中,现在要把它保存到本地
//通过编辑器API创建一个数据资源文件第二个参数为资源文件在Assets目录下的路径
AssetDatabase.CreateAsset(asset, "Assets/TimerLock.asset");
//保存创建的资源
AssetDatabase.SaveAssets();
//刷新界面
AssetDatabase.Refresh();
}
[MenuItem("Tools/生成Timer文件")]
private static void GeneratorTimer()
{
if (File.Exists(Application.dataPath + "/TimerLock.asset"))
{
string path = "Assets/TimerLock.asset";
var asset = AssetDatabase.LoadAssetAtPath<TimerLock>(path);
if (asset != null)
{
if (string.IsNullOrEmpty(asset.time) == false)
{
//第一次获取获取系统时间
DateTime currentDateTime = DateTime.Now;
string RecordData = currentDateTime.ToString("yyyy-MM-dd HH:mm:ss");
string strMerge = asset.time + "|" + RecordData;
EncryptFileCreator.EncryptAndSaveData(strMerge, "Timer.txt");
}
}
}
//刷新界面
AssetDatabase.Refresh();
}
}
#endif