| | |
| | | using UnityEngine; |
| | | using TowerDefense.Level; |
| | | |
| | | namespace TowerDefense.UI.HUD |
| | | { |
| | | /// <summary> |
| | | /// States the placement tile can be in |
| | | /// </summary> |
| | | public enum PlacementTileState |
| | | { |
| | | Filled, |
| | | Empty |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Simple class to illustrate tile placement locations |
| | | /// 主要功能是在场景内能够表示可以放置Tower的位置 |
| | | /// </summary> |
| | | public class PlacementTile : MonoBehaviour |
| | | { |
| | | /// <summary> |
| | | /// Material to use when this tile is empty |
| | | /// </summary> |
| | | public Material emptyMaterial; |
| | | /// <summary> |
| | | /// Material to use when this tile is filled |
| | | /// </summary> |
| | | public Material filledMaterial; |
| | | /// <summary> |
| | | /// The renderer whose material we're changing |
| | | /// </summary> |
| | | public Renderer tileRenderer; |
| | | /// <summary> |
| | | /// States the placement tile can be in |
| | | /// </summary> |
| | | public enum PlacementTileState |
| | | { |
| | | Filled, |
| | | Empty |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 等待购买的材质 |
| | | /// </summary> |
| | | public Material waitBuyMat; |
| | | /// <summary> |
| | | /// Simple class to illustrate tile placement locations |
| | | /// 主要功能是在场景内能够表示可以放置Tower的位置 |
| | | /// </summary> |
| | | public class PlacementTile : MonoBehaviour |
| | | { |
| | | /// <summary> |
| | | /// Material to use when this tile is empty |
| | | /// </summary> |
| | | public Material emptyMaterial; |
| | | /// <summary> |
| | | /// Material to use when this tile is filled |
| | | /// </summary> |
| | | public Material filledMaterial; |
| | | /// <summary> |
| | | /// The renderer whose material we're changing |
| | | /// </summary> |
| | | public Renderer tileRenderer; |
| | | |
| | | /// <summary> |
| | | /// 已开放的材质. |
| | | /// </summary> |
| | | public Material openMat; |
| | | /// <summary> |
| | | /// 等待购买的材质 |
| | | /// </summary> |
| | | public Material waitBuyMat; |
| | | |
| | | /// <summary> |
| | | /// 塔位已被破坏的材质 |
| | | /// </summary> |
| | | public Material destroyedMat; |
| | | /// <summary> |
| | | /// 已开放的材质. |
| | | /// </summary> |
| | | public Material openMat; |
| | | |
| | | /// <summary> |
| | | /// Update the state of this placement tile |
| | | /// </summary> |
| | | public void SetState(PlacementTileState newState) |
| | | { |
| | | switch (newState) |
| | | { |
| | | case PlacementTileState.Filled: |
| | | if (tileRenderer != null && filledMaterial != null) |
| | | { |
| | | tileRenderer.sharedMaterial = filledMaterial; |
| | | } |
| | | break; |
| | | case PlacementTileState.Empty: |
| | | if (tileRenderer != null && emptyMaterial != null) |
| | | { |
| | | tileRenderer.sharedMaterial = emptyMaterial; |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 塔位已被破坏的材质 |
| | | /// </summary> |
| | | public Material destroyedMat; |
| | | |
| | | /// <summary> |
| | | /// 可以放置的塔位 |
| | | /// </summary> |
| | | public Renderer canPlaceRenderer; |
| | | |
| | | /// <summary> |
| | | /// 可以放置的 |
| | | /// </summary> |
| | | public Material canPlaceMat; |
| | | |
| | | /// <summary> |
| | | /// 放置在当前位置 |
| | | /// </summary> |
| | | public Material selectMat; |
| | | |
| | | public ParticleSystem myPS;//可以升级的特效 |
| | | |
| | | |
| | | /// <summary> |
| | | /// 根据传入的参数来设置当前Grid对应的显示信息 |
| | | /// WORK START: 从这个函数开始,替换相关的显示效果 |
| | | /// </summary> |
| | | /// <param name="newtype"></param> |
| | | public void SetTileType( PlacementGridType newtype) |
| | | /// <summary> |
| | | /// Update the state of this placement tile |
| | | /// </summary> |
| | | public void SetState(PlacementTileState newState) |
| | | { |
| | | switch( newtype) |
| | | switch (newState) |
| | | { |
| | | case PlacementGridType.EGridWaitBuy: |
| | | if (tileRenderer != null && waitBuyMat != null) |
| | | tileRenderer.sharedMaterial = waitBuyMat; |
| | | break; |
| | | case PlacementGridType.EGridOpen: |
| | | if (tileRenderer != null && openMat != null) |
| | | tileRenderer.sharedMaterial = openMat; |
| | | break; |
| | | case PlacementGridType.EGridDestroyed: |
| | | if (tileRenderer != null && destroyedMat != null) |
| | | tileRenderer.sharedMaterial = destroyedMat; |
| | | break; |
| | | case PlacementTileState.Filled: |
| | | if (tileRenderer != null && filledMaterial != null) |
| | | { |
| | | tileRenderer.sharedMaterial = filledMaterial; |
| | | } |
| | | break; |
| | | case PlacementTileState.Empty: |
| | | if (tileRenderer != null && emptyMaterial != null) |
| | | { |
| | | tileRenderer.sharedMaterial = emptyMaterial; |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void SetParticleSystem(bool isOn) |
| | | { |
| | | if (isOn) |
| | | { |
| | | if (myPS.gameObject.activeSelf != isOn) myPS.gameObject.SetActive(isOn); |
| | | myPS.Play(); |
| | | |
| | | } |
| | | else |
| | | { |
| | | myPS.Stop(); |
| | | if (myPS.gameObject.activeSelf != isOn) myPS.gameObject.SetActive(isOn); |
| | | |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置是否可以放置 |
| | | /// </summary> |
| | | /// <param name="canPlace"></param> |
| | | public void CheckCanPlace(bool canPlace) |
| | | { |
| | | if (canPlaceRenderer) |
| | | { |
| | | if (canPlaceRenderer.enabled != canPlace) |
| | | canPlaceRenderer.enabled = canPlace; |
| | | if (canPlace) |
| | | { |
| | | SetSelect(false); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置当前材质 |
| | | /// </summary> |
| | | /// <param name="isSelect"></param> |
| | | public void SetSelect(bool isSelect) |
| | | { |
| | | canPlaceRenderer.material = isSelect ? selectMat : canPlaceMat; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 根据传入的参数来设置当前Grid对应的显示信息 |
| | | /// WORK START: 从这个函数开始,替换相关的显示效果 |
| | | /// </summary> |
| | | /// <param name="newtype"></param> |
| | | public void SetTileType(PlacementGridType newtype) |
| | | { |
| | | switch (newtype) |
| | | { |
| | | case PlacementGridType.EGridWaitBuy: |
| | | if (tileRenderer != null && waitBuyMat != null) |
| | | tileRenderer.sharedMaterial = waitBuyMat; |
| | | break; |
| | | case PlacementGridType.EGridOpen: |
| | | if (EndlessLevelManager.instanceExists) |
| | | { |
| | | tileRenderer.enabled = false; |
| | | } |
| | | else |
| | | { |
| | | if (tileRenderer != null && openMat != null) |
| | | tileRenderer.sharedMaterial = openMat; |
| | | } |
| | | break; |
| | | case PlacementGridType.EGridDestroyed: |
| | | if (tileRenderer != null && destroyedMat != null) |
| | | tileRenderer.sharedMaterial = destroyedMat; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |