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
7
Question by Pekuja · May 11, 2010 at 09:52 PM · editortilemap

Making a tilemap editor within the Unity Editor

Is it possible to customize the Unity Editor so that I could "paint" objects into my scene, like in a tilemap editor such as Mappy or TileStudio? Basically I want to be able to click on my scene and have an object added at that position on a specified plane and grid. Something a bit like the terrain editor's foliage paintbrush.

Can I use OnSceneGUI for this perhaps?

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
9
Best Answer

Answer by Pekuja · May 13, 2010 at 02:24 PM

Ok, so here's what I've come up with: Make a custom editor for a "Tilemap" MonoBehaviour, and in it have an OnSceneGUI. In the OnSceneGUI, generate a controlID with GUIUtility.GetControlID and add the control as default with HandleUtility.AddDefaultControl. This way, the Unity Editor won't use your mouse clicks on the scene for selecting things, but instead you can do whatever you like with the clicks. Here's a simple example I wrote in Boo, that basically will move any part of the map that you click on by five units:

 import UnityEditor
 import UnityEngine
 
 [CustomEditor(Tilemap)]
 class TilemapEditor (Editor):
     def OnSceneGUI():
         controlID as int = GUIUtility.GetControlID(FocusType.Passive)
         if Event.current.type == EventType.mouseDown:
             hit as RaycastHit
             if Physics.Raycast(Event.current.mouseRay, \
                hit, Mathf.Infinity, 1 << (target as Tilemap).terrainLayer):
                 Debug.Log("Hit a part of the terrain")
                 hit.transform.position.y += 5
         if Event.current.type == EventType.layout:
             HandleUtility.AddDefaultControl(controlID)

Obviously it still needs a lot of work to be a real editor; this is just a proof of concept.

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 dkoontz · Apr 24, 2011 at 03:56 AM 0
Share

Thank you very much for figuring this stuff out, it was exactly what I needed.

avatar image kirpigiller · Jun 01, 2011 at 10:23 AM 0
Share

Yep. Good solution. But how to avoid seletion. On left click Unity editor will select a gameobject under the cursor.

avatar image yoyo · Nov 30, 2012 at 07:57 AM 0
Share

kirpigiller, the AddDefaultControl voodoo should prevent left-click selection. Worked for me, thanks Pekka!

avatar image vikingfabian-com · Oct 17, 2015 at 09:02 AM 0
Share

I had to remove "if Event.current.type == EventType.layout:" to make it work in Unity5

avatar image
2

Answer by duck · May 12, 2010 at 12:31 PM

Yes, I think technically it's possible, because the terrain editor system itself is written using Unity's own Editor Scripting API, so anything done there - you can do.

Unfortunately this is an area that is not well documented at all in the manual - for example, the OnInspectorGUI manual page contains just two short sentences as a description, and no example at all! - so it may be tough going, but good luck with it!

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 Pekuja · May 13, 2010 at 11:46 PM 0
Share

It does seem like the documentation is pretty bad. Hopefully the situation will improve. Currently I'm going by random code snippets and guesswork.

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

Instantiate prefabs before runtime, inside editor 1 Answer

tilemap tiles broken 0 Answers

Rule Tile "GameObject" duplicating in build version 3 Answers

how to keep static variables or 2d array value 0 Answers

Questions about using the tilemap. 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