示例#1
0
        private static void SetupVehicle()
        {
            EditorHelper.SetUndoGroup("Setup Vehicle");

            GameObject selected = Selection.activeGameObject;

            //Create raycast anchor
            GameObject anchor = EditorHelper.CreateGameObject("Raycast Anchor", selected.transform);

            //Add AI scripts
            VehicleAI  veAi       = EditorHelper.AddComponent <VehicleAI>(selected);
            WheelDrive wheelDrive = EditorHelper.AddComponent <WheelDrive>(selected);

            TrafficSystem ts = GameObject.FindObjectOfType <TrafficSystem>();

            //Configure the vehicle AI script with created objects
            anchor.transform.localPosition = Vector3.zero;
            anchor.transform.localRotation = Quaternion.Euler(Vector3.zero);
            veAi.raycastAnchor             = anchor.transform;

            if (ts != null)
            {
                veAi.trafficSystem = ts;
            }

            //Create layer AutonomousVehicle if it doesn't exist
            EditorHelper.CreateLayer("AutonomousVehicle");

            //Set the tag and layer name
            selected.tag = "AutonomousVehicle";
            EditorHelper.SetLayer(selected, LayerMask.NameToLayer("AutonomousVehicle"), true);
        }
        private void AddWaypoint(Vector3 position)
        {
            GameObject go = EditorHelper.CreateGameObject("Waypoint-" + wps.curSegment.waypoints.Count, wps.curSegment.transform);

            go.transform.position = position;

            Waypoint wp = EditorHelper.AddComponent <Waypoint>(go);

            wp.Refresh(wps.curSegment.waypoints.Count, wps.curSegment);

            //Record changes to the TrafficSystem (string not relevant here)
            Undo.RecordObject(wps.curSegment, "");
            wps.curSegment.waypoints.Add(wp);
        }
        private void AddSegment(Vector3 position)
        {
            int        segId = wps.segments.Count;
            GameObject segGo = EditorHelper.CreateGameObject("Segment-" + segId, wps.transform.GetChild(0).transform);

            segGo.transform.position = position;

            wps.curSegment              = EditorHelper.AddComponent <Segment>(segGo);
            wps.curSegment.id           = segId;
            wps.curSegment.waypoints    = new List <Waypoint>();
            wps.curSegment.nextSegments = new List <Segment>();

            //Record changes to the TrafficSystem (string not relevant here)
            Undo.RecordObject(wps, "");
            wps.segments.Add(wps.curSegment);
        }
        private void AddIntersection(Vector3 position)
        {
            int        intId = wps.intersections.Count;
            GameObject intGo = EditorHelper.CreateGameObject("Intersection-" + intId, wps.transform.GetChild(1).transform);

            intGo.transform.position = position;

            BoxCollider bc = EditorHelper.AddComponent <BoxCollider>(intGo);

            bc.isTrigger = true;
            Intersection intersection = EditorHelper.AddComponent <Intersection>(intGo);

            intersection.id = intId;

            //Record changes to the TrafficSystem (string not relevant here)
            Undo.RecordObject(wps, "");
            wps.intersections.Add(intersection);
        }
        private static void CreateTraffic()
        {
            EditorHelper.SetUndoGroup("Create Traffic Objects");

            GameObject mainGo = EditorHelper.CreateGameObject("Traffic System");

            mainGo.transform.position = Vector3.zero;
            EditorHelper.AddComponent <TrafficSystem>(mainGo);

            GameObject segmentsGo = EditorHelper.CreateGameObject("Segments", mainGo.transform);

            segmentsGo.transform.position = Vector3.zero;

            GameObject intersectionsGo = EditorHelper.CreateGameObject("Intersections", mainGo.transform);

            intersectionsGo.transform.position = Vector3.zero;

            //Close Undo Operation
            Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
        }