示例#1
0
 public MoveAlongWaypointRouteInstruction(IMovable gameObject, WaypointRoute route) : base(gameObject)
 {
     Route   = route;
     OnRoute = false;
     NextDestinationRandom = new Random();
     NextDestination       = null;
 }
示例#2
0
        public StorageCore()
        {
            var g = new GreenTile();

            this.Objects = new List <FrameworkObject>();
            this.Objects.Add(g);

            Waypoint[,] net = new Waypoint[3, 3];

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    net[i, j] = new Waypoint(new Vector2(150 + j * 100, 200 + i * 100));
                    this.Objects.Add(net[i, j]);
                }
            }

            var fin = new Waypoint(new Vector2(700, 550));

            this.Objects.Add(fin);

            WaypointRoute r = new WaypointRoute(net[1, 1]);

            r.AddWaypoint(net[1, 1], net[0, 0]);
            r.AddWaypoint(net[1, 1], net[0, 2]);
            r.AddWaypoint(net[1, 1], net[2, 2]);
            r.AddWaypoint(net[1, 1], net[2, 0]);

            r.AddWaypoint(net[0, 0], net[0, 1]);
            r.AddWaypoint(net[0, 2], net[1, 2]);
            r.AddWaypoint(net[2, 2], net[2, 1]);
            r.AddWaypoint(net[2, 0], net[1, 0]);

            r.AddWaypoint(net[0, 1], net[1, 1]);
            r.AddWaypoint(net[1, 2], net[1, 1]);
            r.AddWaypoint(net[2, 1], net[1, 1]);
            r.AddWaypoint(net[1, 0], net[1, 1]);

            r.AddWaypoint(net[2, 2], fin);

            this.Objects.Add(r);
            var i1 = new MoveTowardWaypointInstruction(g, net[1, 1]);
            var m1 = new MoveInstructionSet(i1);

            g.AddInstructionSet(m1);
            g.AddInstructionSet(new MoveInstructionSet(new MoveTowardPointInstruction(g, new Vector2(500, 10))));

            g.AddInstructionSet(new MoveInstructionSet(new MoveAlongWaypointRouteInstruction(g, r)));

            g.AddInstructionSet(new MoveInstructionSet(new MoveTowardPointInstruction(g, new Vector2(500, 10))));
        }
示例#3
0
 public override void OnInspectorGUI()
 {
     //        EditorGUILayout.HelpBox("Two Types of paths\n" +
     //            "1. No margin : It starts from the first path points.\n" +
     //            "2. With margin : it starts from the second path points.\n\n" +
     //            "Option 2 needs more than two path points. " +
     //            "This is useful if there are more than two paths they needed to be smoothly blended. " +
     //            "This can be achieved by positioning the first two path points of the later path " +
     //            "at the last two path points of the prior one", MessageType.Info);
     DrawDefaultInspector();
     myScript = target as WaypointRoute;
     if (GUILayout.Button("Rebuild Path"))
     {
         myScript.UpdateNodes();
     }
 }
示例#4
0
 // Use this for initialization
 void Start()
 {
     if (route == null || route.Destination != Destination)
     {
         WaypointNode closest = WaypointNode.GetClosest(transform.position);
         if (closest == null)
         {
             route = new WaypointRoute(this, Destination);
         }
         else
         {
             route = new WaypointRoute(this, closest.GetRouteTo(Destination));
         }
         route.NextWaypointReachedEvent  = NextWaypointReachedEvent;
         route.FinalWaypointReachedEvent = FinalWaypointReachedEvent;
     }
 }
示例#5
0
    void OnSceneGUI()
    {
        myScript        = target as WaypointRoute;
        handleTransform = myScript.transform;
        Transform[] nodes = myScript.nodes;

        normalStyle.normal.textColor = Color.green;
        normalStyle.fontSize         = 14;
        Vector3 camPos = Camera.current.transform.position;
        Vector3 camUp  = Camera.current.transform.up;

        // node handle
        Handles.color = new Color(0, 1f, 0, 1f);// green
        for (int i = 0; i < nodes.Length; i++)
        {
            float   size = HandleUtility.GetHandleSize(nodes[i].position);
            Vector3 temp = Vector3.Cross((nodes[i].position - camPos), camUp).normalized *myScript.NodeSize;;

            if (myScript.showName)
            {
                Handles.Label(myScript.transform.position, myScript.name, normalStyle);
            }

            Handles.Label(nodes[i].position + temp, i.ToString(), normalStyle);

            if (Handles.Button(nodes[i].position, Quaternion.identity, size * handleSize, size * pickSize, Handles.DotCap))
            {
                nodeSelected = true;
                selectedNode = i;
                break;
            }
            if (nodeSelected)
            {
                EditorGUI.BeginChangeCheck();
                Vector3 point = Handles.DoPositionHandle(nodes[selectedNode].position, Quaternion.identity);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(myScript, "move node");
                    EditorUtility.SetDirty(myScript);
                    myScript.nodes[selectedNode].position = point;
                }
            }
        }
    }
示例#6
0
        public WaypointRoute GenerateWaypointRoute(String startNodeName, String endNodeName)
        {
            WaypointRoute r = new WaypointRoute();

            List<String> bestPath;
            Double distance;
            FindShortestPath(new List<string>(), startNodeName, endNodeName, out distance, out bestPath);
            //r.Add(new Waypoint(startNodeName, m_nodes[startNodeName].Location));
            foreach (String nodeName in bestPath)
            {
                r.Add(new Waypoint(nodeName, m_nodes[nodeName].Location));
            }

            return r;
        }
示例#7
0
 public void Move(WaypointRoute path)
 {
     throw new NotImplementedException();
 }