private void Start( ) { slimeRects = GetComponent <SlimeRects>( ); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { float realSize = pixelSize * size; GameObject go = new GameObject($"slime[{x},{y}]"); go.transform.SetParent(transform); go.transform.localPosition = new Vector2(realSize * x, realSize * y); go.transform.localScale = new Vector2(size, size); SpriteRenderer sr = go.AddComponent <SpriteRenderer>( ); sr.sprite = slimeSprite; sr.color = slimeColor; sr.sortingLayerName = "Slime"; sr.enabled = Ents[x, y]; SlimeEntity se = go.AddComponent <SlimeEntity>( ); se.X = x; se.Y = y; se.State = Ents[x, y]; se.Size = realSize; Ents[x, y] = se; } } SetState(slimeStart.x, slimeStart.y, true); for (int i = 0; i < slimeIterations; i++) { Grow( ); } EventHandler.RegisterTickEvent(Grow); }
private void OnSceneGUI( ) { if (target == null) { return; } SlimeRects slimeRects = (SlimeRects)target; Vector3 pos = slimeRects.transform.position; float s = (Camera.main.orthographicSize / 360) * 12; foreach (Rect rect in slimeRects.ForbiddenAreas) { Vector2 origin = new Vector2(pos.x + rect.x * s, pos.y + rect.y * s); Vector3[] area = new Vector3[] { new Vector3(origin.x, origin.y, pos.z), new Vector3(origin.x, origin.y + rect.height * s, pos.z), new Vector3(origin.x + rect.width * s, origin.y + rect.height * s, pos.z), new Vector3(origin.x + rect.width * s, origin.y, pos.z) }; Handles.DrawSolidRectangleWithOutline(area, slimeRects.FaceColor, slimeRects.OutlineColor); } }