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
0
Question by Kroltan · Apr 28, 2012 at 03:24 PM · editorarraycustomproperty

Array of classes on SerializedProperty

So, I have a custom class, with a custom inspector, and I need to alter a array with the custom inspector. The problem is, I can't use the default array inspector, because I need to change 2 values of each class in the array. I have the class: #InteractiveObject.js

 #pragma strict
 
 class InteractiveObject extends MonoBehaviour {
     public static var name : String = "Unnamed Object";
     public static var version : int = 0x001;
     public var propagate : InteractionPacket[];
     final function Start() {
         //Reserved
         Init();
     }
     public function Interact(type : InteractionType, sender : InteractiveObject) : InteractionResults {
         return InteractionResults.NotImplemented;
     }
     private function Init() {}
     
     static public function Interact(sender : InteractiveObject, p :InteractionPacket) : InteractionResults {
         return p.target.Interact(p.type, sender);
     }
 }
 public enum InteractionType {
     Activate,
     Toggle,
     Deactivate,
     TurnOn,
     TurnOff
 }
 public enum InteractionResults {
     Sucess,
     Failed,
     InvalidInput,
     NotImplemented,
     Exception
 }
 public class InteractionPacket {
     public var type : InteractionType;
     public var target : InteractiveObject;
 }

And its editor class: #Editor/InteractiveObjectEditor.js

 #pragma strict
 @CustomEditor(InteractiveObject)
 @CanEditMultipleObjects
 class InteractiveObjectEditor extends Editor {
     var propagate : SerializedProperty;
     
     //EDITOR SCRIPT VARIABLES
     private var propagateControls : boolean[] = new boolean[4];
     //END EDITOR SCRIPT VARIABLES
     
     function OnEnable() {
         propagate = serializedObject.FindProperty("propagate");
     }
     function OnInspectorGUI() {
         serializedObject.Update();
         EditorGUILayout.BeginHorizontal();
         propagateControls[0] = EditorGUILayout.Foldout(propagateControls[0], "Propagate");
         propagateControls[1] = GUILayout.Button("+", EditorStyles.miniButtonLeft, GUILayout.MaxWidth(30));
         propagateControls[2] = GUILayout.Button("-", EditorStyles.miniButtonMid, GUILayout.MaxWidth(30));
         propagateControls[3] = GUILayout.Button("Clear", EditorStyles.miniButtonRight);
         EditorGUILayout.EndHorizontal();
         if (propagateControls[0]) {
         }
     }
 }

I want to create a editor that displays each entry in the propagate variable like this: alt text

A selector for a InteractiveObject class, a enum dropdown for InteractionType and a button to remove the entry. It would be simple, if I could access the variable contents. I can't seem to find a way to modify a array as a SerializedProperty...

Comment
Add comment · Show 1
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 spectre1989 · Aug 10, 2013 at 10:23 PM 0
Share

You can use these to edit an array serialized property:

 public void InsertArrayElementAtIndex( int index );
 public bool $$anonymous$$oveArrayElement( int srcIndex, int dstIndex );
 public SerializedProperty GetArrayElementAtIndex( int index );

So you would use GetArrayElementAtIndex to get the SerializedProperty of one of the InteractionPacket objects in the array (InteractionPacket needs to be System.Serializable).

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by AndyP · Jun 23, 2012 at 09:03 AM

I'm having the same problem. I have a class TrackData which contains a list of TrackDataPoint objects. Both classes are marked as serializeable and the TrackDataPoint only contains standard serializeable types (Vector3 and float). Whilst I can loop through the list of TrackDataPoints in my editor class, I can't figure out how to extract the properties of each point. Either they are not serialized because TrackDataPoint is not a standard class, or there is some syntactic acrobatics I need to perform in order to extract the data from each point. I tried using an IEnumerator via GetEnumerator, but its value was null.

Would be nice to have some more in depth Editor tutorials on the Unity site actually. In addition to documentation and examples lacking for c# users, it would be great to see a few more complicated examples.

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 thienhaflash · Jun 28, 2012 at 09:24 AM 0
Share

I want to know this also, anyone can provide a good answer ?

avatar image
-1

Answer by SmallCar · Nov 08, 2012 at 03:39 AM

http://catlikecoding.com/unity/tutorials/star/ this is a tutorial of the Unity Inspector.

Comment
Add comment · 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

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

7 People are following this question.

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

Related Questions

Custom editor window resets array 1 Answer

Working with Arrays for Custom Inspector 0 Answers

Add custom properties to Objects 1 Answer

Editor Window with settings and Asset Creation 1 Answer

Help with array/lists manipulation in Editor script 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