Ejemplo n.º 1
0
    void PlaceShiftedLane(bool right)
    {
        if (BaseLane == null)
        {
            return;
        }

        Curve c1 = BaseLane.xz_curve.Clone();

        c1.ShiftRight(right ? shiftStep : -shiftStep);
        BaseLane = new Lane(c1, BaseLane.y_func);

        var placeCmd = new PlaceLaneCommand();

        inputHandler.commandSequence.Push(placeCmd);
        placeCmd.Execute(BaseLane);
        BaseLane.SetGameobjVisible(false);

        // Set new BaseLane
        foreach (Lane added in placeCmd.added)
        {
            if ((added.GetThreedPos(1f) - BaseLane.GetThreedPos(1f)).sqrMagnitude < 0.001f)
            {
                BaseLane = added;
                break;
            }
        }

        BuildRoad.UseDefaultStickyMouseForRoad(inputHandler.stickyMouse);
    }
Ejemplo n.º 2
0
    void OnEnable()
    {
        inputHandler.OnClick += delegate(object sender, (Vector3, Curve3DSampler)pos_parent) {
            if (pos_parent.Item2 == null)
            {
                BaseLane = null;
            }
            else
            {
                BaseLane = (Lane)pos_parent.Item2;
            }
        };

        inputHandler.OnForwardKeyPressed += delegate {
            if (BaseLane == null)
            {
                return;
            }

            Function currentFunc  = new LinearFunction(0f, 0f); // TODO: Create more
            Curve    currentCurve = null;

            if (spawnType == typeof(Line))
            {
                var curveParams = appendAtFront ?
                                  new List <Vector3> {
                    BaseLane.xz_curve.GetTwodPos(1f), BaseLane.xz_curve.GetTwodPos(1f) + BaseLane.xz_curve.GetFrontDir(1f) * forwardStep
                } :
                new List <Vector3> {
                    BaseLane.xz_curve.GetTwodPos(0f) - BaseLane.xz_curve.GetFrontDir(0f) * forwardStep, BaseLane.xz_curve.GetTwodPos(0f)
                };
                currentCurve = new Line(curveParams[0], curveParams[1]);
            }
            else
            {
                if (spawnType == typeof(Arc))
                {
                    float radius = forwardStep / turnStep;
                    if (BaseLane.xz_curve is Arc)
                    {
                        radius = ((Arc)(BaseLane.xz_curve)).Radius;
                    }

                    if (appendAtFront)
                    {
                        if (turnRight)
                        {
                            currentCurve = new Arc(
                                BaseLane.xz_curve.GetTwodPos(1f) + BaseLane.xz_curve.GetRightDir(1f) * radius,
                                BaseLane.xz_curve.GetTwodPos(1f),
                                -turnStep);
                        }
                        else
                        {
                            currentCurve = new Arc(
                                BaseLane.xz_curve.GetTwodPos(1f) - BaseLane.xz_curve.GetRightDir(1f) * radius,
                                BaseLane.xz_curve.GetTwodPos(1f),
                                turnStep);
                        }
                    }
                    else
                    {
                        if (turnRight)
                        {
                            currentCurve = new Arc(
                                BaseLane.xz_curve.GetTwodPos(0f) - BaseLane.xz_curve.GetRightDir(0f) * radius,
                                BaseLane.xz_curve.GetTwodPos(0f),
                                -turnStep);
                            currentCurve.Crop(1f, 0f);
                        }
                        else
                        {
                            currentCurve = new Arc(
                                BaseLane.xz_curve.GetTwodPos(0f) + BaseLane.xz_curve.GetRightDir(0f) * radius,
                                BaseLane.xz_curve.GetTwodPos(0f),
                                turnStep);
                            currentCurve.Crop(1f, 0f);
                        }
                    }
                }
                else
                {
                    // Bezeir mode not supported
                    return;
                }
            }


            BaseLane = new Lane(currentCurve, currentFunc);
            var placeCmd = new PlaceLaneCommand();
            inputHandler.commandSequence.Push(placeCmd);
            placeCmd.Execute(BaseLane);

            BaseLane.SetGameobjVisible(false);

            // Set new BaseLane
            foreach (Lane added in placeCmd.added)
            {
                if ((added.GetThreedPos(1f) - BaseLane.GetThreedPos(1f)).sqrMagnitude < 0.001f)
                {
                    BaseLane = added;
                    break;
                }
            }

            BuildRoad.UseDefaultStickyMouseForRoad(inputHandler.stickyMouse);
        };

        inputHandler.OnLeftKeyPressed += delegate {
            PlaceShiftedLane(false);
        };

        inputHandler.OnRightKeyPressed += delegate {
            PlaceShiftedLane(true);
        };
    }