Beispiel #1
0
        public void UpdateBlockAreaEnter()
        {
            if (UsingUI())
            {
                return;
            }
            if (_isDraggingFunctionBlock || _isSelectFunctionBlock)
            {
                return;
            }
            FunctionBlockBase selectBlock = TryGetRaycastHitBlock(Input.mousePosition);

            if (selectBlock != null && _isShowBlockTip == false)
            {
                _isShowBlockTip = true;
                CameraEvent camera = new CameraEvent()
                {
                    blockBase = selectBlock,
                };
                if (OnBlockAreaEnter != null)
                {
                    OnBlockAreaEnter.Invoke(camera);
                }
            }
            else if (selectBlock == null)
            {
                CameraEvent camera = new CameraEvent()
                {
                    blockBase = null
                };
                _isShowBlockTip = false;
                OnBlockAreaExit.Invoke(camera);
            }
        }
Beispiel #2
0
 public void OnBlockAreaEnter(CameraManager.CameraEvent camera)
 {
     _currentEnterBlock = camera.blockBase;
     if (_currentEnterBlock != null)
     {
         _currentEnterBlock.SetBlockAreaEnter(true);
     }
 }
Beispiel #3
0
 /// <summary>
 /// Drag End
 /// </summary>
 /// <param name="camera"></param>
 public void OnBlockDragEnd(CameraManager.CameraEvent camera)
 {
     if (_dragBlock != null)
     {
         _dragBlock.OnBlockDragEnd(camera);
         _dragBlock = null;
     }
 }
Beispiel #4
0
 public void OnBlockAreaExit(CameraManager.CameraEvent camera)
 {
     if (_currentEnterBlock != null && camera.blockBase == null)
     {
         FunctionBlockBase temp = _currentEnterBlock;
         _currentEnterBlock = null;
         temp.SetBlockAreaEnter(false);
     }
 }
Beispiel #5
0
 public void OnGroundSelect(CameraManager.CameraEvent camera)
 {
     if (selectBlock != null)
     {
         FunctionBlockBase temp = selectBlock;
         selectBlock = null;
         temp.SetSelect(false);
     }
 }
Beispiel #6
0
        public void SetData()
        {
            _blockBase = UIUtility.SafeGetComponent <FunctionBlockBase>(transform);
            _infoData  = new BlockNormalInfoData(_blockBase.info.BlockID);
            _blockBase.OnBlockSelectAction    += Onselect;
            _blockBase.OnBlockAreaEnterAction += OnBlockAreaEnter;

            _infoData.InitModifier(_blockBase);
        }
Beispiel #7
0
        public void SetData()
        {
            _blockBase      = UIUtility.SafeGetComponent <FunctionBlockBase>(transform);
            manufactoryInfo = new ManufactoryInfo(_blockBase.functionBlock);
            formulaInfo     = new ManufactFormulaInfo(_blockBase.functionBlock.FunctionBlockID);

            _blockBase.OnBlockSelectAction    += Onselect;
            _blockBase.OnBlockAreaEnterAction += OnBlockAreaEnter;
        }
Beispiel #8
0
 public void InitModifier(FunctionBlockBase blockBase)
 {
     if (blockModifierList != null)
     {
         for (int i = 0; i < blockModifierList.Count; i++)
         {
             MainShipManager.Instance.AddPowerAreaModifier(blockBase, blockModifierList[i].modiferBase);
         }
     }
 }
Beispiel #9
0
        public void OnBlockSelect(CameraManager.CameraEvent camera)
        {
            var block = camera.blockBase;

            if (selectBlock != null)
            {
                selectBlock.SetSelect(false);
            }
            selectBlock = block;
            block.SetSelect(true);
        }
Beispiel #10
0
 public void RemoveItem(FunctionBlockBase block)
 {
     if (_functionBlockInstances.ContainsKey(block.instanceID))
     {
         _functionBlockInstances.Remove(block.instanceID);
     }
     if (block != null)
     {
         ObjectManager.Instance.ReleaseObject(block.gameObject, 0, true);
     }
 }
Beispiel #11
0
        /// <summary>
        /// Add Block
        /// </summary>
        /// <param name="functionBlockID"></param>
        /// <param name="instanceID"></param>
        /// <returns></returns>
        public FunctionBlockBase AddFunctionBlock(int functionBlockID, uint instanceID, int posX, int posZ)
        {
            if (instanceID == 0)
            {
                instanceID = getUnUsedInstanceID();
            }

            FunctionBlockBase instance = Utility.CreateInstace(BaseFunctionBlockPath, FunctionBlockContainer, true).transform.SafeGetComponent <FunctionBlockBase>();

            instance.instanceID = instanceID;
            _functionBlockInstances.Add(instanceID, instance);

            instance.InitData(functionBlockID, posX, posZ);

            return(instance);
        }
Beispiel #12
0
        public void AddMainShipPowerAreaModifier(FunctionBlockBase block, MainShipPowerAreaInfo areaInfo, ModifierBase modifierBase)
        {
            if (modifierBase == null)
            {
                DebugPlus.LogError("Modifier Base Data is null");
                return;
            }
            if (modifierBase.ParseTargetType(modifierBase.Target) != ModifierTarget.MainShipPowerArea)
            {
                DebugPlus.LogError("ModifierTargetError  Name=" + modifierBase.ModifierName);
                return;
            }

            ModifierData data = null;

            switch (modifierBase.ParseModifierPowerAreaType(modifierBase.effectType))
            {
            case ModifierMainShip_PowerArea.EnergyStorageMax:
                //Modifier Speed
                if (!IsAddPowerAreaModifier(areaInfo, modifierBase))
                {
                    data = ModifierData.Create(modifierBase, delegate
                    {
                        areaInfo.AddMaxStoragePower(block.info.modifierRootType, block.instanceID, block.info.BlockID, (int)modifierBase.Value);
                    });
                }
                break;

            case ModifierMainShip_PowerArea.AreaDurability:
                if (!IsAddPowerAreaModifier(areaInfo, modifierBase))
                {
                    data = ModifierData.Create(modifierBase, delegate
                    {
                        areaInfo.ChangeAreaDurability_Max(block.info.modifierRootType, block.instanceID, block.info.BlockID, (int)modifierBase.Value);
                    });
                }
                break;
            }

            if (data != null)
            {
                ///ADD modifier
                areaInfo.areaModifier.OnAddModifier(data);
            }
        }
Beispiel #13
0
        public void UpdateBlockSelect()
        {
            if (!Input.GetMouseButtonDown(0))
            {
                return;
            }

            if (_isDraggingFunctionBlock)
            {
                return;
            }

            if (UsingUI())
            {
                return;
            }

            FunctionBlockBase selectBlock = TryGetRaycastHitBlock(Input.mousePosition);

            if (selectBlock != null)
            {
                _isSelectFunctionBlock = true;
                _selectFunctionBlock   = selectBlock;

                CameraEvent camera = new CameraEvent()
                {
                    blockBase = selectBlock
                };
                if (OnBlockSelect != null)
                {
                    OnBlockSelect.Invoke(camera);
                }
            }
            else
            {
                _isSelectFunctionBlock = false;
                _selectFunctionBlock   = null;
            }
        }
Beispiel #14
0
        /// <summary>
        /// 初始化格
        /// </summary>
        public void InitAllNodes()
        {
            for (int x = 0; x < nodeLength; x++)
            {
                for (int z = 0; z < nodeWidth; z++)
                {
                    Vector2 v2 = new Vector2(x, z);
                    _gridInfo.Add(v2, new ShipMapGridInfo
                    {
                        blockInstanceID = 0,
                        canPlace        = true,
                        coordinate      = v2,
                        isBarrier       = false
                    });
                }
            }

            foreach (KeyValuePair <uint, FunctionBlockBase> kvp in FunctionBlockManager.Instance.GetBlockInstancesDic())
            {
                FunctionBlockBase block = kvp.Value;
                UpdateFunctionBlockNodes(block, Action.ADD);
            }
        }
