示例#1
0
        public void UnselectCell(HexCoord hc)
        {
            CellSelection sel =
                hc.GetComponentInChildren <CellSelection> ();

            _SelectedCells.Remove(sel);
        }
示例#2
0
        public void UpdateTextMesh()
        {
            HexCoord hc  = _CCtrl.GetComponent <HexCoord> ();
            string   txt = hc._hex.CoordString();

            _TxtMsh.text = txt;
        }
示例#3
0
        public bool CanMove(int dir)
        {
            if (_TgtObj == null)
            {
                return(false);
            }

            HexCoord  hc = GetComponent <HexCoord> ();
            Transform tf = hc._Neighbors[dir];

            if (tf == null)
            {
                return(false);
            }

            CellObjCtrl nxtCellObjCtrl =
                tf.gameObject.GetComponent <CellObjCtrl> ();

            if (nxtCellObjCtrl._TgtObj != null ||
                nxtCellObjCtrl._bBlocked)
            {
                return(false);
            }

            return(true);
        }
示例#4
0
        void OperateBwdAnteller(
            HexCoord hc,
            MiroV1ModelSetting mSetThis,
            MiroModelV1 model)
        {
            int  DirBwd = _cellCtrl.GetBwdDir();
            bool bBwd   = CheckValidInDir(mSetThis, hc, DirBwd);

            ChangeAnteller(bBwd, model._Antellers [1]);
        }
示例#5
0
        public Hex GetLastOperatedCCtrlHex()
        {
            Hex h = new Hex(int.MaxValue, 0, 0);

            if (_LastOperatedCCtrl != null)
            {
                HexCoord hc = _LastOperatedCCtrl.GetComponent <HexCoord> ();
                h = hc._hex;
            }
            return(h);
        }
示例#6
0
		public static List<List<Hex> > GetBackToBacks()
		{
			List<List<Hex> > bbs = new List<List<Hex> > ();
			foreach (var lstCtrl in _Farms) {
				List<Hex> lstHex = new List<Hex> ();
				foreach (CellObjCtrl ctrl in lstCtrl) {
					HexCoord hc = ctrl.GetComponent<HexCoord> ();
					lstHex.Add (hc._hex);
				}
				bbs.Add (lstHex);
			}
			return bbs;
		}
示例#7
0
 public Hex GetHexOfModel(MiroModelV1 model)
 {
     if (_Model2Cell.ContainsKey(model))
     {
         CellObjCtrl ctrl = _Model2Cell [model];
         HexCoord    hc   = ctrl.GetComponent <HexCoord> ();
         Hex         h    = hc._hex;
         return(h);
     }
     else
     {
         return(new Hex(int.MaxValue, 0, 0));
     }
 }
示例#8
0
        public void PointToCurrentDir()
        {
            if (_TgtObj == null)
            {
                return;
            }
            HexCoord hc = GetComponent <HexCoord> ();

            if (hc._Neighbors [_Dir] != null)
            {
                LerpLookAt lerplookat = GetLerpLookAtFromObj(_TgtObj);
                lerplookat.enabled = true;
                lerplookat._Tgt    = hc._Neighbors [_Dir].transform;
            }
        }
示例#9
0
        public static List <List <Hex> > GetFaceToFaces()
        {
            List <List <Hex> > FFs = new List <List <Hex> > ();

            foreach (var lstCtrl in _Holes)
            {
                List <Hex> lstHex = new List <Hex> ();
                foreach (CellObjCtrl ctrl in lstCtrl)
                {
                    HexCoord hc = ctrl.GetComponent <HexCoord> ();
                    lstHex.Add(hc._hex);
                }
                FFs.Add(lstHex);
            }
            return(FFs);
        }
        static void ConfigAbsorbingSrcFor(CellObjCtrl cCtrl)
        {
            int dirFwd = cCtrl.GetDir();
            int dirBwd = (int)Mathf.Repeat((float)(cCtrl.GetDir() + 3), (float)6);

            if (cCtrl._TgtObj == null)
            {
                return;
            }
            MiroModelV1 model = cCtrl._TgtObj.GetComponent <MiroModelV1> ();
            HexCoord    hc    = cCtrl.GetComponent <HexCoord> ();
            Transform   tfFwd = hc._Neighbors [dirFwd];
            Transform   tfBwd = hc._Neighbors [dirBwd];

            model.SetFwdAbsorbingSrcTF(tfFwd);
            model.SetBwdAbsorbingSrcTF(tfBwd);
        }
示例#11
0
        public static List <List <Hex> > GetRings()
        {
            List <List <Hex> > rings = new List <List <Hex> > ();

            foreach (var lstRing in _Rings)
            {
                List <Hex> lstHex = new List <Hex> ();
                foreach (var cctrl in lstRing)
                {
                    HexCoord hc     = cctrl.GetComponent <HexCoord> ();
                    Hex      hcoord = hc._hex;
                    lstHex.Add(hcoord);
                }
                rings.Add(lstHex);
            }
            return(rings);
        }
示例#12
0
        void AddHexNeighborInfoToNewCell(GameObject newObj)
        {
            HexCoord hc = newObj.GetComponent <HexCoord> ();

            for (int i = 0; i < 6; i++)
            {
                Hex hexDir = Hex.directions [i];
                Hex nbHex  = Hex.Add(hc._hex, hexDir);
                if (_HexToCells.ContainsKey(nbHex))
                {
                    hc._Neighbors [i] = _HexToCells [nbHex].transform;
                }
                else
                {
                    hc._Neighbors [i] = null;
                }
            }
        }
示例#13
0
        void OnMouseExit()
        {
            if (!enabled)
            {
                return;
            }
            if (!_AllEnable)
            {
                return;
            }
            HexCoord hc = _cctrl.GetComponent <HexCoord> ();

            if (hc != null)
            {
                //Debug.Log ("Mouse Exit: " + gameObject.name);
                _Exit.Invoke(hc);
            }
        }
示例#14
0
        override protected void _Calculate()
        {
            bool bCtrlling = CellObjCtrlUtils.IsControllingObj(_cellCtrl);

            if (!bCtrlling)
            {
                return;
            }
            HexCoord hc = _cellCtrl.GetComponent <HexCoord> ();

            MiroV1ModelSetting mSetThis =
                _cellCtrl._TgtObj.GetComponent <MiroV1ModelSetting> ();
            MiroModelV1 model = mSetThis.GetComponent <MiroModelV1> ();

            OperateFwdAnteller(hc, mSetThis, model);
            OperateBwdAnteller(hc, mSetThis, model);

            MiroV1PlacementMgr.ConfigAbsorbingSrcForTF(_cellCtrl.transform);
        }
示例#15
0
        private bool GetCellObjCtrlPair(out CellObjCtrl ctrlA, out CellObjCtrl ctrlB)
        {
            ctrlA = null;
            ctrlB = null;
            int cellCnt =
                _gridCtrl._Cells.Count;

            int rId = (int)Random.Range(0, (float)cellCnt - 1.0f);

            GameObject gb = _gridCtrl._Cells [rId];

            ctrlA = gb.GetComponent <CellObjCtrl> ();
            bool bPlacableA = !ctrlA.IsBlocked();
            bool bOccupiedA = CellObjCtrlUtils.IsControllingObj(ctrlA) && bPlacableA;

            if (bOccupiedA)
            {
                return(false);
            }

            HexCoord hc = gb.GetComponent <HexCoord> ();

            if (hc._hex.q == 0 && hc._hex.r == 0 && hc._hex.s == 0)
            {
                return(false);
            }

            Hex hA = hc._hex;
            Hex h0 = new Hex(0, 0, 0);
            Hex hB = Hex.Subtract(h0, hA);

            ctrlB = _gridCtrl.GetCellCtrlAt(hB);
            bool bPlacableB = !ctrlB.IsBlocked();
            bool bOccupiedB = CellObjCtrlUtils.IsControllingObj(ctrlB) && bPlacableB;

            if (bOccupiedB)
            {
                return(false);
            }

            return(true);
        }
示例#16
0
        private bool CheckValidInDir(MiroV1ModelSetting mSetThis, HexCoord hc, int dir)
        {
            bool bValid = true;

            if (hc._Neighbors [dir] != null)
            {
                CellObjCtrl fwdCtrl =
                    hc._Neighbors [dir].GetComponent <CellObjCtrl> ();
                if (fwdCtrl._TgtObj != null)
                {
                    MiroV1ModelSetting mSetFwd =
                        fwdCtrl._TgtObj.GetComponent <MiroV1ModelSetting> ();
                    if (mSetFwd != null && !mSetFwd.IsSameCamp(mSetThis))
                    {
                        bValid = false;
                    }
                }
            }
            return(bValid);
        }
示例#17
0
        public static bool IsControllingObj(CellObjCtrl cctrl)
        {
            if (cctrl == null)
            {
                return(false);
            }

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

            HexCoord hc = cctrl.GetComponent <HexCoord> ();

            if (hc == null)
            {
                return(false);
            }

            return(true);
        }
示例#18
0
        public void CheckEdgeToBlock()
        {
            HexCoord hc = GetComponent <HexCoord> ();

            if (hc == null)
            {
                return;
            }
            bool bEdge = false;

            for (int i = 0; i < 6; i++)
            {
                bEdge = (hc._Neighbors [i] == null);
                if (bEdge)
                {
                    break;
                }
            }

            _bBlocked = bEdge;
            _CheckEdge.Invoke();
        }
示例#19
0
        private bool IsXPointToY(CellObjCtrl X, CellObjCtrl Y)
        {
            if (X == null || Y == null)
            {
                return(false);
            }

            HexCoord HA = X.GetComponent <HexCoord> ();
            HexCoord HB = Y.GetComponent <HexCoord> ();

            if (HA == null || HB == null)
            {
                return(false);
            }

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

            Transform ANbrTf = HA._Neighbors [X.GetDir()];

            if (ANbrTf == null)
            {
                return(false);
            }
            CellObjCtrl NbrCtrl = ANbrTf.GetComponent <CellObjCtrl> ();

            if (NbrCtrl == Y)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#20
0
        public static CellObjCtrl GetNbCellObjCtrl(CellObjCtrl cctrl, int RelativeDir)
        {
            if (!IsInChessBoard(cctrl))
            {
                return(null);
            }

            int FwdDir = cctrl.GetFwdDir();
            int dir    = FwdDir + RelativeDir;

            dir = (int)Mathf.Repeat((float)dir, 6.0f);
            HexCoord  hc   = cctrl.GetComponent <HexCoord> ();
            Transform NbTF = hc._Neighbors [dir];

            if (NbTF == null)
            {
                return(null);
            }

            CellObjCtrl nbCtrl =
                NbTF.GetComponent <CellObjCtrl> ();

            return(nbCtrl);
        }
示例#21
0
        public void GenGrid()
        {
            CheckCellParent();

            Layout L = new Layout(
                Layout.pointy,
                new Point(_CellInterval, _CellInterval),
                new Point(0.0f, 0.0f));

            Hex h0 = new Hex(0, 0, 0);

            int lv = _GridLevel - 1;

            for (int q = -lv; q < lv + 1; q++)
            {
                for (int r = -lv; r < lv + 1; r++)
                {
                    int   s   = -r - q;
                    Hex   h   = new Hex(q, r, s);
                    Point pos = Layout.HexToPixel(L, h);

                    int dist = Hex.Distance(h, h0);
                    if (dist >= _GridLevel)
                    {
                        continue;
                    }

                    GameObject newObj =
                        Instantiate(_CellPrefab, Vector3.zero, Quaternion.identity) as GameObject;
                    newObj.transform.SetParent(_CellParent, true);
                    newObj.transform.localPosition =
                        new Vector3((float)pos.x, (float)pos.y, 0.0f);
                    _Cells.Add(newObj);
                    _HexToCells [h] = newObj;
                    if (!_Hexes.Contains(h))
                    {
                        _Hexes.Add(h);
                    }

                    newObj.name =
                        "(" + h.q.ToString() +
                        "," + h.r.ToString() + ","
                        + h.s.ToString() + ")";

                    AddHexInfoToNewCell(h, newObj);
                }
            }

            foreach (GameObject gb in _Cells)
            {
                AddHexNeighborInfoToNewCell(gb);
            }

            if (_LinkParent == null)
            {
                return;
            }
            //Debug.Log ("CellObjCnt:" + _Cells.Count);

            int count = 0;

            for (int i = 0; i < _Cells.Count; i++)
            {
                for (int j = i + 1; j < _Cells.Count; j++)
                {
                    count++;
                    //Debug.Log ("count:" + count);

                    GameObject A    = _Cells [i];
                    GameObject B    = _Cells [j];
                    HexCoord   ac   = A.GetComponent <HexCoord> ();
                    HexCoord   bc   = B.GetComponent <HexCoord> ();
                    Hex        HexA = ac._hex;
                    Hex        HexB = bc._hex;

                    if (Hex.Distance(HexA, HexB) != 1)
                    {
                        continue;
                    }

                    Vector2 linkPos = Vector2.zero;

                    Point pta = Layout.HexToPixel(L, HexA);
                    Point ptb = Layout.HexToPixel(L, HexB);

                    Vector2 PA = new Vector2((float)pta.x, (float)pta.y);
                    Vector2 PB = new Vector2((float)ptb.x, (float)ptb.y);

                    linkPos = Vector2.Lerp(PA, PB, 0.5f);
                    //Debug.Log ("linkPos:" + linkPos);
                    if (_HexPairToNbLinks.ContainsKey(linkPos))
                    {
                        continue;
                    }

                    Vector3 pos = Vector3.Lerp(
                        A.transform.position,
                        B.transform.position, 0.5f);

                    GameObject newLink =
                        Instantiate(_LinkPrefab, Vector3.zero, Quaternion.identity);
                    InitNewLinkObjTF(pos, newLink);
                    AddNewLinkObjToContainers(linkPos, newLink);

                    TwoObjectLink lk = newLink.GetComponent <TwoObjectLink> ();
                    lk.SetA(A);
                    lk.SetB(B);
                    newLink.name = A.name + "-" + B.name;
                }
            }

            _GridGenerated.Invoke();
        }
示例#22
0
        public static bool IsInChessBoard(CellObjCtrl cctrl)
        {
            HexCoord hc = cctrl.GetComponent <HexCoord> ();

            return(hc != null);
        }
示例#23
0
        /*
         * static void DispHexPairInfo(HexPair hp)
         * {
         *      Hex h = hp.A;
         *      Hex l = hp.B;
         *      Debug.Log (
         *              "A:" + h.q + "," + h.r + "," + h.s +
         *              " B:" + l.q + "," + l.r + "," + l.s);
         *
         *
         * }
         */

        void AddHexInfoToNewCell(Hex h, GameObject newObj)
        {
            HexCoord hc = newObj.AddComponent <HexCoord> ();

            hc._hex = h;
        }