Пример #1
0
        /// <summary>
        /// Scan if a merge point is ahead of the car, and if so, handle merging.
        /// </summary>
        private void HandleMerging()
        {
            double totalDist = Util.Distance(x, y, CurrentCityPath.e.x, CurrentCityPath.e.y);

            foreach (CityPath p in path)
            {
                if (p != CurrentCityPath)
                {
                    totalDist += Util.Distance(p.s.x, p.s.y, p.e.x, p.e.y);
                }

                if (p.e is MergeNode)
                {
                    if (2 * Util.StopDistance(speed, DEACCELERATION) + 25 >= totalDist)
                    {
                        MergeNode m = p.e as MergeNode;
                        if (!m.intersection.Contains(this))
                        {
                            m.intersection.VehicleApproach(this);
                        }
                        MergePoint point = m.intersection as MergePoint;
                        if (point.inside.Contains(this))
                        {
                            limits.RemoveAll(l => l.name == "merge");
                            return;
                        }
                        else if (Util.StopDistance(speed, DEACCELERATION) + 25 >= totalDist)
                        {
                            limits.RemoveAll(l => l.name == "merge");
                            limits.Add(new SpeedLimiter(0, "merge"));
                        }
                    }
                }
            }
        }
Пример #2
0
        private string[] handleSequenceNode(ref string[] scene, MergeNode currentMergeNode, List <ScriptMapping>
                                            scriptMappings, KeyValuePair <YamlNode, YamlNode> yamlNode)
        {
            int line = yamlNode.Key.Start.Line - 1;

            scene[line] = scene[line].ReplaceFirst(currentMergeNode.OriginalValue, currentMergeNode.NameToExportTo);
            string type = currentMergeNode.Type;

            ScriptMapping scriptMapping =
                scriptMappings.FirstOrDefault(script => script.oldClassModel.Name == type);

            if (scriptMapping == null)
            {
                Debug.Log("Could not find scriptMapping for MergeNode, Type : " + currentMergeNode.Type +
                          " originalValue : " +
                          currentMergeNode.OriginalValue);
                return(scene);
            }

            var items = yamlNode.Value.GetItems();

            if (items == null || items.Count == 0)
            {
                return(scene);
            }

            foreach (YamlNode item in items)
            {
                scene = recursiveReplaceField(ref scene, scriptMapping.MergeNodes, item, scriptMappings);
            }

            return(scene);
        }
Пример #3
0
        private string[] handleValueNode(ref string[] scene, MergeNode currentMergeNode, string yamlNodeKey,
                                         int line,
                                         KeyValuePair <YamlNode, YamlNode> yamlNode)
        {
            if (!string.IsNullOrEmpty(currentMergeNode.NameToExportTo))
            {
                scene[line] = scene[line]
                              .ReplaceFirst(currentMergeNode.OriginalValue, currentMergeNode.NameToExportTo);
            }
            else
            {
                Debug.Log("Mapping failed for : " + yamlNodeKey + " node : " + yamlNode.ToString());
            }

            return(scene);
        }
Пример #4
0
            public ScriptMappingWrapper(ScriptMapping scriptMapping)
            {
                ScriptMapping        = scriptMapping;
                FieldSelectionStates = new bool[scriptMapping.MergeNodes.Count];

                for (var i = 0; i < scriptMapping.MergeNodes.Count; i++)
                {
                    MergeNode mergeNode = scriptMapping.MergeNodes[i];
                    FieldSelectionStates[i] = mergeNode.OriginalValue != mergeNode.NameToExportTo;
                }

                OptionSelections = new int[scriptMapping.MergeNodes.Count];
                for (int i = 0; i < OptionSelections.Length; i++)
                {
                    OptionSelections[i] = 0;
                }
            }
