Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Olly · Jan 12, 2016 at 09:35 PM · c#unity 5script.color

Accessing color presets in c# script.

I have many hex color presets that I'm tweaking in the game to get some nice effects. Thing is, lots of my particles relay on script that sets their colors. At the moment I have to store each of the presets as hex constants which is really inefficient.

My question, Can I access the presets in C# script? Something like Presets.RedPreset etc etc ?

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 Ronnie_0 · Jan 03, 2018 at 12:24 AM

@Olly, looks like there is a class called ColorPresetLibrary, but it's not accessible via code. However, you can work around that by using a SerializedObject.

For this example, I have a color preset saved in my project at Assets/Editor/UI Colors.color.

 string colorPresetPath = "Assets/Editor/UI Colors.colors";
 UnityEngine.Object presetObject = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(colorPresetPath);
 SerializedObject so = new SerializedObject(presetObject);
 SerializedProperty presets = so.FindProperty("m_Presets");
 SerializedProperty firstElement= presets.GetArrayElementAtIndex(0);
 Debug.Log(firstElement.FindPropertyRelative("m_Color").colorValue);


Comment
Add comment · Show 1 · 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 dizzymediainc · Oct 03, 2020 at 05:28 AM 0
Share

Just found this while trying to access my custom Curve Preset Library and was able to use your method with a slight tweak to get it working, cheers!

             SerializedObject so = new SerializedObject(presetObject);
             
             SerializedProperty presets = so.FindProperty("m_Presets");
             SerializedProperty firstElement = presets.GetArrayElementAtIndex(0);
             SerializedProperty newCurve = firstElement.FindPropertyRelative("m_Curve");
 
             AnimationCurve curveSkirt = newCurve.animationCurveValue;

and then the usage:

newDynamBone.m_RadiusDistrib = curveSkirt;

The whole thing is pretty interesting, was previously trying to access values directly through the curve library but it stated the values were inaccessible, so serialization was the best method. With the animationCurveValue in SerializedProperty scripting docs makes that even more apparent.

But yea cheers again and will be playing with this more often :P

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

6 People are following this question.

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

Related Questions

How to change a buttons color? 2 Answers

c# How Do I disable current script or anyother script in the program within code? 2 Answers

GameObject keeps acting like gameObject. 1 Answer

character not moving forward 1 Answer

Problem with all my scripts (Not Working Properly) 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