public static void addConeCogwheelObject(List <SceneObject> sceneObjects, Dictionary <GameObject, SceneObject> addedSceneObjects, GameObject obj) { if (obj.tag.Equals("Cogwheel")) { ConeCogwheelObject newObject = new ConeCogwheelObject(); List <Interlockable> interlockingObjects = obj.GetComponentInChildren <RotatableCogwheel>().getInterlockingParts(); newObject.interlockingObjects = new int[interlockingObjects.Count]; for (int i = 0; i < interlockingObjects.Count; i++) { if (!addedSceneObjects.ContainsKey(interlockingObjects[i].getRootTransform().gameObject)) { SceneLoaderDictionary.addSceneObjectDictionary[interlockingObjects[i].getRootTransform().tag].Invoke(sceneObjects, addedSceneObjects, interlockingObjects[i].getRootTransform().gameObject); } newObject.interlockingObjects[i] = addedSceneObjects[interlockingObjects[i].getRootTransform().gameObject].id; } newObject.id = sceneObjects.Count; newObject.kind = "ConeCogwheelObject"; Vector3 objPosition = obj.transform.position; newObject.position = new Vector3Object(objPosition.x, objPosition.y, objPosition.z); Vector3 objRotation = obj.transform.eulerAngles; newObject.rotation = new Vector3Object(objRotation.x, objRotation.y, objRotation.z); ConeCogwheel coneCogwheelModeling = obj.GetComponentInChildren <ConeCogwheel>(); newObject.radius = coneCogwheelModeling.getRadius(); newObject.cogCount = coneCogwheelModeling.getCogCount(); newObject.height = coneCogwheelModeling.getHeight(); sceneObjects.Add(newObject); addedSceneObjects.Add(obj, newObject); } else { Debug.Log("JsonConfigInteraction.addConeCogwheelObject: object is not tagged with 'Cogwheel'."); } }
public static void loadConeCogwheelObject(SceneObject obj) { if (obj.GetType().Equals(typeof(ConeCogwheelObject))) { ConeCogwheelObject ccObject = (ConeCogwheelObject)obj; GameObject cogwheel = Instantiate(prefabDictionary[obj.GetType()]); cogwheel.GetComponentInChildren <Cogwheel>().generateMesh(ccObject.height, ccObject.cogCount, ccObject.radius); cogwheel.transform.position = new Vector3(ccObject.position.x, ccObject.position.y, ccObject.position.z); cogwheel.transform.eulerAngles = new Vector3(ccObject.rotation.x, ccObject.rotation.y, ccObject.rotation.z); foreach (int id in ccObject.interlockingObjects) { Tuple <SceneObject, GameObject> tuple = addedSceneObjects.Find(tp => tp.Item1.id.Equals(id)); if (tuple != null) { cogwheel.GetComponentInChildren <Interlockable>().addInterlockingPart(tuple.Item2.GetComponentInChildren <Interlockable>()); } } //Set Layer for gameobject and all its children string tagLayerName = "Cogwheel"; SetLayerRecursively(cogwheel, LayerMask.NameToLayer(tagLayerName)); cogwheel.gameObject.tag = tagLayerName; //Create new CogwheelFact and add to global FactList int cogId = GameState.Facts.Count; float radius = cogwheel.GetComponentInChildren <Cogwheel>().getRadius(); float insideRadius = cogwheel.GetComponentInChildren <Cogwheel>().getInsideRadius(); float outsideRadius = cogwheel.GetComponentInChildren <Cogwheel>().getOutsideRadius(); CogwheelFact newFact = new CogwheelFact(cogId, cogwheel.transform.position, cogwheel.transform.up, radius, insideRadius, outsideRadius); newFact.Representation = cogwheel; GameState.Facts.Insert(cogId, newFact); UnityEngine.Debug.Log("Successfully added new CogwheelFact with backendUri: " + newFact.backendURI); addedSceneObjects.Add(new Tuple <SceneObject, GameObject>(obj, cogwheel)); } }