コード例 #1
0
 public static Tileset GetSelectedTileset()
 {
     if (Selection.activeObject is Tileset)
     {
         return(Selection.activeObject as Tileset);
     }
     else if (Selection.activeObject is TilesetBrush)
     {
         return((Selection.activeObject as TilesetBrush).Tileset);
     }
     else if (Selection.activeObject is GameObject)
     {
         Tilemap tilemap = (Selection.activeObject as GameObject).GetComponent <Tilemap>();
         if (tilemap == null)
         {
             TilemapGroup tilemapGroup = (Selection.activeObject as GameObject).GetComponent <TilemapGroup>();
             if (tilemapGroup != null)
             {
                 tilemap = tilemapGroup.SelectedTilemap;
             }
         }
         if (tilemap != null)
         {
             return(tilemap.Tileset);
         }
     }
     return(null);
 }
コード例 #2
0
 private void OnEnable()
 {
     m_target = target as TilemapGroup;
     m_target.Refresh();
     m_tilemapReordList       = CreateTilemapReorderableList();
     m_tilemapReordList.index = serializedObject.FindProperty("m_selectedIndex").intValue;
 }
コード例 #3
0
 /// <summary>
 /// Creates a new MapTileNode
 /// </summary>
 /// <param name="idx">The index is a concatenation of the two grid positions</param>
 /// <param name="owner"></param>
 public MapTileNode(TilemapGroup tilemapGroup, MapPathFinding owner, int idx)
 {
     m_owner        = owner;
     m_tilemapGroup = tilemapGroup;
     SetGridPos(idx >> 16, (int)(short)idx, m_owner.CellSize);
     //NOTE: calculate m_costFactor here using Tile parameters
     m_costFactor = 1f;
 }
コード例 #4
0
 private void OnEnable()
 {
     m_target = target as TilemapGroup;
     m_target.Refresh();
     m_selectedIndexProp           = serializedObject.FindProperty("m_selectedIndex");
     m_displayTilemapRList         = serializedObject.FindProperty("m_displayTilemapRList");
     m_tilemapReordList            = CreateTilemapReorderableList();
     m_tilemapReordList.index      = m_selectedIndexProp.intValue;
     m_sceneViewTilemapRList       = CreateTilemapReorderableList();
     m_sceneViewTilemapRList.index = m_selectedIndexProp.intValue;
     if (!m_target.DisplayTilemapRList)
     {
         m_sceneViewTilemapRList.elementHeight = 0f;
         m_sceneViewTilemapRList.draggable     = m_sceneViewTilemapRList.elementHeight > 0f;
         m_sceneViewTilemapRList.displayAdd    = m_sceneViewTilemapRList.draggable;
         m_sceneViewTilemapRList.displayRemove = m_sceneViewTilemapRList.draggable;
     }
 }
コード例 #5
0
        void OnValidate()
        {
            BuildTilechunkDictionary();
            m_parentTilemapGroup = GetComponentInParent <TilemapGroup>();
#if UNITY_EDITOR
            // fix: for tilemaps created with version 1.3.5 or below
            if (m_tintColor == default(Color))
            {
                Debug.Log("Fixing tilemap made with version below 1.3.5: " + name);
                m_tintColor = m_material.color; //take the color from the material
                m_pixelSnap = Material.HasProperty("PixelSnap") && Material.IsKeywordEnabled("PIXELSNAP_ON");
                bool fixMaterial = string.IsNullOrEmpty(UnityEditor.AssetDatabase.GetAssetPath(m_material));
                if (fixMaterial)
                {
                    m_material = Resources.GetBuiltinResource <Material>("Sprites-Default.mat");
                }
            }
            //---
#endif
            PixelSnap = m_pixelSnap;
        }
