248 lines
10 KiB
C#
248 lines
10 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace Thousandto.SkillEditor.DIY
|
|
{
|
|
//技能播放器UI
|
|
public class SkillEditorPlayerUI
|
|
{
|
|
#region//界面
|
|
public static void OnGUI()
|
|
{
|
|
if (_fastSkillNames == null)
|
|
{
|
|
_fastSkillNames = new List<string>[6];
|
|
for (int i = 0; i < _fastSkillNames.Length; ++i)
|
|
{
|
|
var skillParams = PlayerPrefs.GetString(string.Format("EditorFastSkill{0}", i));
|
|
_fastSkillNames[i] = new List<string>();
|
|
if (!string.IsNullOrEmpty(skillParams))
|
|
{
|
|
var skills = skillParams.Split(';');
|
|
for (int j = 0; j < skills.Length; ++j)
|
|
{
|
|
_fastSkillNames[i].Add(skills[j]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
GUILayout.Label("技能释放者");
|
|
_selectUserModelType = EditorGUILayout.Popup(_selectUserModelType, _skillModels);
|
|
EditorGUILayout.BeginHorizontal();
|
|
GUILayout.Label("模型ID", GUILayout.Width(60));
|
|
_inputUserModelID = EditorGUILayout.IntField(_inputUserModelID, GUILayout.Width(150));
|
|
EditorGUILayout.EndHorizontal();
|
|
EditorGUILayout.BeginHorizontal();
|
|
GUILayout.Label("缩放", GUILayout.Width(60));
|
|
_userScale = EditorGUILayout.FloatField(_userScale, GUILayout.Width(150));
|
|
EditorGUILayout.EndHorizontal();
|
|
EditorGUILayout.BeginHorizontal();
|
|
GUILayout.Label("移动速度", GUILayout.Width(60));
|
|
_userMoveSpeed = EditorGUILayout.FloatField(_userMoveSpeed, GUILayout.Width(150));
|
|
EditorGUILayout.EndHorizontal();
|
|
if (GUILayout.Button("载入"))
|
|
{
|
|
if (!SkillEditorScene.LoadModel(true, _selectUserModelType, _inputUserModelID, 1, _userScale, _userMoveSpeed))
|
|
{
|
|
_userLoadErrorText = "载入使用者模型失败!";
|
|
}
|
|
else
|
|
{
|
|
_userLoadErrorText = string.Empty;
|
|
}
|
|
}
|
|
if(SkillEditorScene.LocalUser != null)
|
|
{
|
|
EditorGUILayout.BeginHorizontal();
|
|
GUILayout.Label("载入武器", GUILayout.Width(50));
|
|
_inputUserWeaponID = EditorGUILayout.IntField(_inputUserWeaponID, GUILayout.Width(90));
|
|
if (GUILayout.Button("载入", GUILayout.Width(50)))
|
|
{
|
|
if (!SkillEditorScene.LocalUser.LoadWeapon(_inputUserWeaponID))
|
|
{
|
|
_userLoadErrorText = "载入武器模型失败!";
|
|
}
|
|
else
|
|
{
|
|
_userLoadErrorText = string.Empty;
|
|
}
|
|
}
|
|
EditorGUILayout.EndHorizontal();
|
|
}
|
|
|
|
GUI.color = Color.red;
|
|
GUILayout.Label(_userLoadErrorText);
|
|
GUI.color = Color.white;
|
|
|
|
GUILayout.Space(30);
|
|
GUILayout.Label("技能受击者");
|
|
_selectTargetModelType = EditorGUILayout.Popup(_selectTargetModelType, _skillModels);
|
|
EditorGUILayout.BeginHorizontal();
|
|
GUILayout.Label("模型ID", GUILayout.Width(60));
|
|
_inputTargetModelID = EditorGUILayout.IntField(_inputTargetModelID, GUILayout.Width(150));
|
|
EditorGUILayout.EndHorizontal();
|
|
EditorGUILayout.BeginHorizontal();
|
|
GUILayout.Label("缩放", GUILayout.Width(60));
|
|
_targetScale = EditorGUILayout.FloatField(_targetScale, GUILayout.Width(150));
|
|
EditorGUILayout.EndHorizontal();
|
|
if (GUILayout.Button("载入"))
|
|
{
|
|
if (!SkillEditorScene.LoadModel(false, _selectTargetModelType, _inputTargetModelID, 1, _targetScale))
|
|
{
|
|
_targetLoadErrorText = "载入受击者模型失败!";
|
|
}
|
|
else
|
|
{
|
|
_targetLoadErrorText = string.Empty;
|
|
}
|
|
}
|
|
if (GUILayout.Button("载入10个"))
|
|
{
|
|
if (!SkillEditorScene.LoadModel(false, _selectTargetModelType, _inputTargetModelID, 10, _targetScale))
|
|
{
|
|
_targetLoadErrorText = "载入受击者模型失败!";
|
|
}
|
|
else
|
|
{
|
|
_targetLoadErrorText = string.Empty;
|
|
}
|
|
}
|
|
if (GUILayout.Button("随机载入10个怪物"))
|
|
{
|
|
for (int i = 0; i < 10; ++i)
|
|
{
|
|
if (!SkillEditorScene.LoadModel(false, 1, UnityEngine.Random.Range(1, 98)))
|
|
{
|
|
_targetLoadErrorText = "载入受击者模型失败!";
|
|
}
|
|
else
|
|
{
|
|
_targetLoadErrorText = string.Empty;
|
|
}
|
|
}
|
|
}
|
|
if (GUILayout.Button("清除所有怪物"))
|
|
{
|
|
SkillEditorScene.ClearAllMonster();
|
|
}
|
|
GUI.color = Color.red;
|
|
GUILayout.Label(_targetLoadErrorText);
|
|
GUI.color = Color.white;
|
|
|
|
GUILayout.Label("快捷技能设置");
|
|
_selectFastKeyIndex = EditorGUILayout.Popup(_selectFastKeyIndex, _fastKeyNames);
|
|
var list = _fastSkillNames[_selectFastKeyIndex];
|
|
for (int i = 0; i < list.Count; ++i)
|
|
{
|
|
EditorGUILayout.BeginHorizontal();
|
|
GUILayout.Label(list[i]);
|
|
if(GUILayout.Button("X", GUILayout.Width(30)))
|
|
{
|
|
list.RemoveAt(i);
|
|
StringBuilder sb = new StringBuilder();
|
|
for (int j = 0; j < list.Count; ++j)
|
|
{
|
|
sb.Append(list[j]);
|
|
if (j < list.Count - 1)
|
|
{
|
|
sb.Append(';');
|
|
}
|
|
}
|
|
PlayerPrefs.SetString(string.Format("EditorFastSkill{0}", _selectFastKeyIndex), sb.ToString());
|
|
break;
|
|
}
|
|
EditorGUILayout.EndHorizontal();
|
|
}
|
|
_fastSkillEditText = EditorGUILayout.TextField(_fastSkillEditText);
|
|
if (GUILayout.Button("保存"))
|
|
{
|
|
var skill = SkillEditorData.FindSkill(_fastSkillEditText);
|
|
if (skill != null)
|
|
{
|
|
list.Add(_fastSkillEditText);
|
|
_fastSkillEditText = string.Empty;
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
for (int i = 0; i < list.Count; ++i)
|
|
{
|
|
sb.Append(list[i]);
|
|
if (i < list.Count - 1)
|
|
{
|
|
sb.Append(';');
|
|
}
|
|
}
|
|
PlayerPrefs.SetString(string.Format("EditorFastSkill{0}", _selectFastKeyIndex), sb.ToString());
|
|
}
|
|
else
|
|
{
|
|
EditorUtility.DisplayDialog("提示", "输入的技能不存在!", "确定");
|
|
}
|
|
}
|
|
|
|
//GUILayout.Space(80);
|
|
for (int i = 0; i < 3; ++i)
|
|
{
|
|
EditorGUILayout.BeginHorizontal();
|
|
if (GUILayout.Button(string.Format("快捷键{0}", i * 2 + 1), GUILayout.Width(80), GUILayout.Height(80)))
|
|
{
|
|
if (SkillEditorScene.LocalUser != null)
|
|
{
|
|
SkillEditorScene.LocalUser.StopAllSkill();
|
|
var useSkillList = _fastSkillNames[i * 2];
|
|
for (int j = 0; j < useSkillList.Count; ++j)
|
|
{
|
|
var skillInfo = SkillEditorData.FindSkill(useSkillList[j]);
|
|
if (skillInfo != null)
|
|
{
|
|
SkillEditorScene.LocalUser.UseSkill(skillInfo);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (GUILayout.Button(string.Format("快捷键{0}", i * 2 + 2), GUILayout.Width(80), GUILayout.Height(80)))
|
|
{
|
|
if (SkillEditorScene.LocalUser != null)
|
|
{
|
|
SkillEditorScene.LocalUser.StopAllSkill();
|
|
var useSkillList = _fastSkillNames[i * 2 + 1];
|
|
for (int j = 0; j < useSkillList.Count; ++j)
|
|
{
|
|
var skillInfo = SkillEditorData.FindSkill(useSkillList[j]);
|
|
if (skillInfo != null)
|
|
{
|
|
SkillEditorScene.LocalUser.UseSkill(skillInfo);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
EditorGUILayout.EndHorizontal();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region//私有变量
|
|
private static string[] _skillModels = new string[] { "玩家模型", "怪物模型" };
|
|
private static int _selectUserModelType = 0;
|
|
private static int _inputTargetModelID = 0;
|
|
private static string _userLoadErrorText = string.Empty;
|
|
|
|
private static int _selectTargetModelType = 1;
|
|
private static int _inputUserModelID = 0;
|
|
private static string _targetLoadErrorText = string.Empty;
|
|
|
|
private static int _inputUserWeaponID = 0;
|
|
private static float _userScale = 1f;
|
|
private static float _userMoveSpeed = 6f;
|
|
|
|
private static int _selectFastKeyIndex = 0;
|
|
private static string[] _fastKeyNames = new string[] { "快捷键1", "快捷键2", "快捷键3", "快捷键4", "快捷键5", "快捷键6" };
|
|
private static List<string>[] _fastSkillNames = null;
|
|
private static string _fastSkillEditText = string.Empty;
|
|
private static float _targetScale = 1f;
|
|
#endregion
|
|
}
|
|
}
|