Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by DocteurCox · Jun 10, 2013 at 11:05 AM · audioassetclipfmod

Create a custom asset type ?

Hello there,

Thanks to a .NET plugin I found on the net, I'm reimplementing Unity sound system (AudioSource, DSPs, Spatialization etc. ) with FMOD for a personnal project. To make the use of that custom system easier, I would like to create a new asset type (pretty much like AudioClip) which would define if the sound should be streamed or fully loaded, its length, its path etc. everything needed by my custom AudioSource to know what to do.

Is there a way I can do that in Unity ?

Thanks in advance for your answers :)

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
2

Answer by Leslie-Young · Jun 10, 2013 at 11:41 AM

Yes, you can. I'm not sure just how much you can do custom assets yet since I needed it for pretty basic stuff and can get away with Unity serializing the data for me.

Here's some code to get you started in your research. I use these to create my custom .asset files.

 /// <summary> will create the asset file if it does not exist and add the object and save the file</summary>
 public static void AddObjectToAssetFile(Object obj, string assetFile)
 {
     if (!RelativeFileExist(assetFile))
     {
         AssetDatabase.CreateAsset(obj, assetFile);
     }
     else
     {
         AssetDatabase.AddObjectToAsset(obj, assetFile);
         AssetDatabase.ImportAsset(assetFile); // force a save
     }
 }
 
 /// <summary>
 /// will create a new asset of the type, save it and return a reference to it. 
 /// assetFile should be a relative path to the file to store the new asset in
 /// if createNewIfExist then a unique name will be generated if the file allready
 /// exist and the asset will be saved there
 /// </summary>
 public static UnityEngine.Object CreateAsset(System.Type type, string objectName, string assetFile, bool createNewIfExist)
 {
     Object obj = ScriptableObject.CreateInstance(type);
     obj.name = objectName;
 
     if (!RelativeFileExist(assetFile))
     {
         AssetDatabase.CreateAsset(obj, assetFile);
     }
     else
     {
         if (createNewIfExist)
         {
             string fn = AssetDatabase.GenerateUniqueAssetPath(assetFile);
             AssetDatabase.CreateAsset(obj, fn);
         }
         else
         {
             AssetDatabase.AddObjectToAsset(obj, assetFile);
             AssetDatabase.ImportAsset(assetFile); // force a save
         }
     }
 
     return obj;
 }

To use it I do something like this. Attribute is a class that is derived from ScriptableObject and contains a bunch of public variables that can be serialized/ deserialized by unity.

 curr = ScriptableObject.CreateInstance<Attribute>();
 SomeClassName.AddObjectToAssetFile(curr, "Assets/SomeData/Attributes.asset");

That is how I create/save my custom assets. Have a look AssetDatabase to see how you can load 'em or simply save a reference like you would a prefab, if that is possible.

Comment
Add comment · Show 2 · 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 DocteurCox · Jun 10, 2013 at 01:53 PM 0
Share

Thanks for your answer. I will have a look at it :)

avatar image Bunny83 · Jun 10, 2013 at 02:00 PM 0
Share

Also have a look at AssetPostprocessor.OnPostprocessAudio. It will be called whenever an AudioClip is imported. I'm not sure if you can add sub assets to AudioClips, but i guess it should work.

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

16 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

Related Questions

Audio source not playing 7 Answers

FMOD Distance Parameter: At 0 distance the sound is very quiet when it's supposed to be full volume? 0 Answers

How to get the AI enemy character to play random audio clips over time? 1 Answer

Random, 3d sound. 1 Answer

Getting at raw imported audio data via AssetDatabase. 1 Answer


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