Пример #1
0
 //-------------------------------------------------------------------
 void ConnectionsChanged(VirtualNetworkController conn)
 {
     if (ConnectionCountText != null)
     {
         ConnectionCountText.text = "Players: " + GameObject.FindObjectsOfType <VirtualNetworkController>().Length;
     }
 }
Пример #2
0
 //-------------------------------------------------------------------
 void ReadyCountChanged(VirtualNetworkController ctrl)
 {
     if (null != ConnectionReadyText)
     {
         ConnectionReadyText.text = "Ready: " + HopperNetwork.GetReadyCount();
     }
 }
Пример #3
0
    //---------------------------------------------------------------------
    void UpdateKnib(Vector2 pos)
    {
        Vector2 localPos;

        if (!RectTransformUtility.ScreenPointToLocalPointInRectangle((RectTransform)transform, pos, Camera.main, out localPos))
        {
            return;
        }

        Vector2 offset = localPos - new Vector2(Origin.transform.localPosition.x, Origin.transform.localPosition.y);
        float   length = offset.magnitude;
        Vector2 dir    = Vector2.zero;

        if (length > .1f)
        {
            dir    = offset / length;
            length = Mathf.Clamp(length, 0.0f, MaxRadius);
            offset = dir * length;
        }

        Knib.transform.localPosition = Origin.localPosition + new Vector3(offset.x, offset.y, 0.0f);

        VirtualNetworkController controller = HopperNetwork.GetMyController();

        if (controller != null)
        {
            Vector2 movement = dir * (length / MaxRadius);
            UpdateMovementKnib(movement);
            controller.SetMovement(movement);
        }
    }
Пример #4
0
    //---------------------------------------------------------------------
    void ProcessTouch(Touch touch)
    {
        if (ActiveFingerID == touch.fingerId)
        {
            if ((touch.phase == TouchPhase.Ended) || (touch.phase == TouchPhase.Canceled))
            {
                ActiveFingerID = -1;
                VirtualNetworkController controller = HopperNetwork.GetMyController();
                if (controller != null)
                {
                    controller.SetMovement(Vector2.zero);
                }
                Knib.transform.localPosition = Origin.transform.localPosition;
            }
            else if (touch.phase == TouchPhase.Moved)
            {
                UpdateKnib(touch.position);
            }
            return;
        }

        if (touch.phase == TouchPhase.Began)
        {
            if ((ActiveFingerID == -1) && InMoveArea(touch.position))
            {
                // Okay, starting a touch;
                ActiveFingerID = touch.fingerId;
                UpdateKnib(touch.position);
            }
            else if (InActionArea(touch.position))
            {
                UpdateAction(touch);
            }
        }
    }
Пример #5
0
    //---------------------------------------------------------------------
    void UpdateAction(Touch touch)
    {
        VirtualNetworkController controller = HopperNetwork.GetMyController();

        if (controller != null)
        {
            DoAction();
        }
    }
Пример #6
0
    //-------------------------------------------------------------------
    public void UpdateDiscovery()
    {
        var state = HopperNetwork.GetState();

        if (state == HopperNetwork.eState.CLIENT_READY)
        {
            Controller = HopperNetwork.GetMyController();
            SetState(eClientState.LOBBY);
        }
        else if (!HopperNetwork.Instance.isNetworkActive)
        {
            JoinUI.SetActive(true);
        }
    }
Пример #7
0
    //-------------------------------------------------------------------------------------------------
    private void AddPlayer(VirtualNetworkController controller)
    {
        Vector3 spawnLocation = Vector3.zero;

        spawnLocation.z = GAME_Z;
        GameObject     preyObject = Instantiate(m_preyPrefab, spawnLocation, Quaternion.identity);
        PreyController prey       = preyObject.GetComponent <PreyController>();

        prey.m_netController = controller;

        m_UIJoin.SetActive(false);
        if (m_firstGame)
        {
            m_UIInstructions.SetActive(true);
        }
    }
Пример #8
0
    // Update is called once per frame
    void Update()
    {
        if (NetworkManager.singleton.isNetworkActive)
        {
            AddressText.gameObject.SetActive(true);
            AddressText.text = HopperNetwork.Instance.networkAddress + ":" + HopperNetwork.Instance.networkPort;
        }
        else
        {
            AddressText.gameObject.SetActive(false);
        }

        HopperNetwork.eState state = HopperNetwork.GetState();
        switch (state)
        {
        case HopperNetwork.eState.DISCONNECTED:
            StatusText.text = "DISCONNECTED";
            break;

        case HopperNetwork.eState.CLIENT_JOINED:
            StatusText.text = "JOINING: " + HopperNetwork.Instance.networkAddress;
            break;

        case HopperNetwork.eState.CLIENT_LOOKING:
            StatusText.text = "SEARCHING...";
            break;

        case HopperNetwork.eState.CLIENT_READY:
            VirtualNetworkController me = HopperNetwork.GetMyController();
            if (me.ClientIsReady)
            {
                StatusText.text = "READY";
            }
            else
            {
                StatusText.text = "NOT READY";
            }
            break;

        default:
            StatusText.text = "UNKNOWN: " + state;
            break;
        }
    }
