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); } } }
// 将当前正在操作的棋子取消 public bool CancelOperatingChess( out Hex coord, out int dir, out int campId) { CellObjCtrl newestCtrl = _StdChessSpawer.GetSpawningCellObjCtrl(); if (newestCtrl == null) { coord = new Hex(); dir = -1; campId = -1; return(false); } coord = newestCtrl.GetComponent <HexCoord> ()._hex; dir = newestCtrl.GetDir(); MiroV1ModelSetting msetting = CellObjCtrlUtils.GetModelSettingFromCtrl(newestCtrl); campId = _MiroMgr.GetIdOfMiroModelSetting(msetting); _StdChessSpawer.Cancel(); //_GridCtrl.ConfirmOccupiedCells (); //DisableAllChessOperation (); _GridCtrl.TurnDragRotatersOnEmptyPlacableCells(true); return(true); }
public static CellObjCtrl GetNbCellObjCtrlInAbsDir(CellObjCtrl cctrl, int Dir) { int rdir = Dir - cctrl.GetDir(); rdir = (int)Mathf.Repeat((float)rdir, 6.0f); return(GetNbCellObjCtrl(cctrl, rdir)); }
public static bool IsFaceToFace(CellObjCtrl ctrl) { if (ctrl == null || ctrl._TgtObj == null) { return(false); } bool bFwdFriend = CellObjCtrlUtils.IsNbSameCamp(ctrl, 0); if (bFwdFriend) { CellObjCtrl fwdCtrl = GetNbCellObjCtrl(ctrl, 0); if (fwdCtrl.GetDir() == ctrl.GetBwdDir()) { return(true); } else { return(false); } } else { return(false); } }
/* * public static bool IsNbEnemy(CellObjCtrl cctrl, int relativeDir) * { * if (cctrl._TgtObj == null) { * return false; * } * * CellObjCtrl nbCtrl = GetNbCellObjCtrl (cctrl, relativeDir); * bool bEnemy = false; * if (nbCtrl != null && nbCtrl._TgtObj!=null) { * var settingMe = * cctrl._TgtObj.GetComponent<MiroV1ModelSetting> (); * var settingNb = * nbCtrl._TgtObj.GetComponent<MiroV1ModelSetting> (); * bEnemy = (settingMe._CampName!=settingNb._CampName); * } * * return bEnemy; * }*/ public static bool IsBackToBack(CellObjCtrl ctrl) { if (ctrl == null || ctrl._TgtObj == null) { return(false); } bool bBwdFriend = CellObjCtrlUtils.IsNbSameCamp(ctrl, 3); if (bBwdFriend) { CellObjCtrl bwdCtrl = GetNbCellObjCtrl(ctrl, 3); if (bwdCtrl.GetDir() == ctrl.GetBwdDir()) { return(true); } else { return(false); } } else { return(false); } }
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); }
public int GetDirOfModel(MiroModelV1 model) { if (_Model2Cell.ContainsKey(model)) { CellObjCtrl ctrl = _Model2Cell [model]; int dir = ctrl.GetDir(); return(dir); } else { return(-1); } }
// 棋格方向: 0~5 正常方向; -1:棋格不存在 public int GetDirAt(Hex coord) { CellObjCtrl cctrl = _GridCtrl.GetCellCtrlAt(coord); if (cctrl != null) { return(cctrl.GetDir()); } else { return(-1); } }
// Update is called once per frame void Update() { //_cellObjCtrl._Dir float rotDegs = _cellObjCtrl.GetDir() * 60.0f; Quaternion rot = _BaseRot * Quaternion.AngleAxis(rotDegs, _RotAxis); Quaternion rotNow = transform.localRotation; float dt = Time.deltaTime; Quaternion rot2 = Quaternion.Lerp(rotNow, rot, dt * _LerpSpd); transform.localRotation = rot2; }
public bool TurnDirAt(Hex coord, int DirChange = 1) { CellObjCtrl cctrl = _GridCtrl.GetCellCtrlAt(coord); if (cctrl == null) { return(false); } if (cctrl.IsBlocked()) { return(false); } if (cctrl._TgtObj == null) { return(false); } cctrl.TurnToDir(cctrl.GetDir() + DirChange); return(true); }
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); } }