Beispiel #15
0
        /// <summary>
        /// 选择建筑,面板
        /// </summary>
        void HandleBlockPanelSelect()
        {
            if (isSelectBlock_Panel == true && currentSelectBuildID != -1)
            {
                if (CameraManager.Instance.InBlockPanelPos() == false)
                {
                    return;
                }
                if (_hasAddBlockToMap == false)
                {
                    var pos = CameraManager.Instance.TryGetRaycastHitGround(Input.mousePosition);
                    currentInitBlock = FunctionBlockManager.Instance.AddFunctionBlock(PlayerModule.GetBuildingPanelDataByKey(currentSelectBuildID).FunctionBlockID, (int)pos.x, (int)pos.z);
                    currentInitBlock.currentState = FunctionBlockBase.BlockState.Move;
                    currentInitBlock.SetSelect(true);
                    _hasAddBlockToMap = true;
                    CameraManager.Instance.currentBlockMode = CameraManager.BlockMode.Move;
                }
                else if (_hasAddBlockToMap == true && currentInitBlock != null)
                {
                    CameraManager.Instance.UpdateBlockMove(currentInitBlock);
                }
            }

            /// ESC to  Delete
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                if (_hasAddBlockToMap == true)
                {
                    FunctionBlockManager.Instance.RemoveItem(currentInitBlock);
                    currentInitBlock  = null;
                    _hasAddBlockToMap = false;
                    InitBlockBuildPanelSelect(-1, false);
                    CameraManager.Instance.currentBlockMode = CameraManager.BlockMode.None;
                    CameraManager.Instance.ResetDragState();
                }
            }
        }
Beispiel #16
0
        /// <summary>
        /// 刷新建筑
        /// </summary>
        /// <param name="block"></param>
        public void UpdateFunctionBlockNodes(FunctionBlockBase block, Action action)
        {
            Vector3 pos = block.GetPosition();
            int     x   = (int)pos.x;
            int     z   = (int)pos.z;

            int sizeX = (int)block.info.districtInfo.size.x;
            int sizeZ = (int)block.info.districtInfo.size.y;

            for (int indexX = x; indexX < x + sizeX; indexX++)
            {
                for (int indexZ = z; indexZ < z + sizeZ; indexZ++)
                {
                    if (action == Action.ADD)
                    {
                        var info = GetGridInfoByCoordinate(new Vector2(indexX, indexZ));
                        if (info != null)
                        {
                            info.blockInstanceID = block.instanceID;
                            info.canPlace        = false;
                        }
                    }
                    else if (action == Action.REMOVE)
                    {
                        var info = GetGridInfoByCoordinate(new Vector2(indexX, indexZ));
                        if (info != null)
                        {
                            if (info.blockInstanceID == block.instanceID)
                            {
                                info.blockInstanceID = 0;
                                info.canPlace        = true;
                            }
                        }
                    }
                }
            }
        }
Beispiel #17
0
        void Start()
        {
            FunctionBlockBase blockBase = GetComponentInParent <FunctionBlockBase>();
            var maxSize = blockBase.info.districtInfo.size;

            ArrowRight  = UIUtility.FindTransfrom(transform, "ArrowObj/Right");
            ArrowLeft   = UIUtility.FindTransfrom(transform, "ArrowObj/Left");
            ArrowTop    = UIUtility.FindTransfrom(transform, "ArrowObj/Top");
            ArrowBottom = UIUtility.FindTransfrom(transform, "ArrowObj/Bottom");

            Grid              = UIUtility.SafeGetComponent <SpriteRenderer>(UIUtility.FindTransfrom(transform, "Grid"));
            CanPlaceSprite    = Utility.LoadSprite("SpriteOutput/Map/grid_green");
            CannotPlaceSprite = Utility.LoadSprite("SpriteOutput/Map/grid_red");

            ArrowRight.localPosition = new Vector3(ArrowRight.localPosition.x - (maxSize.y / 2), 0, ArrowRight.localPosition.z);
            ArrowLeft.localPosition  = new Vector3(ArrowLeft.localPosition.x + (maxSize.y / 2), 0, ArrowLeft.localPosition.z);

            ArrowTop.localPosition    = new Vector3(ArrowTop.localPosition.x, 0, ArrowTop.localPosition.z - (maxSize.x / 2));
            ArrowBottom.localPosition = new Vector3(ArrowBottom.localPosition.x, 0, ArrowBottom.localPosition.z + (maxSize.x / 2));

            Grid.size = maxSize;
            Grid.transform.localPosition = new Vector3(0, -transform.localScale.y / 2, 0);
            ShowGrid(false);
        }
Beispiel #18
0
 public void AddPowerAreaModifier(FunctionBlockBase block, ModifierBase modifier)
 {
     ModifierManager.Instance.AddMainShipPowerAreaModifier(block, mainShipInfo.powerAreaInfo, modifier);
 }
Beispiel #19
0
 /// <summary>
 /// Drag Start
 /// </summary>
 /// <param name="camera"></param>
 public void OnBlockDragStart(CameraManager.CameraEvent camera)
 {
     _dragBlock = camera.blockBase;
     _dragBlock.OnBlockDragStart(camera);
 }
Beispiel #20
0
 public void SetData(FunctionBlockBase baseBlock)
 {
     _baseBlock = baseBlock;
 }
Beispiel #21
0
        public void UpdateBlockMove(FunctionBlockBase selectBlock)
        {
            if (currentBlockMode != BlockMode.Move)
            {
                return;
            }

            if (selectBlock != null)
            {
                _isSelectFunctionBlock   = true;
                selectBlock.currentState = FunctionBlockBase.BlockState.Move;
            }
            else
            {
                return;
            }

            if (_selectBlockStartPos != Config.GlobalConfigData.InfinityVector)
            {
                if (_isSelectFunctionBlock /*selectBlock == _selectStartRaycastBlock*/)
                {
                    Vector3 currentSelectPos = TryGetRaycastHitGround(Input.mousePosition);
                    if (Vector3.Distance(_selectBlockStartPos, currentSelectPos) >= _minMoveDistance)
                    {
                        ///Start Move
                        CameraEvent camera = new CameraEvent()
                        {
                            point     = currentSelectPos,
                            blockBase = selectBlock
                        };

                        if (!_isDragStart)
                        {
                            _isDragStart = true;
                            if (OnBlockDragStart != null)
                            {
                                OnBlockDragStart.Invoke(camera);
                            }
                        }
                        _isDraggingFunctionBlock = true;

                        if (OnBlockDrag != null)
                        {
                            OnBlockDrag.Invoke(camera);
                        }
                    }
                }
            }

            /// 按下 放置方块
            if (Input.GetMouseButtonDown(0))
            {
                Debug.Log("Place!");
                _selectBlockStartPos   = Config.GlobalConfigData.InfinityVector;
                _isSelectFunctionBlock = false;
                if (_isDragStart)
                {
                    _isDragStart             = false;
                    _isDraggingFunctionBlock = false;
                    if (OnBlockDragEnd != null)
                    {
                        OnBlockDragEnd.Invoke(null);
                    }
                    currentBlockMode = BlockMode.None;
                    MapManager.Instance.InitBlockBuildPanelSelect(-1, false);
                    MapManager.Instance._hasAddBlockToMap = false;
                    selectBlock.currentState = FunctionBlockBase.BlockState.Idle;
                }
            }


            //if (Input.GetMouseButtonUp(0))
            //{
            //    _selectBlockStartPos = TryGetRaycastHitGround(Input.mousePosition);
            //    _selectStartRaycastBlock = TryGetRaycastHitBlock(Input.mousePosition);
            //    _isDraggingFunctionBlock = false;
            //    _isDragStart = false;
            //}
        }
Beispiel #22
0
 public void AddMainShipPowerAreaModifier(FunctionBlockBase block, MainShipPowerAreaInfo areaInfo, string modifierName)
 {
     AddMainShipPowerAreaModifier(block, areaInfo, GetModifierBase(modifierName));
 }