97 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			97 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			C#
		
	
	
	
|  | using System; | |||
|  | using System.Collections; | |||
|  | using System.Collections.Generic; | |||
|  | using UnityEngine; | |||
|  | 
 | |||
|  | public class BlockSlot : MonoBehaviour | |||
|  | { | |||
|  |     public BlockUnit MyUnit => mUnit; | |||
|  |     public bool HasUnit => mUnit != null; | |||
|  |     public int Index => mIndex; | |||
|  | 
 | |||
|  |     private Action<int> mDelPickUp; | |||
|  |     private Action<int> mDelMove; | |||
|  |     private Action<int> mDelDrowDown; | |||
|  | 
 | |||
|  |     [SerializeField] MeshRenderer mRdrFloor; | |||
|  | 
 | |||
|  |     private BoxCollider mCol; | |||
|  |     private BlockUnit mUnit; | |||
|  | 
 | |||
|  |     private int mIndex; | |||
|  |      | |||
|  |     private void Awake() | |||
|  |     { | |||
|  |         mUnit = GetComponentInChildren<BlockUnit>(); | |||
|  |     } | |||
|  | 
 | |||
|  |     public void Init(int pIndex, Action<int> pDelPickUp = null, Action<int> pDelMove = null, Action<int> pDelDropDown = null) | |||
|  |     { | |||
|  |         if (mCol == null) | |||
|  |         { | |||
|  |             mCol = GetComponent<BoxCollider>(); | |||
|  |         } | |||
|  | 
 | |||
|  |         mIndex = pIndex; | |||
|  | 
 | |||
|  |         SetDelegate(pDelPickUp, pDelMove, pDelDropDown); | |||
|  | 
 | |||
|  |         SetState(BlockState.Normal); | |||
|  |     } | |||
|  | 
 | |||
|  |     public void SetDelegate(Action<int> pDelPickUp = null, Action<int> pDelMove = null, Action<int> pDelDropDown = null) | |||
|  |     { | |||
|  |         mDelPickUp = pDelPickUp; | |||
|  |         mDelMove = pDelMove; | |||
|  |         mDelDrowDown = pDelDropDown; | |||
|  | 
 | |||
|  |         mCol.enabled = mDelPickUp != null; | |||
|  |     } | |||
|  | 
 | |||
|  |     public void ShowFloor(bool pShow) | |||
|  |     { | |||
|  |         mRdrFloor.enabled = pShow; | |||
|  |     } | |||
|  | 
 | |||
|  |     public void SetUnit(BlockUnit pUnit) | |||
|  |     { | |||
|  |         mUnit = pUnit; | |||
|  |         if (mUnit != null) | |||
|  |         { | |||
|  |             mUnit.SetGroupID(mIndex); | |||
|  |             mUnit.transform.SetParent(transform); | |||
|  |             Utils.NormalizeGameObject(mUnit.gameObject); | |||
|  |         } | |||
|  |     } | |||
|  | 
 | |||
|  |     public void SetState(BlockState pState) | |||
|  |     { | |||
|  |         mRdrFloor.gameObject.SetActive(pState != BlockState.Normal); | |||
|  |         Material tMat = ResourceManager.Instance.LoadRes<Material>(Const.Path.GetBlockMat(pState)); | |||
|  |         mRdrFloor.material = tMat; | |||
|  |     } | |||
|  | 
 | |||
|  |     private void OnMouseDown() | |||
|  |     { | |||
|  |         mDelPickUp?.Invoke(mIndex); | |||
|  |     } | |||
|  | 
 | |||
|  |     private void OnMouseDrag() | |||
|  |     { | |||
|  |         mDelMove?.Invoke(mIndex); | |||
|  |     } | |||
|  | 
 | |||
|  |     private void OnMouseUp() | |||
|  |     { | |||
|  |         mDelDrowDown?.Invoke(mIndex); | |||
|  |     } | |||
|  | } | |||
|  | 
 | |||
|  | public enum BlockState | |||
|  | { | |||
|  |     Normal, | |||
|  |     Picked, | |||
|  |     Movable, | |||
|  |     Mergable, | |||
|  |     Forbidden | |||
|  | } |