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
13
Question by Ashkan_gc · Mar 06, 2010 at 08:30 PM · editorruntimegizmohandle

how to create handles like editor gizmos in runtime?

i would like to create gizmos like movement gizmos of the editor at runtime. i want to know how can i implement one for the runtime? i would be more than happy if the real implementer of editor handles answer me and tell me what to do.

Comment
Add comment · Show 5
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 Lipis · Mar 15, 2010 at 08:19 PM 0
Share

@Ashkan just leave the question open til the deadline.. you might have another cool answer.. this is a good one :) Let's see..

avatar image Cyclops · Mar 16, 2010 at 02:46 PM 0
Share

I'm reluctantly forced to agree. :) Just don't let it expire. Plus, I can't wait to see Lipis's answer, I'm sure it's almost done. :)

avatar image Lipis · Mar 16, 2010 at 08:41 PM 0
Share

@Cyclops.. hehe..! actually I wasn't about to implementing it.. but since I got some ideas.. let's see.. :)

avatar image lx904 · Dec 01, 2014 at 05:34 PM 0
Share

doesn't work. it says Assets/Gizmo/Gizmo.js(23,18): BCE0017: The best overload for the method 'GizmoHandle.setType(GizmoType)' is not compatible with the argument list '(UnityEditor.GizmoType)'. Any solutions?

avatar image khos85 · Jan 10, 2015 at 04:33 PM 0
Share

Did you get the error fixed Lx904 ?

7 Replies

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

Answer by Lipis · Mar 17, 2010 at 03:06 AM

Here is my Gizmo solution in action.

Gizmos in action

This is a full working gizmos and you are able to change Position, Rotation and Scale of the any object during run-time.

Feel free to download the source code and if you have any question drop a line in the comments.

Comment
Add comment · Show 25 · 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 Lipis · Mar 17, 2010 at 03:07 AM 0
Share

@Ashkan Just let me know if thats what you were looking for?

avatar image Cyclops · Mar 17, 2010 at 01:38 PM 1
Share

@Lipis. Dang - way better than $$anonymous$$e. I had to open my mouth... :)

avatar image Lipis · Mar 17, 2010 at 05:37 PM 0
Share

@Cyclops it's easier than you think.. the whole thing is not taking more than an hour from scratch.. :)

avatar image Cyclops · Mar 17, 2010 at 05:48 PM 0
Share

@Lipis, maybe easy for you, but I always seem to do things the hard way... :)

avatar image Lipis · Mar 17, 2010 at 06:01 PM 4
Share

If it's complicated it's wrong...!! :)

Show more comments
avatar image
5

Answer by Cyclops · Mar 14, 2010 at 09:13 PM

Well, I have written a basic implementation of a faked run-time version of a three-axis Location Gizmo that allows you to - click on an axis to move an object along the chosen axis (try saying that three times fast...)

Turned out to be a lot harder than I expected when I started - I thought, "okay, first I need to draw three orthogonal lines", and things went down-hill from there. Who knew drawing a line was that hard? :)

What I wound up doing was creating a Procedural Mesh (and there was another learning curve) of an arrow, in triplicate, attach a red/blue/green material to it, and rotate each as needed. Then attach a mouse-down script to each axis, that moves both the Gizmo object and its Parent object as long as the mouse is held down. It's not a true mouse-drag, which would have been a lot more work, and this was plenty as it is.

All of this is done procedurally - it requires three scripts, one of which, s_GizmoCreate.cs, you drag/drop to a Hierarchy object. When the game starts, the script creates the Gizmo onto the object. You could also build it into a GUI, such that the script is attached to an object you clicked on - but again, that's another metric ton of work. :)

As I said, this is a basic implementation of a single Gizmo type (specifically the 3-axis Move Gizmo). But it demonstrates all the programming techniques that you would use for others, such as the Rotation Gizmo.

I've put a complete sample package, with the three scripts needed, on the Unify Wiki at:

Fake Gizmo Demo

Comment
Add comment · Show 4 · 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 Ashkan_gc · Mar 15, 2010 at 06:34 AM 0
Share

thank you for the great work

avatar image Ashkan_gc · Mar 15, 2010 at 07:17 AM 0
Share

i have some questions about meshes and FBX files man. can you email me at ashkan_gc(at)yahoo(dot)com?

avatar image Cyclops · Mar 15, 2010 at 02:11 PM 0
Share

Glad you liked it. Enough to check the Bounty box/checkbox? :) While I realize it's crude - it was only intended as proof-of-concept and to demo the techniques. If you want a full, professional implementation, then we're talking hourly rates. :)

avatar image Lipis · Mar 17, 2010 at 10:23 AM 0
Share

@Cyclops I didn't manage to see your solution in action..

avatar image
5

Answer by HiddenMonk · Oct 20, 2016 at 04:00 AM

I have taken Murchos answer approach of using the GL class and made a decent replica of the unity editor transform gizmo. Its not just for show either, you can move, rotate, and scale at runtime.

Here is a video demonstrating it - https://www.youtube.com/watch?v=IUQqhS8tsNo

Here is the source code - https://github.com/HiddenMonk/Unity3DRuntimeTransformGizmo

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 remusasimion · Dec 05, 2020 at 07:32 PM 0
Share

Total beginner here, so please don't hate the dumb question. I know program$$anonymous$$g but my Unity is really bad (i just learned what gizmos are): How would i do this with some custom (package-provided) gizmos? I have a spline generator that i'd like to turn into a road generator for a game, which means I need to access the control points and anchors of the spline in gamemode.

Thank you so much!

avatar image
4

Answer by Murcho · Mar 14, 2010 at 01:05 AM

Here's a start, by using the GL.LINES mode with immediate drawing during the OnPostRender() function, you are able to draw the handles. I've got as far as the actual lines drawing, however not the ability to select them. Something tells me that will require a lot more code.

Place this script onto your camera, then drag the target for the handle into the target slot. This also handles local and global direction handles with a drop down on the script, and you can change the length of the handles with the handleLength variable.

using UnityEngine; using System.Collections;

public class LineDrawing : MonoBehaviour { static Material lineMaterial; public enum TransformSpace { Global, Local }

 public Transform target;

 public TransformSpace space = TransformSpace.Global;
 public float handleLength = 5.0f;

 static void CreateLineMaterial()
 {
     if (!lineMaterial)
     {
         lineMaterial = new Material("Shader \"Lines/Colored Blended\" {" +
         "SubShader { Pass { " +
         "    Blend SrcAlpha OneMinusSrcAlpha " +
         "    ZWrite Off Cull Off Fog { Mode Off } " +
         "    BindChannels {" +
         "      Bind \"vertex\", vertex Bind \"color\", color }" +
         "} } }");
         lineMaterial.hideFlags = HideFlags.HideAndDontSave;
         lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
     }
 }

 void OnPostRender()
 {
     Vector3 xAxisEnd;
     Vector3 yAxisEnd;
     Vector3 zAxisEnd;

     if (space == TransformSpace.Global)
     {
         xAxisEnd = target.transform.position + Vector3.right * handleLength;
         yAxisEnd = target.transform.position + Vector3.up * handleLength;
         zAxisEnd = target.transform.position + Vector3.forward * handleLength;
     }
     else
     {
         xAxisEnd = target.transform.position + target.transform.TransformDirection(Vector3.right * handleLength);
         yAxisEnd = target.transform.position + target.transform.TransformDirection(Vector3.up * handleLength);
         zAxisEnd = target.transform.position + target.transform.TransformDirection(Vector3.forward * handleLength);
     }

     CreateLineMaterial();
     lineMaterial.SetPass(0);
     GL.Begin(GL.LINES);
     // X line
     GL.Color(new Color(1, 0, 0, 0.5f));
     GL.Vertex3(target.transform.position.x, target.transform.position.y, target.transform.position.z);
     GL.Vertex3(xAxisEnd.x, xAxisEnd.y, xAxisEnd.z);
     // Y line
     GL.Color(new Color(0, 1, 0, 0.5f));
     GL.Vertex3(target.transform.position.x, target.transform.position.y, target.transform.position.z);
     GL.Vertex3(yAxisEnd.x, yAxisEnd.y, yAxisEnd.z);        
     // Z line
     GL.Color(new Color(0, 0, 1, 0.5f));
     GL.Vertex3(target.transform.position.x, target.transform.position.y, target.transform.position.z);
     GL.Vertex3(zAxisEnd.x, zAxisEnd.y, zAxisEnd.z);
     GL.End();
 }

}

From here you should get a good idea on how to draw lines in the same fashion handles are drawn, but in runtime. If you want to try and draw the cones on the end, use GL.Begin(GL.TRIANGLES) and send three vertex3 calls through at a time. You may need to do some matrix maths to get them looking right however.

Comment
Add comment · Show 3 · 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 Cyclops · Mar 17, 2010 at 01:39 PM 0
Share

Isn't GL.Lines, a Pro-only feature?

avatar image Murcho · Mar 18, 2010 at 03:21 AM 0
Share

You are correct, sorry I tend to not notice those notices (Pro user here).

avatar image HiddenMonk · Oct 20, 2016 at 04:04 AM 0
Share

I have taken your approach and finalized it. Currently its on the second page of these answers, so I am leaving a comment here so people know. Here is a demo video - https://www.youtube.com/watch?v=IUQqhS8tsNo Source code - https://github.com/Hidden$$anonymous$$onk/Unity3DRuntimeTransformGizmo

avatar image
-2

Answer by Stelimar · Mar 06, 2010 at 10:05 PM

Short Answer: Unfortunately, you can't.

Long Answer: The Handles class which is used to create movement/scale/rotation handles is an Editor class, which means you can only use it within editor scripts, not at runtime. There is no runtime equivalent, and as far as I know, there is no way to use editor classes at runtime. If you really HAVE to have this functionality, you would have to write your own implementation.

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 Ashkan_gc · Mar 07, 2010 at 06:28 AM 0
Share

i know that man. i want to implement one myself. i told this in my question.

avatar image Ashkan_gc · Mar 15, 2010 at 06:37 AM 0
Share

i wrote in my question that i want to implement one.

  • 1
  • 2
  • ›

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

17 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

Related Questions

How to disable the default transform gizmo in editor? 1 Answer

How to prevent PositionHandle to become FreeMoveHandle when shift key is pressed 0 Answers

Refreshing Editor Scripts 1 Answer

StreamWriter issue c# 0 Answers

Post Processing Profile not changing in build 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