using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; public class BlockSpawner : MonoBehaviour { <<<<<<< HEAD ======= private void Start() { _playerInput = GetComponent(); } >>>>>>> shader [SerializeField] private GameObject _blockToPlace; public GameObject BlockToPlace { get { return _blockToPlace; } set { DisablePreviewMode(); _blockToPlace = value; } } PlayerInput _playerInput; public float spawnDistance = 3f; public Shader previewShader; private GameObject _blockInstance; private bool _isPreview = false; private Shader _initialShader; public bool _blockRotating = false; private Quaternion _lastRotationState; private Shader _initialShader; public void OnPlaceBlock() { if (!_isPreview) return; _blockInstance.transform.SetParent(null); SwitchToDefaultRender(); _blockInstance = null; DisablePreviewMode(); } public void OnTogglePreviewMode(InputValue value) { float valueAsFloat = value.Get(); if (valueAsFloat == 1f) { EnablePreviewMode(); } else { DisablePreviewMode(); } } public void OnEnterRotateBlock(InputValue value) { float valueAsFloat = value.Get(); Debug.Log(valueAsFloat); _blockRotating = true; } public void OnExitRotateBlock(InputValue value) { float valueAsFloat = value.Get(); Debug.Log(valueAsFloat); _blockRotating = false; } public void OnRotateBlock(InputValue value) { if (_isPreview && _blockRotating) { Vector2 iMouseMovement = value.Get(); Transform vTransform = _blockInstance.transform; //vTransform.Rotate(iMouseMovement.y / 10, iMouseMovement.x / 10, 0); vTransform.RotateAround(vTransform.position, transform.right, iMouseMovement.y / 10.0f); vTransform.RotateAround(vTransform.position, transform.up, iMouseMovement.x / 10.0f); //vTransform.eulerAngles += vTransform.worldToLocalMatrix.MultiplyVector(new Vector3(iMouseMovement.y / 10, iMouseMovement.x / 10, 0)); //vTransform.Rotate(iMouseMovement.y/10, iMouseMovement.x/10, 0); _lastRotationState = vTransform.rotation; } } private void EnablePreviewMode() { if (_blockToPlace == null) return; Vector3 spawnPos = Vector3.forward * spawnDistance; _blockInstance = Instantiate(_blockToPlace, spawnPos, Quaternion.identity); _blockInstance.transform.SetParent(this.transform, false); _blockInstance.transform.rotation = _lastRotationState; _isPreview = true; SwitchToMeshRender(); } private void DisablePreviewMode() { if (_blockInstance != null) Destroy(_blockInstance); _isPreview = false; } private void SwitchToMeshRender() { MeshRenderer vRenderer = _blockInstance.GetComponent(); Material vMaterial = vRenderer.material; _initialShader = vMaterial.shader; vMaterial.shader = previewShader; } private void SwitchToDefaultRender() { MeshRenderer vRenderer = _blockInstance.GetComponent(); Material vMaterial = vRenderer.material; vMaterial.shader = _initialShader; } <<<<<<< HEAD ======= >>>>>>> shader }