Пример #9
0
    //-------------------------------------------------------------------
    public void UpdateInGame()
    {
        VirtualNetworkController controller = HopperNetwork.GetMyController();

        if (!controller.IsInGame())
        {
            SetState(eClientState.LOBBY);
            return;
        }

        if (controller.IsWolf)
        {
            ActionImage.sprite = WolfAction;
        }
        else
        {
            ActionImage.sprite = BunnyAction;
        }
    }
Пример #10
0
    //---------------------------------------------------------------------
    void DoAction()
    {
        ActionAnimator.SetTrigger("DoAction");

        VirtualNetworkController controller = HopperNetwork.GetMyController();

        if (controller != null)
        {
            controller.DoAction();
            if (controller.IsInGame())
            {
                if (controller.IsWolf)
                {
                    AudioManager.Play(eSoundType.FOX_BITE);
                }
                else
                {
                    AudioManager.Play(eSoundType.BUNNY_LAUGH);
                }
            }
        }
    }
Пример #11
0
    //-------------------------------------------------------------------------------------------------
    private void RemovePlayer(VirtualNetworkController controller)
    {
        //Find controller if it was a prey
        GameObject[] preys = GameObject.FindGameObjectsWithTag(TAG_PREY);
        for (int preyIndex = 0; preyIndex < preys.Length; ++preyIndex)
        {
            PreyController prey = preys[preyIndex].GetComponent <PreyController>();
            if (prey != null)
            {
                if (prey.m_netController == controller)
                {
                    // C4 - ghosts were multiplying really fast
                    GameObject.Destroy(prey.gameObject);
                }
            }

            if (m_firstGame && (HopperNetwork.GetPlayerCount() == 0))
            {
                m_UIJoin.SetActive(true);
                m_UIInstructions.SetActive(false);
            }
        }

        //Find controller if it was a predator
        GameObject[] predators = GameObject.FindGameObjectsWithTag(TAG_PREDATOR);
        for (int predatorIndex = 0; predatorIndex < predators.Length; ++predatorIndex)
        {
            PredatorController predator = predators[predatorIndex].GetComponent <PredatorController>();
            if (predator != null)
            {
                if (predator.m_netController == controller)
                {
                    Destroy(predator);
                    return;
                }
            }
        }
    }
Пример #12
0
    //-------------------------------------------------------------------
    public void UpdateDebugText()
    {
        if (DebugText == null)
        {
            return;
        }

        DebugText.gameObject.SetActive(true);
        VirtualNetworkController controller = HopperNetwork.GetMyController();

        if (controller == null)
        {
            DebugText.text = "No Controller";
            return;
        }

        string str = "";

        str           += "Ready: " + (controller.ClientIsReady ? "Y" : "N") + "\n";
        str           += "Game: " + (controller.IsInGame() ? "Y" : "N") + "\n";
        str           += "Wolf: " + (controller.IsWolf ? "Y" : "N") + "\n";
        DebugText.text = str;
    }
Пример #13
0
    //-------------------------------------------------------------------
    public void UpdateLobby()
    {
        // this state, just wait around until server tells us to move on
        VirtualNetworkController control = HopperNetwork.GetMyController();

        if (control.ConsumeAllActions())
        {
            ToggleReady();
        }

        if (Controller.IsInGame())
        {
            SetState(eClientState.IN_GAME);
        }

        if (Controller.ClientIsReady)
        {
            ActionImage.sprite = ReadyBunny;
        }
        else
        {
            ActionImage.sprite = SleepyBunny;
        }
    }
Пример #14
0
    //---------------------------------------------------------------------
    // Update is called once per frame
    void Update()
    {
        if ((Application.platform == RuntimePlatform.WindowsEditor) || (Application.platform == RuntimePlatform.WindowsEditor))
        {
            VirtualNetworkController controller = HopperNetwork.GetMyController();

            if (controller != null)
            {
                float x      = Input.GetAxis("Horizontal");
                float y      = Input.GetAxis("Vertical");
                bool  action = Input.GetButtonDown("Fire1");

                Vector2 move = new Vector2(x, y);
                if (move.sqrMagnitude > 1.0f)
                {
                    move.Normalize();
                }


                UpdateMovementKnib(move);
                controller.SetMovement(move);

                if (action)
                {
                    DoAction();
                }
            }
        }

        if (!Input.touchSupported)
        {
            // fake touch
            if (Input.GetMouseButton(0) && (!HackActionDown || (ActiveFingerID >= 0)))
            {
                HackActionDown = true;
                Touch touch = new Touch();
                touch.fingerId = 1;
                if (ActiveFingerID == -1)
                {
                    touch.phase = TouchPhase.Began;
                }
                else
                {
                    touch.phase = TouchPhase.Moved;
                }

                touch.position = Input.mousePosition;
                ProcessTouch(touch);
            }
            else if (HackActionDown && !Input.GetMouseButton(0))
            {
                Touch touch = new Touch();
                touch.phase    = TouchPhase.Ended;
                touch.fingerId = ActiveFingerID;
                touch.position = Input.mousePosition;
                ProcessTouch(touch);
                HackActionDown = false;
            }
        }

        if (Input.touches.Length > 0)
        {
            for (int i = 0; i < Input.touches.Length; ++i)
            {
                ProcessTouch(Input.touches[i]);
            }
        }
    }
Пример #15
0
 //-------------------------------------------------------------------
 private void Start()
 {
     VirtualController = GetComponent <VirtualNetworkController>();
 }