public void CreateTower(TowerData towerData, IPlacementArea placementArea, IntVector2 placeGrid, Vector3 position, Quaternion rotation)
        {
            if (towerData == null)
            {
                return;
            }

            TowerLevelData towerLevelData = towerData.GetTowerLevelData(0);

            if (dataPlayer.Energy < towerLevelData.BuildEnergy)
            {
                return;
            }

            dataPlayer.AddEnergy(-towerLevelData.BuildEnergy);

            Tower tower = dataTower.CreateTower(towerData.Id);

            if (tower == null)
            {
                Log.Error("Create tower fail,Tower data id is '{0}'.", towerData.Id);
                return;
            }

            entityLoader.ShowEntity(towerData.EntityId, TypeUtility.GetEntityType(tower.Type),
                                    (entity) =>
            {
                EntityTowerBase entityTowerBase = entity.Logic as EntityTowerBase;
                dicTowerInfo.Add(tower.SerialId, TowerInfo.Create(tower, entityTowerBase, placementArea, placeGrid));
            }
                                    , EntityDataTower.Create(tower, position, rotation));

            HidePreviewTower();
        }
            public static TowerInfo Create(Tower tower, EntityTowerBase entityTower, IPlacementArea placementArea, IntVector2 placeGrid)
            {
                TowerInfo towerInfo = ReferencePool.Acquire <TowerInfo>();

                towerInfo.Tower         = tower;
                towerInfo.EntityTower   = entityTower;
                towerInfo.PlacementArea = placementArea;
                towerInfo.PlaceGrid     = placeGrid;
                return(towerInfo);
            }
        public void Update(float elapseSeconds, float realElapseSeconds)
        {
            if (level == null)
            {
                return;
            }

            if (dataLevel.LevelState != EnumLevelState.Prepare && dataLevel.LevelState != EnumLevelState.Normal)
            {
                return;
            }

            if (!level.Finish)
            {
                level.ProcessLevel(elapseSeconds, realElapseSeconds);
            }

            if (isBuilding)
            {
                if (Input.GetMouseButtonDown(0) && previewTowerEntityLogic != null && previewTowerEntityLogic.CanPlace)
                {
                    previewTowerEntityLogic.TryBuildTower();
                }
                if (Input.GetMouseButtonDown(1))
                {
                    HidePreviewTower();
                }
            }
            else
            {
                if (Input.GetMouseButtonDown(0))
                {
                    Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                    RaycastHit raycastHit;
                    if (Physics.Raycast(ray, out raycastHit, float.MaxValue, LayerMask.GetMask("Towers")))
                    {
                        if (raycastHit.collider != null)
                        {
                            EntityTowerBase entityTowerBase = raycastHit.collider.gameObject.GetComponent <EntityTowerBase>();
                            if (entityTowerBase != null)
                            {
                                entityTowerBase.ShowControlForm();
                            }
                        }
                    }
                }
            }
        }