Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 DaiMangouDev · Sep 01, 2016 at 12:33 AM · c#transformeditor-scriptingtransform.positioncustom-inspector

How to make my own Transform inspector without using a Custom Inspector to override Transform ?

Hi guys ,

I am creating a script custom Transform component which I place on my objects . I do not wish to use a custom Inspector to override Transform.

I can set the position of my objects from the inspector but when i move the object in the scene and stop dragging it , the object moves back to the position I had set in my custom transform inspector.

here is my script :

     using UnityEngine;
     [ExecuteInEditMode]
     public class CustomTransform : MonoBehaviour {
         public Vector3 position
         {    
             get
             {
    return transform.position;
             }
             set
             {
              transform.position = new value;
             }    
         }  
     }


This is where i will now use my own CustomInspector to target the CustomTransform script and draw the GUI.

 using UnityEngine;
 using UnityEditor;
 
 
 [CustomEditor(typeof(CustomTransform))]
 public class CustomTransformInspector : Editor
 {
 
     private float x, y, z;
     public override void OnInspectorGUI()
     {
         CustomTransform myTarget = (CustomTransform)target;
 
 
 
   
                 x = EditorGUILayout.FloatField("X", x);
                 y = EditorGUILayout.FloatField("Y", y);
                 z = EditorGUILayout.FloatField("Z", z);
 
 
 
         myTarget.position = new Vector3(x, y, z);
 
     }
 }

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by LTK · Sep 01, 2016 at 03:35 AM

Sure if you want position inspector = position you move gameobject on scene, you need add update position current into your custom inspector

  void OnEnable()
     {
          CustomTranform myTarget  = (CustomTranform)target;
          x = myTarget.position.x;
          y = myTarget.position.y;
          z = myTarget.position.z;
     }

void OnEnable will be called when gameobject selected

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 DaiMangouDev · Sep 01, 2016 at 11:15 AM 0
Share

nice, that works when i move it in OnInspectorGUI()

 [CustomEditor(typeof(CustomTransform))]
 public class CustomTransformInspector : Editor
 {
     private Vector3 pos;
 
     public override void OnInspectorGUI()
     {
         CustomTransform $$anonymous$$yTransform = (CustomTransform)target;
 
 
             pos.x = $$anonymous$$yTransform.position.x;
             pos.y = $$anonymous$$yTransform.position.y;
             pos.z = $$anonymous$$yTransform.position.z;
          
                 pos.x = EditorGUILayout.FloatField("X", pos.x);
                 pos.y = EditorGUILayout.FloatField("Y", pos.y);
                 pos.z = EditorGUILayout.FloatField("Z", pos.z);
 
         $$anonymous$$yTransform.position = new Vector3(pos.x, pos.y, pos.z);
 
     }
 }
avatar image
0

Answer by DevMashup · Sep 24, 2020 at 11:39 PM

Thsanks man. I think this will helpme with my custom editor.

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

220 People are following this question.

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

Related Questions

Can't get smooth 2d movement for an object using transform.position 1 Answer

Reorderable list of UnityEvents 2 Answers

Rotate Parent using Child as Pivot 0 Answers

How to access Custom Inspector own gameObject 1 Answer

transform.position not setting position OR animation setting position even though it shouldn't 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