예제 #1
0
    private void OnDeath()
    {
        toy.Drop(transform);

        Instantiate(deathEffectPrefab, transform.position, Quaternion.identity, transform.parent);
        Destroy(gameObject);
    }
예제 #2
0
파일: Game.cs 프로젝트: daaqing452/GazeDock
                private void FixedUpdate()
                {
                    // counter
                    if (dwellCounter > 0)
                    {
                        dwellCounter--;
                        if (dwellCounter == DWELL_PROGRESS_COUNTER)
                        {
                            progressbarBg.SetActive(true);
                            progressbarFg.SetActive(true);
                            Debug.Log("yyy " + progressbarBg.activeSelf);
                        }
                        if (dwellCounter < DWELL_PROGRESS_COUNTER)
                        {
                            RenewProgressbar(1.0f * (DWELL_PROGRESS_COUNTER - dwellCounter) / DWELL_PROGRESS_COUNTER);
                        }
                        if (dwellCounter == 0)
                        {
                            progressbarBg.SetActive(false);
                            progressbarFg.SetActive(false);
                            if (state == 1)
                            {
                                // trigger menu
                                headTarget = headFocus;
                                dwellMenu.SetActive(true);
                                state = 3;
                                Log("trigger dwell");
                            }
                            else if (state == 2)
                            {
                                // gaze forward
                                if (gazeFocus.name == "Trigger 0")
                                {
                                    MoveForward();
                                    state = 0;
                                    Log("forward gaze");
                                }
                                else if (gazeFocus.name == "Trigger 1")
                                {
                                    headTarget = null;
                                    dwellMenu.SetActive(true);
                                    state = 3;
                                    Log("trigger gaze");
                                }
                            }
                            else if (state == 3)
                            {
                                // select gaze menu
                                if (gazeFocus.name == "Item 0")
                                {
                                    int res = toy.Pick(headTarget);
                                    Log("pick " + res);
                                }
                                else if (gazeFocus.name == "Item 1")
                                {
                                    int res = toy.Drop(headTarget);
                                    Log("drop " + res);
                                }
                                else if (gazeFocus.name == "Item 2")
                                {
                                    int res = MoveForward();
                                    Log("move " + res);
                                }
                                else if (gazeFocus.name == "Item 3")
                                {
                                    Log("exit");
                                }
                                dwellMenu.SetActive(false);
                                state = 0;
                            }
                        }
                    }
                    if (infoCounter > 0)
                    {
                        infoCounter--;
                        if (infoCounter == 0)
                        {
                            info.SetActive(false);
                        }
                    }

                    // get gaze
                    initialMenu();
                    border = Oval.Border;
                    if (SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.WORKING &&
                        SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.NOT_SUPPORT)
                    {
                        return;
                    }
                    Vector3 GazeOriginCombinedLocal, GazeDirectionCombinedLocal;

                    if (SRanipal_Eye.GetGazeRay(GazeIndex.COMBINE, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal))
                    {
                    }
                    else if (SRanipal_Eye.GetGazeRay(GazeIndex.LEFT, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal))
                    {
                    }
                    else if (SRanipal_Eye.GetGazeRay(GazeIndex.RIGHT, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal))
                    {
                    }
                    else
                    {
                    };
                    Vector3 GazeDirectionCombined = Camera.main.transform.TransformDirection(GazeDirectionCombinedLocal);

                    GazeRayRenderer.SetPosition(0, Camera.main.transform.position - Camera.main.transform.up * 0.05f);
                    GazeRayRenderer.SetPosition(1, Camera.main.transform.position + GazeDirectionCombined * LengthOfRay);
                    Log("gaze " + GazeDirectionCombined.x + " " + GazeDirectionCombined.y + " " + GazeDirectionCombined.z);

                    // gaze dock
                    if (technique == Technique.GazeDock)
                    {
                        Vector3 Gaze_oval = GazeDirectionCombinedLocal - new Vector3(Oval.X0, Oval.Y0, 0);
                        Vector2 Choice    = new Vector2(Gaze_oval.x, Gaze_oval.y);

                        // (0,0,1) is blink
                        if (!GazeDirectionCombinedLocal.Equals(new Vector3(0, 0, 1)))
                        {
                            //in
                            if (GetVal(Choice, Gaze_oval, 1) && isStart)
                            {
                                trigger = true;
                                ring_up();
                                Log("ringup");
                            }
                            else if (trigger)
                            {
                                // highlight
                                if (dis_out.Count > 0 && dis_out[dis_out.Count - 1].y > 0)
                                {
                                    string str = GetChoice(Choice);
                                    if (!selection.Equals(str))
                                    {
                                        if (area >= 0)
                                        {
                                            if (area_bf >= 0)
                                            {
                                                ren[area_bf % 4].material = bf;
                                            }
                                            bf = ren[area % 4].material;
                                            ren[area % 4].material = s;
                                        }
                                        area_bf   = area;
                                        selection = str;
                                    }
                                }
                                ring_up();
                            }
                            // out
                            if (GetVal(Choice, Gaze_oval, 0))
                            {
                                if (trigger && isStart)
                                {
                                    trigger = false;
                                    //RaiseInfo(selection);
                                    if (selection == "↑")
                                    {
                                        int res = MoveForward();
                                        Log("move " + res);
                                    }
                                    else if (selection == "Pick")
                                    {
                                        int res = toy.Pick(headFocus);
                                        Log("pick " + res);
                                    }
                                    else if (selection == "Drop")
                                    {
                                        int res = toy.Drop(headFocus);
                                        Log("drop " + res);
                                    }
                                    dis_in.Clear();
                                    Log("ringdown");
                                }
                                ring_down();
                            }
                        }
                        else
                        {
                            dis_in.Clear();
                            dis_out.Clear();
                        }
                        time_recorder += Time.fixedDeltaTime;
                    }

                    // dwell
                    if (technique == Technique.Dwell)
                    {
                        ring_down();
                        RaycastHit hit;
                        if (Physics.Raycast(new Ray(Camera.main.transform.position - Camera.main.transform.up * 0.05f + GazeDirectionCombined * PENETRATE_GAZEDOCK, GazeDirectionCombined), out hit))
                        {
                            GameObject g = hit.collider.gameObject;
                            if (g.name != gazeNameLast)
                            {
                                progressbarBg.SetActive(false);
                                progressbarFg.SetActive(false);
                                if (gazeFocus != null && gazeFocus.name.Substring(0, 4) == "Item")
                                {
                                    gazeFocus.GetComponent <Renderer>().material.color = Color.red;
                                }
                                if (g.name.Substring(0, 4) == "Item")
                                {
                                    g.GetComponent <Renderer>().material.color = Color.yellow;
                                    dwellCounter = DWELL_START_COUNTER;
                                    gazeFocus    = g;
                                    Log("dwell start item");
                                }
                                else if (g.name.Substring(0, 4) == "Trig")
                                {
                                    if (technique == Technique.Dwell)
                                    {
                                        if (state == 0)
                                        {
                                            state        = 2;
                                            dwellCounter = DWELL_START_COUNTER;
                                            Log("dwell start gaze");
                                        }
                                    }
                                    gazeFocus = g;
                                }
                                else
                                {
                                    if (state == 2)
                                    {
                                        state        = 0;
                                        dwellCounter = 0;
                                        Log("dwell quit gaze");
                                    }
                                    if (state == 3)
                                    {
                                        dwellCounter = 0;
                                        Log("dwell quit item");
                                    }
                                }
                            }
                            gazeNameLast = g.name;
                        }
                        else
                        {
                            progressbarBg.SetActive(false);
                            progressbarFg.SetActive(false);
                            gazeNameLast = "";
                            if (state == 2)
                            {
                                state        = 0;
                                dwellCounter = 0;
                                Log("dwell quit gaze");
                            }
                            if (state == 3)
                            {
                                dwellCounter = 0;
                                Log("dwell quit item");
                            }
                        }
                    }


                    if (Input.GetKey(KeyCode.W))
                    {
                        Vector3 vc = mainCamera.transform.forward;
                        vc.y = 0;
                        GameObject.Find("Movable").transform.Translate(vc / vc.magnitude * 0.1f);
                    }
                    if (Input.GetKey(KeyCode.S))
                    {
                        Vector3 vc = mainCamera.transform.forward;
                        vc.y = 0;
                        GameObject.Find("Movable").transform.Translate(vc / vc.magnitude * -0.1f);
                    }
                }
예제 #3
0
    void Update()
    {
        if (playerMovement.CurrentState == PlayerMovement.MoveState.IDLE || playerMovement.CurrentState == PlayerMovement.MoveState.MOVING)
        {
            if (InputManager.Instance.GetButtonActionDown(ButtonActionEnum.TAKE_X_OBJECT, playerIndex) == true)
            {
                if (chest.TakeObject(1, playerIndex))
                {
                    SetDefaultObjectPosition();
                }
            }
            if (InputManager.Instance.GetButtonActionDown(ButtonActionEnum.TAKE_Y_OBJECT, playerIndex) == true)
            {
                if (chest.TakeObject(2, playerIndex))
                {
                    SetDefaultObjectPosition();
                }
            }
            if (InputManager.Instance.GetButtonActionDown(ButtonActionEnum.TAKE_B_OBJECT, playerIndex) == true)
            {
                if (chest.TakeObject(3, playerIndex))
                {
                    SetDefaultObjectPosition();
                }
            }
            if (InputManager.Instance.GetButtonActionDown(ButtonActionEnum.TRHOW_OBJECT, playerIndex) == true)
            {
                if (toyHasTaken != null)
                {
                    Toy.DropResult dropResult = toyHasTaken.CanDrop();

                    if (dropResult == Toy.DropResult.NONE)
                    {
                        playerAnimator.SetBool("IsBigObject", false);

                        if (toyHasTaken.CurrentObjectType == Toy.ObjectType.SMALL)
                        {
                            playerAudioSource.PlayOneShot(throwAudioClip);

                            Vector3 throwDir = toyHasTaken.transform.position - transform.position;
                            throwDir.Normalize();

                            toyHasTaken.Throw(throwDir, PlayerIndex);
                        }
                        else
                        {
                            playerAudioSource.PlayOneShot(dropAudioClip);
                            toyHasTaken.Drop();
                        }

                        if (toyHasTaken.PlayerIndex == PlayerIndex && toyHasTaken.FirstValidDrop)
                        {
                            Collider2D[] overlapColliders = Physics2D.OverlapPointAll(toyHasTaken.transform.position);

                            bool canScore = false;

                            for (int i = 0; i < overlapColliders.Length; ++i)
                            {
                                if (overlapColliders[i].gameObject.layer == LayerMask.NameToLayer("PlayerZone"))
                                {
                                    if ((playerIndex == 0 && overlapColliders[i].gameObject.name == "Player1Zone" && playerIndex == toyHasTaken.originalPlayerIndex) || (playerIndex == 1 && overlapColliders[i].gameObject.name == "Player2Zone" && playerIndex == toyHasTaken.originalPlayerIndex))
                                    {
                                        canScore = true;
                                        break;
                                    }
                                }
                            }


                            if (canScore == true)
                            {
                                toyHasTaken.FirstValidDrop = false;
                                GameManager.Instance.PlayerScored(playerIndex, toyHasTaken.Points);
                            }
                        }

                        toyHasTaken = null;
                    }
                    else if (dropResult == Toy.DropResult.CHEST)
                    {
                        GameManager.Instance.PlayerScored(playerIndex, toyHasTaken.Points);
                        Destroy(toyHasTaken.gameObject);
                        toyHasTaken = null;
                        return;
                    }
                }
                else
                {
                    if (Vector3.Distance(transform.position, bed.transform.position) < distanceToHide)
                    {
                        bed.GetComponent <Collider2D>().enabled = false;
                        transform.position = bed.transform.position;
                        isHidden           = true;

                        playerMovement.Hide(bed, bed.GetComponent <BedWakeUpZone>().WakeUpZone);
                    }
                    else
                    {
                        GameObject[] objects;

                        objects = GameObject.FindGameObjectsWithTag("Toy");
                        Toy     objectToPickUp = null;
                        Vector3 newDistance    = new Vector3(10, 10, 10);

                        foreach (GameObject Object in objects)
                        {
                            Vector3 distance;

                            distance = Object.transform.position - transform.position;

                            if (distance.magnitude < newDistance.magnitude && distance.magnitude < sizeToPickUpObject)
                            {
                                newDistance = distance;

                                if (!Object.gameObject.GetComponent <Toy>().IsInChest)
                                {
                                    objectToPickUp = Object.gameObject.GetComponent <Toy>();
                                }
                            }
                        }
                        if (objectToPickUp != null)                        // && objectToPickUp.FirstValidDrop == false)
                        {
                            if (gameObject == GameManager.Instance.PlayerOne.gameObject && GameManager.Instance.PlayerTwo.toyHasTaken == objectToPickUp)
                            {
                                GameManager.Instance.PlayerTwo.toyHasTaken = null;
                            }
                            else if (gameObject == GameManager.Instance.PlayerTwo.gameObject && GameManager.Instance.PlayerOne.toyHasTaken == objectToPickUp)
                            {
                                GameManager.Instance.PlayerOne.toyHasTaken = null;
                            }

                            objectToPickUp.Taken(playerIndex);
                            SetDefaultObjectPosition();
                        }
                    }
                }
            }
        }
        UpdateObjectPosition();
    }