Пример #5
0
        /// <summary>
        /// Helper method for the<see cref="MigrateFields"/> to replace the fields in the scripts.
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="currentMergeNodes"></param>
        /// <param name="rootYamlNode"></param>
        /// <returns></returns>
        private string[] recursiveReplaceField(ref string[] scene, List <MergeNode> currentMergeNodes,
                                               YamlNode rootYamlNode, // todo : refactor to multiple methods
                                               List <ScriptMapping> scriptMappings)
        {
            IDictionary <YamlNode, YamlNode> yamlChildren = rootYamlNode.GetChildren();

            foreach (KeyValuePair <YamlNode, YamlNode> yamlNode in yamlChildren)
            {
                string yamlNodeKey = yamlNode.Key.ToString();
                if (constants.MonoBehaviourFieldExclusionList.Contains(yamlNodeKey))
                {
                    continue;
                }

                int line = yamlNode.Key.Start.Line - 1;

                MergeNode currentMergeNode =
                    currentMergeNodes.FirstOrDefault(node => node.OriginalValue == yamlNodeKey);
                if (currentMergeNode == null)
                {
                    Debug.LogError("[DataLoss] Could not find mergeNode for key : " + yamlNodeKey);
                    continue;
                }

                if (yamlNode.Value is YamlMappingNode)
                {
                    scene = handleMappingNode(ref scene, currentMergeNode, scriptMappings, yamlNode);
                }
                else if (yamlNode.Value is YamlSequenceNode)
                {
                    scene = handleSequenceNode(ref scene, currentMergeNode, scriptMappings, yamlNode);
                }
                else
                {
                    scene = handleValueNode(ref scene, currentMergeNode, yamlNodeKey, line, yamlNode);
                }
            }

            return(scene);
        }
Пример #6
0
        private List <MergeNode> CombineMergeNodes(List <MergeNode> oldMergeNodes, List <MergeNode> newMergeNodes)
        {
            List <MergeNode> mergeNodesToAdd = new List <MergeNode>();

            foreach (MergeNode newMergeNode in newMergeNodes)
            {
                MergeNode mergeNode =
                    oldMergeNodes.FirstOrDefault(old => old.NameToExportTo == newMergeNode.OriginalValue);
                if (mergeNode == null)
                {
                    mergeNodesToAdd.Add(newMergeNode);
                    Debug.Log("Could not find mergeNode for new mergeNode: " + newMergeNode.OriginalValue +
                              " adding new mergeNodes.");
                    continue;
                }

                mergeNode.NameToExportTo = newMergeNode.NameToExportTo;
            }

            oldMergeNodes.AddRange(mergeNodesToAdd);
            return(oldMergeNodes);
        }
Пример #7
0
        private string[] handleMappingNode(ref string[] scene, MergeNode currentMergeNode,
                                           List <ScriptMapping> scriptMappings
                                           , KeyValuePair <YamlNode, YamlNode> yamlNode)
        {
            var recursiveChildren = yamlNode.Value.GetChildren();

            if (recursiveChildren == null || recursiveChildren.Count == 0)
            {
                return(scene);
            }

            string type = currentMergeNode.Type;

            if (string.IsNullOrEmpty(type))
            {
                Debug.LogError("Type was null for yamlKey : " + yamlNode.Key.ToString());
                return(scene);
            }

            int line = yamlNode.Key.Start.Line - 1;

            scene[line] = scene[line].ReplaceFirst(currentMergeNode.OriginalValue, currentMergeNode.NameToExportTo);

            List <MergeNode> typeNodes =
                scriptMappings.FirstOrDefault(script => script.oldClassModel.FullName == type)?.MergeNodes;

            if (typeNodes != null)
            {
                scene = recursiveReplaceField(ref scene, typeNodes, yamlNode.Value, scriptMappings);
            }
            else
            {
                Debug.Log("Found a mappingNode but could not find subclasses in class : " + type);
            }

            return(scene);
        }
Пример #8
0
        /// <summary>
        /// Распарсить XMI файл и создать объекты соответствующих классов
        /// </summary>
        /// <param name="diagram">Исходная диаграмма</param>
        /// <param name="hasJoinOrFork">Имеется ли join\fork</param>
        /// <returns></returns>
        public bool Parse(Diagram diagram, ref bool hasJoinOrFork)
        {
            xmlFile = diagram.doc;
            XmlNodeList xPackagedList;

            try {
                xPackagedList = xmlFile.GetElementsByTagName("packagedElement");
            } catch (NullReferenceException) {
                //Console.WriteLine("[x] Тег packagedElement не найден");
                return(false);
            }


            // получим корневой элемент
            XmlNode xRoot = FindActivePackageEl(xPackagedList);

            if (xRoot == null)
            {
                //Console.WriteLine("[x] Вид диаграммы не AD");
                return(false);
            }

            var attr = xRoot.Attributes["xsi:type"];

            if (attr == null)
            {
                //Console.WriteLine("[x] Не удалось распарсить xmi файл");
                return(false);
            }
            if (!attr.Value.Equals("uml:Activity"))
            {
                //Console.WriteLine("[x] Вид диаграммы не AD");
                return(false);
            }

            // пройтись по всем тегам и создать объекты
            foreach (XmlNode node in xRoot.ChildNodes)
            {
                var elAttr = node.Attributes["xsi:type"];
                if (elAttr == null)
                {
                    continue;
                }

                if (elAttr.Value == "uml:OpaqueAction" || elAttr.Value == "uml:InitialNode" || elAttr.Value == "uml:ActivityFinalNode" ||
                    elAttr.Value == "uml:FlowFinalNode" || elAttr.Value == "uml:DecisionNode" || elAttr.Value == "uml:MergeNode" ||
                    elAttr.Value == "uml:ForkNode" || elAttr.Value == "uml:JoinNode")
                {
                    DiagramElement nodeFromXMI = null;
                    switch (elAttr.Value)
                    {
                    // активность
                    case "uml:OpaqueAction":
                        nodeFromXMI = new ActivityNode(node.Attributes["xmi:id"].Value,
                                                       AttrAdapter(node.Attributes["inPartition"]), AttrAdapter(node.Attributes["name"]));
                        nodeFromXMI.setType(ElementType.ACTIVITY);
                        adNodesList.addLast(nodeFromXMI);
                        break;

                    // узел инициализации
                    case "uml:InitialNode":
                        nodeFromXMI = new InitialNode(node.Attributes["xmi:id"].Value, AttrAdapter(node.Attributes["inPartition"]));
                        nodeFromXMI.setType(ElementType.INITIAL_NODE);
                        adNodesList.addLast(nodeFromXMI);
                        break;

                    // конечное состояние
                    case "uml:ActivityFinalNode":
                    case "uml:FlowFinalNode":
                        nodeFromXMI = new FinalNode(node.Attributes["xmi:id"].Value, AttrAdapter(node.Attributes["inPartition"]));
                        nodeFromXMI.setType(ElementType.FINAL_NODE);
                        adNodesList.addLast(nodeFromXMI);
                        break;

                    // условный переход
                    case "uml:DecisionNode":
                        nodeFromXMI = new DecisionNode(node.Attributes["xmi:id"].Value, AttrAdapter(node.Attributes["inPartition"]), AttrAdapter(node.Attributes["question"]));
                        nodeFromXMI.setType(ElementType.DECISION);
                        adNodesList.addLast(nodeFromXMI);
                        break;

                    // узел слияния
                    case "uml:MergeNode":
                        nodeFromXMI = new MergeNode(node.Attributes["xmi:id"].Value, AttrAdapter(node.Attributes["inPartition"]));
                        nodeFromXMI.setType(ElementType.MERGE);
                        adNodesList.addLast(nodeFromXMI);
                        break;

                    // разветвитель
                    case "uml:ForkNode":
                        nodeFromXMI = new ForkNode(node.Attributes["xmi:id"].Value, AttrAdapter(node.Attributes["inPartition"]));
                        nodeFromXMI.setType(ElementType.FORK);
                        adNodesList.addLast(nodeFromXMI);
                        hasJoinOrFork = true;
                        break;

                    // синхронизатор
                    case "uml:JoinNode":
                        nodeFromXMI = new JoinNode(node.Attributes["xmi:id"].Value, AttrAdapter(node.Attributes["inPartition"]));
                        nodeFromXMI.setType(ElementType.JOIN);
                        adNodesList.addLast(nodeFromXMI);
                        hasJoinOrFork = true;
                        break;
                    }
                    // добавляем ид входящих и выходящих переходов
                    if (nodeFromXMI != null)
                    {
                        string idsIn  = node.Attributes["incoming"]?.Value;
                        string idsOut = node.Attributes["outgoing"]?.Value;
                        nodeFromXMI.addIn(idsIn ?? "");
                        nodeFromXMI.addOut(idsOut ?? "");
                    }
                }
                // создаем переход
                else if (node.Attributes["xsi:type"].Value.Equals("uml:ControlFlow"))
                {
                    // находим подпись перехода
                    var    markNode = node.ChildNodes[1];
                    string mark     = markNode.Attributes["value"].Value.Trim();    // если подпись является "yes", значит это подпись по умолчанию

                    ControlFlow temp = new ControlFlow(node.Attributes["xmi:id"].Value, mark.Equals("true") ? "" : mark);
                    temp.setType(ElementType.FLOW);
                    temp.setSrc(AttrAdapter(node.Attributes["source"]));
                    temp.setTarget(AttrAdapter(node.Attributes["target"]));
                    adNodesList.addLast(temp);
                }
                // создаем дорожку
                else if (node.Attributes["xsi:type"].Value.Equals("uml:ActivityPartition"))
                {
                    Swimlane temp = new Swimlane(node.Attributes["xmi:id"].Value, AttrAdapter(node.Attributes["name"]))
                    {
                        ChildCount = node.Attributes["node"] == null ? 0 : node.Attributes["node"].Value.Split().Length
                    };
                    temp.setType(ElementType.SWIMLANE);
                    if (temp.Name != "")
                    {
                        diagram.Actors.Add(temp);
                    }
                    adNodesList.addLast(temp);
                }
                // неизвестный элемент
                else
                {
                    var unknownNode = new UnknownNode(node.Attributes["xmi:id"].Value);
                    unknownNode.setType(ElementType.UNKNOWN);
                    unknownNodes.Add(unknownNode);
                }
            }

            XmlNode coordRoot = null;

            try {
                coordRoot = xmlFile.GetElementsByTagName("plane")[0];
            } catch (NullReferenceException) {
                //Console.WriteLine("[x] Тег packagedElement не найден");
            }

            if (coordRoot != null)
            {
                FindCoordinates(coordRoot, diagram);
            }
            for (int i = 0; i < adNodesList.size(); i++)
            {
                var node = adNodesList.get(i);
                if (node is DiagramElement)
                {
                    var nodeFromXMI = (DiagramElement)node;
                    switch (nodeFromXMI.getType())
                    {
                    case ElementType.FINAL_NODE:
                        if (nodeFromXMI.inSize() == 0)
                        {
                            // ошибка
                            ADMistakeFactory.createMistake(MistakesSeriousness.mistakes[MISTAKES.NO_IN], MistakeAdapter.toString(MISTAKES.NO_IN), new ADNodesList.ADNode(nodeFromXMI), ALL_MISTAKES.NO_IN);
                        }
                        break;

                    case ElementType.INITIAL_NODE:
                        if (nodeFromXMI.outSize() == 0)
                        {
                            // ошибка
                            ADMistakeFactory.createMistake(MistakesSeriousness.mistakes[MISTAKES.NO_OUT], MistakeAdapter.toString(MISTAKES.NO_OUT), new ADNodesList.ADNode(nodeFromXMI), ALL_MISTAKES.NO_OUT);
                        }
                        break;

                    default:
                        if (nodeFromXMI.inSize() == 0 || nodeFromXMI.outSize() == 0)
                        {
                            // ошибка
                            if (nodeFromXMI.inSize() == 0)
                            {
                                ADMistakeFactory.createMistake(MistakesSeriousness.mistakes[MISTAKES.NO_IN], MistakeAdapter.toString(MISTAKES.NO_IN), new ADNodesList.ADNode(nodeFromXMI), ALL_MISTAKES.NO_IN);
                            }
                            if (nodeFromXMI.outSize() == 0)
                            {
                                ADMistakeFactory.createMistake(MistakesSeriousness.mistakes[MISTAKES.NO_OUT], MistakeAdapter.toString(MISTAKES.NO_OUT), new ADNodesList.ADNode(nodeFromXMI), ALL_MISTAKES.NO_OUT);
                            }
                        }
                        break;
                    }
                }
            }
            // ошибка - тип элемента не принадлежит AD
            foreach (var node in unknownNodes)
            {
                ADMistakeFactory.createMistake(MistakesSeriousness.mistakes[MISTAKES.FORBIDDEN_ELEMENT], MistakeAdapter.toString(MISTAKES.FORBIDDEN_ELEMENT), node, ALL_MISTAKES.FORBIDDEN_ELEMENT);
            }

            return(true);
        }
Пример #9
0
        private void ConvertPrefabsDataInScene(ref string[] scene, string oldRootPath, YamlStream yamlStream,
                                               List <ScriptMapping> scriptMappings)
        {
            // Copy prefabs
            List <YamlDocument> yamlPrefabs =
                yamlStream.Documents.Where(document => document.GetName() == "PrefabInstance").ToList();

            List <PrefabModel> oldPrefabs = prefabController.ExportPrefabs(oldRootPath);

            foreach (YamlDocument prefabInstance in yamlPrefabs)
            {
                //Get the prefab file we're working with
                string      prefabGuid  = (string)prefabInstance.RootNode["PrefabInstance"]["m_SourcePrefab"]["guid"];
                PrefabModel prefabModel = oldPrefabs.FirstOrDefault(prefabFile => prefabFile.Guid == prefabGuid);
                if (prefabModel == null || string.IsNullOrEmpty(prefabModel.Path))
                {
                    Debug.LogWarning(
                        "Found reference to prefab, but could not find the prefab. Might be a model file, not migrating. Prefab guid: " +
                        prefabGuid);
                    continue;
                }

                //Load in the prefab file
                YamlStream   prefabStream     = new YamlStream();
                string[]     lines            = File.ReadAllLines(prefabModel.Path).PrepareSceneForYaml();
                StringReader tempStringReader = new StringReader(string.Join("\r\n", lines));
                prefabStream.Load(tempStringReader);
                tempStringReader.Close();


                //Get the modifications that have been done
                YamlSequenceNode modifications =
                    (YamlSequenceNode)prefabInstance.RootNode["PrefabInstance"]["m_Modification"]["m_Modifications"];

                //change the modifications
                foreach (YamlNode modification in modifications)
                {
                    YamlNode target       = modification["target"];
                    string   fileID       = (string)target["fileID"];
                    string   propertyPath = (string)modification["propertyPath"];

                    YamlDocument scriptReference =
                        prefabStream.Documents.FirstOrDefault(document =>
                                                              document.RootNode.Anchor == fileID);
                    if (scriptReference == null)
                    {
//                        // handle nested prefab
//
//                        int FileID_of_nested_PrefabInstance = 0;
//                        int FileID_of_object_in_nested_Prefab = 0;
//                        var a = (FileID_of_nested_PrefabInstance ^ FileID_of_object_in_nested_Prefab) & 0x7fffffffffffffff;


                        Debug.LogError(
                            "Nested prefab detected! Can not migrate fields in the scene. If there are any field name changes these will not be migrated. Could not find reference to script in file! Currently nested prefabs are not supported.  fileID : " +
                            fileID);
                        continue;
                    }

                    if (scriptReference.GetName() != "MonoBehaviour")
                    {
                        continue;
                    }

                    YamlNode IDs = scriptReference.RootNode["MonoBehaviour"]["m_Script"];

                    string scriptGuid   = (string)IDs["guid"];
                    string scriptFileID = (string)IDs["fileID"];

                    ScriptMapping scriptMappingType =
                        scriptMappings.FirstOrDefault(node =>
                                                      node.oldClassModel.Guid == scriptGuid && node.oldClassModel.FileID == scriptFileID);
                    if (scriptMappingType == null)
                    {
//                        Debug.Log("Could not find mapping for guid: " + scriptGuid + " fileID: " + scriptFileID);
                        continue;
                    }

                    string[]         properties        = propertyPath.Split('.');
                    List <MergeNode> currentMergeNodes = scriptMappingType.MergeNodes;

                    for (var i = 0; i < properties.Length; i++)
                    {
                        string property = properties[i];
                        if (property == "Array" && properties.Length > i + 1 && properties[i + 1].StartsWith("data["))
                        {
                            // this is a list or array and can be skipped;
                            i++;
                            continue;
                        }


                        MergeNode currentMergeNode =
                            currentMergeNodes.FirstOrDefault(node => node.OriginalValue == property);
                        if (currentMergeNode == null)
                        {
                            Debug.Log("Could not find mergeNode for property: " + property);
                            continue;
                        }

                        properties[i] = currentMergeNode.NameToExportTo;

                        currentMergeNodes =
                            scriptMappings
                            .FirstOrDefault(script => script.oldClassModel.FullName == currentMergeNode.Type)
                            ?.MergeNodes;
                    }

                    int line = modification["propertyPath"].Start.Line - 1;
                    scene[line] = scene[line].ReplaceFirst(propertyPath, string.Join(".", properties));
                }
            }
        }
        public override void Build(City c)
        {
            MergePoint m1  = new MergePoint();
            CityNode   nw1 = wTop = new MergeNode(x - 40, y - 80, m1, "nw1");
            CityNode   ne1 = eTop = new CityNode(x + 40, y - 80, "ne1");
            CityPath   p1  = ne1.Connect(nw1, CityPathType.privates);

            m1.priority = p1;

            MergePoint m2  = new MergePoint();
            CityNode   nw2 = wLeft = new MergeNode(x - 80, y + 40, m2, "nw2");
            CityNode   ne2 = eLeft = new CityNode(x - 80, y - 40, "ne2");
            CityPath   p2  = ne2.Connect(nw2, CityPathType.privates);

            m2.priority = p2;

            MergePoint m3  = new MergePoint();
            CityNode   nw3 = wBottom = new MergeNode(x + 40, y + 80, m3, "nw3");
            CityNode   ne3 = eBottom = new CityNode(x - 40, y + 80, "ne3");
            CityPath   p3  = ne3.Connect(nw3, CityPathType.privates);

            m3.priority = p3;

            MergePoint m4  = new MergePoint();
            CityNode   nw4 = wRight = new MergeNode(x + 80, y - 40, m4, "nw4");
            CityNode   ne4 = eRight = new CityNode(x + 80, y + 40, "ne4");
            CityPath   p4  = ne4.Connect(nw4, CityPathType.privates);

            m4.priority = p4;

            nw1.Connect(ne2, CityPathType.privates, 40);
            nw2.Connect(ne3, CityPathType.privates, 40);
            nw3.Connect(ne4, CityPathType.privates, 40);
            nw4.Connect(ne1, CityPathType.privates, 40);

            pTopLeft     = new CityNode(x - 100, y - 100);
            pTopRight    = new CityNode(x + 100, y - 100);
            pBottomLeft  = new CityNode(x - 100, y + 100);
            pBottomRight = new CityNode(x + 100, y + 100);

            pTopLeft.Connect(pTopRight, CityPathType.pedestrians);
            pTopLeft.Connect(pBottomLeft, CityPathType.pedestrians);

            pTopRight.Connect(pTopLeft, CityPathType.pedestrians);
            pTopRight.Connect(pBottomRight, CityPathType.pedestrians);

            pBottomLeft.Connect(pBottomRight, CityPathType.pedestrians);
            pBottomLeft.Connect(pTopLeft, CityPathType.pedestrians);

            pBottomRight.Connect(pBottomLeft, CityPathType.pedestrians);
            pBottomRight.Connect(pTopRight, CityPathType.pedestrians);

            c.nodes.Add(pTopLeft);
            c.nodes.Add(pTopRight);
            c.nodes.Add(pBottomLeft);
            c.nodes.Add(pBottomRight);

            c.nodes.Add(nw1);
            c.nodes.Add(ne1);

            c.nodes.Add(nw2);
            c.nodes.Add(ne2);

            c.nodes.Add(nw3);
            c.nodes.Add(ne3);

            c.nodes.Add(nw4);
            c.nodes.Add(ne4);
        }
