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
0
Question by Kadrasko · Aug 29, 2013 at 11:08 AM · c#camerajavascriptgizmosimulate

How to mimic Unity Scene Gizmo?

I am trying to build a product visualization platform inside Unity and I think that the Scene Gizmo type of control is best suited for the job. Any ideas how can I accomplish that in code?

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

Answer by gheeler · Aug 29, 2013 at 11:39 AM

http://starscenesoftware.com/vectrosity.html

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 Kadrasko · Aug 29, 2013 at 12:21 PM 0
Share

Don't really see how vectrosity can help. The question is how to simulate the behavior of the scene gizmo (similar to the autodesk view cube). Basically lets say that I have a cube, when I click on the left side of the face the cube rotates 90deg to the left; same for right. Top side gets you top view. Also, all this motions happening for the cube needs to happen to the whole scene in game mode. No idea how to do this

avatar image gheeler · Aug 29, 2013 at 12:55 PM 0
Share

my bad, thought it was the visual effects you were talking about

avatar image
0

Answer by hellaeon · Aug 29, 2013 at 12:49 PM

Hi Kadrasko,

Im not sure of the example you gave but gizmos can be used to show paths or points in the editor for some items in your script. For example with waypoints you draw lines between some given points and say a sphere at each point:

 public Vector3[] waypoints;
 private float node_radius = 0.5f; // gizmo
 
 public void OnDrawGizmos() 
     {
         if(waypoints == null)
             return;
  
         for(int i=0;i< waypoints.Length;i++) {
             Vector3 pos = waypoints[i];
             Gizmos.color = Color.yellow;
          Gizmos.DrawSphere(pos, node_radius);
             if(i>0) {
                 Vector3 prev = waypoints[i-1];
                 Gizmos.DrawLine(prev,pos);
             }
         }
     }

Anything to do with the gizmos should be done in OnDrawGizmos(). It's also an excellent addition to any bezier script so you can see the effect before running it to generate bezier curves in a scene. Following this thread, I needed to simulate hanging wires all over my scene, and I could not see them before playing the game, so I added in some gizmo code:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class Bezier : MonoBehaviour 
 {
     public bool draw = true;
     public Transform pos_from;    // start of curve
     public Transform pos_to;         // other end of curve
     public Vector3 pos_pivot_1;    // in relation to pos_from
     public Vector3 pos_pivot_2;    // in relation to pos_from
     public int segments = 5;
     
     private LineRenderer lineRenderer;
     
     void Start()
     {
         lineRenderer = GetComponent<LineRenderer>();
         lineRenderer.useWorldSpace = true;
         lineRenderer.SetVertexCount(segments);
     }
     
     void Update()
     {
         if(draw)
         {
             draw_curve();
             draw = false;
         }
     }
     
     void draw_curve()
     {
         Vector3 _from = pos_from.position;
         Vector3 piv_1 = pos_from.position - pos_pivot_1;
         Vector3 piv_2 = pos_to.position - pos_pivot_2;
         Vector3 _to = pos_to.position;
         Vector3 v;
         
         for (int i = 0; i < segments; i++)
         {
             float point = 1.0f/segments*i;
             v = CalculateBezierPoint(point, _from, piv_1, piv_2, _to);
             lineRenderer.SetPosition(i,v);
         }
         
         v = CalculateBezierPoint(1, _from, piv_1, piv_2, _to);
         lineRenderer.SetPosition(segments-1,v);
         
     }
     
     private void OnDrawGizmos() 
     {
         Vector3 _from = pos_from.position;
         Vector3 piv_1 = pos_from.position - pos_pivot_1;
         Vector3 piv_2 = pos_to.position - pos_pivot_2;
         Vector3 _to = pos_to.position;
         Vector3 v = Vector3.zero;
         
         for (int i = 0; i < segments; i++)
         {
             float point = 1.0f/segments*i;
             v = CalculateBezierPoint(point, _from, piv_1, piv_2, _to);
             Gizmos.color = Color.yellow;
             Gizmos.DrawSphere(v, 0.1f);
             if(i>0) {
                 point = 1.0f/segments*(i-1);
                 Vector3 prev = CalculateBezierPoint(point, _from, piv_1, piv_2, _to);
                 Gizmos.DrawLine(prev,v);
             }
         }        
         
         Gizmos.DrawLine(v,_to);
     }
     
     Vector3 CalculateBezierPoint(float t, Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3)
     {
         float u = 1.0f-t;
         float tt = t*t;
         float uu = u*u;
         float uuu = uu*u;
         float ttt = tt*t;
     
         Vector3 p = uuu * p0; //first term
         p += 3 * uu * t * p1; //second term
         p += 3 * u * tt * p2; //third term
         p += ttt * p3; //fourth term
 
         return p;
     }
 }

Hopefully these 2 examples can help get you on your way Cheers

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 Kadrasko · Aug 29, 2013 at 01:16 PM 0
Share

Thanks, I looked at and tested the code, and even thought I cannot use it for this scene, it will prove really useful in the future, thanks again.


But, still, I didn't make myself understood. $$anonymous$$y bad. I want to make a visualization project and I need to have a GUI element in the game, who's functionality mimics the one of the scene gizmoalt text Click on the cones- the scene rotates, click on the cube-changes cameras. Plus the scene gizmo rotates with the camera.

capture.png (2.7 kB)
avatar image hellaeon · Aug 29, 2013 at 01:54 PM 0
Share

ahhhh ok, a similar question was asked previously with no response. There is a way though! Try some of the methods outlined in this link here. It goes into detail about adjusting the scene editor, the section you will want to look at is Setting the position and rotation directly This should get you on your way. Love to know how it goes, so let me know.

avatar image Kadrasko · Aug 29, 2013 at 02:21 PM 0
Share

Yap, I checked that out, and also I am looking at the SceneViewRotation decompiled from the Unity.dll but its a lot I don't understand. I'll keep you posted when I get something working

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

Multiple Cars not working 1 Answer

How do I make a Game Object invisible? 1 Answer

Camera Effect + Translating US to C# 3 Answers

I want to put main camera floating 0 Answers

Natural camera sway 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