Example #1
0
        // ------------------- 棋子操作 ------------------------
        // 落子
        public bool TryPlaceChessAt(int campId, int dir, Hex coord)
        {
            CellObjCtrl cctrl = _GridCtrl.GetCellCtrlAt(coord);

            if (cctrl == null)
            {
                return(false);
            }
            if (cctrl.IsBlocked())
            {
                return(false);
            }
            if (cctrl._TgtObj != null)
            {
                return(false);
            }

            cctrl.SetDir(dir);
            _MiroMgr.SetMiroPrefabID(campId);

            _MiroMgr.SpawnAtCellCtrl(cctrl);
            cctrl.SetDir(dir);
            cctrl.PointToCurrentDir();

            //int direction = cctrl.GetDir ();
            return(true);
        }
Example #2
0
        public void SpawnOne()
        {
            bool        bFind      = false;
            CellObjCtrl emptyCCtrl = null;
            int         count      = 0;

            List <CellObjCtrl> epCtrls =
                _gridCtrl.GetEmptyPlacableCellObjCtrls();

            if (epCtrls.Count == 0)
            {
                return;
            }
            int rid = (int)Random.Range(0, (float)(epCtrls.Count - 0.0001f));

            emptyCCtrl = epCtrls [rid];

            int dir = Mathf.FloorToInt(Random.Range(0.0f, 5.999999f));

            _mgr.SetMiroPrefabID(_campId);
            emptyCCtrl.SetDir(dir);
            _mgr.SpawnAtCellCtrl(emptyCCtrl);
            _Spawned.Invoke();
            print("Spawned!");
        }
        void OnMouseDrag()
        {
            if (!MiroPlayingStatus.bPlaying)
            {
                return;
            }

            if (CheckBlock())
            {
                return;
            }

            if (enabled)
            {
                _bDragging = true;
                //Debug.Log (_cctrl.name + " OnMouseDrag" + " rotate");

                Vector3 hitDir = GetHitDir();

                int   rightDir = _cctrl.GetDir();
                float minAngle = 100000.0f;
                for (int dir = 0; dir < 6; dir++)
                {
                    if (_banDirs.Contains(dir))
                    {
                        continue;
                    }
                    CellObjCtrl nbCtrl =
                        CellObjCtrlUtils.GetNbCellObjCtrlInAbsDir(_cctrl, dir);
                    if (nbCtrl == null)
                    {
                        continue;
                    }
                    Vector3 nbDir = nbCtrl.transform.position - _cctrl.transform.position;
                    nbDir.Normalize();

                    float angle = Vector3.Angle(hitDir, nbDir);
                    if (angle < minAngle)
                    {
                        minAngle = angle;
                        rightDir = dir;
                    }
                }

                if (rightDir != _cctrl.GetDir())
                {
                    _cctrl.SetDir(rightDir);
                    _cctrl.ChangeDir();
                    //print ("ChangeDir" + rightDir);

                    _RightDir = rightDir;
                    _DirChanged.Invoke(rightDir);
                }
            }
        }
Example #4
0
        public void MoveInDir(int dir)
        {
            /*
             * if (_TgtObj == null) {
             *      return;
             * }
             *
             * HexCoord hc = GetComponent<HexCoord> ();
             * Transform tf = hc._Neighbors[dir];
             * if (tf == null) {
             *      return;
             * }
             *
             * CellObjCtrl nxtCellObjCtrl =
             *      tf.gameObject.GetComponent<CellObjCtrl> ();
             * if (nxtCellObjCtrl._TgtObj != null ||
             *      nxtCellObjCtrl._bBlocked) {
             *      return;
             * }*/

            bool bCanMove = CanMove(_Dir);

            if (!bCanMove)
            {
                return;
            }

            CellObjCtrl nxtCellObjCtrl =
                CellObjCtrlUtils.GetNbCellObjCtrl(this, 0);

            LerpMoveTo lerpMoveTo = _TgtObj.GetComponent <LerpMoveTo> ();

            if (lerpMoveTo == null)
            {
                lerpMoveTo = _TgtObj.AddComponent <LerpMoveTo> ();
            }
            lerpMoveTo.enabled = true;

            Transform tf = nxtCellObjCtrl.transform;

            lerpMoveTo._TgtTF = tf;

            nxtCellObjCtrl.SetTargetObj(_TgtObj);
            _TgtObj = null;


            nxtCellObjCtrl.SetDir(_Dir);
            nxtCellObjCtrl.PointToCurrentDir();

            InvokeTgtObjChanged();
        }
Example #5
0
        public bool TeleportTo(CellObjCtrl otherCtrl, int dir = -1)
        {
            if (otherCtrl == null ||
                otherCtrl == this ||
                otherCtrl._TgtObj != null)
            {
                return(false);
            }

            LerpMoveTo lerpMoveTo = _TgtObj.GetComponent <LerpMoveTo> ();

            if (lerpMoveTo == null)
            {
                lerpMoveTo = _TgtObj.AddComponent <LerpMoveTo> ();
            }
            lerpMoveTo.enabled = true;

            Transform tf = otherCtrl.transform;

            lerpMoveTo._TgtTF = tf;

            otherCtrl.SetTargetObj(_TgtObj);
            _TgtObj = null;

            if (dir < 0)
            {
                otherCtrl.SetDir(_Dir);
            }
            else
            {
                otherCtrl.SetDir(dir);
            }
            otherCtrl.PointToCurrentDir();

            InvokeTgtObjChanged();
            return(true);
        }
Example #6
0
        public void PlaceChesses(
            List <ChessInfo> chesses)
        {
            foreach (ChessInfo chInfo in chesses)
            {
                CellObjCtrl cctrl = _GridCtrl.GetCellCtrlAt(chInfo.pos);
                if (cctrl == null)
                {
                    continue;
                }

                cctrl.SetDir(chInfo.dir);
                _MiroMgr.SetMiroPrefabID(chInfo.campId);
                _MiroMgr.SpawnAtCellCtrl(cctrl);
            }
        }
Example #7
0
        public bool SetDirAt(Hex coord, int dir)
        {
            CellObjCtrl cctrl = _GridCtrl.GetCellCtrlAt(coord);

            if (cctrl == null)
            {
                return(false);
            }
            if (cctrl.IsBlocked())
            {
                return(false);
            }
            if (cctrl._TgtObj == null)
            {
                return(false);
            }

            cctrl.SetDir(dir);
            return(true);
        }