public static void addShaftHolderObject(List <SceneObject> sceneObjects, Dictionary <GameObject, SceneObject> addedSceneObjects, GameObject obj) { if (obj.tag.Equals("ShaftHolder")) { ShaftHolderObject newObject = new ShaftHolderObject(); newObject.id = sceneObjects.Count; newObject.kind = "ShaftHolderObject"; 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); ShaftHolder shaftHolderModeling = obj.GetComponentInChildren <ShaftHolder>(); newObject.radius = shaftHolderModeling.innerRadius; newObject.thickness = shaftHolderModeling.thickness; sceneObjects.Add(newObject); addedSceneObjects.Add(obj, newObject); } else { Debug.Log("JsonConfigInteraction.addConeCogwheelObject: object is not tagged with 'ShaftHolder'."); } }
public static void loadShaftHolderObject(SceneObject obj) { if (obj.GetType().Equals(typeof(ShaftHolderObject))) { ShaftHolderObject shhObject = (ShaftHolderObject)obj; GameObject shaftHolder = Instantiate(prefabDictionary[obj.GetType()]); float diameter = shhObject.radius * 2.0f; float shaftHolderBorderWidth = 1.0f; shaftHolder.transform.position = new Vector3(shhObject.position.x, shhObject.position.y, shhObject.position.z); shaftHolder.transform.eulerAngles = new Vector3(shhObject.rotation.x, shhObject.rotation.y, shhObject.rotation.z); //After the generateMesh-Call, the head of the shaftHolder has the following properties: width = (2*radius + 2*borderWidth), height = (2*radius + 2*borderWidth), depth = thickness shaftHolder.GetComponentInChildren <ShaftHolder>().generateMesh(shhObject.radius, shhObject.thickness); Transform stand = shaftHolder.transform.GetChild(0); Transform bottom = shaftHolder.transform.GetChild(1); //width = z, height = y, thickness = x stand.localScale = new Vector3(stand.localScale.x * shhObject.thickness, stand.localScale.y * shhObject.radius, 2 * shhObject.radius + 2 * shaftHolderBorderWidth); bottom.localScale = new Vector3(bottom.localScale.x * shhObject.radius, bottom.localScale.y * shhObject.thickness, stand.localScale.z * 2); stand.localPosition = new Vector3((-(stand.localScale.y / 2 + shaftHolderBorderWidth + shhObject.radius)), stand.localPosition.y * shhObject.thickness, stand.localPosition.z); bottom.localPosition = new Vector3((-(shaftHolderBorderWidth + shhObject.radius + stand.localScale.y - bottom.localScale.x / 2)), bottom.localPosition.y * shhObject.thickness, bottom.localPosition.z); float height = shaftHolder.transform.position.y; stand.localScale = new Vector3(stand.localScale.x, height - shhObject.radius - shaftHolderBorderWidth, stand.localScale.z); stand.localPosition = new Vector3(-(shaftHolder.transform.GetChild(0).localScale.y / 2 + shhObject.radius + shaftHolderBorderWidth), stand.localPosition.y, stand.localPosition.z); bottom.localPosition = new Vector3((-(shaftHolderBorderWidth + shhObject.radius + shaftHolder.transform.GetChild(0).localScale.y - shaftHolder.transform.GetChild(1).localScale.x / 2)), bottom.localPosition.y, bottom.localPosition.z); //Set Layer for gameobject and all its children string tagLayerName = "ShaftHolder"; SetLayerRecursively(shaftHolder, LayerMask.NameToLayer(tagLayerName)); shaftHolder.gameObject.tag = tagLayerName; addedSceneObjects.Add(new Tuple <SceneObject, GameObject>(obj, shaftHolder)); } }