Unity, created by Scriptableobject. Asset

Source: Internet
Author: User

Create a. asset file from Class X that inherits from Scriptableobject.

Suppose class X is defined as:

[System.serializable]

public class X:scriptableobject {
public float m_a;
}

Method One: Write code creation.

#if Unity_editor
String path = "Assets/resources/x.asset";
X scriptableobj = scriptableobject.createinstance<x> ();
UnityEditor.AssetDatabase.CreateAsset (scriptableobj, path);
UnityEditor.AssetDatabase.SaveAssets ();
UnityEditor.AssetDatabase.Refresh ();
#endif

(add: For X.asset created above, the loading notation is:

If loading with assetdatabase:

#if Unity_editor

UnityEditor.AssetDatabase.LoadAssetAtPath ("Assets/resources/x.asset");

#endif

If loading with resource.load:

Resources.load ("X");

Method Two: Created through the menu.

Adding the Createassetmenu property before class X automatically adds the corresponding menu item to the System create menu.

[Createassetmenu (filename= "x", Menuname= "(custom) x")]
[System.serializable]
public class X:scriptableobject {
public float m_a;
}

Reference:

http://baba-s.hatenablog.com/entry/2015/06/13/000000

Http://answers.unity3d.com/questions/1079664/how-do-i-use-the-createassetmenu-attribute.html

Unity, created by Scriptableobject. Asset

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.