using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEditor;
|
using UnityEngine.UI;
|
|
|
public class NewBieGuideEditorWindow : EditorWindow
|
{
|
[MenuItem("程序/引导编辑器")]
|
public static void Create()
|
{
|
var window = GetWindow(typeof(NewBieGuideEditorWindow), false, "引导编辑器") as NewBieGuideEditorWindow;
|
window.Show();
|
window.autoRepaintOnSceneChange = true;
|
}
|
|
|
private void OnGUI()
|
{
|
if (!Application.isPlaying)
|
{
|
//重新编辑 EditorGUILayout
|
EditorGUILayout.BeginVertical();
|
GUILayout.Label("请先运行游戏");
|
EditorGUILayout.EndVertical();
|
return;
|
}
|
EditorGUILayout.BeginVertical();
|
|
EditorGUILayout.BeginHorizontal();
|
if (GUILayout.Button("拷贝组件路径到剪切板"))
|
{
|
GameObject go = Selection.activeGameObject;
|
if (go == null)
|
{
|
Debug.LogError("请先选择一个GameObject");
|
return;
|
}
|
|
|
// 获取 GameObject 的路径
|
string path = GetGameObjectPath(go);
|
|
// 拷贝到剪切板
|
GUIUtility.systemCopyBuffer = path;
|
Debug.Log("已拷贝到剪切板: " + path);
|
}
|
EditorGUILayout.EndHorizontal();
|
|
EditorGUILayout.BeginHorizontal();
|
|
if (GUILayout.Button("重置所有引导"))
|
{
|
NewBieCenter.Instance.ResetAllGuides();
|
}
|
|
if (GUILayout.Button("结束所有引导"))
|
{
|
NewBieCenter.Instance.CompleteAllGuides();
|
}
|
EditorGUILayout.EndHorizontal();
|
|
DrawNewbieGuides();
|
|
EditorGUILayout.EndVertical();
|
}
|
|
|
// 递归获取 GameObject 的路径
|
private static string GetGameObjectPath(GameObject obj)
|
{
|
if (obj == null)
|
return string.Empty;
|
|
if (obj.transform.parent == null)
|
{
|
return obj.name;
|
}
|
|
if (obj.transform.parent.name == "UIRoot")
|
{
|
// 如果父节点是 UIRoot,则返回当前节点的名称
|
return obj.name;
|
}
|
|
|
return GetGameObjectPath(obj.transform.parent.gameObject) + "/" + obj.name;
|
}
|
|
|
List<NewBieGuide> newbieGuides = null;
|
private Vector2 scrollPosition;
|
|
void DrawNewbieGuides()
|
{
|
if (newbieGuides == null)
|
{
|
newbieGuides = new List<NewBieGuide>();
|
var guides = GuideConfig.GetValues();
|
foreach (var config in guides)
|
{
|
if (config.PreGuideId == 0)
|
{
|
newbieGuides.Add(new NewBieGuide(config.ID));
|
}
|
}
|
}
|
|
if (newbieGuides != null)
|
{
|
scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, false);
|
foreach (var newbieGuide in newbieGuides)
|
{
|
EditorGUILayout.Space();
|
EditorGUILayout.BeginHorizontal();
|
|
EditorGUILayout.Space();
|
|
EditorGUILayout.LabelField("引导ID:" + newbieGuide.guideId);
|
|
EditorGUILayout.Toggle("Completed", newbieGuide.completed);
|
|
GUI.skin.button.normal.textColor = newbieGuide.guideId == NewBieCenter.Instance.currentGuide ? Color.red : Color.white;
|
|
if (GUILayout.Button("开始"))
|
{
|
newbieGuide.Begin();
|
}
|
|
GUI.skin.button.normal.textColor = Color.white;
|
if (GUILayout.Button("完成"))
|
{
|
newbieGuide.Finish();
|
}
|
|
if (GUILayout.Button("重置"))
|
{
|
newbieGuide.Reset();
|
}
|
|
EditorGUILayout.Space();
|
EditorGUILayout.EndHorizontal();
|
}
|
|
GUILayout.EndScrollView();
|
}
|
|
}
|
|
|
public class NewBieGuide
|
{
|
public int guideId;
|
public bool completed { get { return NewBieCenter.Instance.completeGuidesBuf.Contains(guideId); } }
|
|
public NewBieGuide(int _guideId)
|
{
|
guideId = _guideId;
|
}
|
|
public void Begin()
|
{
|
if (!NewBieCenter.Instance.CheckGuideCondition(guideId, true))
|
{
|
Debug.LogError("引导条件不满足");
|
return;
|
}
|
NewBieCenter.Instance.StartNewBieGuide(guideId);
|
}
|
|
public void Finish()
|
{
|
NewBieCenter.Instance.FinishNewBieGuide(guideId);
|
}
|
|
public void Reset()
|
{
|
NewBieCenter.Instance.ResetGuide(guideId);
|
}
|
}
|
|
|
|
}
|