Пример #1
0
    void OnEnable()
    {
        if (inputHandler.stickyMouse != null)
        {
            UseDefaultStickyMouseForRoad(inputHandler.stickyMouse);
        }

        // Init behavior
        inputHandler.OnClick += delegate(object sender, (Vector3, Curve3DSampler)pos_parent) {
            if (currentLane == null)
            {
                Debug.Log("add new");
                Curve currentCurve = null;
                if (spawnType == typeof(Line))
                {
                    currentCurve = Line.GetDefault();
                }
                if (spawnType == typeof(Arc))
                {
                    currentCurve = Arc.GetDefault();
                }
                if (spawnType == typeof(Bezier))
                {
                    currentCurve = Bezier.GetDefault();
                }

                Function currentFunc = new LinearFunction(); // TODO: Create more
                currentLane = new Lane(currentCurve, currentFunc);
            }

            Vector3        position;
            Curve3DSampler parentCurve; // which virtual curve does the road under construction belong to?
            (position, parentCurve) = pos_parent;


            new PlaceEndingCommand(position).Execute(currentLane);

            if (currentLane.IsValid)
            {
                // Place
                GetComponent <FollowMouseBehavior>().enabled = false;
                var placeCmd = new PlaceLaneCommand();
                inputHandler.commandSequence.Push(placeCmd);
                placeCmd.Execute(currentLane);
                currentLane.SetGameobjVisible(false);
                currentLane = null;
                GetComponent <HighLightCtrlPointBehavior>().radius = highlightRadius;

                UseDefaultStickyMouseForRoad(inputHandler.stickyMouse);
            }
            else
            {
                // Next ctrl point Pending
                if (parentCurve != null)
                {
                    UseSingleVirtualCurveForRoad(parentCurve);
                }
                else
                {
                    UseDefaultStickyMouseForRoad(inputHandler.stickyMouse);
                }

                GetComponent <FollowMouseBehavior>().enabled = true;
                GetComponent <FollowMouseBehavior>().SetTarget(currentLane);
                GetComponent <HighLightCtrlPointBehavior>().radius = 0f;
            }
        };

        // Adjust behavior
        inputHandler.OnDragStart += delegate(object sender, Vector3 position)
        {
            Lane targetLane = RoadPositionRecords.QueryClosestCPs3DCurve(position);
            if (targetLane != null)
            {
                GetComponent <FollowMouseBehavior>().enabled = true;
                currentLane = new Lane(targetLane);
                GetComponent <FollowMouseBehavior>().SetTarget(currentLane);

                //replace targetLane with a temporary object (currentLane)
                var removeCmd = new RemoveLaneCommand();
                inputHandler.commandSequence.Push(removeCmd);
                removeCmd.Execute(targetLane);

                GetComponent <HighLightCtrlPointBehavior>().radius = 0f;
            }
        };

        inputHandler.OnDragEnd += delegate(object sender, Vector3 position)
        {
            if (currentLane != null)
            {
                GetComponent <FollowMouseBehavior>().enabled       = false;
                GetComponent <HighLightCtrlPointBehavior>().radius = highlightRadius;

                // add actual lane to network
                var placeCmd = new PlaceLaneCommand();
                inputHandler.commandSequence.Push(placeCmd);
                placeCmd.Execute(currentLane);

                currentLane.SetGameobjVisible(false);
                currentLane = null;
            }
        };
    }
Пример #2
0
    private void Start()
    {
        // Init behavior
        inputHandler.OnClick += delegate(object sender, Vector3 position) {
            Debug.Log("Onclick");

            if (currentLane == null)
            {
                Curve currentCurve = null;
                if (spawnType == typeof(Line))
                {
                    currentCurve = Line.GetDefault();
                }
                if (spawnType == typeof(Arc))
                {
                    currentCurve = Arc.GetDefault();
                }
                if (spawnType == typeof(Bezier))
                {
                    currentCurve = Bezier.GetDefault();
                }

                Function currentFunc = new LinearFunction(); // TODO: Create more
                currentLane = new Lane(currentCurve, currentFunc);
            }

            new PlaceEndingCommand(position).Execute(currentLane);

            if (currentLane.IsValid)
            {
                // Quit Init
                GetComponent <FollowMouseBehavior>().enabled = false;
                var placeCmd = new PlaceLaneCommand();
                commandSequence.Push(placeCmd);
                placeCmd.Execute(currentLane);
                currentLane.SetGameobjVisible(false);
                currentLane = null;
                GetComponent <HighLightCtrlPointBehavior>().radius = highlightRadius;
            }
            else
            {
                // Pending
                GetComponent <FollowMouseBehavior>().enabled = true;
                GetComponent <FollowMouseBehavior>().SetTarget(currentLane);
                GetComponent <HighLightCtrlPointBehavior>().radius = 0f;
            }
        };

        // Adjust behavior
        inputHandler.OnDragStart += delegate(object sender, Vector3 position)
        {
            Lane targetLane = RoadPositionRecords.QueryClosestCPs3DCurve(position);
            if (targetLane != null)
            {
                GetComponent <FollowMouseBehavior>().enabled = true;
                currentLane = new Lane(targetLane);
                GetComponent <FollowMouseBehavior>().SetTarget(currentLane);

                //replace targetLane with a temporary object (currentLane)
                var removeCmd = new RemoveLaneCommand();
                commandSequence.Push(removeCmd);
                removeCmd.Execute(targetLane);

                GetComponent <HighLightCtrlPointBehavior>().radius = 0f;
            }
        };

        inputHandler.OnDragEnd += delegate(object sender, Vector3 position)
        {
            if (currentLane != null)
            {
                GetComponent <FollowMouseBehavior>().enabled       = false;
                GetComponent <HighLightCtrlPointBehavior>().radius = highlightRadius;

                // add actual lane to network
                var placeCmd = new PlaceLaneCommand();
                commandSequence.Push(placeCmd);
                placeCmd.Execute(currentLane);

                currentLane.SetGameobjVisible(false);
                currentLane = null;
            }
        };

        inputHandler.OnUndoPressed += delegate {
            var latestCmd = commandSequence.Pop();
            latestCmd.Undo();
        };
    }