public override void DoModalWindow(int windowID) { base.DoModalWindow(windowID); //makes GUI window scrollable scrollPosition = GUILayout.BeginScrollView(scrollPosition); selected = GUILayout.SelectionGrid(selected, listItems, 1, buttonStyle, GUILayout.ExpandWidth(true)); GUILayout.EndScrollView(); if (selected != -1) { render = false; VoxemeInspectorModalWindow newInspector = GameObject.Find("VoxWorld").AddComponent <VoxemeInspectorModalWindow>(); newInspector.InspectorPosition = new Vector2(25, 25); newInspector.windowRect = new Rect(newInspector.InspectorPosition.x, newInspector.InspectorPosition.y, newInspector.inspectorWidth, newInspector.inspectorHeight); newInspector.InspectorVoxeme = "programs/" + listItems[selected]; newInspector.Render = true; selected = -1; } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { if (Helper.PointOutsideMaskedAreas( new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y), windowManager.windowManager.Values.Select(v => v.windowRect).ToArray())) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; // Casts the ray and get the first game object hit Physics.Raycast(ray, out hit); if (hit.collider == null) { //if (!Helper.PointInRect (new Vector2 (Input.mousePosition.x, Screen.height - Input.mousePosition.y), inspector.InspectorRect)) { //inspector.InspectorObject = null; selectedObjects.Clear(); //} // if (!Helper.PointInRect (new Vector2 (Input.mousePosition.x, Screen.height - Input.mousePosition.y), inspector.InspectorRect)) { // inspector.DrawInspector = false; // } } else { selectedObjects.Clear(); //selectedObjects.Add (hit.transform.root.gameObject); //inspector.InspectorObject = hit.transform.root.gameObject; //Debug.Log (selectedObjects.Count); } // if (!Helper.PointInRect (new Vector2 (Input.mousePosition.x, Screen.height - Input.mousePosition.y), inspector.InspectorRect)) { // inspector.DrawInspector = false; // } } } else if (Input.GetMouseButtonDown(1)) { if (Helper.PointOutsideMaskedAreas( new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y), windowManager.windowManager.Values.Select(v => v.windowRect).ToArray())) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; // Casts the ray and get the first game object hit Physics.Raycast(ray, out hit); // if (hit.collider == null) { // if (!Helper.PointInRect (new Vector2 (Input.mousePosition.x, Screen.height - Input.mousePosition.y), inspector.InspectorRect)) { // inspector.DrawInspector = false; // } // } // else { // inspector.DrawInspector = true; // inspector.ScrollPosition = new Vector2 (0, 0); // inspector.InspectorChoice = -1; // inspector.InspectorObject = Helper.GetMostImmediateParentVoxeme (hit.transform.gameObject); // //inspector.InspectorObject = hit.transform.root.gameObject; // inspector.InspectorPosition = new Vector2 (Input.mousePosition.x, Screen.height - Input.mousePosition.y); // } if (hit.collider != null) { string objName = hit.collider.gameObject.transform.root.gameObject.name; if (File.Exists(string.Format("{0}/{1}", Data.voxmlDataPath, string.Format("objects/{0}.xml", objName)))) { using (StreamReader sr = new StreamReader( string.Format("{0}/{1}", Data.voxmlDataPath, string.Format("objects/{0}.xml", objName)))) { String ml = sr.ReadToEnd(); if (ml != null) { // float textSize = GUI.skin.label.CalcSize (new GUIContent (objName)).x; // float padSize = GUI.skin.label.CalcSize (new GUIContent (" ")).x; // int padLength = (int)(((inspectorWidth - 85) - textSize) / (int)padSize); // if (GUILayout.Button (objName.PadRight (padLength + objName.Length - 3), GUILayout.Width (inspectorWidth - 85))) { // if (ml != null) { if (windowManager.windowManager.Values.Where(v => v.GetType() == typeof(VoxemeInspectorModalWindow) && ((VoxemeInspectorModalWindow)v).InspectorObject == hit.collider.gameObject.transform.root.gameObject).ToList().Count == 0) { VoxemeInspectorModalWindow newInspector = gameObject.AddComponent <VoxemeInspectorModalWindow>(); //LoadMarkup (ml.text); //newInspector.DrawInspector = true; newInspector.InspectorPosition = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y); newInspector.windowRect = new Rect(newInspector.InspectorPosition.x, newInspector.InspectorPosition.y, newInspector.inspectorWidth, newInspector.inspectorHeight); newInspector.InspectorVoxeme = "objects/" + objName; newInspector.InspectorObject = hit.collider.gameObject.transform.root.gameObject; newInspector.Render = true; } // } // else { // } } } } else { if (editableVoxemes) { VoxemeInspectorModalWindow newInspector = gameObject.AddComponent <VoxemeInspectorModalWindow>(); newInspector.InspectorPosition = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y); newInspector.windowRect = new Rect(newInspector.InspectorPosition.x, newInspector.InspectorPosition.y, newInspector.inspectorWidth, newInspector.inspectorHeight); newInspector.InspectorVoxeme = "objects/" + objName; newInspector.InspectorObject = hit.collider.gameObject.transform.root.gameObject; newInspector.Render = true; } } } } } }
void DisplayObjectMarkup() { scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, false); inspectorStyle = GUI.skin.box; inspectorStyle.alignment = TextAnchor.MiddleLeft; inspectorStyle.stretchWidth = true; inspectorStyle.wordWrap = true; GUILayout.BeginVertical(inspectorStyle); GUILayout.Label("LEX"); GUILayout.BeginHorizontal(inspectorStyle); GUILayout.Label("Pred"); GUILayout.Box(mlPred, GUILayout.Width(inspectorWidth - 100)); GUILayout.EndHorizontal(); GUILayout.BeginVertical(inspectorStyle); GUILayout.BeginHorizontal(); GUILayout.Label("Type"); GUILayout.BeginVertical(); for (int i = 0; i < mlTypeCount; i++) { GUILayout.BeginHorizontal(); GUILayout.Box(mlTypes[i], GUILayout.Width(inspectorWidth - 130), GUILayout.ExpandWidth(true)); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.EndVertical(); GUILayout.BeginVertical(inspectorStyle); GUILayout.Label("TYPE"); GUILayout.BeginHorizontal(inspectorStyle); GUILayout.Label("Head"); GUILayout.Box(mlHead, GUILayout.Width(inspectorWidth - 130), GUILayout.ExpandWidth(true)); GUILayout.EndHorizontal(); GUILayout.BeginVertical(inspectorStyle); GUILayout.BeginHorizontal(); GUILayout.Label("Components"); GUILayout.EndHorizontal(); GUILayout.BeginVertical(inspectorStyle); for (int i = 0; i < mlComponentCount; i++) { string componentName = mlComponents[i].Split(new char[] { '[' })[0]; //TextAsset ml = Resources.Load (componentName) as TextAsset; if (File.Exists(string.Format("{0}/{1}", Data.voxmlDataPath, string.Format("objects/{0}.xml", componentName)))) { using (StreamReader sr = new StreamReader( string.Format("{0}/{1}", Data.voxmlDataPath, string.Format("objects/{0}.xml", componentName)))) { String ml = sr.ReadToEnd(); if (ml != null) { float textSize = GUI.skin.label.CalcSize(new GUIContent(mlComponents[i])).x; float padSize = GUI.skin.label.CalcSize(new GUIContent(" ")).x; int padLength = (int)(((inspectorWidth - 85) - textSize) / (int)padSize); if (GUILayout.Button(mlComponents[i].PadRight(padLength + mlComponents[i].Length - 3), GUILayout.Width(inspectorWidth - 85))) { if (ml != null) { VoxemeInspectorModalWindow newInspector = gameObject.AddComponent <VoxemeInspectorModalWindow>(); //LoadMarkup (ml.text); //newInspector.DrawInspector = true; newInspector.windowRect = new Rect(inspectorRect.x + 25, inspectorRect.y + 25, inspectorWidth, inspectorHeight); //newInspector.InspectorTitle = mlComponents [i]; newInspector.InspectorVoxeme = "objects/" + componentName; newInspector.Render = true; } else { } } } } } else { GUILayout.Box(mlComponents[i], GUILayout.Width(inspectorWidth - 85)); } } GUILayout.EndVertical(); GUILayout.EndVertical(); GUILayout.BeginHorizontal(inspectorStyle); GUILayout.Label("Concavity"); GUILayout.Box(mlConcavity, GUILayout.Width(inspectorWidth - 130), GUILayout.ExpandWidth(true)); GUILayout.EndHorizontal(); GUILayout.BeginVertical(inspectorStyle); GUILayout.Label("Rotational Symmetry"); GUILayout.BeginHorizontal(); GUILayout.Toggle(mlRotatSymX, "X"); GUILayout.Toggle(mlRotatSymY, "Y"); GUILayout.Toggle(mlRotatSymZ, "Z"); GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.BeginVertical(inspectorStyle); GUILayout.Label("Reflectional Symmetry"); GUILayout.BeginHorizontal(); GUILayout.Toggle(mlReflSymXY, "XY"); GUILayout.Toggle(mlReflSymXZ, "XZ"); GUILayout.Toggle(mlReflSymYZ, "YZ"); GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.EndVertical(); GUILayout.BeginVertical(inspectorStyle); GUILayout.Label("HABITAT"); GUILayout.BeginVertical(inspectorStyle); GUILayout.BeginHorizontal(); GUILayout.Label("Intrinsic"); GUILayout.EndHorizontal(); for (int i = 0; i < mlIntrHabitatCount; i++) { GUILayout.BeginHorizontal(); GUILayout.Box(mlIntrHabitats[i].Split(new char[] { '=' }, 2)[0], GUILayout.Width(inspectorWidth - 150)); GUILayout.Box(mlIntrHabitats[i].Split(new char[] { '=' }, 2)[1], GUILayout.Width(inspectorWidth - 140)); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUILayout.BeginVertical(inspectorStyle); GUILayout.BeginHorizontal(); GUILayout.Label("Extrinsic"); GUILayout.EndHorizontal(); for (int i = 0; i < mlExtrHabitatCount; i++) { GUILayout.BeginHorizontal(); GUILayout.Box(mlExtrHabitats[i].Split(new char[] { '=' }, 2)[0], GUILayout.Width(inspectorWidth - 150)); GUILayout.Box(mlExtrHabitats[i].Split(new char[] { '=' }, 2)[1], GUILayout.Width(inspectorWidth - 140)); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUILayout.EndVertical(); GUILayout.BeginVertical(inspectorStyle); GUILayout.Label("AFFORD_STR"); GUILayout.BeginVertical(inspectorStyle); for (int i = 0; i < mlAffordanceCount; i++) { GUILayout.BeginHorizontal(); GUILayout.Box(mlAffordances[i], GUILayout.Width(inspectorWidth - 85)); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUILayout.EndVertical(); GUILayout.BeginVertical(inspectorStyle); GUILayout.Label("EMBODIMENT"); GUILayout.BeginHorizontal(inspectorStyle); GUILayout.Label("Scale"); GUILayout.Box(mlScale, GUILayout.Width(inspectorWidth - 130), GUILayout.ExpandWidth(true)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(inspectorStyle); GUILayout.Label("Movable"); GUILayout.Toggle(mlMovable, ""); GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.BeginVertical(inspectorStyle); GUILayout.Label("PARTICIPATION"); GUILayout.BeginVertical(inspectorStyle); object[] programs = Directory.GetFiles(string.Format("{0}/programs", Data.voxmlDataPath)); //object[] assets = Resources.LoadAll ("Programs"); foreach (object program in programs) { if (program != null) { List <string> participations = new List <string>(); foreach (string affordance in mlAffordances) { if (affordance.Contains(((string)program).Substring(((string)program).LastIndexOf('/') + 1) .Split('.')[0])) { if (!participations.Contains(((string)program) .Substring(((string)program).LastIndexOf('/') + 1).Split('.')[0])) { participations.Add(((string)program).Substring(((string)program).LastIndexOf('/') + 1) .Split('.')[0]); } } } foreach (string p in participations) { using (StreamReader sr = new StreamReader( string.Format("{0}/{1}", Data.voxmlDataPath, string.Format("programs/{0}.xml", p)))) { //TextAsset ml = Resources.Load ("Programs/" + p) as TextAsset; String ml = sr.ReadToEnd(); if (ml != null) { float textSize = GUI.skin.label.CalcSize(new GUIContent(p)).x; float padSize = GUI.skin.label.CalcSize(new GUIContent(" ")).x; int padLength = (int)(((inspectorWidth - 85) - textSize) / (int)padSize); if (GUILayout.Button(p.PadRight(padLength + p.Length - 3), GUILayout.Width(inspectorWidth - 85))) { if (ml != null) { VoxemeInspectorModalWindow newInspector = gameObject.AddComponent <VoxemeInspectorModalWindow>(); //LoadMarkup (ml.text); //newInspector.DrawInspector = true; newInspector.windowRect = new Rect(inspectorRect.x + 25, inspectorRect.y + 25, inspectorWidth, inspectorHeight); //newInspector.InspectorTitle = mlComponents [i]; newInspector.InspectorVoxeme = "programs/" + p; newInspector.Render = true; } else { } } } else { GUILayout.Box((string)program, GUILayout.Width(inspectorWidth - 85)); } } } } } GUILayout.EndVertical(); GUILayout.EndVertical(); GUILayout.BeginVertical(inspectorStyle); GUILayout.Label("ATTRIBUTES"); GUILayout.BeginVertical(inspectorStyle); AttributeSet attrSet = inspectorObject.GetComponent <AttributeSet>(); if (attrSet != null) { foreach (string s in attrSet.attributes) { GUILayout.Box(s, GUILayout.Width(inspectorWidth - 85)); } } GUILayout.EndVertical(); GUILayout.EndVertical(); GUILayout.EndScrollView(); }