• 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 RichHurst · Sep 15, 2014 at 08:33 PM · classloopeditor scripting

Custom editor script loop through class

Hi,

I am hoping someone might be able to help me, or point me in the right direction. I currently have a custom class called platform_mover which moves a platform depending on some options set. I am using a custom editor script to allow me to choose things such as the platform type (horizontal, vertical, rotation) via enums so that it is easy to place a prefab in and make a platform behave as desired. This all works, but I have recently changed my tween engine and it allows for sequences and I wish to expand my platform prefabs to have this option too.

So I want to now be able to choose a platform type called sequences that once chosen, provides me with a variable called sequences and that will determine how many different sequences and platform types displayed. I am assuming I want to use a loop to create the various fields like I did before, however, I'm not sure how I should do this correctly so that it creates individual dynamic ones as currently the code I have implemented is all linked to itself (which makes sense). Im guessing maybe I need to create an array or list but not sure how to fully implement it. Just incase this doesnt make sense I thought it would be useful to roughly outline it below...

(eg. platform type = sequencese, sequences = 2 { platform type = horizontal, time = 1, horizontal = 2, looptype = loop, ease = inoutquad} { platform type = vertical, time = .5, vertical = 2, looptype = loop, ease = inoutquad}

I have included the code for the editor script, although I am assuming I will need to alter the platform_mover class too, but all that really does at the moment is handle the enums, variables and tweens accordingly, I think I should be able to handle that once I am pointed in the right direction.

Any help is welcome and I apologise in advance if this hurts someone else's head trying to read / understand as it has mine trying to write and explain.

Thanks

Rich using UnityEditor; using UnityEngine;

 [CustomEditor(typeof(platform_mover)), CanEditMultipleObjects]
 public class platformEditor : Editor {
  
     public SerializedProperty 
         platform_Prop,
           time_Prop,
         horizontal_Prop,
         vertical_Prop,
         rotation_Prop,
         hold_pause_Prop,
         ease_Prop,
         loop_Prop,
         sequences_Prop;
         
     void OnEnable () {
         // Setup the SerializedProperties
            platform_Prop = serializedObject.FindProperty ("Platform");
            time_Prop = serializedObject.FindProperty("time");
         horizontal_Prop = serializedObject.FindProperty("horizontal");
         vertical_Prop = serializedObject.FindProperty("vertical");
         rotation_Prop = serializedObject.FindProperty("rotation");
         hold_pause_Prop = serializedObject.FindProperty("hold_pause");
         ease_Prop = serializedObject.FindProperty("ease");
         loop_Prop = serializedObject.FindProperty("loop");
         sequences_Prop = serializedObject.FindProperty("sequences");
     }
 
  
     public override void OnInspectorGUI() {
        serializedObject.Update ();
  
        EditorGUILayout.PropertyField( platform_Prop );
  
        platform_mover.platformType st = (platform_mover.platformType)platform_Prop.enumValueIndex;
  
        switch( st ) {
        case platform_mover.platformType.Type1:        
          //EditorGUILayout.PropertyField( controllable_Prop, new GUIContent("controllable") );       
             EditorGUILayout.PropertyField (time_Prop, new GUIContent("time"));
             EditorGUILayout.PropertyField (horizontal_Prop, new GUIContent("horizontal"));
             EditorGUILayout.PropertyField (hold_pause_Prop, new GUIContent("pause length"));
             EditorGUILayout.PropertyField( ease_Prop, new GUIContent("ease") );
             EditorGUILayout.PropertyField( loop_Prop, new GUIContent("loop") );
 
          //EditorGUILayout.IntSlider ( valForAB_Prop, 0, 100, new GUIContent("valForAB") );
          break;
  
        case platform_mover.platformType.Type2:        
          //EditorGUILayout.FloatField ( time_Prop, 0, 10, new GUIContent("time") );
             EditorGUILayout.PropertyField (time_Prop, new GUIContent("time"));
             EditorGUILayout.PropertyField (vertical_Prop, new GUIContent("vertical"));    
             EditorGUILayout.PropertyField (hold_pause_Prop, new GUIContent("pause length"));    
             EditorGUILayout.PropertyField( ease_Prop, new GUIContent("ease") );        
             EditorGUILayout.PropertyField( loop_Prop, new GUIContent("loop") );
          break;
  
        case platform_mover.platformType.Type3:        
          //EditorGUILayout.FloatField ( time_Prop, 0, 10, new GUIContent("time") );
             EditorGUILayout.PropertyField (time_Prop, new GUIContent("time"));
             EditorGUILayout.PropertyField (rotation_Prop, new GUIContent("rotation"));
             EditorGUILayout.PropertyField (hold_pause_Prop, new GUIContent("pause length"));
             EditorGUILayout.PropertyField( ease_Prop, new GUIContent("ease") );
             EditorGUILayout.PropertyField( loop_Prop, new GUIContent("loop") );
          break;
         
         case platform_mover.platformType.Off:        
             //EditorGUILayout.PropertyField( controllable_Prop, new GUIContent("controllable") );       
             //            EditorGUILayout.PropertyField (time_Prop, new GUIContent("time"));
             //            EditorGUILayout.PropertyField (horizontal_Prop, new GUIContent("horizontal"));
             //            EditorGUILayout.PropertyField (hold_pause_Prop, new GUIContent("pause length"));
             //            EditorGUILayout.PropertyField( ease_Prop, new GUIContent("ease") );
             //            EditorGUILayout.PropertyField( loop_Prop, new GUIContent("loop") );
             
             //EditorGUILayout.IntSlider ( valForAB_Prop, 0, 100, new GUIContent("valForAB") );
             break;
 
         case platform_mover.platformType.Sequence:    
             EditorGUILayout.PropertyField (sequences_Prop, new GUIContent("sequences"));
             int i;
             for (i=0; i < sequences_Prop.intValue; i++) {
 
                 EditorGUILayout.PropertyField( platform_Prop, new GUIContent("platform"+i) );
                 //platform_mover.platformType str = (platform_mover.platformType)platform_Prop.enumValueIndex;
                 platform_mover.platformType str = new platform_mover.platformType();
 
                 switch( str ) {
                 case platform_mover.platformType.Type1:        
                     //EditorGUILayout.PropertyField( controllable_Prop, new GUIContent("controllable") ); 
                     EditorGUILayout.LabelField(new GUIContent("platform"+i));
                     EditorGUILayout.PropertyField (time_Prop, new GUIContent("time"));
                     EditorGUILayout.PropertyField (horizontal_Prop, new GUIContent("horizontal"));
                     EditorGUILayout.PropertyField (hold_pause_Prop, new GUIContent("pause length"));
                     EditorGUILayout.PropertyField( ease_Prop, new GUIContent("ease") );
                     EditorGUILayout.PropertyField( loop_Prop, new GUIContent("loop") );
                     
                     //EditorGUILayout.IntSlider ( valForAB_Prop, 0, 100, new GUIContent("valForAB") );
                     break;
                     
                 case platform_mover.platformType.Type2:        
                     //EditorGUILayout.FloatField ( time_Prop, 0, 10, new GUIContent("time") );
                     EditorGUILayout.PropertyField (time_Prop, new GUIContent("time"));
                     EditorGUILayout.PropertyField (vertical_Prop, new GUIContent("vertical"));    
                     EditorGUILayout.PropertyField (hold_pause_Prop, new GUIContent("pause length"));    
                     EditorGUILayout.PropertyField( ease_Prop, new GUIContent("ease") );        
                     EditorGUILayout.PropertyField( loop_Prop, new GUIContent("loop") );
                     break;
                     
                 case platform_mover.platformType.Type3:        
                     //EditorGUILayout.FloatField ( time_Prop, 0, 10, new GUIContent("time") );
                     EditorGUILayout.PropertyField (time_Prop, new GUIContent("time"));
                     EditorGUILayout.PropertyField (rotation_Prop, new GUIContent("rotation"));
                     EditorGUILayout.PropertyField (hold_pause_Prop, new GUIContent("pause length"));
                     EditorGUILayout.PropertyField( ease_Prop, new GUIContent("ease") );
                     EditorGUILayout.PropertyField( loop_Prop, new GUIContent("loop") );
                     break;
                     
                 case platform_mover.platformType.Off:        
                     //EditorGUILayout.PropertyField( controllable_Prop, new GUIContent("controllable") );       
                     //            EditorGUILayout.PropertyField (time_Prop, new GUIContent("time"));
                     //            EditorGUILayout.PropertyField (horizontal_Prop, new GUIContent("horizontal"));
                     //            EditorGUILayout.PropertyField (hold_pause_Prop, new GUIContent("pause length"));
                     //            EditorGUILayout.PropertyField( ease_Prop, new GUIContent("ease") );
                     //            EditorGUILayout.PropertyField( loop_Prop, new GUIContent("loop") );
                     
                     //EditorGUILayout.IntSlider ( valForAB_Prop, 0, 100, new GUIContent("valForAB") );
                     break;
                 }
             }
 
             break; 
        }
  
  
        serializedObject.ApplyModifiedProperties ();
     }
 }
Comment
Add comment · Show 2
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 VesuvianPrime · Sep 15, 2014 at 08:46 PM 0
Share

Am I correct in saying you want the following hierarchy:

 public class Platform$$anonymous$$over : $$anonymous$$onoBehaviour
 {
     public List<Sequence> sequences;
 }

And you simply want to know how to present that in the inspector?

avatar image RichHurst · Sep 15, 2014 at 09:56 PM 0
Share

Sorry, no I don't think that's it unfortunately... I think my confusion with this is that I kind of want to have an array / list of the class of platform_mover inside the editor script, but that editor script handles platform_mover... The script posted in original post sort of works and generates a number of platform_mover sets but if you change one property it changes them all...

Thank you for replying though and I apologise for the bad explanation...

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to store children of a class inside that class 0 Answers

Method containing while loop in custom class? 1 Answer

How Reset Variable After Loop 1 Answer

Implementing an Item system - Defining Items 1 Answer

Overriding a function. 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges