Window detect.
상속: UWEBase
예제 #1
0
    public string caster;     //who has cast the project. It will ignore them.

    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.name == caster)
        {
            return;
        }
        if (HasHit == true)
        {        //Only impact once.
            return;
        }
        else

        {
            HasHit = true;
            SpriteRenderer sprt = this.GetComponentInChildren <SpriteRenderer>();
            sprt.enabled = false;
            BoxCollider box = this.GetComponent <BoxCollider>();
            box.enabled = false;
            WindowDetect.FreezeMovement(this.gameObject);

            ObjectInteraction objInt = collision.gameObject.GetComponent <ObjectInteraction>();

            if (objInt != null)
            {
                objInt.Attack(damage);
                Impact imp = this.gameObject.AddComponent <Impact>();
                imp.FrameNo  = objInt.GetHitFrameStart();
                imp.EndFrame = objInt.GetHitFrameEnd();
                StartCoroutine(imp.Animate());
            }
            else
            {
                //test if this is a player.
                if (collision.gameObject.GetComponent <UWCharacter>() != null)
                {
                    collision.gameObject.GetComponent <UWCharacter>().ApplyDamage(damage);
                }
                else
                {
                    //do a miss impact
                    Impact imp = this.gameObject.AddComponent <Impact>();
                    imp.FrameNo  = 46;
                    imp.EndFrame = 50;
                    StartCoroutine(imp.Animate());
                }
            }

            DestroyObject(this.gameObject, 1);
        }
    }
예제 #2
0
    public void SpillContents()
    {    //Removes the contents of a container out in the real world.
        int     counter;
        TileMap tm = GameObject.Find("Tilemap").GetComponent <TileMap>();

        WindowDetect.FreezeMovement(this.gameObject);
        ObjectInteraction objInt = this.gameObject.GetComponent <ObjectInteraction>();

        objInt.SetWorldDisplay(objInt.GetEquipDisplay());
        for (int i = 0; i < MaxCapacity(); i++)
        {
            if (GetItemAt(i) != "")
            {
                GameObject Spilled = GameObject.Find(GetItemAt(i));
                if (Spilled != null)
                {
                    bool    flag        = false;
                    Vector3 randomPoint = this.transform.position;
                    counter = 0;
                    while ((flag == false) && (counter < 25))
                    {
                        randomPoint = this.transform.position + Random.insideUnitSphere;
                        if (randomPoint.y < this.transform.position.y)
                        {
                            randomPoint.y = this.transform.position.y + 0.1f;
                        }
                        flag = ((!Physics.CheckSphere(randomPoint, 0.5f)) && (tm.ValidTile(randomPoint)));
                        counter++;
                    }
                    if (flag == true)
                    {                    //No object interferes with the spill
                        RemoveItemFromContainer(i);
                        Spilled.transform.position = randomPoint;
                        Spilled.GetComponent <ObjectInteraction>().PickedUp = false;
                        WindowDetect.UnFreezeMovement(Spilled);
                    }
                    else
                    {                    //No where to put the item. Put it at the containers position.
                        RemoveItemFromContainer(i);
                        Spilled.transform.position = this.transform.position;
                        Spilled.GetComponent <ObjectInteraction>().PickedUp = false;
                        WindowDetect.UnFreezeMovement(Spilled);
                    }
                }
            }
        }
        WindowDetect.UnFreezeMovement(this.gameObject);
    }
    private void CreateRuneStone(int ItemID)
    {
        string     Item  = ItemID.ToString("000");
        GameObject myObj = new GameObject("SummonedObject_" + playerUW.PlayerMagic.SummonCount++);

        myObj.layer = LayerMask.NameToLayer("UWObjects");
        //myObj.transform.position = playerUW.playerInventory.InventoryMarker.transform.position;
        //myObj.transform.parent=playerUW.playerInventory.InventoryMarker.transform;
        ObjectInteraction.CreateObjectGraphics(myObj, "Sprites/OBJECTS_224", true);
        ObjectInteraction.CreateObjectInteraction(myObj, 0.5f, 0.5f, 0.5f, 0.5f, "Sprites/OBJECTS_224", "Sprites/OBJECTS_" + Item, "Sprites/OBJECTS_" + Item, ObjectInteraction.RUNE, 224, 1, 40, 0, 1, 1, 0, 1, 1, 0, 0, 1);

        myObj.AddComponent <RuneStone>();

        myObj.transform.position = new Vector3(64.5f, 4.0f, 24.5f);
        WindowDetect.UnFreezeMovement(myObj);
    }