コード例 #6
0
ファイル: TilemapUtils.cs プロジェクト: wszhhx/SwordDefence
        //ref: http://answers.unity3d.com/questions/1193700/what-is-the-proper-way-to-draw-previews-for-custom.html
        /// <summary>
        /// Creates a Texture2D with a preview of a tilemap or tilemapGroup. In case you use a tilemapGroup, the tilemap will be used as reference for the PixelsPerUnits.
        /// </summary>
        /// <param name="tilemap"></param>
        /// <param name="tilemapGroup"></param>
        /// <returns></returns>
        public static Texture2D CreateTilemapGroupPreviewTexture(STETilemap tilemap, TilemapGroup tilemapGroup = null)
        {
            float  pixelToUnits       = tilemap.Tileset.TilePxSize.x / tilemap.CellSize.x;
            Bounds tilemapGroupBounds = tilemap.MapBounds;

            if (tilemapGroup)
            {
                tilemapGroup.IterateTilemapWithAction((STETilemap tmap) => tilemapGroupBounds.Encapsulate(tmap.MapBounds));
            }
            Vector2 size = tilemapGroupBounds.size * pixelToUnits;

            Camera previewCamera = Camera.main ? Camera.main : Object.FindObjectOfType <Camera>();

            previewCamera   = GameObject.Instantiate(previewCamera);
            s_previewCamera = previewCamera;
            RenderTexture rendTextr = new RenderTexture((int)size.x, (int)size.y, 32, RenderTextureFormat.ARGB32);

            rendTextr.Create();
            previewCamera.transform.position = tilemap.transform.TransformPoint(new Vector3(tilemapGroupBounds.center.x, tilemapGroupBounds.center.y, -10));

            RenderTexture savedActiveRT         = RenderTexture.active;
            RenderTexture savedCamTargetTexture = previewCamera.targetTexture;

            RenderTexture.active           = rendTextr;
            previewCamera.targetTexture    = rendTextr;
            previewCamera.orthographicSize = (previewCamera.pixelRect.height) / (2f * pixelToUnits);
            previewCamera.Render();
            Texture2D outputTexture = new Texture2D((int)size.x, (int)size.y, TextureFormat.ARGB32, false);

            outputTexture.ReadPixels(new Rect(0, 0, (int)size.x, (int)size.y), 0, 0);
            outputTexture.Apply();
            previewCamera.targetTexture = savedCamTargetTexture;
            RenderTexture.active        = savedActiveRT;

            Object.DestroyImmediate(rendTextr);
            Object.DestroyImmediate(previewCamera.gameObject);
            s_previewCamera = null;

            return(outputTexture);
        }
コード例 #7
0
ファイル: STEditorToolbars.cs プロジェクト: chickenlegs0/Luka
        private void OnToolSelected_BrushToolbar(ToolbarControl source, int selectedToolIdx, int prevSelectedToolIdx)
        {
            ToolIcons.eToolIcon toolIcon = (ToolIcons.eToolIcon)selectedToolIdx;
            switch (toolIcon)
            {
            case ToolIcons.eToolIcon.Pencil:
                TilemapEditor.s_brushMode = TilemapEditor.eBrushMode.Paint;
                Tools.current             = Tool.None;
                break;

            case ToolIcons.eToolIcon.Erase:
                TilemapEditor.s_brushMode = TilemapEditor.eBrushMode.Erase;
                brushPaintToolbar.TriggerButton(0);
                Tools.current = Tool.None;
                break;

            case ToolIcons.eToolIcon.Fill:
                TilemapEditor.s_brushMode = TilemapEditor.eBrushMode.Fill;
                brushPaintToolbar.TriggerButton(0);
                Tools.current = Tool.None;
                break;

            case ToolIcons.eToolIcon.FlipV:
                BrushBehaviour.SFlipV();
                Tools.current      = Tool.None;
                source.SelectedIdx = prevSelectedToolIdx;
                break;

            case ToolIcons.eToolIcon.FlipH:
                BrushBehaviour.SFlipH();
                Tools.current      = Tool.None;
                source.SelectedIdx = prevSelectedToolIdx;
                break;

            case ToolIcons.eToolIcon.Rot90:
                BrushBehaviour.SRot90();
                Tools.current      = Tool.None;
                source.SelectedIdx = prevSelectedToolIdx;
                break;

            case ToolIcons.eToolIcon.Info:
                TilemapEditor.s_displayHelpBox = !TilemapEditor.s_displayHelpBox;
                Tools.current      = Tool.None;
                source.SelectedIdx = prevSelectedToolIdx;
                source.SetHighlight(selectedToolIdx, TilemapEditor.s_displayHelpBox);
                break;

            case ToolIcons.eToolIcon.Refresh:
                TilemapGroup tilemapGroup = Selection.activeGameObject.GetComponent <TilemapGroup>();
                if (tilemapGroup)
                {
                    foreach (STETilemap tilemap in tilemapGroup.Tilemaps)
                    {
                        tilemap.Refresh(true, true, true, true);
                    }
                }
                else
                {
                    STETilemap tilemap = Selection.activeGameObject.GetComponent <STETilemap>();
                    if (tilemap)
                    {
                        tilemap.Refresh(true, true, true, true);
                    }
                }
                Tools.current      = Tool.None;
                source.SelectedIdx = prevSelectedToolIdx;
                break;
            }
        }