Пример #11
0
        protected override bool DrawWizardGUI()
        {
            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, GUIStyle.none, GUI.skin.verticalScrollbar);
            EditorGUILayout.BeginVertical(paddingStyle);

            EditorGUILayout.LabelField(
                "The following class fields differ between the original and current project. Proposals for substitute fields are shown. Please select the correct field manually.",
                richtextStyle);
            GUILayout.Box(GUIContent.none, horizontalLineStyle);

            for (int i = 0; i < foundScripts.Count; i++)
            {
                ClassModel         classModel    = foundScripts[i].newClassModel;
                FoundScriptWrapper wrapper       = foundScriptWrappers[i];
                List <MergeNode>   fieldsToMerge = foundScripts[i].MergeNodes;

                EditorGUILayout.LabelField(classModel.FullName, classNameStyle);
                GUILayout.Box(GUIContent.none, verticalMarginStyle);

                GUILayout.BeginHorizontal();

                EditorGUILayout.LabelField("<b>Use</b>", richtextStyle, GetColumnWidth(1));
                EditorGUILayout.LabelField("<b>Fields</b>", richtextStyle, GetColumnWidth(5));
                EditorGUILayout.LabelField("<b>Type</b>", richtextStyle, GetColumnWidth(6));

                GUILayout.EndHorizontal();

                GUILayout.Box(GUIContent.none, verticalMarginStyle);


                for (int j = 0; j < fieldsToMerge.Count; j++)
                {
                    MergeNode fieldToMerge = fieldsToMerge[j];

                    string originalName = fieldToMerge.OriginalValue;

                    GUILayout.BeginHorizontal();

                    wrapper.FieldSelectionStates[j] =
                        EditorGUILayout.Toggle(wrapper.FieldSelectionStates[j], GetColumnWidth(1));
                    GUI.enabled = wrapper.FieldSelectionStates[j];
                    EditorGUILayout.LabelField(originalName, richtextStyle, GetColumnWidth(5));
                    EditorGUILayout.LabelField(fieldToMerge.Type + (fieldToMerge.IsIterable ? "[]" : ""), richtextStyle,
                                               GetColumnWidth(6));

                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();

                    EditorGUILayout.LabelField("", GetColumnWidth(1));

                    EditorGUILayout.BeginVertical();

                    wrapper.OptionSelections[j] = EditorGUILayout.Popup(wrapper.OptionSelections[j],
                                                                        fieldToMerge.Options, GetColumnWidth(5));

                    int optionsIndex = wrapper.OptionSelections[j];
                    if (fieldToMerge.Options != null && optionsIndex < fieldToMerge.Options.Length)
                    {
                        fieldToMerge.NameToExportTo = fieldToMerge.Options[optionsIndex];
                    }
                    else
                    {
                        wrapper.FieldSelectionStates[j] = false;
                    }

                    EditorGUILayout.EndVertical();

                    GUI.enabled = true;

                    GUILayout.EndHorizontal();

                    GUILayout.Box(GUIContent.none, verticalMarginStyle);

                    foundScripts[i].MergeNodes[j] = fieldToMerge;
                }

                foundScriptWrappers[i] = wrapper;

                GUILayout.Box(GUIContent.none, horizontalLineStyle);
            }

            EditorGUILayout.EndVertical();
            EditorGUILayout.EndScrollView();

            return(base.DrawWizardGUI());
        }
