Пример #1
0
    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;
        }
    }
Пример #2
0
    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);
    }