Ejemplo n.º 1
0
    public void DetachHeavyObject(int index, bool destroy = false)
    {
        if (index < 0 || index >= this.m_Attached.Count)
        {
            return;
        }
        Transform transform = this.m_Attached.Keys.ElementAt(index);

        if (transform == null)
        {
            this.m_Attached.Remove(transform);
            return;
        }
        HeavyObject heavyObject = this.m_Attached[transform];

        Physics.IgnoreCollision(Player.Get().GetComponent <Collider>(), heavyObject.GetComponent <Collider>(), false);
        heavyObject.gameObject.transform.parent = null;
        heavyObject.OnItemDetachedFromHand();
        this.m_Attached.Remove(transform);
        if (destroy)
        {
            UnityEngine.Object.Destroy(heavyObject.gameObject);
        }
        else
        {
            heavyObject.transform.rotation = Player.Get().transform.rotation;
            Vector3 position = new Vector3(0.5f, 0.5f, 1.1f);
            position.x = System.Math.Max(0.5f, position.x);
            Vector3 a = Camera.main.ViewportToWorldPoint(position);
            heavyObject.transform.position = a + Vector3.up * (float)(index + 1) * 0.2f;
        }
    }
Ejemplo n.º 2
0
    public void AttachHeavyObject(HeavyObject ho)
    {
        if (!ho)
        {
            return;
        }
        Transform transform = this.FindFreeSlot();

        if (transform)
        {
            HeavyObject x = null;
            if (!this.m_Attached.TryGetValue(transform, out x) || x == null)
            {
                Physics.IgnoreCollision(Player.Get().GetComponent <Collider>(), ho.GetComponent <Collider>(), true);
                ho.transform.position          = transform.position;
                ho.transform.rotation          = transform.rotation;
                ho.gameObject.transform.parent = transform;
                this.m_Attached[transform]     = ho;
                ho.OnItemAttachedToHand();
            }
        }
    }