public void CreateAndSave(string location) { #if UNITY_EDITOR BakedTrafficPath path = (BakedTrafficPath)AssetDatabase.LoadAssetAtPath(BuildFilePath(location, pathName), typeof(BakedTrafficPath)); if (path != null) { Debug.Log("Refreshing: " + BuildFilePath(location, pathName)); path.PathNodes = pathNodes; path.PathName = pathName; path.type = type; path.speedLitmit = speedLitmit; path.bakedResolution = bakedResolution; path.actualSpeedLimit = actualSpeedLimit; path.enableSmartVehicles = enableSmartVehicles; path.splitToChance = splitToChance; path.notes = notes; path.vehiclesCount = vehiclesCount; EditorUtility.SetDirty(path); } else { Debug.Log("Creating: " + BuildFilePath(location, pathName)); AssetDatabase.CreateAsset(this, BuildFilePath(location, pathName)); } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); #endif }
public override void OnInspectorGUI() { so.Update(); using (new EditorGUI.DisabledGroupScope(true)) { EditorGUILayout.PropertyField(so.FindProperty("m_Script")); } sp = so.FindProperty("path"); EditorGUILayout.PropertyField(sp); path = (BakedTrafficPath)sp.objectReferenceValue; sp = so.FindProperty("type"); EditorGUILayout.PropertyField(sp); switch (sp.enumValueIndex) { //single case 0: node = so.FindProperty("node").intValue; using (new EditorGUI.DisabledGroupScope(path == null)) { node = EditorGUILayout.IntField(new GUIContent("node"), node); node = Mathf.Clamp(node, 0, path == null ? 0 : path.PathNodes.Count - 1); } so.FindProperty("node").intValue = node; break; //length case 1: start = so.FindProperty("startNode").intValue; end = so.FindProperty("endNode").intValue; using (new EditorGUI.DisabledGroupScope(path == null)) { start = EditorGUILayout.IntField(new GUIContent("start"), start); start = Mathf.Clamp(start, 0, path == null ? 0 : path.PathNodes.Count - 1); end = EditorGUILayout.IntField(new GUIContent("end"), end); end = Mathf.Clamp(end, 0, path == null ? 0 : path.PathNodes.Count - 1); length = end - start; using (new EditorGUI.DisabledGroupScope(true)) { EditorGUILayout.IntField(new GUIContent("length"), length); } } so.FindProperty("startNode").intValue = start; so.FindProperty("endNode").intValue = end; break; } so.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { so.Update(); SerializedProperty scriptNameProp = so.FindProperty("m_Script"); using (new EditorGUI.DisabledScope(true)) { EditorGUILayout.PropertyField(scriptNameProp); } var pp = serializedObject.FindProperty("nodes"); EditorGUILayout.PropertyField(pp, true); pp = serializedObject.FindProperty("drawSphere"); EditorGUILayout.PropertyField(pp, true); pp = serializedObject.FindProperty("path"); EditorGUILayout.PropertyField(pp, true); if (pp.objectReferenceValue != null) { path = pp.objectReferenceValue as BakedTrafficPath; nodesDelta = 0; for (int i = 0; i < path.PathNodes.Count - 1; i++) { nodesDelta += Vector3.Distance(path.PathNodes[i], path.PathNodes[i + 1]); } nodesDelta /= path.PathNodes.Count - 1; calculatedLength = Mathf.CeilToInt(dis / nodesDelta); } using (new EditorGUI.DisabledScope(true)) { EditorGUILayout.FloatField(new GUIContent("Nodes Delta: "), nodesDelta); EditorGUILayout.IntField(new GUIContent("Calculated Length: "), calculatedLength); } so.ApplyModifiedProperties(); }
private void MonitorStatusRoutine() { int aliveCount = 0; for (int i = 0; i < pathInfos.Count; i++) { if (pathInfos[i].threadHandle.IsAlive) { aliveCount++; } } if (aliveCount == 0) { Debug.Log("Baking Done"); //all done //write data to asset for (int i = 0; i < pathInfos.Count; i++) { if (pathInfos[i].bakedNodes == null) { continue; } TrafficPath path = pathInfos[i].path; Debug.Log(pathInfos[i].bakedNodes.Count); BakedTrafficPath bakedPath = ScriptableObject.CreateInstance <BakedTrafficPath>(); bakedPath.Init(pathInfos[i].bakedNodes, path.gameObject.name, path.type, path.pathSpeedMPH, path.bakedResolution, path.splitChance, path.notes); bakedPath.CreateAndSave(serializedObject.FindProperty("savedLocation").stringValue); pathInfos[i].bakedNodes = null; return; } //reset EditorApplication.update -= MonitorStatusRoutine; status = BakeStatus.Preparing; } }
private void GetTransitNodes(BakedTrafficPath majorPath, BakedTrafficPath minorPath, out int transitionNode, out int connectingNode) { int tempI = -1; int tempJ = -1; float minDis = float.MaxValue; float dis; for (int i = 0; i < majorPath.PathNodes.Count; i++) { for (int j = 0; j < minorPath.PathNodes.Count; j++) { dis = Vector3.Distance(majorPath.PathNodes[i], minorPath.PathNodes[j]); if (dis < minDis) { minDis = dis; tempI = i; tempJ = j; } } } transitionNode = tempI; connectingNode = tempJ; }
private int GetTransitionNode(BakedTrafficPath mainPath, BakedTrafficPath turnedPath, int indexToSearch = 0) { if (turnedPath == null) { return(0); } float minDistance = float.MaxValue; int node = 0; for (int i = 0; i < mainPath.PathNodes.Count; i++) { Vector3 v3 = mainPath.PathNodes[i]; Vector3 v33 = turnedPath.PathNodes[indexToSearch]; float currentDistance = Vector3.Distance(mainPath.PathNodes[i], turnedPath.PathNodes[indexToSearch]); if (currentDistance < minDistance) { minDistance = currentDistance; node = i; } } return(node); }