Skip to content

ZeroUltra/UnityScriptableObjectSingleton

Repository files navigation

Unity ScriptableObjectSingleton

说明

unity中的ScriptableSingleton

unity中存在一个ScriptableSingleton

但是他有点难用

  • hideflag 为 dontsave
  • 并不会监听创建时是否已存在
  • ....

如何使用

  • 如果是Editor的ScriptableObject可直接继承ScriptableObjectSingletonEditor使用,(也可以不继承,但是必须要实现ISingletion接口)
  • 如果是Runtime的ScriptableObject需要实现ISingletion接口

示例:

using System.Collections;
using UnityEngine;
using UnityScriptableObjectSingleton.Editor;
using UnityScriptableObjectSingleton.Runtime;
/// <summary>
/// ____DESC:      
/// </summary>
[CreateAssetMenu(fileName = "TestScriptableObjectSingleton", menuName = "Test/TestScriptableObjectSingleton", order = 0)]
public class TestScriptableObjectSingleton : ScriptableObject, ISingletion
{
    //手动实现Instance
    private static TestScriptableObjectSingleton _instance;
    public static TestScriptableObjectSingleton Instance
    {
        get
        {
            if (_instance == null)
            {
                _instance = Resources.Load<TestScriptableObjectSingleton>("TestScriptableObjectSingleton");
                if (_instance == null)
                {
                    Debug.LogError("Can't find the instance of TestScriptableObjectSingleton");
                }
            }
            return _instance;
        }
    }
    public int value;
}
using System.Collections;
using UnityEngine;
using UnityScriptableObjectSingleton.Editor;
/// <summary>
/// ____DESC:      
/// </summary>
[CreateAssetMenu(fileName = "TestEditorScriptableObjectSingleton", menuName = "Test/TestEditorScriptableObjectSingleton", order = 0)]

public class TestEditorScriptableObjectSingleton : ScriptableObjectSingletonEditor<TestEditorScriptableObjectSingleton>
{
    public int value;
}

具体可查看Samples里面的示例

About

No description or website provided.

Topics

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages