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 SZ_95 · Dec 05, 2015 at 06:13 PM · c#editorcustom editorcustomization

Custom Editor applies changes to every instance of the component/class its for, how do I fix this to modify the target instance component only?

Hi Everyone,

Background: Recently I started dabbing in using the custom editor to organize the data I had in my class (in this case a class for Limbs.) The interface works as it's supposed to however I realized when I apply the script as a component to a game object and then add the script as a component to a completely separate object the stats between them will be the same and changing the stats in one will change them all.

Question: I would like to emulate how Unity, by default, keeps the data of the same component type in two different objects as different, how can I accomplish this?

Cube

Demonstration of error, note that in VALimb the "Name" is the same in the Cube and Capsule object. The New Behaviour Script has no custom editor and maintains that "NAME" (in this case) is different between the two objects, though it's the same component type.

Capsule Thanks, SZ95

Code of VALimb Custom Editor:

     using UnityEditor;
     using UnityEngine;
     using System.Collections;
      
     [CustomEditor(typeof(VALimb))]
     public class VALimbEditor : Editor
     {
         private static bool TorsoToggle;
         private static bool ArmToggle;
         private static bool LegToggle;
         private static bool BackpackToggle;
     
         private static string TorsoName;
         private static string ArmName;
         private static string LegName;
         private static string backpackName;
     
         private static int AccessTorsoHP;
         private static int AccessArmHP;
         private static int AccessLegHP;
         private static int HardpointCount;
     
         private static VALimb.LimbPosition ArmLimbs;
         private static VALimb.LimbPosition LegLimbs;
     
         public override void OnInspectorGUI()
         {
             VALimb _evCtrl = (VALimb)target;
             GUILayout.BeginHorizontal();
             GUILayout.Label("Torso Limb", GUILayout.Width(70));
             TorsoToggle = EditorGUILayout.Toggle("Torso Toggle", TorsoToggle);
             GUILayout.EndHorizontal();
             if (TorsoToggle == true)
             {
                 ArmToggle = false;
                 LegToggle = false;
                 BackpackToggle = false;
                 GUILayout.Space(5);
                 GUILayout.BeginHorizontal();
                 GUILayout.Label("Name", GUILayout.Width(70));
                 TorsoName = EditorGUILayout.TextField(TorsoName);
                 _evCtrl.setName(TorsoName);
                 GUILayout.EndHorizontal();
     
                 GUILayout.Space(5);
                 GUILayout.BeginHorizontal();
                 GUILayout.Label("HP", GUILayout.Width(70));
                 AccessTorsoHP = EditorGUILayout.IntField(AccessTorsoHP);
                 _evCtrl.setHP(AccessTorsoHP);
                 GUILayout.EndHorizontal();
     
                 GUILayout.Space(5);
                 GUILayout.BeginHorizontal();
                 //GUILayout.Label("Limb Type", GUILayout.Width(70));
                 VALimb.LimbType BTT = VALimb.LimbType.TORSO;
                 _evCtrl.LBT = (VALimb.LimbType)EditorGUILayout.EnumPopup("Limb Type", BTT);
                 _evCtrl.isTorso = true;
                 GUILayout.EndHorizontal();
     
                 GUILayout.Space(5);
                 GUILayout.BeginHorizontal();
                 GUILayout.Label("Hardpoints", GUILayout.Width(70));
                 HardpointCount = EditorGUILayout.IntSlider(HardpointCount, 0, 2);
                 _evCtrl.HardpointCount = HardpointCount;
                 GUILayout.EndHorizontal();
             }
             else if (TorsoToggle == false)
             {
                 TorsoName = "N/A";
                 AccessTorsoHP = 0;
                 //HardpointCount = 0;
                 _evCtrl.LBT = VALimb.LimbType.NONE;
                 _evCtrl.isTorso = false;
             }
     
             GUILayout.BeginHorizontal();
             GUILayout.Label("Arm Limb", GUILayout.Width(70));
             ArmToggle = EditorGUILayout.Toggle("Arm Toggle", ArmToggle);
             GUILayout.EndHorizontal();
             if (ArmToggle == true )
             {
                 TorsoToggle = false;
                 LegToggle = false;
                 BackpackToggle = false;
                 GUILayout.Space(5);
                 GUILayout.BeginHorizontal();
                 GUILayout.Label("Name", GUILayout.Width(70));
                 ArmName = EditorGUILayout.TextField(ArmName);
                 _evCtrl.setName(ArmName);
                 GUILayout.EndHorizontal();
     
                 GUILayout.Space(5);
                 GUILayout.BeginHorizontal();
                 GUILayout.Label("HP", GUILayout.Width(70));
                 AccessArmHP = EditorGUILayout.IntField(AccessArmHP);
                 _evCtrl.setHP(AccessArmHP);
                 GUILayout.EndHorizontal();
     
                 GUILayout.Space(5);
                 GUILayout.BeginHorizontal();
                 GUILayout.Label("Accuracy", GUILayout.Width(70));
                 _evCtrl.vAccuracy = EditorGUILayout.FloatField(_evCtrl.vAccuracy);
                 //Debug.Log(_evCtrl.vAccuracy);
                 GUILayout.EndHorizontal();
     
                 GUILayout.Space(5);
                 GUILayout.BeginHorizontal();
                 ArmLimbs = (VALimb.LimbPosition)EditorGUILayout.EnumPopup("Limb Postion", ArmLimbs);
                 _evCtrl.ArmPosition = ArmLimbs;
                 GUILayout.EndHorizontal();
     
                 GUILayout.Space(5);
                 GUILayout.BeginHorizontal();
                 //GUILayout.Label("Limb Type", GUILayout.Width(70));
                 VALimb.LimbType BTT = VALimb.LimbType.ARM;
                 _evCtrl.LBT = (VALimb.LimbType)EditorGUILayout.EnumPopup("Limb Type", BTT);
                 _evCtrl.isLeg = true;
                 GUILayout.EndHorizontal();
     
                 GUILayout.Space(5);
                 GUILayout.BeginHorizontal();
                 GUILayout.Label("Hardpoints", GUILayout.Width(70));
                 HardpointCount = EditorGUILayout.IntSlider(HardpointCount, 0, 3);
                 _evCtrl.HardpointCount = HardpointCount;
                 GUILayout.EndHorizontal();
             }
             else if(ArmToggle != true)
             {
                 ArmName = "N/A";
                 AccessArmHP = 0;
                 //HardpointCount = 0;
                 ArmLimbs = VALimb.LimbPosition.NONE;
                 _evCtrl.LBT = VALimb.LimbType.NONE;
                 _evCtrl.isArm = false;
                 _evCtrl.vAccuracy = 0.0f;
             }
     
             GUILayout.BeginHorizontal();
             GUILayout.Label("Leg Limb", GUILayout.Width(70));
             LegToggle = EditorGUILayout.Toggle("Leg Toggle", LegToggle);
             GUILayout.EndHorizontal();
             if (LegToggle == true)
             {
                 TorsoToggle = false;
                 ArmToggle = false;
                 BackpackToggle = false;
     
                 GUILayout.Space(5);
                 GUILayout.BeginHorizontal();
                 GUILayout.Label("Name", GUILayout.Width(70));
                 LegName = EditorGUILayout.TextField(LegName);
                 _evCtrl.setName(LegName);
                 GUILayout.EndHorizontal();
     
                 GUILayout.Space(5);
                 GUILayout.BeginHorizontal();
                 GUILayout.Label("HP", GUILayout.Width(70));
                 AccessLegHP = EditorGUILayout.IntField(AccessLegHP);
                 _evCtrl.setHP(AccessArmHP); 
                 //_evCtrl.LegHP = EditorGUILayout.IntField(_evCtrl.LegHP);
                 GUILayout.EndHorizontal();
     
                 GUILayout.Space(5);
                 GUILayout.BeginHorizontal();
                 GUILayout.Label("Movement", GUILayout.Width(70));
                 _evCtrl.vMove = EditorGUILayout.IntField(_evCtrl.vMove);
                 GUILayout.EndHorizontal();
     
                 GUILayout.Space(5);
                 GUILayout.BeginHorizontal();
                 //GUILayout.Label("Limb Type", GUILayout.Width(70));
                 LegLimbs = (VALimb.LimbPosition)EditorGUILayout.EnumPopup("Limb Position", LegLimbs);
                 GUILayout.EndHorizontal();
     
                 GUILayout.Space(5);
                 GUILayout.BeginHorizontal();
                 //GUILayout.Label("Limb Type", GUILayout.Width(70));
                 VALimb.LimbType BTT = VALimb.LimbType.LEG;
                 _evCtrl.LBT = (VALimb.LimbType)EditorGUILayout.EnumPopup("Limb Type", BTT);
                 _evCtrl.isLeg = true;
                 GUILayout.EndHorizontal();
     
             }
             else if (LegToggle != true)
             {
                  LegName = "N/A";
                  AccessLegHP = 0;
                  _evCtrl.LBT = VALimb.LimbType.NONE;
                  _evCtrl.isLeg = false;
                  _evCtrl.vMove = 0;
             }
     
             GUILayout.BeginHorizontal();
             GUILayout.Label("Backpack", GUILayout.Width(70));
             BackpackToggle = EditorGUILayout.Toggle("Backpack Toggle", BackpackToggle);
             GUILayout.EndHorizontal();
             if (BackpackToggle == true)
             {
                 TorsoToggle = false;
                 LegToggle = false;
                 ArmToggle = false;
                 GUILayout.Space(5);
                 GUILayout.BeginHorizontal();
                 GUILayout.Label("Name", GUILayout.Width(70));
                 backpackName = EditorGUILayout.TextField(backpackName);
                 _evCtrl.vIName = backpackName;
                 GUILayout.EndHorizontal();
     
                 GUILayout.Space(5);
                 GUILayout.BeginHorizontal();
                 GUILayout.Label("Pack Size", GUILayout.Width(70));
                 _evCtrl.bSize = EditorGUILayout.IntField(_evCtrl.bSize);
                 GUILayout.EndHorizontal();
     
                 GUILayout.Space(5);
                 GUILayout.BeginHorizontal();
                 //GUILayout.Label("Limb Type", GUILayout.Width(70));
                 VALimb.LimbType BTT = VALimb.LimbType.BACKPACK;
                 _evCtrl.LBT = (VALimb.LimbType)EditorGUILayout.EnumPopup("Limb Type", BTT);
                 _evCtrl.isBackpack = true;
                 GUILayout.EndHorizontal();
     
                 GUILayout.Space(5);
                 GUILayout.BeginHorizontal();
                 _evCtrl.BackpackType = (VALimb.bType)EditorGUILayout.EnumPopup("Backpack Size", _evCtrl.BackpackType);
                 GUILayout.EndHorizontal();
     
             }
             else if(BackpackToggle != true)
             {
                 backpackName = "N/A";
                 _evCtrl.LBT = VALimb.LimbType.NONE;
                 _evCtrl.BackpackType = VALimb.bType.NONE;
                 _evCtrl.isBackpack = false;
                 _evCtrl.bSize = 0;
             }
     
         }
     }
 

ss-on-1.png (264.2 kB)
ss-on-2.png (264.1 kB)
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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Custom Editor for interfaces 2 Answers

View and Edit Properties of List items in inspector 1 Answer

Can the GameObjectInspector window be customized? 0 Answers

Initialising List array for use in a custom Editor 1 Answer

Is there a way of changing the editor's splash image when Unity boots up? 0 Answers


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