Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by NarallandaKaratoga · Jan 22 at 01:29 PM · assetimporting assetstextasset

How to make a custom TextAsset?

I simply write in ScriptedImporter:

         var t = new LuaScriptAsset(content);
         ctx.AddObjectToAsset("Content", t);

where LuaScriptAsset is:

         public class LuaScriptAsset : TextAsset { ... }

Unity looks not recognize the type "LuaScriptAsset".

In MonoBehaviour script I write

         public LuaScriptAsset script;

I can't drag my script asset to the object field in inspector; but using TextAsset could do.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Pangamini · Jan 23 at 12:29 AM

I don't think you can extend the TextAsset class in this way, just like you can't extend other Unity's built-in classes (such as Collider). There are only few classes that derive from UnityEngine.Object that you can extend further (and have them properly used by the engine), such as MonoBehaviour, ScriptableObject and those derived from them (such as EditorWindow and StateMachineBehaviour). If you want to create a custom asset type, start from ScriptableObject, if you want to create a custom component, start from MonoBehaviour.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image NarallandaKaratoga · Jan 23 at 12:56 AM 0
Share

Lua file is text format source file. That's why I'm trying to extend TextAsset. It's neither ScriptableObject asset (yaml format .asset file), nor MonoBehaviour (C# source format .cs sfile). I simply want to attach some configuration to each lua file; Creating a scriptable object for each lua file could be messy.

avatar image NarallandaKaratoga NarallandaKaratoga · Jan 23 at 01:29 AM 0
Share

Oh wait I misunderstand it. I can attach ScriptableObject to Lua file and set it to main... It works well..

avatar image Pangamini NarallandaKaratoga · Jan 23 at 01:35 AM 0
Share

It doesn't have to be. Either create a ScriptableObject that has a serialized reference to the lua TextAsset, or have a serialized string property with the actual lua code. Make the creation of them automatic by some editor scripts. But you really can't extend TextAsset class. Anyway, I always considered the benefits of using lua to be mostly that you can change them after the game is built, to load them dynamically (so players can mod the game, for example). Your textAssets will be baked into the build's resource files, and thus won't be present as separate *.lua files. If you want to achieve that, the easiest way is to use Strea$$anonymous$$gAssets and simply load the files ingame using System.IO.File or something.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

135 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to assign variables like Texture2D, TextAsset, Transform, etc. using code? 1 Answer

Loading TextAsset returns null 1 Answer

Importing meshes during runtime from a server 0 Answers

Change pixels per unit for an imported asseet, but only on x axis 1 Answer

Import obj and mtl file with more textures than one? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges