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 cupsster · Apr 13, 2011 at 09:51 AM · editorsceneinstancepaintingobject-paint

Object Painter Editor Help

Hello I'm trying to complete my "Object Painter" editor.. but no luck. What it should do: paint objects in scene based on raycasts and use curently selected prefab as a source for instancing. Also replacing "Fire1" with other right mouse button would be nice. BUG: not instancing

class ObjectPainter extends EditorWindow {

static var thePaintPrefab:GameObject; static var paintActive:boolean=false; var buttonText:String;

@MenuItem("Custom/Object Painter") static function Init() { var window = GetWindow(ObjectPainter); paintActive = false; window.position = Rect(0,0,170,60); window.Show(); thePaintPrefab = Selection.activeGameObject; }

function OnGUI() {

 var newObject : GameObject = EditorUtility.InstantiatePrefab(thePaintPrefab) as GameObject;

 if (paintActive) {
     buttonText = "-=ACTIVE=-";
 } else {
     buttonText = "-Paint-";
 }
 if(GUI.Button(Rect(3,25,position.width-6, 30),buttonText)){
     if (paintActive == false) {
         thePaintPrefab = Selection.activeGameObject;
         Debug.Log("Prefab: " + thePaintPrefab.name);
     }
     paintActive = !paintActive;
 }

}

function Update() { if (paintActive) { if (Input.GetButtonDown("Fire1")) { var ray : Ray = SceneView.lastActiveSceneView.camera.ScreenPointToRay(Input.mousePosition); var hit : RaycastHit;

         if (Physics.Raycast(ray, hit, 100))     {
             var otherObj : GameObject = hit.collider.gameObject;
             Debug.Log("Hit: " + otherObj.name);

             var newPos : Vector3 = new Vector3(hit.point.x,hit.point.y, hit.point.z );
             if (thePaintPrefab) {
                 var newObject : GameObject = EditorUtility.InstantiatePrefab(thePaintPrefab) as GameObject;
                 newObject.transform.position = newPos;
                 Debug.Log("Prefab: " + thePaintPrefab.name+" @pos "+ newPos);
             }
         }
     }
 }

}

}

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 cupsster · May 11, 2011 at 10:50 AM 0
Share

yeah, for sure.. I abandoned this script cause it consumed to much development time. I'll rework it when I have more time available. $$anonymous$$eep this updated as well.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Apr 13, 2011 at 11:01 AM

I'll guess it's because you use the MainCamera. In what view do you want to paint? SceneViews have their own cameras you can get the camera of the last active SceneView with:

SceneView.lastActiveSceneView.camera

Unfortunately the SceneView class is not documented yet, but with C# and visual studio intelliSense can show you all public classes. AFAIK MonoDevelop have also a similar feature, but i never really used MonoDevelop yet ;)

There's also the SceneView.sceneViews array that contains all open scene views.

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 cupsster · Apr 13, 2011 at 11:57 AM 0
Share

so ins$$anonymous$$d of Camera.main.ScreenPointToRay I should write SceneView.lastActiveSceneView.camera.ScreenPointToRay ? Is this correct?

avatar image cupsster · Apr 13, 2011 at 06:41 PM 0
Share

Still unable to to figure it out... I tryed various combinations but still unable to instantiate object where it should be after click or key press.. Code posted here is executed by docs 10 times per Gui update so it will spawn prefab at Vector3.zero as soon as window is open.. any advice is welcome

avatar image Bunny83 · Apr 13, 2011 at 08:40 PM 0
Share

Well, i just saw that you use the Input class. That could be a problem because it's not made for the editor. You could try to use at least Input.Get$$anonymous$$ouseButton(0) since it doesn't depend on the Input$$anonymous$$anager. I guess that should work. You could (or maybe should) use HandleUtility.GUIPointToWorldRay() ins$$anonymous$$d of Camera.ScreenPointToRay because i've read that it can happen that ScreenPointToRay doesn't work correct in the editor, but i haven't used it yet ;)

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

No one has followed this question yet.

Related Questions

Unity Scene File in Build Question 1 Answer

Editor split scene 1 Answer

Executing first scene in build settings when pressing play button in editor? 2 Answers

Determine the Scene that is selected when using context menu 0 Answers

Editor Scene? 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