336 lines
6.6 KiB
C#
336 lines
6.6 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2021-11-25
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "BattleEditor" company="Kunpo"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace G
|
|
{
|
|
/// <summary>
|
|
/// 战斗编辑器
|
|
/// </summary>
|
|
public class BattleEditor : KUIWidget
|
|
{
|
|
#if UNITY_EDITOR || DEBUG_MY
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class TextWidget : KUIWidget
|
|
{
|
|
Text _text;
|
|
|
|
public override void Refresh()
|
|
{
|
|
if (this.data is ItemMinion minion)
|
|
{
|
|
if (!string.IsNullOrEmpty(minion.name))
|
|
_text.text = minion.name;
|
|
else
|
|
_text.text = $"小兵{minion.id}";
|
|
return;
|
|
}
|
|
|
|
if (this.data is ItemBoss boss)
|
|
{
|
|
if (!string.IsNullOrEmpty(boss.name))
|
|
_text.text = boss.name;
|
|
else
|
|
_text.text = $"首领{boss.id}";
|
|
return;
|
|
}
|
|
|
|
if (this.data is ItemMoves moves)
|
|
{
|
|
_text.text = moves.name;
|
|
return;
|
|
}
|
|
|
|
if (this.data is ItemLevel level)
|
|
{
|
|
_text.text = level.name;
|
|
return;
|
|
}
|
|
}
|
|
|
|
void OnClick()
|
|
{
|
|
if (this.data is ItemMinion minion)
|
|
{
|
|
_Instance.SpawnMinion(minion.id, 0);
|
|
return;
|
|
}
|
|
|
|
if (this.data is ItemBoss boss)
|
|
{
|
|
_Instance.SpawnBoss(boss.id, 0);
|
|
return;
|
|
}
|
|
|
|
if (this.data is ItemMoves moves)
|
|
{
|
|
_Instance.StudySkill(moves.id);
|
|
return;
|
|
}
|
|
|
|
if (this.data is ItemLevel level)
|
|
{
|
|
_Instance.ReplaceScene(level.assets[0]);
|
|
return;
|
|
}
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
_text = Find<Text>("Text");
|
|
GetComponent<Button>().onClick.AddListener(this.OnClick);
|
|
}
|
|
}
|
|
|
|
#region Field
|
|
|
|
[KUIFlag]
|
|
GameObject _goEditor;
|
|
[KUIFlag]
|
|
Button _btnControl;
|
|
[KUIFlag]
|
|
Text _txtControl;
|
|
|
|
[KUIFlag]
|
|
Button _btnMinion;
|
|
[KUIFlag]
|
|
Button _btnBoss;
|
|
[KUIFlag]
|
|
Button _btnSkill;
|
|
[KUIFlag]
|
|
Button _btnScene;
|
|
[KUIFlag]
|
|
Toggle _tgDaddy;
|
|
[KUIFlag]
|
|
Toggle _tgPause;
|
|
|
|
[KUIFlag]
|
|
GameObject _goMinion;
|
|
[KUIFlag]
|
|
GameObject _goBoss;
|
|
[KUIFlag]
|
|
GameObject _goSpawnPoint;
|
|
[KUIFlag]
|
|
GameObject _goSkill;
|
|
[KUIFlag]
|
|
GameObject _goScene;
|
|
[KUIFlag]
|
|
KUIList __listMinions;
|
|
[KUIFlag]
|
|
KUIList __listBosses;
|
|
[KUIFlag]
|
|
KUIList __listSpawnPoints;
|
|
[KUIFlag]
|
|
KUIList __listSkills;
|
|
[KUIFlag]
|
|
KUIList __listScenes;
|
|
|
|
|
|
Dictionary<string, ItemLevel> _sceneDict = new Dictionary<string, ItemLevel>();
|
|
List<ItemLevel> _levels = new List<ItemLevel>();
|
|
|
|
#endregion
|
|
|
|
#region Method
|
|
|
|
public override void Refresh()
|
|
{
|
|
__listMinions.Clear();
|
|
var minionItems = ItemProxy.Instance.GetStaticItems<ItemMinion>();
|
|
foreach (var item in minionItems)
|
|
{
|
|
__listMinions.GetItem().SetData(item);
|
|
}
|
|
|
|
__listBosses.Clear();
|
|
var bossItems = ItemProxy.Instance.GetStaticItems<ItemBoss>();
|
|
foreach (var item in bossItems)
|
|
{
|
|
__listBosses.GetItem().SetData(item);
|
|
}
|
|
|
|
__listSkills.Clear();
|
|
var movesItems = ItemProxy.Instance.GetStaticItems<ItemMoves>();
|
|
foreach (var item in movesItems)
|
|
{
|
|
if (item.targetType <= 1)
|
|
__listSkills.GetItem().SetData(item);
|
|
}
|
|
|
|
var levelItems = ItemProxy.Instance.GetStaticItems<ItemLevel>();
|
|
foreach (var item in levelItems)
|
|
{
|
|
if (item.assets != null && item.assets.Length > 0 && !_sceneDict.ContainsKey(item.assets[0]))
|
|
_sceneDict.Add(item.assets[0], item);
|
|
}
|
|
__listScenes.Clear();
|
|
foreach (var item in _sceneDict)
|
|
{
|
|
__listScenes.GetItem().SetData(item.Value);
|
|
}
|
|
|
|
OnMinionBtnClick();
|
|
}
|
|
|
|
void OnMinionBtnClick()
|
|
{
|
|
_goMinion.SetActive(true);
|
|
_goSpawnPoint.SetActive(true);
|
|
|
|
_goBoss.SetActive(false);
|
|
_goSkill.SetActive(false);
|
|
_goScene.SetActive(false);
|
|
}
|
|
|
|
void OnBossBtnClick()
|
|
{
|
|
_goBoss.SetActive(true);
|
|
_goSpawnPoint.SetActive(true);
|
|
|
|
_goMinion.SetActive(false);
|
|
_goSkill.SetActive(false);
|
|
_goScene.SetActive(false);
|
|
}
|
|
|
|
void OnSkillBtnClick()
|
|
{
|
|
_goBoss.SetActive(false);
|
|
_goSpawnPoint.SetActive(false);
|
|
|
|
_goMinion.SetActive(false);
|
|
_goSkill.SetActive(true);
|
|
_goScene.SetActive(false);
|
|
}
|
|
|
|
void OnSceneBtnClick()
|
|
{
|
|
_goBoss.SetActive(false);
|
|
_goSpawnPoint.SetActive(false);
|
|
|
|
_goMinion.SetActive(false);
|
|
_goSkill.SetActive(false);
|
|
_goScene.SetActive(true);
|
|
}
|
|
|
|
void OnDaddyToggleValueChanged(bool value)
|
|
{
|
|
|
|
}
|
|
|
|
void OnPauseToggleValueChanged(bool value)
|
|
{
|
|
Time.timeScale = value ? 0f : 1f;
|
|
}
|
|
|
|
void SpawnMinion(int id, int spawnPointIndex)
|
|
{
|
|
var spawnPoint = GameLevel.Instance.GetSpawnPoint(spawnPointIndex);
|
|
GameLevel.Instance.SpawnMinion(id, spawnPoint);
|
|
}
|
|
|
|
void SpawnBoss(int id, int spawnPointIndex)
|
|
{
|
|
var spawnPoint = GameLevel.Instance.GetSpawnPoint(spawnPointIndex);
|
|
GameLevel.Instance.SpawnBoss(id, spawnPoint);
|
|
}
|
|
|
|
void StudySkill(int id)
|
|
{
|
|
MovesShop.Instance.StudyMoves(new int[] { id });
|
|
}
|
|
|
|
void ReplaceScene(string mapAsset)
|
|
{
|
|
StartCoroutine(GameLevel.Instance.LoadStageCO(mapAsset));
|
|
}
|
|
|
|
void OnControlBtnClick()
|
|
{
|
|
_goEditor.SetActive(!_goEditor.activeSelf);
|
|
_txtControl.text = _goEditor.activeSelf ? "隐藏" : "显示";
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Unity &&
|
|
|
|
// Use this for initialization
|
|
private void Awake()
|
|
{
|
|
_Instance = this;
|
|
SetViewData();
|
|
|
|
_btnControl.onClick.AddListener(OnControlBtnClick);
|
|
|
|
__listMinions.AddTemplate<TextWidget>(true);
|
|
__listBosses.AddTemplate<TextWidget>(true);
|
|
__listSkills.AddTemplate<TextWidget>(true);
|
|
__listScenes.AddTemplate<TextWidget>(true);
|
|
|
|
_btnBoss.onClick.AddListener(this.OnBossBtnClick);
|
|
_btnMinion.onClick.AddListener(this.OnMinionBtnClick);
|
|
_btnSkill.onClick.AddListener(this.OnSkillBtnClick);
|
|
_btnScene.onClick.AddListener(this.OnSceneBtnClick);
|
|
_tgPause.onValueChanged.AddListener(this.OnPauseToggleValueChanged);
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
Refresh();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
private void Update()
|
|
{
|
|
if (_tgDaddy.isOn && EntityMainPlayer.Instance)
|
|
{
|
|
EntityMainPlayer.Instance.invincible = true;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Static
|
|
|
|
static BattleEditor _Instance;
|
|
|
|
public static void Show()
|
|
{
|
|
if (_Instance)
|
|
_Instance.gameObject.SetActive(true);
|
|
else
|
|
{
|
|
var prefab = Resources.Load<GameObject>("BattleEditor");
|
|
if (prefab)
|
|
Instantiate(prefab).SetActive(true);
|
|
}
|
|
}
|
|
|
|
public static void Hide()
|
|
{
|
|
if (_Instance)
|
|
_Instance.gameObject.SetActive(false);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endif
|
|
}
|
|
}
|