using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using Random = UnityEngine.Random; public class TileController : MonoBehaviour { public static TileController Instance; public Shader standartPattern; public Shader oneTileRotetePattern; public Shader twoTilePattern; public Shader brickWallPatern; public Shader blockShader; private int scalingNormalMap = 5; public List tileTextureList; public List normalMapTextureList; private float grout = 0; private void Awake() { if (Instance == null) Instance = this; } public void SetStandartPatternMaterial(GameObject currentWall, Texture tileTexture,Texture normalMap ,Texture groutTexture, Color groutColor,float tileWidth, float tileHeight, float groutWidth ,float rotatateAngle = 0, int smoothness = 0) { Debug.Log($"Last Cplor: {groutColor}"); Renderer renderer = currentWall.GetComponent(); Material material = new Material(renderer.material); Material oldMaterial = renderer.material; material.shader = standartPattern; material.SetTexture("_TileTexture", tileTexture); material.SetTexture("_GroutTexture", groutTexture); material.SetTexture("_TileNormalMap", normalMap); material.SetFloat("_TileWidth", tileWidth); material.SetFloat("_TileHeight", tileHeight); material.SetFloat("_GroutWidth", groutWidth); material.SetColor("_GroutColor", groutColor); material.SetFloat("_TileSmoothness", smoothness); material.SetFloat("_TileNormalScale", scalingNormalMap); material.SetFloat("_RotationAngle", rotatateAngle); renderer.material = material; SaveChangeModel.Instance.SaveChangeMaterial(currentWall, renderer,material, oldMaterial); } public void SetOnTileRotatePattern(GameObject currentWall, Texture tileTexture, Texture normalMap, Texture groutTexture, Color groutColor,float tileWidth, float tileHeight, float groutWidth, float rotatateAngle = 0, int smoothness = 0) { Renderer renderer = currentWall.GetComponent(); Material material = new Material(renderer.material); Material oldMaterial = renderer.material; material.shader = oneTileRotetePattern; material.SetTexture("_TileTexture", tileTexture); material.SetTexture("_TileNormalMap", normalMap); material.SetTexture("_GroutTexture", groutTexture); material.SetFloat("_TileWidth", tileWidth); material.SetFloat("_TileHeight", tileHeight); material.SetFloat("_GroutWidth", groutWidth); material.SetColor("_GroutColor", groutColor); material.SetFloat("_TileSmoothness", smoothness); material.SetFloat("_TileNormalScale", scalingNormalMap); material.SetFloat("_RotationAngle", rotatateAngle); renderer.material = material; SaveChangeModel.Instance.SaveChangeMaterial(currentWall, renderer,material, oldMaterial); } public void SetTwoTileRotatePattern(GameObject currentWall, Texture tileTexture,Texture normalMap ,Texture secondTileTexture ,Texture secondNormalMap,Texture groutTexture, Color groutColor,float tileWidth, float tileHeight, float groutWidth,float rotatateAngle = 0, int smoothness = 0) { Renderer renderer = currentWall.GetComponent(); Material material = new Material(renderer.material); Material oldMaterial = renderer.material; material.shader = twoTilePattern; material.SetTexture("_TileTexture1", tileTexture); material.SetTexture("_TileNormalMap1", normalMap); material.SetTexture("_TileTexture2", secondTileTexture); material.SetTexture("_TileNormalMap2", secondNormalMap); material.SetTexture("_GroutTexture", groutTexture); material.SetFloat("_TileWidth", tileWidth); material.SetFloat("_TileHeight", tileHeight); material.SetFloat("_GroutWidth", groutWidth); material.SetColor("_GroutColor", groutColor); material.SetFloat("_TileSmoothness", smoothness); material.SetFloat("_TileNormalScale", scalingNormalMap); material.SetFloat("_RotationAngle", rotatateAngle); renderer.material = material; SaveChangeModel.Instance.SaveChangeMaterial(currentWall, renderer,material, oldMaterial); } public void SetBrickWallPattern(GameObject currentWall, Texture tileTexture,Texture normalMap ,Texture groutTexture, Color groutColor,float tileWidth, float tileHeight, float groutWidth,float rotatateAngle = 0, int smoothness = 0) { Renderer renderer = currentWall.GetComponent(); Material material = new Material(renderer.material); Material oldMaterial = renderer.material; material.shader = brickWallPatern; material.SetTexture("_TileTexture", tileTexture); material.SetTexture("_TileNormalMap", normalMap); material.SetTexture("_GroutTexture", groutTexture); material.SetFloat("_TileWidth", tileWidth); material.SetFloat("_TileHeight", tileHeight); material.SetFloat("_GroutWidth", groutWidth); material.SetColor("_GroutColor", groutColor); material.SetFloat("_TileSmoothness", smoothness); material.SetFloat("_TileNormalScale", scalingNormalMap); material.SetFloat("_RotationAngle", rotatateAngle); renderer.material = material; SaveChangeModel.Instance.SaveChangeMaterial(currentWall, renderer,material, oldMaterial); } public void SetBlockPattern(GameObject currentWall, Texture tileTexture,Texture normalMap ,Texture groutTexture, Color groutColor,float tileWidth, float tileHeight, float groutWidth,float rotatateAngle = 0, int smoothness = 0) { // tileWidth *= 3; // tileHeight *= 3; Renderer renderer = currentWall.GetComponent(); Material material = new Material(renderer.material); Material oldMaterial = renderer.material; material.shader = blockShader; material.SetTexture("_TileTexture", tileTexture); material.SetTexture("_TileNormalMap", normalMap); material.SetTexture("_GroutTexture", groutTexture); material.SetFloat("_BlockWidth", tileWidth); material.SetFloat("_BlockHeight", tileHeight); material.SetFloat("_GroutWidth", groutWidth); material.SetColor("_GroutColor", groutColor); material.SetFloat("_TileSmoothness", smoothness); material.SetFloat("_TileNormalScale", scalingNormalMap); material.SetFloat("_RotationAngle", rotatateAngle); renderer.material = material; SaveChangeModel.Instance.SaveChangeMaterial(currentWall, renderer,material, oldMaterial); } public void TestPatterns() { float[] g = new[] {123f, 12f, 95f}; JsonTile tile = new JsonTile(); tile.angle = 0; tile.pattern = "standart"; tile.firstName = "cabinet"; tile.groutColor = g; tile.secondName = ""; tile.tileHeight = 20; tile.tileWidth = 20; tile.groutWidth = 1; string s = JsonUtility.ToJson(tile); Debug.Log(s); JsonTile t2 = JsonUtility.FromJson(s); grout += t2.groutWidth; Color groutColor = new Color(t2.groutColor[0]/ 255, t2.groutColor[1]/255, t2.groutColor[2]/255, 1); Debug.Log($"GROUT COLOR: {groutColor}"); SetBlockPattern(BuildingRoom.Instance.GetSelectedObj(), tileTextureList[0],null, null, groutColor, t2.tileWidth, t2.tileHeight, grout, t2.angle); // SetTwoTileRotatePattern(BuildingRoom.Instance.GetSelectedObj(), tileTextureList[0], null,tileTextureList[1], null, null, groutColor, t2.tileWidth,t2.tileHeight, grout, 0,0); } public void TestChangePattern(TilePatternsEnum type,string firstName, string secondName, string groutName, float height, float width, float grout, float angle) { GameObject selectedWall = BuildingRoom.Instance.GetSelectedObj(); if (!selectedWall.CompareTag("Wall")) { selectedWall = null; return; } Texture firstText = null; Texture secondTexture = null; Texture groutText = null; Texture normalMapFirst = null; Texture normalMapSecond = null; for (int i = 0; i < tileTextureList.Count; i++) { if (tileTextureList[i].name == firstName) { firstText = tileTextureList[i]; normalMapFirst = normalMapTextureList[i]; } if (tileTextureList[i].name == secondName) { secondTexture = tileTextureList[i]; normalMapSecond = normalMapTextureList[i]; } if (tileTextureList[i].name == groutName) { //groutText = tileTextureList[i]; } } SetStandartPatternMaterial(selectedWall, firstText, normalMapFirst, groutText, Color.red, width, height, grout, angle); // SetOnTileRotatePattern(selectedWall, firstText, normalMapFirst, groutText, Color.white, width, height, grout, angle); // SetTwoTileRotatePattern(selectedWall, firstText,normalMapFirst,secondTexture,normalMapSecond, groutText, Color.white,width,height, grout, angle); // SetBlockPattern(selectedWall, firstText, normalMapFirst, groutText, Color.white, width, height, grout, angle); // SetBrickWallPattern(selectedWall, firstText, normalMapFirst, groutText, Color.white, width, height, grout, angle); } } [Serializable] public class JSColor { public Color groutColor; }