public override bool Equals(object p_obj) { var v_complexShape = p_obj as ComplexShape; if (v_complexShape == null || v_complexShape.IsEmpty()) { return(IsEmpty()); } else if (Shapes.Count == v_complexShape.Shapes.Count && RectBounds.Equals(v_complexShape.RectBounds)) { Shapes.RemoveNulls(); List <PolygonShape> v_shapesToCheck = new List <PolygonShape>(v_complexShape.Shapes); v_shapesToCheck.RemoveNulls(); foreach (var v_shape in Shapes) { bool v_hasEqual = false; for (int i = 0; i < v_shapesToCheck.Count; i++) { if (v_shape.Equals(v_shapesToCheck[i])) { v_hasEqual = true; v_shapesToCheck.RemoveAt(i); break; } } if (!v_hasEqual) { break; } } //If we removed all checked shapes, it means that both shapes are equal return(v_shapesToCheck.Count == 0); } return(false); }
protected virtual void BaseStart() { body = this.GetComponent <Rigidbody2D>(); Camera cam = Camera.main; this.camBounds = cam.GetCamWorldBounds(); body.velocity = new Vector2(1.0f, 1.0f) * MoveSpeed; }
public static RectBounds GetCamWorldBounds(this Camera cam, float padding = 0.0f) { RectBounds bounds = new RectBounds() { UpperBound = cam.orthographicSize + cam.transform.position.x - padding, RightBound = cam.orthographicSize * cam.aspect + cam.transform.position.y - padding }; bounds.LeftBound = -bounds.RightBound + padding; bounds.LowerBound = -bounds.UpperBound + padding; return(bounds); }
public SuiControllerWalkOnBridge(Suicider sui, Vector2 startPosition, float direction, RectBounds bridgeWalkArea) : base(sui) { Suiciders.Add(sui); sui.transform.position = startPosition; m_horiDirection = direction; float speed = Random.Range(0.2f, 0.4f); m_walker = new Walker(sui.transform, m_horiDirection, speed); m_bridgeWalkArea = bridgeWalkArea; sui.IsKinematic = true; sui.Dude.SetBobyPartsKinematic(true); sui.DudeAnimator.Walk(); }
public override bool Equals(object p_obj) { var v_polygonShape = p_obj as PolygonShape; if (p_obj == this) { return(true); } else if (v_polygonShape == null || v_polygonShape.IsEmpty()) { return(IsEmpty()); } else if (v_polygonShape.Vertices.Count == Vertices.Count && RectBounds.Equals(v_polygonShape.RectBounds)) { var v_firstSelfVertice = Vertices[0]; var v_verticeIndexInOtherShape = v_polygonShape.Vertices.IndexOf(v_firstSelfVertice); if (v_verticeIndexInOtherShape < 0) { return(false); } else { var v_sucess = true; for (int i = 0; i < Vertices.Count; i++) { var v_currentVertice = Vertices[i]; var v_otherVerticeIndex = i + v_verticeIndexInOtherShape; if (v_otherVerticeIndex >= v_polygonShape.Vertices.Count) { v_otherVerticeIndex -= v_polygonShape.Vertices.Count; } var v_otherVertice = v_polygonShape.Vertices[v_otherVerticeIndex]; if (v_currentVertice != v_otherVertice) { v_sucess = false; break; } } return(v_sucess); } } return(false); }
static bool IsRecordVisible(CellData cr, RectBounds recyclerBounds) { Vector2 halfCardSize = cr.RectTransformData.rect.size / 2.0f; Vector2 cardWorldPos = cr.RectTransformData.parent.TransformPoint( cr.RectTransformData.localPosition); var cardWorldBounds = new RectBounds() { Top = cardWorldPos.y + halfCardSize.y, Bottom = cardWorldPos.y - halfCardSize.y, Right = cardWorldPos.x + halfCardSize.x, Left = cardWorldPos.x - halfCardSize.x }; return(cardWorldBounds.Right >= recyclerBounds.Left && cardWorldBounds.Left <= recyclerBounds.Right && cardWorldBounds.Bottom <= recyclerBounds.Top && cardWorldBounds.Top >= recyclerBounds.Bottom); }
// Use this for initialization void Start() { bounds = Camera.main.GetCamWorldBounds(1.0f); ObjectCollection col = this.Collections.GetRandom(); List <ClickyObject> objects = col.GetChildren <ClickyObject>().ToList(); ClickyObject target = objects.GetRandom(); objects.RemoveAll(a => a.name == target.name); this.TargetName = target.name; for (int i = 0; i < SpawnNumber - 1; i++) { CreateObj(objects.GetRandom()); } CreateObj(target); }
void DrawAreaGraph(int radarIndex) { if (radarIndex == 0) { showAreaGraph = EditorGUI.ToggleLeft(lastRect, "Show Area Graph", showAreaGraph); } if (showAreaGraph) { Vector2 basePosition = new Vector2(standardSpacing, position.height - standardHeight * 2); Rect areaGraphRect = new Rect(basePosition, areaGraphSize).AddPosition(-Vector2.up * (standardSpacing * 4 + areaGraphSize.y)); RectBounds bounds = areaGraphRect.Bounds(); float maxArea = GetArea(radarIndex, AreaType.Max); float usedMaxGraphArea = useCustomMaxArea ? customMaxGraphArea : maxArea; if (radarIndex == 0) { areaGraphSize = EditorGUI.Vector2Field(lastRect.AddPosition(-Vector2.up * (standardHeight * 3 + 5)), "Graph Size", areaGraphSize); customMaxGraphArea = EditorGUI.FloatField(lastRect.AddPosition(new Vector2(150, -(standardHeight * 1 + 5))), "Max Area", customMaxGraphArea); useCustomMaxArea = EditorGUI.ToggleLeft(lastRect.AddPosition(-Vector2.up * (standardHeight * 1 + 5)), "Use Custom Max", useCustomMaxArea); DrawBoundaryLine(bounds.BottomLeft, bounds.BottomRight); DrawBoundaryLine(bounds.BottomLeft, bounds.TopLeft); EditorGUI.LabelField(new Rect(areaGraphRect).AddPosition(-Vector2.up * standardSpacing), string.Format("{0:0.#}", usedMaxGraphArea)); } float xPercent = (float)(radarIndex + 1) / iRadarGraphs.Count; float adjustedXPercent = xPercent - 0.5f / iRadarGraphs.Count; Vector2 startPos = bounds.BottomLeft + adjustedXPercent * (bounds.BottomRight - bounds.BottomLeft); float area = GetArea(radarIndex); float yPercent = area / usedMaxGraphArea; Vector2 ballPos = startPos - Vector2.up * areaGraphRect.height * yPercent; DrawActualValueLine(radarIndex, startPos, ballPos); Handles.color = iRadarGraphs[radarIndex].Color; Vector3 ballPosition = new Vector3(ballPos.x, ballPos.y, -10); Handles.DrawSphere(43, ballPosition, Quaternion.identity, 5); EditorGUI.LabelField(new Rect(ballPosition, new Vector2(30, standardHeight)).AddPosition(-Vector2.up * standardSpacing), string.Format("{0:0.#}", area)); } }
private void Awake() { Bounds = GetComponent <RectBounds>(); }
MapBoundsController InstantiateBounds(RectBounds rb, Material bound_material, float width_multiplier = 1f) { return(InstantiateBounds(rb.right - rb.left, rb.top - rb.bottom, rb.left, rb.bottom, bound_material, width_multiplier)); }
public void ShowAndPositionVisibleCells() { if (CellPrefab == null) { Assert.Never(ICellLayout.LayoutGroup.gameObject.name + ": ChildCell prefab was null"); return; } // Cache bounds for the viewport ScrollRecycler.ScrollRect.viewport.GetWorldCorners(ScrollRecycler.ViewportWorldCorners); // TODO: Add thresholds for each of these measurements (if actually needed) RectBounds recyclerBounds = new RectBounds() { Top = Vector3Extensions.GetMaxY(ScrollRecycler.ViewportWorldCorners), Bottom = Vector3Extensions.GetMinY(ScrollRecycler.ViewportWorldCorners), Left = Vector3Extensions.GetMinX(ScrollRecycler.ViewportWorldCorners), Right = Vector3Extensions.GetMaxX(ScrollRecycler.ViewportWorldCorners) }; #if UNITY_EDITOR Debug.DrawLine(new Vector3(recyclerBounds.Left, recyclerBounds.Top, 0.0f), new Vector3(recyclerBounds.Right, recyclerBounds.Top, 0.0f), Color.green); Debug.DrawLine(new Vector3(recyclerBounds.Left, recyclerBounds.Bottom, 0.0f), new Vector3(recyclerBounds.Right, recyclerBounds.Bottom, 0.0f), Color.green); Debug.DrawLine(new Vector3(recyclerBounds.Right, recyclerBounds.Top, 0.0f), new Vector3(recyclerBounds.Right, recyclerBounds.Bottom, 0.0f), Color.green); Debug.DrawLine(new Vector3(recyclerBounds.Left, recyclerBounds.Top, 0.0f), new Vector3(recyclerBounds.Left, recyclerBounds.Bottom, 0.0f), Color.green); #endif for (int i = 0; i < CellRecords.Count; ++i) // Optimization: use 2D List grouping records by content space position { CellData cellRecord = CellRecords[i]; // If that unit was active and we should cull it, return to pool if (cellRecord.Instance != null && !IsRecordVisible(cellRecord, recyclerBounds)) { CellPool.ReturnPooledObject(cellRecord.Instance); cellRecord.Instance = null; } } for (int i = 0; i < CellRecords.Count; ++i) // Optimization: use 2D List grouping records by content space position { CellData cellRecord = CellRecords[i]; // If that unit was not active and we should show it, find a free pool unit, init and position if (cellRecord.Instance == null && IsRecordVisible(cellRecord, recyclerBounds)) { cellRecord.Instance = CellPool.GetPooledObject(); if (cellRecord.Instance) // Need to null check for pending cards { var cellInstance = cellRecord.Instance.GetComponent <IRecyclableCell>(); var cellInstanceRtx = ((RectTransform)cellRecord.Instance.transform); // Position cell cellInstanceRtx.CopyFromRectTransformDimensions(cellRecord.RectTransformData); cellInstanceRtx.position = cellRecord.RectTransformData.parent.TransformPoint(cellRecord.RectTransformData.localPosition); cellInstanceRtx.SetAnchoredPosition3DZ(0.0f); cellInstance.OnCellShow(cellRecord); } } } }