Пример #12
0
        public override void Build(City c)
        {
            if (this.n1 is BuilderAllWayStopNode)
            {
                BuilderAllWayStopNode n1 = this.n1 as BuilderAllWayStopNode;
                n1.Connect(this, out s1, out e1, out p11, out p12);
            }
            if (this.n1 is BuilderTrafficCircleNode)
            {
                BuilderTrafficCircleNode n1 = this.n1 as BuilderTrafficCircleNode;
                n1.Connect(this, out s1, out e1, out p11, out p12);
            }
            if (this.n1 is BuilderDeadEndNode)
            {
                BuilderDeadEndNode n1 = this.n1 as BuilderDeadEndNode;
                n1.Connect(this, out s1, out e1, out p11, out p12);
            }


            if (this.n2 is BuilderAllWayStopNode)
            {
                BuilderAllWayStopNode n2 = this.n2 as BuilderAllWayStopNode;
                n2.Connect(this, out s2, out e2, out p21, out p22);
            }
            if (this.n2 is BuilderTrafficCircleNode)
            {
                BuilderTrafficCircleNode n2 = this.n2 as BuilderTrafficCircleNode;
                n2.Connect(this, out s2, out e2, out p21, out p22);
            }
            if (this.n2 is BuilderDeadEndNode)
            {
                BuilderDeadEndNode n2 = this.n2 as BuilderDeadEndNode;
                n2.Connect(this, out s2, out e2, out p21, out p22);
            }

            double dist      = Util.Distance(s1.x, s1.y, e2.x, e2.y);
            int    parkCount = (int)(dist / PARKING_LENGTH);
            double dir       = Util.GetLookatDir(s1.x, s1.y, e2.x, e2.y);

            CityNode last     = s1;
            CityNode lastPark = p11;

            for (int i = 1; i <= parkCount; i++)
            {
                int       x    = s1.x + (int)(i * PARKING_LENGTH * Math.Cos(dir));
                int       y    = s1.y + (int)(i * PARKING_LENGTH * Math.Sin(dir));
                MergeNode exit = new MergeNode(x, y, new MergePoint());

                x -= (int)(PARKING_LENGTH / 2 * Math.Cos(dir));
                x += (int)(20 * Math.Cos(dir + Math.PI / 2));
                y -= (int)(PARKING_LENGTH / 2 * Math.Sin(dir));
                y += (int)(20 * Math.Sin(dir + Math.PI / 2));
                ParkingNode park = new ParkingNode(x, y);

                CityPath priority = last.Connect(exit, CityPathType.privates);
                last.Connect(park, CityPathType.privates);
                park.Connect(exit, CityPathType.privates);

                lastPark.Connect(park, CityPathType.pedestrians);
                park.Connect(lastPark, CityPathType.pedestrians);

                c.nodes.Add(exit);
                c.nodes.Add(park);

                (exit.intersection as MergePoint).priority = priority;

                last     = exit;
                lastPark = park;
            }
            last.Connect(e2, CityPathType.privates);
            lastPark.Connect(p22, CityPathType.pedestrians);
            p22.Connect(lastPark, CityPathType.pedestrians);


            dist      = Util.Distance(s2.x, s2.y, e1.x, e1.y);
            parkCount = (int)(dist / PARKING_LENGTH);
            dir       = Util.GetLookatDir(s2.x, s2.y, e1.x, e1.y);

            last     = s2;
            lastPark = p21;
            for (int i = 1; i <= parkCount; i++)
            {
                int      x    = s2.x + (int)(i * PARKING_LENGTH * Math.Cos(dir));
                int      y    = s2.y + (int)(i * PARKING_LENGTH * Math.Sin(dir));
                CityNode exit = new CityNode(x, y);

                x -= (int)(PARKING_LENGTH / 2 * Math.Cos(dir));
                x += (int)(20 * Math.Cos(dir + Math.PI / 2));
                y -= (int)(PARKING_LENGTH / 2 * Math.Sin(dir));
                y += (int)(20 * Math.Sin(dir + Math.PI / 2));
                ParkingNode park = new ParkingNode(x, y);

                last.Connect(exit, CityPathType.privates);
                last.Connect(park, CityPathType.privates);
                park.Connect(exit, CityPathType.privates);

                lastPark.Connect(park, CityPathType.pedestrians);
                park.Connect(lastPark, CityPathType.pedestrians);

                c.nodes.Add(exit);
                c.nodes.Add(park);

                last     = exit;
                lastPark = park;
            }
            last.Connect(e1, CityPathType.privates);
            lastPark.Connect(p12, CityPathType.pedestrians);
            p12.Connect(lastPark, CityPathType.pedestrians);
        }