Example #1
0
    public GrabbableScript GrabRandomObject(Transform ownerTransform)
    {
        GrabbableScript ret = null;

        if (IsThereAnything)
        {
            ret = GrabbablesAvailable.First(c => !c.IsGrabbed);
        }
        return(ret);
    }
Example #2
0
    public void ClientGrab(int grabbed_id, int player_id)
    {
        // Check if client is already holding dice or tokens
        bool holding_anything          = false;
        bool holding_anything_but_dice = false;

        foreach (GameObject grabbable in grabbable_objects)
        {
            GrabbableScript grabbable_script = grabbable.GetComponent <GrabbableScript>();
            if (grabbable_script.held_by_player_ == player_id)
            {
                holding_anything = true;
                if (!grabbable.GetComponent <DiceScript>())
                {
                    holding_anything_but_dice = true;
                }
            }
        }
        CursorScript cursor_script = null;

        foreach (GameObject cursor in cursor_objects)
        {
            if (cursor.GetComponent <CursorScript>().id() == player_id)
            {
                cursor_script = cursor.GetComponent <CursorScript>();
            }
        }
        // See if client can grab object given already-grabbed objects
        foreach (GameObject grabbable in grabbable_objects)
        {
            GrabbableScript grabbable_script = grabbable.GetComponent <GrabbableScript>();
            if (grabbable_script.id_ == grabbed_id)
            {
                if (grabbable_script.held_by_player_ == player_id)
                {
                    return;
                }
                if ((grabbable.GetComponent <DiceScript>() && !holding_anything_but_dice) ||
                    (grabbable.GetComponent <TokenScript>() && !holding_anything) ||
                    (grabbable.GetComponent <ParentTokenScript>() && !holding_anything) ||
                    (grabbable.GetComponent <DeckScript>() && !holding_anything) ||
                    (grabbable.GetComponent <CardScript>() && !holding_anything) ||
                    (grabbable.GetComponent <CoinScript>() && !holding_anything))
                {
                    grabbable_script.held_by_player_ = player_id;
                    if (grabbable.GetComponent <DiceScript>())
                    {
                        grabbable.GetComponent <DiceScript>().PickUpSound();
                    }
                    if (grabbable.GetComponent <CoinScript>())
                    {
                        grabbable.GetComponent <CoinScript>().PickUpSound();
                    }
                    if (grabbable.GetComponent <DeckScript>())
                    {
                        cursor_script.SetCardFaceUp((grabbable.transform.up.y > 0.0f));
                        cursor_script.SetCardRotated(GetRotateFromGrabbable(grabbable));
                        grabbable.GetComponent <DeckScript>().PickUpSound();
                    }
                    if (grabbable.GetComponent <CardScript>())
                    {
                        cursor_script.SetCardFaceUp((grabbable.transform.up.y < 0.0f));
                        cursor_script.SetCardRotated(GetRotateFromGrabbable(grabbable));
                        grabbable.GetComponent <CardScript>().PickUpSound();
                    }
                    if (grabbable.GetComponent <TokenScript>())
                    {
                        grabbable.GetComponent <TokenScript>().PickUpSound();
                    }
                    if (grabbable.GetComponent <ParentTokenScript>())
                    {
                        grabbable.GetComponent <ParentTokenScript>().PickUpSound();
                        cursor_script.SetCardRotated(GetRotateFromGrabbable(grabbable));
                    }
                    grabbable.rigidbody.mass = 0.2f;
                }
            }
        }
    }
Example #3
0
    void Update()
    {
        var player_list = PlayerListScript.Instance().GetPlayerInfoList();

        if (player_list.ContainsKey(id_))
        {
            SetColor(player_list[id_].color_);
        }
        if (networkView.isMine)
        {
            if (Input.GetKeyDown("f"))
            {
                card_face_up_ = !card_face_up_;
            }
            if (Input.GetKeyDown("e"))
            {
                card_rotated_ = (card_rotated_ + 1) % 4;
            }
            if (Input.GetKeyDown("q"))
            {
                card_rotated_ = (card_rotated_ + 3) % 4;
            }
            if (Input.GetKeyDown("r"))
            {
                card_face_up_ = false;
                card_rotated_ = 0;
            }
            tapping_ = Input.GetKey("t");
            var     main_camera = GameObject.Find("Main Camera").camera;
            Vector3 pos         = new Vector3();
            {
                Ray        ray         = main_camera.ScreenPointToRay(Input.mousePosition);
                RaycastHit raycast_hit = new RaycastHit();
                if (Physics.Raycast(ray, out raycast_hit, 100.0f, 1 << 8))
                {
                    pos = raycast_hit.point - ray.direction;
                }
            }

            if (Input.GetMouseButton(0))
            {
                Ray          ray = main_camera.ScreenPointToRay(Input.mousePosition);
                RaycastHit[] raycast_hits;
                raycast_hits = Physics.RaycastAll(ray);
                System.Array.Sort(raycast_hits, new RaycastHitComparator());
                int hit_deck_id = -1;
                foreach (RaycastHit hit in raycast_hits)
                {
                    var hit_obj = hit.collider.gameObject;
                    if (hit_obj.layer != LayerMask.NameToLayer("Dice") &&
                        hit_obj.layer != LayerMask.NameToLayer("Tokens") &&
                        hit_obj.layer != LayerMask.NameToLayer("Cards"))
                    {
                        continue;
                    }
                    GrabbableScript grabbable_script = hit_obj.GetComponent <GrabbableScript>();
                    if (!grabbable_script)
                    {
                        hit_obj          = hit_obj.transform.parent.gameObject;
                        grabbable_script = hit_obj.GetComponent <GrabbableScript>();
                    }
                    if (hit_obj.GetComponent <DeckScript>())
                    {
                        hit_deck_id = grabbable_script.id_;
                    }
                    if (grabbable_script.held_by_player_ == id_)
                    {
                        continue;
                    }
                    if (hit_obj.GetComponent <DeckScript>() && deck_held_time_ > 0.0f && grabbable_script.id_ == deck_held_id_)
                    {
                        deck_held_time_ += Time.deltaTime;
                        if (deck_held_time_ > DECK_HOLD_THRESHOLD)
                        {
                            Grab(grabbable_script.id_, id_);
                        }
                        break;
                    }
                    if (!hit_obj.GetComponent <DiceScript>() && !Input.GetMouseButtonDown(0))
                    {
                        continue;
                    }
                    if (hit_obj.GetComponent <DeckScript>())
                    {
                        deck_held_time_ = Time.deltaTime;
                        deck_held_id_   = grabbable_script.id_;
                        break;
                    }
                    Grab(grabbable_script.id_, id_);
                }
                if (hit_deck_id != deck_held_id_ && deck_held_time_ > 0.0f)
                {
                    if (!Network.isServer)
                    {
                        networkView.RPC("TellObjectManagerAboutCardPeel", RPCMode.Server, deck_held_id_, id_);
                    }
                    else
                    {
                        TellObjectManagerAboutCardPeel(deck_held_id_, id_);
                    }
                    deck_held_time_ = 0.0f;
                }
            }
            if (Input.GetMouseButtonUp(0))
            {
                if (!Network.isServer)
                {
                    networkView.RPC("TellObjectManagerAboutMouseRelease", RPCMode.Server, id_);
                }
                else
                {
                    TellObjectManagerAboutMouseRelease(id_);
                }
                deck_held_time_ = 0.0f;
            }
            rigidbody.position = pos;
            transform.position = pos;
        }
    }