Пример #1
0
    public static PlacedBuilding CreatePlacedBuilding(BuildingData bldData, Outline outline, GameObject obj)
    {
        PlacedBuilding pb = factoryList[bldData.buildingClass](obj);

        pb.bldData = bldData;
        pb.outline = outline;
        return(pb);
    }
Пример #2
0
    void UpdateModeOutline(bool didHit, RaycastHit hit, Snap snap)
    {
        if (Input.GetButtonUp("Build") && activeBuilding != null)
        {
            builtObjects.Add(activeOutline);
            activeBuilding.Build();
            activeOutline = null;
            foreach (PlacedBuilding plbd in GetComponentsInChildren <PlacedBuilding>())
            {
                if (plbd != activeBuilding)
                {
                    plbd.UpdateWorld();
                }
            }
            activeBuilding = null;
        }

        if (Input.GetButton("AdjustHeight"))
        {
            if (snap == null)
            {
                //TODO: changed from center of bounds, check if works
                Vector3 closest   = activeOutline.getRawDefiningPoints().First();
                Ray     cameraRay = Camera.main.ScreenPointToRay(Input.mousePosition);
                //find closest point
                foreach (Vector3 point in activeOutline.getRawDefiningPoints())
                {
                    if (Vector3.Dot(cameraRay.direction, point - cameraRay.origin) < Vector3.Dot(cameraRay.direction, closest - cameraRay.origin))
                    {
                        closest = point;
                    }
                }
                //find "desired" height
                float distance = Vector3.Dot(cameraRay.direction, cameraRay.origin - closest);
                float height   = (cameraRay.origin + cameraRay.direction * distance).y / 4;
                if (Input.GetButtonDown("AdjustHeight"))
                {
                    originalHeight = activeOutline.Height - height; // offset the height to that the point of clicking = zero height modification
                }
                activeOutline.Height = height + originalHeight;
                activeOutline.OnShapeChanged();
            }
            else
            {
                activeOutline.Height = snap.snappingPoint.y;
            }
        }

        if (Input.GetKeyDown(KeyCode.E))
        {
            if (activeOutline.Extrusion == 0)
            {
                activeOutline.Extrusion = 1;
            }
            else if (activeOutline.BothSideExtrusion == true)
            {
                activeOutline.BothSideExtrusion = false;
                activeOutline.Extrusion         = 0;
            }
            else
            {
                activeOutline.BothSideExtrusion = true;
            }
        }

        DrawModeOutline(didHit, hit, snap);
    }