2025-05-18 01:04:31 +08:00

313 lines
6.6 KiB
C#

// ***********************************************************************
// Assembly : Unity
// Author : Kimch
// Created :
//
// Last Modified By : Kimch
// Last Modified On :
// ***********************************************************************
// <copyright file= "KGMTools" company=""></copyright>
// <summary></summary>
// ***********************************************************************
namespace G
{
using UnityEngine;
public class KGMTools : MonoBehaviour
{
/// <summary>
/// GM指令
/// </summary>
public static class GMCommand
{
public static readonly string Name = "GM";
public static readonly string Description = "GM Command";
public static readonly string Specification = "add id count,add_coin 1,add_diamond 1,add_catfood 1,add_cat id count";
public static string Execute(string args)
{
if (args == null || args.Length == 0)
{
return "无效参数";
}
//if (ServerProxy.Instance)
//{
// ServerProxy.Instance.GMCommand(string.Join(" ", args));
//}
return string.Empty;
}
public static string Execute2(string[] args)
{
if (args == null || args.Length == 0)
{
return ">:无效参数";
}
//if (ServerProxy.Instance)
//{
// ServerProxy.Instance.GMCommand(string.Join(" ", args));
//}
return ">:GM指令发送成功";
}
public static void Callback(int error, string message, object data)
{
if (error == 0)
{
F.Console.Console.Log(">:GM指令发送成功");
}
}
}
public int fps
{
get => Mathf.RoundToInt(_lastFps);
}
#region Unity
public static KGMTools Instance;
// Use this for initialization
private void Awake()
{
Instance = this;
//var prefab = Resources.Load("Console");
//if (prefab)
//{
// GameObject.Instantiate(prefab);
//}
//F.Console.ConsoleCommand.RegisterCommand(GMCommand.Name, GMCommand.Description, GMCommand.Specification, GMCommand.Execute2);
}
// Update is called once per frame
private void Update()
{
UpdateFps();
}
#if UNITY_EDITOR || DEBUG_MY
GameObject _gmWindow;
private void LateUpdate()
{
#if UNITY_EDITOR
if (Input.GetKeyUp(KeyCode.LeftArrow))
{
if (Time.timeScale > 1f)
Time.timeScale -= 1F;
}
else if (Input.GetKeyUp(KeyCode.RightArrow))
{
Time.timeScale += 1F;
}
else if (Input.GetKeyUp(KeyCode.Space))
{
Time.timeScale = 1F;
}
if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
{
if (Input.GetKeyDown(KeyCode.G))
{
if (!_gmWindow)
{
var prefab = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>("Assets/AGame/Editor/GMPanel.prefab");
if (prefab)
{
_gmWindow = Instantiate(prefab);
}
}
if (_gmWindow)
_gmWindow.SetActive(true);
}
if (Input.GetKeyDown(KeyCode.H))
{
if (_gmWindow)
_gmWindow.SetActive(false);
}
}
#endif
if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
BattleEditor.Show();
}
if (Input.GetKeyDown(KeyCode.DownArrow))
{
BattleEditor.Hide();
}
}
#if !UNITY_WEBGL
if (KGMOptions.Instance. && _autoState == 0)
{
_autoState = 1;
}
if (!KGMOptions.Instance. && _autoState != 0)
{
_autoState = 0;
}
#endif
if (_autoState > 0 && Time.time - _lastUpdateTime > 1f)
{
_lastUpdateTime = Time.time;
AutoGame();
}
}
private float _lastUpdateTime;
private int _autoState = 0;
private int _autoSubState = 0;
private void AutoGame()
{
switch (_autoState)
{
case 1:
TutorialProxy.Instance.closeTutorial = true;
StoryProxy.Instance.storyEnabled = false;
_autoState = 2;
_autoSubState = 0;
break;
case 2:
{
_autoSubState++;
if (_autoSubState == 1)
{
PlayerProxy.Instance.energy = 100;
}
else if (_autoSubState == 2)
{
BagProxy.Instance.OneKeySetEquipments();
}
else if (_autoSubState == 3)
{
BagProxy.Instance.OneKeySellEquipments();
}
else if (_autoSubState == 4)
{
int _curGroupIndex = 0;
var groups = KungfuProxy.Instance.GetKungfuGroups();
foreach (var group1 in groups)
{
if (group1.isMaxGrade)
_curGroupIndex += 1;
}
var group = KungfuProxy.Instance.GetKungfuGroupByIndex(_curGroupIndex);
if (group != null)
for (int i = 0; i < 100; i++)
{
var book = group.GetRndStudy();
var price = group.curUpgradeCost;
var notEnoughId = MoneyProxy.Instance.CheckMoney2(price);
if (notEnoughId != 0 || !KungfuProxy.Instance.Study(group, book))
{
break;
}
}
}
else if (_autoSubState == 5)
{
for (int i = 0; i < 6; i++)
{
if (!PlayerProxy.Instance.UpgradeEquipmentSlot(i, false, true))
{
break;
}
}
}
else if (_autoSubState == 6)
{
var result = LevelProxy.Instance.StartLevel();
_autoState = 3;
_autoSubState = 0;
}
}
break;
case 3:
{
if (_autoSubState == 0)
{
if (GameLevel.Instance && !GameLevel.Instance.levelFinish)
{
GameLevel.Instance.gameSpeed = 2f;
if (EntityMainPlayer.Instance)
{
EntityMainPlayer.Instance.autoAttack = true;
EntityMainPlayer.Instance.autoCastSkill = true;
}
_autoSubState = 10;
}
}
else if (_autoSubState == 10)
{
if (!GameLevel.Instance)
{
_autoState = 2;
_autoSubState = 0;
}
}
}
break;
}
}
#endif
#if UNITY_EDITOR || DEBUG_MY
public bool showFps = true;
private GUIStyle _fpsLableStyle;
private void OnGUI()
{
if (showFps)
{
if (_fpsLableStyle == null)
{
_fpsLableStyle = new GUIStyle(GUI.skin.label)
{
fontSize = 16
};
_fpsLableStyle.normal.textColor = new Color(60f / 255f, 200f / 255f, 255f / 255f, 255f / 255f);
}
GUI.Label(new Rect(20f, Screen.height - 26f, 40f, 25f), _lastFps.ToString("f2"), _fpsLableStyle);
}
}
#endif
#endregion
#region Fps
private int _fpsFrameCount = 0;
private float _fpsFrameTime = 0f;
private float _lastFps = 0f;
void UpdateFps()
{
_fpsFrameCount += 1;
_fpsFrameTime += Time.unscaledDeltaTime;
if (_fpsFrameTime >= 1f)
{
_lastFps = _fpsFrameCount / _fpsFrameTime;
_fpsFrameCount = 0;
_fpsFrameTime = 0f;
}
}
#endregion
}
}