public override void Start() { base.Start(); yDist = new Vector3(0, .15f, 0); localInteractions.Add(this); localCell = gameObject.AddComponent <DynamicCell>(); }
// Use this for initialization void Start() { DynamicCell[] cells = transform.GetComponentsInChildren <DynamicCell>(); for (int i = 0; i < 3; ++i) { if (i == 1) { foreach (DynamicCell cell in cells) { celllist.Add(cell); } continue; } foreach (DynamicCell cell in cells) { DynamicCell copyCell = GameObject.Instantiate(cell) as DynamicCell; copyCell.transform.parent = transform; copylist.Add(copyCell); celllist.Add(copyCell); Vector3 trans = new Vector3(movdirx, movdiry, movdirz); Vector3 voffset = trans * offset; trans *= length * (i - 1); trans += voffset; copyCell.transform.localPosition += trans; copyCell.name = "group" + i.ToString(); } } }
protected DynamicCell[,] InitialiseCells(Transform trans, GameObject dot, int multX, int multZ) //spawning the cells on load, still working on this one ..... { int decX = GetDec(trans.localScale.x); int decZ = GetDec(trans.localScale.z); Vector3 top = new Vector3(0, (trans.localScale.y / 2), 0); int x = Mathf.CeilToInt(trans.localScale.x) * multX; int z = Mathf.CeilToInt(trans.localScale.z) * multZ; DynamicCell[,] cells = new DynamicCell[x, z]; for (int i = 0; i < z; i++) { for (int j = 0; j < x; j++) { Vector3 startPos = trans.position + (trans.forward / multZ * z / 2 / decZ) - (trans.right / multX * x / 2 / decX) + (trans.right / multX / 2 / decX) - (trans.forward / multZ / 2 / decZ); //starting at the top right of the object Vector3 newPos = startPos - (trans.forward / multZ / decZ * i) + (trans.right / multX / decX * j) + top; //moving according to dimensions GameObject test = new GameObject("cellPoint", typeof(DynamicCell)); test.transform.position = newPos; test.transform.SetParent(trans); cells[j, i] = test.GetComponent <DynamicCell>(); } } return(cells); }
//找到合适的转移位置 public void MakeRuntimeCorrection() { runtimeCorrection = 0; Vector3 v = Vector3.zero; Vector3 dir = new Vector3(movdirx, movdiry, movdirz); DynamicCell rCell = null; foreach (DynamicCell cell in celllist) { Vector3 tDir = cell.stopPoint - cell.transform.localPosition; if (tDir.normalized.Equals(dir.normalized)) { if (rCell != null) { if ((rCell.stopPoint - cell.transform.localPosition).magnitude > tDir.magnitude) { rCell = cell; } } else { rCell = cell; } } } if (rCell != null) { runtimeCorrection = (rCell.stopPoint - rCell.transform.localPosition).magnitude; if (runtimeCorrection > 10) { runtimeCorrection -= 10; } } }
protected IEnumerator DelayedDrop(List <GenericInteraction> interactions, DynamicCell cell, Interaction main) //experimental function that drops items in an ordered fashion { List <GenericInteraction> tempList = new List <GenericInteraction>(interactions); //creating a temp list as 'interactions' is modified in the 'OnPutDown' function AssignInteraction(tempList[0], cell); StartCoroutine(main.OnPutDown(tempList[0])); //placing the first element down for (int i = 1; i < tempList.Count; i++) //then placing the other items stored { tempList[i].SetDesination(tempList[i].GetCell().transform.position); StartCoroutine(main.ArcMotionPutDown(tempList[i])); yield return(null); } yield return(null); }
// Update is called once per frame void FixedUpdate() { if (mPause) { return; } Vector3 movDir = new Vector3(movdirx, movdiry, movdirz); movDir *= movspeed; movDir *= Time.fixedDeltaTime; movDir += new Vector3(movdirx, movdiry, movdirz) * runtimeCorrection; dynamicbkMoveDistance += movDir.magnitude; runtimeCorrection = 0; foreach (DynamicCell cell in celllist) { cell.transform.localPosition += movDir; if (mInvalidToTarget) { if (Mathf.Abs(cell.transform.localPosition.magnitude - cell.stopPoint.magnitude) < 0.1f) { mInvalidToTarget = false; mPause = true; CameraController.Instance.ShakeCamera(8, 1); if (TargetStopCallBack != null) { TargetStopCallBack(cell.pointname); } } } } if (dynamicbkMoveDistance >= length) { if (celllist.Count > 1) { DynamicCell cell = celllist[celllist.Count - 1]; celllist.RemoveAt(celllist.Count - 1); Vector3 trans = new Vector3(movdirx, movdiry, movdirz); trans *= length * -1; cell.transform.localPosition = celllist[0].transform.localPosition + trans; celllist.Insert(0, cell); } dynamicbkMoveDistance -= length; } }
public CellSpacePartition(int cellX, int cellY, int partitionSize = 4) { cellX /= partitionSize; cellY /= partitionSize; this.partitionSize = partitionSize; int cellIndex = cellX * cellY; cellLength = cellIndex; dynamicCells = new DynamicCell[cellIndex]; staticCells = new DynamicCell[cellIndex]; for (int i = 0; i < cellIndex; i++) { dynamicCells[i] = new DynamicCell(); staticCells[i] = new DynamicCell(); } numCellsX = cellX; numCellsY = cellY; }
protected DynamicCell GetPosition(DynamicCell[,] dynamicCells, Vector3 hitPoint) { float distance = float.MaxValue; DynamicCell cell = null; foreach (DynamicCell pos in dynamicCells) { float tempDist = Vector3.Distance(hitPoint, pos.transform.position); if (tempDist < distance) { distance = tempDist; cell = pos; } } if (!cell.Taken()) { cell.SetTaken(true); return(cell); } return(null); }
protected override void CheckCanPlace(RaycastHit hit, Interaction main) { DynamicCell cell = GetPosition(cells, hit.point); if (cell != null) //position is not taken { if (main.Currents().Count > 1) //if the player is holding more than one item { StartCoroutine(DelayedDrop(main.Currents(), cell, main)); } else { GenericInteraction current = main.Currents()[0]; AssignInteraction(current, cell); StartCoroutine(main.OnPutDown(current)); } } else { Debug.Log("This slot is taken!!"); } }
protected override void CheckCanPlace(RaycastHit hit, Interaction main) { if (main.Currents().Count > 1 || main.Currents()[0].CompareTag(tag))//more than one object in hand { Debug.Log("Cant do that"); } else { DynamicCell cell = GetPosition(dynamicPositions, hit.point); if (cell != null) { GenericInteraction current = main.Currents()[0]; current.SetDesination(cell.transform.position); current.SetParent(this); current.SetCell(cell); localInteractions.Add(current); StartCoroutine(main.OnPutDown(current)); } else { Debug.Log("slot Taken"); } } }
public void SetCell(DynamicCell cell) { surfaceCell = cell; }
protected void AssignInteraction(GenericInteraction interaction, DynamicCell cell) { interaction.SetDesination(cell.transform.position); interaction.SetCell(cell); }