ScriptableObject
ScriptableObject 是一个可独立于类实例来保存大量数据的数据容器。
1.继承?ScriptableObject
2.CreateAssetMenu特性右键创建或者ScriptableObject.CreateInstance<>()代码创建
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "Data", menuName = "ScriptableObjects/ScriptObjectExample", order = 1)]
public class ScriptObjectExample : ScriptableObject
{
public AnimationCurve curve;
public Vector3[] spawnPoints;
}
EditorPrefs
存储和访问 Unity 编辑器偏好设置.。(编辑器版的PlayerPrefs)?
UnityEditor.EditorPrefs - Unity 脚本 APIhttps://docs.unity.cn/cn/current/ScriptReference/EditorPrefs.html
using UnityEngine;
using UnityEditor;
public class ExampleClass : EditorWindow
{
string note = "Notes:\n->\n->";
[MenuItem("Examples/QuickNotes")]
static void Init()
{
ExampleClass window = (ExampleClass)EditorWindow.GetWindow(typeof(ExampleClass));
window.Show();
}
void OnGUI()
{
note = EditorGUILayout.TextArea(note,
GUILayout.Width(position.width - 5),
GUILayout.Height(position.height - 30));
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Reset"))
note = "";
if (GUILayout.Button("Clear Story", GUILayout.Width(72)))
{
note = "Notes:\n->\n->";
}
EditorGUILayout.EndHorizontal();
}
void OnFocus()
{
if (EditorPrefs.HasKey("QuickNotes"))
note = EditorPrefs.GetString("QuickNotes");
}
void OnLostFocus()
{
EditorPrefs.SetString("QuickNotes", note);
}
void OnDestroy()
{
EditorPrefs.SetString("QuickNotes", note);
}
}
编辑器交流讨论群:782290296? ? ? https://jq.qq.com/?_wv=1027&k=A4HYmFPh
|