private void initMetaphorObject() { if (layer == null) { return; } GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); cube.name = layer.getLayerName().ToUpper(); cube.transform.localScale = 0.1f * localScaleOrg; cube.GetComponent <MeshRenderer>().enabled = true; //GameObject.Destroy(Cube.GetComponent<Collider>()); //MeshCollider mc = Cube.AddComponent<MeshCollider>(); //mc.convex = true; BoxCollider bc = cube.GetComponent <BoxCollider>(); bc.center = new Vector3(0.5f, 0f, 0f); bc.size = new Vector3(2.0f, 1f, 1f); Material newMaterial = (Material)Resources.Load("LayerMetaphorDefault", typeof(Material)); cube.GetComponent <Renderer>().material = newMaterial; goText = new GameObject("Text_" + layer.getLayerName()); TextMesh tm = goText.AddComponent <TextMesh>(); tm.text = layer.getLayerName(); tm.characterSize = 2; goText.transform.parent = cube.transform; goText.transform.localPosition = new Vector3(.6f, 0f, 0f); goText.transform.localScale = new Vector3(.1f, .8f, .1f); if (!_oldVersion) { cube.GetComponent <MeshRenderer>().enabled = false; MapARLayerDup layerDup = layer.getDuplication(); layerDup.setDupObjParent(cube.transform); layerDup.hideText(); } Rigidbody rb = cube.AddComponent <Rigidbody>(); rb.useGravity = false; rb.isKinematic = true; cube.AddComponent <LockRotation>(); //InteractionBehaviour ib = cylinder.AddComponent<InteractionBehaviour>(); //System.Action a = () => highLightDup(); //ib.OnGraspBegin = a; //a = () => cancelHighLightDup(); //ib.OnGraspEnd = a; worldObject = cube; interactionBehaviour = worldObject.AddComponent <InteractionBehaviour>();// (standard_ib); interactionBehaviour.moveObjectWhenGrasped = false; //worldObject.transform.Rotate(Vector3.up, 120); }
public MapARLayerDup(MapARLayer originalLayer) { this.originalLayer = originalLayer; this.allRelatedObj = new GameObject(); GameObject layerGameObjectsDup = new GameObject(); List <GameObject> basementGameObjectsDup = new List <GameObject>(); layerGameObjectsDup = UnityEngine.Object.Instantiate(originalLayer.getLayerGameObject(), originalLayer.getLayerGameObject().transform); layerGameObjectsDup.transform.parent = this.allRelatedObj.transform; Material newmaterial = new Material(Shader.Find("Transparent/Diffuse")); newmaterial.color = new Color(1f, 1f, 1f, TranRateOg); Vector3 baseCenterSum = new Vector3(); foreach (GameObject gameObj in originalLayer.getBaseMentGameObject()) { GameObject newGameObj = GameObject.CreatePrimitive(PrimitiveType.Cube); newGameObj.transform.parent = gameObj.transform.parent; newGameObj.transform.position = gameObj.transform.position; newGameObj.transform.localScale = gameObj.transform.localScale; baseCenterSum += newGameObj.GetComponent <Renderer>().bounds.center; newGameObj.GetComponent <Renderer>().material = newmaterial; GameObject.Destroy(newGameObj.GetComponent <BoxCollider>()); MeshFilter mf = newGameObj.GetComponent <MeshFilter>(); mf.mesh = gameObj.GetComponent <MeshFilter>().mesh; newGameObj.transform.parent = this.allRelatedObj.transform; basementGameObjectsDup.Add(newGameObj); } this.renderCenter = baseCenterSum / originalLayer.getBaseMentGameObject().Count; this.setLayerGameObject(layerGameObjectsDup); this.setBasementGameObject(basementGameObjectsDup); this.nameText = new GameObject("DupName_" + originalLayer.getLayerName()); TextMesh tm = nameText.AddComponent <TextMesh>(); tm.text = originalLayer.getLayerName(); tm.transform.Translate(1, 0, -1); tm.transform.localScale = new Vector3(.1f, .1f, .1f); this.nameText.transform.parent = allRelatedObj.transform; //this.allRelatedObj.AddComponent<MeshRenderer>(); //Rigidbody rig = this.allRelatedObj.AddComponent<Rigidbody>(); //rig.useGravity = false; }