public static void ChangeSpriteToClick() { if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { Debug.Log("Je click"); Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition); RaycastHit hitInfo; Debug.Log(Physics.Raycast(worldRay, out hitInfo, int.MaxValue)); if (Physics.Raycast(worldRay, out hitInfo, int.MaxValue)) { Debug.Log("Physics raycast"); if (hitInfo.collider.gameObject != null) { GameObject _hit = hitInfo.collider.gameObject; List <GameObject> _tileSquareList = new List <GameObject>(); for (int i = 0; i < GridGenerator.paintSize; i++) { for (int j = 0; j < GridGenerator.paintSize; j++) { GameObject _tempTile = ToolGridGenerator.GetTileSquare(new Vector2(i + _hit.transform.position.x, j + _hit.transform.position.y)); if (_tempTile == null) { continue; } _tileSquareList.Add(ToolGridGenerator.GetTileSquare(new Vector2(i + _hit.transform.position.x, j + _hit.transform.position.y))); } } foreach (GameObject _tile in _tileSquareList) { _tile.GetComponentInChildren <SpriteRenderer>().sprite = spriteSelected; } Debug.Log("gameobject"); /* Debug.Log(spriteSelected.pixelsPerUnit); * hitInfo.collider.gameObject.GetComponentInChildren<SpriteRenderer>().sprite = spriteSelected; * Debug.Log(ToolGeneric.spriteSelected.texture.height);*/ } } } }
void OnGUI() { arrayIconeTool = Resources.LoadAll <Texture>("Resources/MapEdit2D/_SPRITE/IconeTools"); windowToolSelected = GUILayout.Toolbar(windowToolSelected, new string[] { "Generator", "Tools" }); switch (windowToolSelected) { case 1: EditorGUILayout.Space(); ToolGeneric.CreateButonSearchSpriteFolder(); GUILayout.BeginHorizontal(); GUILayout.TextField(ToolGeneric.pathFolderSprite); ToolGeneric.CreateButtonSearchSprite(); GUILayout.EndHorizontal(); toolsSelected = GUILayout.Toolbar(toolsSelected, new string[] { "1", "2", "3" }); switch (toolsSelected) { default: paintSize = EditorGUILayout.IntSlider("Paint size : ", paintSize, 1, 10, new GUILayoutOption[] { }); EditorGUILayout.Space(); ToolGeneric.CreateSpriteGridScrollView(); break; case 1: break; case 2: break; } break; default: EditorGUILayout.Space(); gridName = EditorGUILayout.TextField("Grid Name : ", gridName); gridSize = EditorGUILayout.Vector2IntField("Grid size :", gridSize); tilesType = EditorGUILayout.Popup("Type", tilesType, new string[] { "Square", "Isometric", "Hexagonal" }); EditorGUILayout.Space(); if (GUILayout.Button("Generate Grid")) { ToolGridGenerator.GridGen(gridSize.y, gridSize.x); } break; } }