/// <summary> /// Moves border gameobject from notshown list to shown list /// </summary> /// <param name="index"></param> protected static void MoveToNotShown(int index) { // Remove index from bordersshown GameObject go = bordersShown[index]; bordersShown.RemoveAt(index); // Store data we need BorderStorageLogic bsl = go.GetComponent <BorderStorage>().bsl; bordersNotShown.Add(bsl); // Reset AnimatedLineRenderer AnimatedLineRenderer alr = go.GetComponent <AnimatedLineRenderer>(); alr.Reset(); // Reset linerenderer go.GetComponent <LineRenderer>().positionCount = 0; // Reset Win line as well alr = go.transform.GetChild(0).gameObject.GetComponent <AnimatedLineRenderer>(); alr.Reset(); // Set parent go.transform.parent = bordersPoolingParent.transform; // Use pooling go.SetActive(false); notUsedBorders.Push(go); }
public static void AddBorderPoints(int[,] points, float[,] winLinePoints, Cell.CellOcc winType) { BorderStorageLogic b = new BorderStorageLogic(points, winLinePoints, winType); bordersNotShown.Add(b); MoveToShown(bordersNotShown.Count - 1); }
/// <summary> /// Move border from notshown to shown /// </summary> /// <param name="index"></param> /// <param name="drawOut">Whether to play the drawin animation</param> protected static void MoveToShown(int index, bool drawOut = true) { // Remove index from the notshown list BorderStorageLogic bsl = bordersNotShown[index]; bordersNotShown.RemoveAt(index); // Use pooling GameObject borderObject; if (notUsedBorders.Count > 0) { borderObject = notUsedBorders.Pop(); } else { borderObject = Instantiate(borderPrefab); } // Set the gameobject active borderObject.SetActive(true); // Set parent borderObject.transform.parent = bordersParent.transform; // Set pos to middlepos borderObject.transform.position = new Vector3(bsl.MiddlePos[0], bsl.MiddlePos[1], borderObject.transform.position.z); // Store Data in Gameobject so later we can read it BorderStorage bs = borderObject.GetComponent <BorderStorage>(); bs.SetData(bsl); LineRenderer lr = borderObject.GetComponent <LineRenderer>(); // Whether we want to draw out the border or not if (drawOut) { // Draw line animation AnimatedLineRenderer lineRenderer = borderObject.GetComponent <AnimatedLineRenderer>(); for (int i = 0; i < bsl.Points.GetLength(0); i++) { lineRenderer.Enqueue(bsl.GetPosAt(i)); } } else { lr.positionCount = bsl.Points.GetLength(0); for (int i = 0; i < bsl.Points.GetLength(0); i++) { lr.SetPosition(i, bsl.GetPosAt(i)); } } lr.material.SetColor("_EmissionColor", SignResourceStorage.Instance.GetColorRelatedTo(bsl.WinType)); // Set color lr.startColor = SignResourceStorage.Instance.GetColorRelatedTo(bsl.WinType); lr.endColor = SignResourceStorage.Instance.GetColorRelatedTo(bsl.WinType); // Win Line Animation AnimatedLineRenderer winLineRenderer = borderObject.transform.GetChild(0).gameObject.GetComponent <AnimatedLineRenderer>(); winLineRenderer.Enqueue(new Vector3(bsl.WinLinePoints[0, 0], bsl.WinLinePoints[0, 1])); winLineRenderer.Enqueue(new Vector3(bsl.WinLinePoints[1, 0], bsl.WinLinePoints[1, 1])); // Move to list bordersShown.Add(borderObject); }