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 Daxva · Sep 21, 2011 at 12:40 PM · prefabloadeditorwindowdata

Load Data from EditorWindow to Prefab

So I’ve created a EditorWindow where I can input some variable to set some settings that will later be used by a script. I store away the variables using the EditorPrefs.SetFloat(). What I wonder is how I can retrieve the variable from the script later. Can I use EditorPrefs or do I need to use something else?

Here is the script for the settings window:

 class PowerUpSettings : EditorWindow 

{ #region Members

 bool showAttackRange   = false;
 bool showEffectRange   = false;
 bool showPushForce     = false;
 bool showTime          = false;

 //Attack Range
 float rangeMelee    = 1;
 float rangeShort    = 5;
 float rangeMedium   = 10;
 float rangeLong     = 15;
 float rangeVeryLong = 20;

 //Effect Range
 float effectSmall   = 1.5f;
 float effectMedium  = 3f;
 float effectBig     = 5f;

 //Push Force
 float pushShort     = 2;
 float pushMedium    = 4;
 float pushLong      = 6;

 //Time
 float timeVeryShort = 1f;
 float timeShort     = 2.5f;
 float timeMedium    = 5f;
 float timeLong      = 10f;
 float timeVeryLong  = 15f;

 #endregion

 [MenuItem("Settings/Power Up Settings")]
 static void Init()
 {
     PowerUpSettings window = (PowerUpSettings)EditorWindow.GetWindow(typeof(PowerUpSettings));
 }

 void Awake()
 {
     LoadData();
 }

 void SaveData()
 {
     //Attack Range
     EditorPrefs.SetFloat("powerupAttackMelee", rangeMelee);
     EditorPrefs.SetFloat("powerupAttackShort", rangeShort);
     EditorPrefs.SetFloat("powerupAttackMedium", rangeMedium);
     EditorPrefs.SetFloat("powerupAttackLong", rangeLong);
     EditorPrefs.SetFloat("powerupAttackVeryLong", rangeVeryLong);

     //Effect Range
     EditorPrefs.SetFloat("powerupEffectSmall", effectSmall);
     EditorPrefs.SetFloat("powerupEffectMedium", effectMedium);
     EditorPrefs.SetFloat("powerupEffectBig", effectBig);

     //Push Force
     EditorPrefs.SetFloat("powerupPushShort", pushShort);
     EditorPrefs.SetFloat("powerupPushMedium", pushMedium);
     EditorPrefs.SetFloat("powerupPushLong", pushLong);

     //Time
     EditorPrefs.SetFloat("powerupTimeVeryShort", timeVeryShort);
     EditorPrefs.SetFloat("powerupTimeVShort", timeShort);
     EditorPrefs.SetFloat("powerupTimeMedium", timeMedium);
     EditorPrefs.SetFloat("powerupTimeLong", timeLong);
     EditorPrefs.SetFloat("powerupTimeVeryLong", timeVeryLong);
 }

 void LoadData()
 {
     //Attack Range
     rangeMelee = EditorPrefs.GetFloat("powerupAttackMelee", 1);
     rangeShort = EditorPrefs.GetFloat("powerupAttackShort", 5);
     rangeMedium = EditorPrefs.GetFloat("powerupAttackMedium", 10);
     rangeLong = EditorPrefs.GetFloat("powerupAttackLong", 15);
     rangeVeryLong = EditorPrefs.GetFloat("powerupAttackVeryLong", 20);

     //Effect Range
     effectSmall = EditorPrefs.GetFloat("powerupEffectSmall", 1.5f);
     effectMedium = EditorPrefs.GetFloat("powerupPushMedium", 3);
     effectBig = EditorPrefs.GetFloat("powerupPushLong", 5);

     //Push Force
     pushShort = EditorPrefs.GetFloat("powerupPushShort", 2);
     pushMedium = EditorPrefs.GetFloat("powerupPushMedium", 2);
     pushLong = EditorPrefs.GetFloat("powerupEffectBig", 2);

     //Time
     timeVeryShort = EditorPrefs.GetFloat("powerupTimeVeryShort", 1);
     timeShort = EditorPrefs.GetFloat("powerupTimeVShort", 2.5f);
     timeMedium = EditorPrefs.GetFloat("powerupTimeMedium", 5);
     timeLong = EditorPrefs.GetFloat("powerupTimeLong", 10);
     timeVeryLong = EditorPrefs.GetFloat("powerupTimeVeryLong", 15);
 }

 void OnGUI()
 {
     GUILayout.Label("Power Up Settings", EditorStyles.boldLabel);

     //Attack Range
     showAttackRange = EditorGUILayout.Foldout(showAttackRange, "Attack Range");
     if (showAttackRange)
     {
         rangeMelee = EditorGUILayout.FloatField("   Melee: ", rangeMelee);
         rangeShort = EditorGUILayout.FloatField("   Short: ", rangeShort);
         rangeMedium = EditorGUILayout.FloatField("   Medium: ", rangeMedium);
         rangeLong = EditorGUILayout.FloatField("   Long: ", rangeLong);
         rangeVeryLong = EditorGUILayout.FloatField("   Very Long: ", rangeVeryLong);
     }

     //Effect Range
     showEffectRange = EditorGUILayout.Foldout(showEffectRange, "Effect Range");
     if (showEffectRange)
     {
         effectSmall = EditorGUILayout.FloatField("   Small: ", effectSmall);
         effectMedium = EditorGUILayout.FloatField("   Medium: ", effectMedium);
         effectBig = EditorGUILayout.FloatField("   Big: ", effectBig);
     }

     //Push Force
     showPushForce = EditorGUILayout.Foldout(showPushForce, "Push Force");
     if (showPushForce)
     {
         pushShort = EditorGUILayout.FloatField("   Small: ", pushShort);
         pushMedium = EditorGUILayout.FloatField("   Medium: ", pushMedium);
         pushLong = EditorGUILayout.FloatField("   Long: ", pushLong);
     }

     //Time
     showTime = EditorGUILayout.Foldout(showTime, "Time");
     if (showTime)
     {
         timeVeryShort = EditorGUILayout.FloatField("   Very Short: ", timeVeryShort);
         timeShort = EditorGUILayout.FloatField("    Short: ", timeShort);
         timeMedium = EditorGUILayout.FloatField("   Medium: ", timeMedium);
         timeLong = EditorGUILayout.FloatField("   Long: ", timeLong);
         timeVeryLong = EditorGUILayout.FloatField("   Very Long: ", timeVeryLong);
     }

     EditorGUILayout.Space();
     EditorGUILayout.Space();

     if (GUILayout.Button("Apply", GUILayout.MaxWidth(50)))
     {
         SaveData();
     }
 }

}

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

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

Drawing prefab on scene for custom editor without instantiating it 0 Answers

How to load nested prefab? 1 Answer

Dynamically load json data to a game: What are the best practices? 1 Answer

Unespected rotation for Instantiate object 1 Answer

List all prefabs in project with a specific name 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