// GUI events to implement FMUToolWindow void OnGUI() { if (GUILayout.Button("Select FMU")) { string delimiterString = "/"; fullpath = EditorUtility.OpenFilePanel("Select a FMU to be visualized.", "", "fmu"); string[] pathLst = fullpath.Split(new string[] { delimiterString }, StringSplitOptions.None); for (int i = 0; i < (pathLst.Length - 1); i++) { pathName = pathName + pathLst[i] + delimiterString; } fileName = pathLst[pathLst.Length - 1]; Debug.Log("Selected fileName " + fileName); Debug.Log("Selected pathName " + pathName); } if (fullpath != null) { GUILayout.Label("Selected File: " + fullpath); } else { GUILayout.Label("No File selected."); } if (GUILayout.Button("Generate GameObjects.")) { //create the simulation master Debug.Log("CREATE FMU_SIMULATOR"); simulatorGO = GameObject.Find("FMU_Simulator"); if (simulatorGO != null) //it exists { DestroyImmediate(simulatorGO); } simulatorGO = new GameObject("FMU_Simulator"); FMU_Simulation fmusim = simulatorGO.AddComponent <FMU_Simulation>(); fmusim.fmuPath = fullpath; fmusim.fmuDir = pathName; fmusim.goIDs = new List <string>(); fmusim.attrIDs = new List <int>(); fmusim.varNames = new List <string>(); //read XML readXML(); //init all shapes initShapes(); } /* * if (GUILayout.Button("Generate Interfaces")) * { * GameObject simulatorGO = GameObject.Find("FMU_Simulator"); * FMU_Simulation fmusim = simulatorGO.GetComponent<FMU_Simulation>(); * fmusim.GetInitialVariables(); * } */ }
void analyseShapeAttribute(GameObject shapeGO, XmlNode nodeIn, string shapeName, int attr) { // the vraiables attributes have to be put in the simulator FMU_Simulation fmuSim = simulatorGO.GetComponent <FMU_Simulation>(); // the constant attributes have to go in the gameObject directly FMUshapeBehaviour fmuShape = shapeGO.GetComponent <FMUshapeBehaviour>(); if (nodeIn.Name == "exp") { float val = Single.Parse(nodeIn.InnerText); //Debug.Log("constant exp "+attr.ToString()+" VAL: "+val.ToString()); fmuShape.setVarAttribute(attr, val); } else if (nodeIn.Name == "cref") { fmuSim.goIDs.Add(shapeName); fmuSim.attrIDs.Add(attr); fmuSim.varNames.Add(nodeIn.InnerText); //FMU_Simulation.varAttr v = new FMU_Simulation.varAttr(shapeName,attr, nodeIn.InnerText, -1); //Debug.Log("THE VARATTR " + v1.debugString()); } }