示例#1
0
    private void DetachFromParent()
    {
        if (this.isCore)
        {
            return;
        }

        Debug.Log("nulling parent's:" + this.IndexRelativeToParent);
        this.Parent.attachedBlocks[this.IndexRelativeToParent] = null;

        this.boxCollider.enabled = false;

        this.transform.SetParent(null);
        this.Parent     = null;
        this.Core       = null;
        this.IsAttached = false;

        this.rb.isKinematic = false;
        this.rb.AddForce(ValidAttachPoints[IndexRelativeToParent] * -1 * DetachThrust);

        this.IndexRelativeToParent = -1;

        StartCoroutine(EnableColliderAfterDelay(boxColliderDelay));

        Debug.Log("detached block: " + this.gameObject.name);
    }
示例#2
0
    void OnCollisionEnter2D(Collision2D coll)
    {
        if (this.isCore == false && this.IsAttached == false && this.attachedInLastTick == false)
        {
            // if we're a free-floating object that's not the ship's core
            // then don't handle collisions
            Debug.Log("ignoring collision");
            return;
        }

        if (coll.gameObject.tag == "Block")
        {
            Debug.Log(this.gameObject.name + " has collided with block " + coll.gameObject.name);

            // what attach direction are we closest to? (within a tolerance)
            Vector3 attachPoint = ClosestAttachPoint(coll.gameObject);
            int     index       = CalculateAttachPointIndex(attachPoint);

            if (index == -1)
            {
                // don't attach
                return;
            }

            Attachable block = coll.gameObject.GetComponent <Attachable>();

            if (block == null)
            {
                Debug.LogError("No Attachable component on the collided block");
            }

            AttachChild(index, block, this.Core);
        }
    }
示例#3
0
    void AttachChild(int index, Attachable block, Attachable core)
    {
        // check if the attempted attach is valid
        if (index < 0)
        {
            Debug.Log("Invalid attach point");
            return;
        }
        if (attachedBlocks[index] != null || block.IsAttached)
        {
            return;
        }

        // update the new child
        block.Core                  = core;
        block.Parent                = this;
        block.IsAttached            = true;
        block.rb.isKinematic        = true;
        block.IndexRelativeToParent = index;
        block.attachedInLastTick    = true; // protect against handling the collision twice

        // move it to the correct position
        block.transform.position = this.transform.position - (Vector3)ValidAttachPoints[index];
        block.transform.SetParent(this.transform);

        // store it
        this.attachedBlocks[index] = block;
        Debug.Log("pushing " + block.gameObject.name + " onto attach stack ("
                  + Core.history.Count + ")");
        Core.history.Push(block);
    }
 public ItemDetachedEventArgs(Attachable item)
 {
     Item = item;
 }
 public InventoryItemSelectedEventArgs(InventoryUI inventoryUI, Attachable item)
 {
     InventoryUI = inventoryUI;
     Item = item;
 }