Gameplay Ingredients是一组用于 Unity 游戏的运行时和编辑器工具:一组脚本的集合,可在制作游戏和原型时简化简单的任务。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

73 行
2.2 KiB

using UnityEditor;
using UnityEngine;
namespace GameplayIngredients.Comments.Editor
{
[CustomEditor(typeof(SceneComment))]
public class SceneCommentEditor : UnityEditor.Editor
{
[SerializeField]
SceneComment sceneComment;
[SerializeField]
SerializedProperty m_Comment;
[SerializeField]
CommentEditor m_CommentEditor;
public static void RequestEdit() { m_NeedEditNext = true; }
public static bool m_NeedEditNext = false;
private void OnEnable()
{
UpdateComment();
if(sceneComment.comment.focus && SceneView.lastActiveSceneView != null)
SceneView.lastActiveSceneView.AlignViewToObject(sceneComment.transform);
}
void UpdateComment()
{
if (m_Comment == null)
m_Comment = serializedObject.FindProperty("m_Comment");
if (m_CommentEditor == null)
m_CommentEditor = new CommentEditor(serializedObject, m_Comment);
sceneComment = (serializedObject.targetObject as SceneComment);
}
public override void OnInspectorGUI()
{
UpdateComment();
GUILayout.Space(4);
m_CommentEditor.DrawComment(sceneComment.comment, m_NeedEditNext);
if (m_NeedEditNext)
m_NeedEditNext = false;
GUILayout.Space(16);
}
[MenuItem("GameObject/Comment", false, 10)]
public static void CreateComment()
{
var go = new GameObject("Comment", typeof(SceneComment));
if (Selection.activeGameObject != null && Selection.activeGameObject.scene != null)
{
go.transform.parent = Selection.activeGameObject.transform;
}
if (SceneView.lastActiveSceneView != null)
{
var cam = SceneView.lastActiveSceneView.camera;
go.transform.position = cam.transform.position;
go.transform.rotation = cam.transform.rotation;
}
Selection.activeGameObject = go;
go.GetComponent<SceneComment>().SetDefault();
SceneCommentEditor.RequestEdit();
}
}
}