public void OnInspectorGUI() { EditorGUILayout.Space(); EditorGUILayout.LabelField("Road Settings", GUIStyles.GroupTitleStyle); #if EASY_ROADS GUILayout.BeginHorizontal(); { // show error color in case there's no container if (erRoad == null) { editor.SetErrorBackgroundColor(); } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(road, new GUIContent("Road", "The Easy Roads road which will get the Biome Mask Area's nodes transferred to")); if (EditorGUI.EndChangeCheck()) { if (road.objectReferenceValue != null) { erRoad = erRoadNetwork.GetRoadByGameObject(road.objectReferenceValue as GameObject); } } // default color in case error color was set editor.SetDefaultBackgroundColor(); } GUILayout.EndHorizontal(); // consistency check for EasyRoads road GUILayout.BeginHorizontal(); if (erRoad == null) { EditorGUILayout.HelpBox("Easy Roads GameObject of type Road required", MessageType.Error); } GUILayout.EndHorizontal(); EditorGUILayout.PropertyField(smoothEnabled, new GUIContent("Smooth", "Perform smoothing on the polygon")); EditorGUILayout.PropertyField(closedTrack, new GUIContent("Closed Track", "Set the Closed Track setting of the road")); EditorGUILayout.PropertyField(minDistance, new GUIContent("Min. Node Distance", "Minimum distance between nodes. Use this to remove close curve jitter")); EditorGUILayout.PropertyField(autoPlaceGameObject, new GUIContent("Auto Placement", "Automatically place a GameObject on the road")); if (autoPlaceGameObject.boolValue) { if (placementGameObject.objectReferenceValue == null) { editor.SetErrorBackgroundColor(); } EditorGUILayout.PropertyField(placementGameObject, new GUIContent("Placement GameObject", "The GameObject to place automatically.")); editor.SetDefaultBackgroundColor(); } #else EditorGUILayout.HelpBox("Requires Easy Roads installed and 'EASY_ROADS' Scripting Define Symbol", MessageType.Error); #endif }
/// <summary> /// Place a gameobject on the road at marker 0 looking at marker 1 /// </summary> private void AutoPlaceGameObject() { if (!editor.extension.roadSettings.autoPlaceGameObject) { return; } if (editor.extension.roadSettings.placementGameObject == null) { Debug.LogError("No GameObject specified"); return; } ERRoadNetwork erRoadNetwork = new ERRoadNetwork(); ERRoad erRoad = erRoadNetwork.GetRoadByGameObject(editor.extension.roadSettings.road); if (erRoad == null) { Debug.LogError("No road gameobject specified"); return; } if (erRoad.GetMarkerCount() < 2) { Debug.LogError("At least 2 markers required"); return; } GameObject gameObject = editor.extension.roadSettings.placementGameObject; // get marker with index 0 and 1 Vector3 positionA = erRoad.GetMarkerPosition(0); Vector3 positionB = erRoad.GetMarkerPosition(1); Bounds prefabBounds = BoundsUtils.GetPrefabBounds(gameObject); // position at marker position gameObject.transform.position = positionA; // look at 2nd marker gameObject.transform.LookAt(positionB); }
public void OnEnable() { biomeMaskArea = editor.FindProperty(x => x.roadSettings.biomeMaskArea); road = editor.FindProperty(x => x.roadSettings.road); smoothEnabled = editor.FindProperty(x => x.roadSettings.smoothEnabled); closedTrack = editor.FindProperty(x => x.roadSettings.closedTrack); minDistance = editor.FindProperty(x => x.roadSettings.minDistance); autoPlaceGameObject = editor.FindProperty(x => x.roadSettings.autoPlaceGameObject); placementGameObject = editor.FindProperty(x => x.roadSettings.placementGameObject); #if EASY_ROADS // create a reference to the road network in the scene erRoadNetwork = new ERRoadNetwork(); erRoad = null; if (road.objectReferenceValue != null) { erRoad = erRoadNetwork.GetRoadByGameObject(road.objectReferenceValue as GameObject); } #endif }