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 codebeans · Mar 09, 2015 at 08:29 PM · editorcustom editorhandles

Custom Handle, affect multiple objects

Hey, hope you can help me with this one.

I create a custom handle slider to affect a variable of my script.

This works perfect for every gameobject with my script attached as long as it is a single selection (Just one instance selected).

Now I wanted to add the functionality to edit multiple objects at once.

Currently I do this:

OnSceneGUI()

  • draw a slider at my transform.position, and calculate the delta movement of the slider as delta

  • edit variable in my script via ((ScriptXY)target).variable += delta

pretty straight forward

Now for multi-objected editing

  • I added CanEditMultipleObjects as it says in the docs.

  • I calculate the new position for the handle as the center of all targets in a callback and assign it in EditorApplication.update

But still one handle is drawn for each instance of myscript in targets in the OnSceneGUI-function. They overlap and only one object is affected by dragging the custom handle. Note that targets must not be used in OnSceneGUI


So how would you solve this problem? Do you know any best practises? Any sample code. Anything working, or just the idea of how to draw only one handle for all objects and affecting them at once would help.

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 Zyl · Jan 26, 2016 at 11:10 PM 0
Share

Having a similar problem right now. It appears that one Editor instance gets every time the selection is changed. I believe multi-object editing was designed primarily for editing in the inspector, not within the scene view. Note that the DrawGizmo attribute sits on a static function, so you can't really utilize any meta information you might have in your Editor instance here; e.g. in my case, a set of selected vertices.

The only solution I see is to have a singleton object that all editor instances have a reference to. Its class would have to:

  • $$anonymous$$now a list of all current targets, and when targets are added or removed.

  • Receive events from within the OnSceneGUI call and do all the logic.

  • Store everything the gizmo rendering function calls need to render as wanted.

There are, of course, plenty of caveats to this. I'll report back as I work something out.

1 Reply

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

Answer by Zyl · Feb 07, 2016 at 06:30 PM

Using the following class I wrote to derive from instead of Editor and then overriding OnMultiEdit() might work for you. It's a bit hacky but works. Basically with [CanEditMultipleObjects] set on your class, a new instance will be made every time the selection changes and it will receive all the OnSceneGUI()-calls for all targets for every event. Any previous state before the selection is changed is lost unless you manage it in static members or otherwise. In below example I build the target list myself to avoid Unity from spamming me with error messages which should really be suppressible warnings instead.

 using UnityEngine;
 using System.Collections;
 using UnityEditor;
 
 public class MultiEditor : Editor {
 
     private System.Collections.Generic.List<Object> targetList;
 
     public MultiEditor() {
         targetList = new System.Collections.Generic.List<Object>(1);
     }
 
     public virtual void OnMultiEdit(System.Collections.Generic.List<Object> targetList) {
     }
 
     public void OnSceneGUI() {
         if (targetList.Contains (target)) {
             // We got all targets.
             if (target == targetList [0]) {
                 // First call of OnSceneGUI(). Time to relay.
                 OnMultiEdit (targetList);
             }
         } else {
             // Build the target list first, skipping the first event.
             // First event usually is a Layout event which is generally not interesting anyway.
             targetList.Add (target);
         }
     }
 }
 
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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Custom Handle. Mutliple Objects 0 Answers

Custom Editor loosing data on play 1 Answer

Handles.matrix seems strange? 2 Answers

Editor Handles Vertex Snap not working on script's object. 0 Answers

Draw ellipse via Handles class 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