void VoxMLUpdated(object sender, EventArgs e) { GameObject voxeme = ((VoxMLEventArgs)e).Voxeme; VoxML voxml = ((VoxMLEventArgs)e).VoxML; if (voxeme != null) { if (voxeme.GetComponent <AttributeSet>() != null) { Debug.Log(voxeme.GetComponent <AttributeSet>().attributes.Count); foreach (string attr in voxeme.GetComponent <AttributeSet>().attributes) { Material newMat = Resources.Load(string.Format("DemoTextures/{0}", attr)) as Material; if (newMat != null) { Debug.Log(newMat); foreach (Renderer renderer in voxeme.GetComponentsInChildren <Renderer>()) { Shader shader = renderer.material.shader; renderer.material = newMat; renderer.material.shader = shader; } } } } } }
bool ObjectLoaded(string text) { bool r = false; try { r = ((VoxML.LoadFromText(text)).Lex.Pred == loadedObject.Lex.Pred); } catch (FileNotFoundException ex) { } return(r); }
bool ObjectLoaded(GameObject obj) { bool r = false; try { r = ((VoxML.Load(obj.name + ".xml")).Lex.Pred == loadedObject.Lex.Pred); } catch (FileNotFoundException ex) { } return(r); }
VoxML LoadMarkup(string text) { VoxML voxml = new VoxML(); try { voxml = VoxML.LoadFromText(text); AssignVoxMLValues(voxml); } catch (FileNotFoundException ex) { } return(voxml); }
VoxML LoadMarkup(VoxML v) { VoxML voxml = new VoxML(); try { voxml = v; AssignVoxMLValues(voxml); } catch (FileNotFoundException ex) { } return(voxml); }
VoxML LoadMarkup(GameObject obj) { VoxML voxml = new VoxML(); try { voxml = VoxML.Load(obj.name + ".xml"); AssignVoxMLValues(voxml); } catch (FileNotFoundException ex) { } return(voxml); }
public void AddNewRelation(List <GameObject> objs, string relation, bool recurse = true) { VoxML voxml = null; try { using (StreamReader sr = new StreamReader( string.Format("{0}/{1}", Data.voxmlDataPath, string.Format("relations/{0}.xml", relation)))) { voxml = VoxML.LoadFromText(sr.ReadToEnd()); } } catch (Exception e) { Debug.Log(e.Message); } foreach (List <GameObject> key in relations.Keys) { if (key.SequenceEqual(objs)) { if (!relations[key].ToString().Contains(relation)) { Debug.Log(string.Format("Adding {0} {1} {2}", relation, objs[0], objs[1])); relations[key] += string.Format(",{0}", relation); if (recurse) { if ((voxml != null) && (voxml.Type.Corresps.Where(c => c.Value == "reflexive").ToList().Count > 0)) { AddNewRelation(Enumerable.Reverse(objs).ToList(), relation, false); } } } UpdateRelationStrings(); return; } } foreach (List <GameObject> key in relations.Keys) { if (key.SequenceEqual(objs.Reverse <GameObject>().ToList())) { if (relations[key].ToString().Contains(relation)) { return; } } } try { Debug.Log(string.Format("Adding {0} {1} {2}", relation, objs[0], objs[1])); } catch (Exception e) { } relations.Add(objs, relation); // add key-val pair or modify value if key already exists if (recurse) { if ((voxml != null) && (voxml.Type.Corresps.Where(c => c.Value == "reflexive").ToList().Count > 0)) { AddNewRelation(Enumerable.Reverse(objs).ToList(), relation, false); } } UpdateRelationStrings(); }
public void RemoveRelation(List <GameObject> objs, string relation, bool recurse = true) { VoxML voxml = null; try { using (StreamReader sr = new StreamReader( string.Format("{0}/{1}", Data.voxmlDataPath, string.Format("relations/{0}.xml", relation)))) { voxml = VoxML.LoadFromText(sr.ReadToEnd()); } } catch (Exception e) { // TODO: fix //Debug.Log (e.Message); } foreach (List <GameObject> key in relations.Keys) { if (key.SequenceEqual(objs)) { if (relations[key].ToString().Contains(relation)) { Debug.Log(string.Format("Removing {0} {1} {2}", relation, objs[0], objs[1])); if (relations[key].ToString().Contains(",")) { Debug.Log(relations[key]); relations[key] = Regex.Replace(relations[key].ToString(), string.Format("{0},?", relation), ""); if (relations[key].ToString().EndsWith(",")) { relations[key] = relations[key].ToString().Trim(new char[] { ',' }); } Debug.Log(relations[key]); if (recurse) { if ((voxml != null) && (voxml.Type.Corresps.Where(c => c.Value == "reflexive").ToList().Count > 0)) { RemoveRelation(Enumerable.Reverse(objs).ToList(), relation, false); } } UpdateRelationStrings(); return; } else { relations.Remove(key); if (recurse) { if ((voxml != null) && (voxml.Type.Corresps.Where(c => c.Value == "reflexive").ToList().Count > 0)) { RemoveRelation(Enumerable.Reverse(objs).ToList(), relation, false); } } UpdateRelationStrings(); return; } } } } }
void AssignVoxMLValues(VoxML voxml) { // assign VoxML values // ENTITY mlEntityType = voxml.Entity.Type; // PRED mlPred = voxml.Lex.Pred; mlTypes = new List <string>(voxml.Lex.Type.Split(new char[] { '*' })); mlTypeCount = mlTypes.Count; mlTypeSelectVisible = new List <int>(new int[] { -1 }); mlTypeSelected = new List <int>(new int[] { -1 }); mlRemoveType = new List <int>(new int[] { -1 }); for (int i = 0; i < mlTypeCount; i++) { mlTypeSelectVisible.Add(-1); mlTypeSelected.Add(-1); mlRemoveType.Add(-1); } // TYPE mlHead = voxml.Type.Head; mlComponents = new List <string>(); foreach (VoxTypeComponent c in voxml.Type.Components) { mlComponents.Add(c.Value); } mlComponentCount = mlComponents.Count; mlConcavity = voxml.Type.Concavity; List <string> rotatSyms = new List <string>(voxml.Type.RotatSym.Split(new char[] { ',' })); mlRotatSymX = (rotatSyms.Contains("X")); mlRotatSymY = (rotatSyms.Contains("Y")); mlRotatSymZ = (rotatSyms.Contains("Z")); List <string> reflSyms = new List <string>(voxml.Type.ReflSym.Split(new char[] { ',' })); mlReflSymXY = (reflSyms.Contains("XY")); mlReflSymXZ = (reflSyms.Contains("XZ")); mlReflSymYZ = (reflSyms.Contains("YZ")); mlArgs = new List <string>(); foreach (VoxTypeArg a in voxml.Type.Args) { mlArgs.Add(a.Value); } mlArgCount = mlArgs.Count; mlSubevents = new List <string>(); foreach (VoxTypeSubevent e in voxml.Type.Body) { mlSubevents.Add(e.Value); } mlSubeventCount = mlSubevents.Count; // HABITAT mlIntrHabitats = new List <string>(); foreach (VoxHabitatIntr i in voxml.Habitat.Intrinsic) { mlIntrHabitats.Add(i.Name + "=" + i.Value); } mlIntrHabitatCount = mlIntrHabitats.Count; mlExtrHabitats = new List <string>(); foreach (VoxHabitatExtr e in voxml.Habitat.Extrinsic) { mlExtrHabitats.Add(e.Name + "=" + e.Value); } mlExtrHabitatCount = mlExtrHabitats.Count; // AFFORD_STR mlAffordances = new List <string>(); foreach (VoxAffordAffordance a in voxml.Afford_Str.Affordances) { mlAffordances.Add(a.Formula); } mlAffordanceCount = mlAffordances.Count; // EMBODIMENT mlScale = voxml.Embodiment.Scale; mlMovable = voxml.Embodiment.Movable; }
public void OnGUI() { if (DrawInspector) { inspectorPositionAdjX = inspectorPosition.x; inspectorPositionAdjY = inspectorPosition.y; if (inspectorPosition.x + inspectorWidth > Screen.width) { if (inspectorPosition.y > Screen.height - inspectorMargin) { inspectorPositionAdjX = inspectorPosition.x - inspectorWidth; inspectorPositionAdjY = inspectorPosition.y - inspectorHeight; inspectorRect = new Rect(inspectorPosition.x - inspectorWidth, inspectorPosition.y - inspectorHeight, inspectorWidth, inspectorHeight); } else if (inspectorPosition.y + inspectorHeight > Screen.height) { inspectorPositionAdjX = inspectorPosition.x - inspectorWidth; inspectorRect = new Rect(inspectorPosition.x - inspectorWidth, inspectorPosition.y, inspectorWidth, Screen.height - inspectorPosition.y); } else { inspectorPositionAdjX = inspectorPosition.x - inspectorWidth; inspectorRect = new Rect(inspectorPosition.x - inspectorWidth, inspectorPosition.y, inspectorWidth, inspectorHeight); } } else if (inspectorPosition.y > Screen.height - inspectorMargin) { inspectorPositionAdjY = inspectorPosition.y - inspectorHeight; inspectorRect = new Rect(inspectorPosition.x, inspectorPosition.y - inspectorHeight, inspectorWidth, inspectorHeight); } else if (inspectorPosition.y + inspectorHeight > Screen.height) { inspectorRect = new Rect(inspectorPosition.x, inspectorPosition.y, inspectorWidth, Screen.height - inspectorPosition.y); } else { inspectorRect = new Rect(inspectorPosition.x, inspectorPosition.y, inspectorWidth, inspectorHeight); } /*#if UNITY_EDITOR || UNITY_STANDALONE * if (File.Exists (inspectorObject.name + ".xml")) { * if (!ObjectLoaded (inspectorObject)) { * loadedObject = LoadMarkup (inspectorObject); * markupCleared = false; * } * } * else { * if (!markupCleared) { * InitNewMarkup (); * loadedObject = new VoxML (); * } * } #endif #if UNITY_WEBPLAYER*/ // Resources load here //TextAsset markup = Resources.Load (inspectorObject.name) as TextAsset; if (File.Exists(string.Format("{0}/{1}", Data.voxmlDataPath, string.Format("objects/{0}.xml", inspectorObject.name)))) { using (StreamReader sr = new StreamReader( string.Format("{0}/{1}", Data.voxmlDataPath, string.Format("objects/{0}.xml", inspectorObject.name)))) { String markup = sr.ReadToEnd(); //if (markup != null) { if (!ObjectLoaded(markup)) { loadedObject = LoadMarkup(markup); inspectorTitle = inspectorObject.name; markupCleared = false; } //} } } else { if (!markupCleared) { InitNewMarkup(); loadedObject = new VoxML(); } } //#endif GUILayout.BeginArea(inspectorRect, GUI.skin.window); switch (mlEntityType) { case VoxEntity.EntityType.Object: DisplayObjectMarkup(); break; case VoxEntity.EntityType.Program: DisplayProgramMarkup(); break; case VoxEntity.EntityType.Attribute: DisplayAttributeMarkup(); break; case VoxEntity.EntityType.Relation: DisplayRelationMarkup(); break; case VoxEntity.EntityType.Function: DisplayFunctionMarkup(); break; default: break; } GUILayout.EndArea(); Vector2 textDimensions = GUI.skin.label.CalcSize(new GUIContent(inspectorTitle)); GUI.Label( new Rect(((2 * inspectorPositionAdjX + inspectorWidth) / 2) - textDimensions.x / 2, inspectorPositionAdjY, textDimensions.x, 25), inspectorTitle); } }
public VoxMLEventArgs(GameObject voxObj, VoxML voxml) { this.Voxeme = voxObj; this.VoxML = voxml; }