public void PosessBody(PowerObject obj) { DebugUtils.Assert(obj != null); if (obj == null) { return; } if (obj.GetType() != typeof(PO_Robot)) { return; } if (m_currentBody) { foreach (Renderer ren in m_currentBody.GetComponentsInChildren <Renderer>(true)) { ren.enabled = true; } m_currentBody.transform.parent = null; } m_transform.root.position = obj.transform.position; obj.transform.parent = m_transform; obj.transform.localRotation = Quaternion.identity; obj.transform.localPosition = Vector3.zero; if (m_currentBody) { //look at the body you came from hPadLook = GetComponent <PadLook>(); hPadLook.LookAt(m_currentBody.transform.position); m_MouseLook = GetComponent <MouseLook>(); } m_currentBody = obj; foreach (Renderer ren in m_currentBody.GetComponentsInChildren <Renderer>(true)) { ren.enabled = false; } }
//All items at places, whose base area is visible can be absorbed //aim at the base to absorb the object //Rocks can be absorbed without seeing the corresponding base area private void FireAbsorbRay() { if (!m_canAbsorb) { return; } RaycastHit hit; Ray grabRay = new Ray(m_cameraTransform.position, m_cameraTransform.forward); Debug.DrawRay(m_cameraTransform.position, m_cameraTransform.forward * grabDistance); if (!Physics.Raycast(grabRay, out hit, grabDistance)) { return; } PowerObject obj = null; switch (hit.collider.transform.root.tag) { case "Tree": case "Rock": case "Robot": case "Sentinel": obj = hit.collider.transform.root.gameObject.GetComponent <PowerObject>(); break; case "Environment": obj = ObjectManager.instance.GetObjectAtPos(hit.point); break; } if (obj != null && (obj.GetType() == typeof(PO_Rock) || obj.CanAbsorb(this))) { power += obj.GetPower(); obj.Absorb(); } }
private void PreviewGenerateObject(System.Type type) { if (!FireRay(out m_hit)) { return; } string colliderTag = m_hit.collider.tag; if (colliderTag != "Environment" && colliderTag != "Rock") { return; } Vector3 newPos = m_hit.point; if (!ObjectManager.instance.CanPositionObject(ref newPos)) { if (m_previewObject != null && m_previewObject.gameObject.activeSelf) { m_previewObject.gameObject.SetActive(false); } return; } bool generateObject = false; if (m_previewObject == null) { generateObject = true; } else if (m_previewObject.GetType() != type) { Destroy(m_previewObject); generateObject = true; } if (generateObject) { m_previewObject = ObjectManager.instance.InstantiateObjectPrefab(type, newPos).GetComponent <PowerObject>(); ObjectManager.instance.RemoveObject(m_previewObject); foreach (Collider col in m_previewObject.GetComponentsInChildren <Collider>()) { col.enabled = false; } Renderer[] renderers = m_previewObject.GetComponentsInChildren <Renderer>(); foreach (Renderer r in renderers) { r.material = _previewMaterial; } } else { m_previewObject.transform.position = newPos; if (!m_previewObject.gameObject.activeSelf) { m_previewObject.gameObject.SetActive(true); } } //Debug.DrawLine(newPos, newPos + Vector3.up, Color.red, 5.0f, false); }