예제 #4
0
    public virtual void Pickup(ObjectInteraction objPicked, PlayerInventory pInv)
    {    //completes the pickup.
        objPicked.PickedUp = true;
        if (objPicked.GetComponent <Container>() != null)
        {
            Container.SetPickedUpFlag(objPicked.GetComponent <Container>(), true);
            Container.SetItemsParent(objPicked.GetComponent <Container>(), InvMarker.transform);
            Container.SetItemsPosition(objPicked.GetComponent <Container>(), InvMarker.transform.position);
        }
        CursorIcon        = objPicked.GetInventoryDisplay().texture;
        pInv.ObjectInHand = objPicked.transform.name;
        //////pInv.JustPickedup=true;//To stop me throwing it away immediately.
        if (objPicked.GetComponent <Rigidbody>() != null)
        {
            WindowDetect.FreezeMovement(objPicked.gameObject);
        }
        objPicked.transform.position = InvMarker.transform.position;
        objPicked.transform.parent   = InvMarker.transform;

        objPicked.Pickup();        //Call pickup event for this object.
    }
예제 #5
0
    protected override void ThrowObjectInHand()
    {
        base.ThrowObjectInHand();
        if (playerUW.playerInventory.GetObjectInHand() != "")
        {                                                       //The player is holding something
            if (playerUW.playerInventory.JustPickedup == false) //To prevent the click event dropping an object immediately after pickup
            {
                //Determine what is directly in front of the player via a raycast
                //If something is in the way then cancel the drop
                //Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                Ray ray;
                if (playerUW.MouseLookEnabled == true)
                {
                    ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
                }
                else
                {
                    ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                }


                RaycastHit hit       = new RaycastHit();
                float      dropRange = 0.5f;
                if (!Physics.Raycast(ray, out hit, dropRange))
                {                //No object interferes with the drop
                    //Calculate the force based on how high the mouse is
                    float force = Input.mousePosition.y / Camera.main.pixelHeight * 200;
                    //float force = Camera.main.ViewportToWorldPoint(Input.mousePosition).y/Camera.main.pixelHeight *200;

                    //Get the object being dropped and moved towards the end of the ray
                    GameObject droppedItem = playerUW.playerInventory.GetGameObjectInHand();            //GameObject.Find(playerUW.playerInventory.ObjectInHand);
                    droppedItem.transform.parent = null;
                    droppedItem.GetComponent <ObjectInteraction>().PickedUp = false;                    //Back in the real world
                    GameObject InvMarker = GameObject.Find("InventoryMarker");
                    if (droppedItem.GetComponent <Container>() != null)
                    {
                        Container.SetPickedUpFlag(droppedItem.GetComponent <Container>(), false);
                        Container.SetItemsParent(droppedItem.GetComponent <Container>(), null);
                        Container.SetItemsPosition(droppedItem.GetComponent <Container>(), InvMarker.transform.position);
                    }
                    droppedItem.transform.position = ray.GetPoint(dropRange - 0.1f);                //playerUW.transform.position;
                    WindowDetect.UnFreezeMovement(droppedItem);
                    if (Camera.main.ScreenToViewportPoint(Input.mousePosition).y > 0.4f)
                    {                    //throw if above a certain point in the view port.
                        Vector3 ThrowDir = ray.GetPoint(dropRange) - playerUW.playerInventory.transform.position;
                        //Apply the force along the direction.
                        droppedItem.GetComponent <Rigidbody>().AddForce(ThrowDir * force);
                    }

                    //Clear the object and reset the cursor
                    playerUW.CursorIcon = playerUW.CursorIconDefault;
                    playerUW.playerInventory.SetObjectInHand("");
                }
            }
            else
            {
                playerUW.playerInventory.JustPickedup = false;              //The next click event will allow dropping.
            }
            //try and drop the item in the world
        }
    }