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
1
Question by Deadcow_ · Apr 08, 2015 at 11:38 AM · c#editorcustom-inspector

Move scene camera to gameObject via Editor script

When you double click on object in hierarchy view the scene camera moves to this object on scene and adjust it's size to fit the object size.

I need to acheive this through Editor script (in custom inspector, by button click). I don't neet this object to be selected in Inspector though, just ping it in hierarchy with EditorGUIUtility.PingObject

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

3 Replies

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

Answer by Deadcow_ · Apr 08, 2015 at 04:35 PM

Wow-wow I made it!

 if (GUILayout.Button(i.ToString(), EditorStyles.toolbarButton, GUILayout.Width(20)))
 {
     EditorGUIUtility.PingObject(item);

     var currentlActive = Selection.activeGameObject;
     Selection.activeGameObject = item.gameObject;

     SceneView.lastActiveSceneView.FrameSelected();

     Selection.activeGameObject = currentlActive;
 }


It works like a charm! It even keeps current hierarchy scroll position of selected object! Regardless of that I swap selected objects. Phew :)

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
avatar image
2

Answer by IMD · Jun 06, 2017 at 08:41 PM

Hello!

Unity provides a function which will take a Vector3 and automatically lerp the scene view camera to that position as if it's being focused on via the Unity UI. Example below:

 SceneView.lastActiveSceneView.LookAt(nextSceneViewPos);

Hope that helps some people :)

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 LukeNukem44 · Apr 10, 2018 at 04:18 AM 0
Share

That is most helpful, thank you. The only issue is that it doesn't zoom the same way the Focus function does. Do you know what the function might be that calls LookAt and Focus?

avatar image
0

Answer by Targaryen · Apr 08, 2015 at 03:11 PM

If you want to move the camera to an specify GameObject, you can use the Vector3.Lerp function. You can find all the info about this in here: http://docs.unity3d.com/ScriptReference/Vector3.Lerp.html

But in the end, it takes 3 parameters:

  1. the initial position of the gameObject (From Vector3)

  2. The destination of the gameObject (To Vector3)

  3. The speed you want to move the gameObject (for this you can setup a var like speed and then you can use "speed * Time.deltaTime")

Hope this helps!

Comment
Add comment · Show 2 · 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 Deadcow_ · Apr 08, 2015 at 03:49 PM 0
Share

$$anonymous$$y english is barely readable sometimes, since I'm not a native speaker, but I mention Editor script and scene camera (ins$$anonymous$$d of game camera). Once again - I want to focus camera on object in Scene View through Editor Script. But thanks for trying to help anyway

avatar image Targaryen · Apr 08, 2015 at 03:58 PM 0
Share

ok! now i understand! I don't even now if it's possible to create scripts to modify the Scene camera; Hopefully someone knows more about it.

sry!

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

21 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

Related Questions

Custom Inspector: Using SeralizedProperty changes the prefab values! 0 Answers

editorguilayout.objectfield issue 1 Answer

How to change inspector with non-Monobehaviour objects ? 1 Answer

Custom Inspector, Collections, SetDirty 0 Answers

Initialising List array for use in a custom Editor 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