コード例 #8
0
ファイル: TilemapEditor.cs プロジェクト: dgellow/ManySpikes
        private void _DoToolbarButton(Rect rToolBtn, ToolIcons.eToolIcon toolIcon)
        {
            BrushBehaviour brush        = BrushBehaviour.GetOrCreateBrush((Tilemap)target);
            int            iconPadding  = 6;
            Rect           rToolIcon    = new Rect(rToolBtn.x + iconPadding, rToolBtn.y + iconPadding, rToolBtn.size.y - 2 * iconPadding, rToolBtn.size.y - 2 * iconPadding);
            Color          activeColor  = new Color(1f, 1f, 1f, 0.8f);
            Color          disableColor = new Color(1f, 1f, 1f, 0.4f);

            switch (toolIcon)
            {
            case ToolIcons.eToolIcon.Pencil:
                GUI.color = GetBrushMode() == eBrushMode.Paint ? activeColor : disableColor;
                if (GUI.Button(rToolBtn, new GUIContent("", "Paint")))
                {
                    s_brushMode = eBrushMode.Paint;
                }
                break;

            case ToolIcons.eToolIcon.Erase:
                GUI.color = GetBrushMode() == eBrushMode.Erase ? activeColor : disableColor;
                if (GUI.Button(rToolBtn, new GUIContent("", "Erase (Hold Shift)")))
                {
                    s_brushMode = eBrushMode.Erase;
                }
                break;

            case ToolIcons.eToolIcon.Fill:
                GUI.color = GetBrushMode() == eBrushMode.Fill ? activeColor : disableColor;
                if (GUI.Button(rToolBtn, new GUIContent("", "Fill (Double click)")))
                {
                    s_brushMode = eBrushMode.Fill;
                }
                break;

            case ToolIcons.eToolIcon.FlipV:
                GUI.color = s_brushFlipV ? activeColor : disableColor;
                if (GUI.Button(rToolBtn, new GUIContent("", "Flip Vertical (" + ShortcutKeys.k_FlipV + ")")))
                {
                    brush.FlipV();
                    s_brushFlipV = !s_brushFlipV;
                }
                break;

            case ToolIcons.eToolIcon.FlipH:
                GUI.color = s_brushFlipH ? activeColor : disableColor;
                if (GUI.Button(rToolBtn, new GUIContent("", "Flip Horizontal (" + ShortcutKeys.k_FlipH + ")")))
                {
                    brush.FlipH();
                    s_brushFlipH = !s_brushFlipH;
                }
                break;

            case ToolIcons.eToolIcon.Rot90:
                GUI.color = s_brushRot90 ? activeColor : disableColor;
                if (GUI.Button(rToolBtn, new GUIContent("", "Rotate 90 clockwise (" + ShortcutKeys.k_Rot90 + "); anticlockwise (" + ShortcutKeys.k_Rot90Back + ")")))
                {
                    if (!s_brushRot90)
                    {
                        brush.Rot90();
                    }
                    else
                    {
                        brush.Rot90Back();
                    }
                    s_brushRot90 = !s_brushRot90;
                }
                break;

            case ToolIcons.eToolIcon.Info:
                GUI.color = m_displayHelpBox ? activeColor : disableColor;
                if (GUI.Button(rToolBtn, new GUIContent("", " Display Help (F1)")))
                {
                    m_displayHelpBox = !m_displayHelpBox;
                }
                break;

            case ToolIcons.eToolIcon.Refresh:
                GUI.color = m_displayHelpBox ? activeColor : disableColor;
                if (GUI.Button(rToolBtn, new GUIContent("", " Refresh Tilemap (F5)")))
                {
                    TilemapGroup tilemapGroup = Selection.activeGameObject.GetComponent <TilemapGroup>();
                    if (tilemapGroup)
                    {
                        foreach (Tilemap tilemap in tilemapGroup.Tilemaps)
                        {
                            tilemap.Refresh(true, true, true, true);
                        }
                    }
                    else
                    {
                        m_tilemap.Refresh(true, true, true, true);
                    }
                }
                break;
            }
            GUI.color = Color.white;
            GUI.DrawTexture(rToolIcon, ToolIcons.GetToolTexture(toolIcon));
        }
コード例 #9
0
ファイル: Tilemap.cs プロジェクト: Emolyptic/PixelGame
 void OnTransformParentChanged()
 {
     m_parentTilemapGroup = GetComponentInParent <TilemapGroup>();
 }
コード例 #10
0
 /// <summary>
 /// Creates a new MapTileNode
 /// </summary>
 /// <param name="idx">The index is a concatenation of the two grid positions</param>
 /// <param name="owner"></param>
 public MapTileNode(TilemapGroup tilemapGroup, MapPathFinding owner)
 {
     m_owner        = owner;
     m_tilemapGroup = tilemapGroup;
 }