コード例 #1
0
ファイル: RingMenu.cs プロジェクト: Hotrian/RingMenuExample
    public void Awake()
    {
        if (Instance != null)
        {
            Destroy(this);
        }

        Instance = this;
    }
コード例 #2
0
ファイル: MenuSelection.cs プロジェクト: seandyer/MenuOfLoci
 // Use this for initialization
 void Start()
 {
     if (scriptObject != null) {
         inputDetector = (InputDetector)scriptObject.GetComponent ("InputDetector");
         ringMenu = (RingMenu)scriptObject.GetComponent ("RingMenu");
     }
     if (userObject != null) {
         startingPosition = userObject.transform.position;
     }
 }
コード例 #3
0
 // Use this for initialization
 void Start()
 {
     if (scriptObject != null)
     {
         inputDetector = (InputDetector)scriptObject.GetComponent("InputDetector");
         ringMenu      = (RingMenu)scriptObject.GetComponent("RingMenu");
     }
     if (userObject != null)
     {
         startingPosition = userObject.transform.position;
     }
 }
コード例 #4
0
    public void _SliderValueChange()
    {
        if (ringMenu_Manager != null)
        {
            ringMenu_Manager._OnSelected -= RingMenu_Manager__OnSelected;
            ringMenu_Manager._OnEnter    -= RingMenu_Manager__OnEnter;
            ringMenu_Manager._OnExit     -= RingMenu_Manager__OnExit;
        }

        DestroyImmediate(ringMenu);

        int R0_B = (int)_sld_anneau0_btn.value;
        int R1_B = (int)_sld_anneau1_btn.value;
        int R2_B = (int)_sld_anneau2_btn.value;
        int R3_B = (int)_sld_anneau3_btn.value;
        int R4_B = (int)_sld_anneau4_btn.value;

        int nbrButtons = R0_B + R1_B + R2_B + R3_B + R4_B;

        _txt_btns.text = nbrButtons + " boutons";

        colors = SetColors(nbrButtons, false, false, 0.8f);

        float R0_R  = _sld_anneau0_taille.value;
        float R1_R  = _sld_anneau1_taille.value;
        float R2_R  = _sld_anneau2_taille.value;
        float R3_R  = _sld_anneau3_taille.value;
        float R4_R  = _sld_anneau4_taille.value;
        float marge = _sld_marge.value;

        Font arial = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;

        try
        {
            List <int> btns = new List <int> {
                R0_B, R1_B, R2_B, R3_B, R4_B
            };
            List <float> epaisseurs = new List <float> {
                R0_R, R1_R, R2_R, R3_R, R4_R
            };
            List <Color[]> couleurs = new List <Color[]> {
                colors, colors, colors, colors, colors
            };

            //Dictionary<int, Dictionary<int, Bouton>> boutons = new Dictionary<int, Dictionary<int, Bouton>>();
            List <Dictionary <int, Bouton> > boutons = new List <Dictionary <int, Bouton> >();

            //int k = 0;
            foreach (int ring_count in btns)
            {
                boutons.Add(new Dictionary <int, Bouton>());
                //boutons.Add(k, new Dictionary<int, Bouton>());
                for (int i = 0; i < ring_count; i++)
                {
                    Bouton bouton = new Bouton();
                    bouton.index                      = i;
                    bouton.name                       = i.ToString();
                    bouton.label                      = "";// RandomString(15);// + "\n" + RandomString(15);
                    bouton.label_color                = RingButton_Manager.ColorIntensity(colors[i], 0.2f);
                    bouton.label_font                 = arial;
                    bouton.label_fontStyle            = FontStyle.Bold;
                    bouton.label_fontSize             = 30;
                    bouton.label_resizeTextForBestFit = true;

                    bouton.icone = (Texture2D)textures[i];

                    boutons[boutons.Count - 1].Add(i, bouton);
                    //boutons[k].Add(i, bouton);
                }
                //k++;
            }

            //ringMenu = RingMenu._DrawRingMenu(btns, epaisseurs, marge, couleurs, null);
            ringMenu         = RingMenu._DrawRingMenu(boutons, epaisseurs, marge, couleurs);
            ringMenu_Manager = ringMenu.GetComponent <RingMenu_Manager>();

            ringMenu_Manager._OnSelected += RingMenu_Manager__OnSelected;
            ringMenu_Manager._OnEnter    += RingMenu_Manager__OnEnter;
            ringMenu_Manager._OnExit     += RingMenu_Manager__OnExit;

            _txt_debug.text = "";
        }
        catch (Exception ex)
        {
#if UNITY_EDITOR
            Debug.LogError(ex);
#else
            _txt_debug.text = ex.Message + "\n\n" + ex.StackTrace;
#endif
        }

        ringMenu.transform.SetPositionAndRotation(Spawn.transform.position, Spawn.transform.rotation);
        ringMenu.transform.localScale = Spawn.transform.localScale;
    }
コード例 #5
0
    void Draw()
    {
        if (Boutons.Length == 0)
        {
            //reset
            DestroyImmediate(ringMenu);
            return;
        }

        int    nbrbuttons = 0;
        Anneau a          = new Anneau(anneau_index, r_interne, r_externe, marge);

        foreach (RingButton_EditorMode item in Boutons)
        {
            if (item == null || !item.visible)
            {
                continue;
            }
            item.button_index_on_ring_int = nbrbuttons;
            item.name = nbrbuttons.ToString();
            a.butons_on_ring.Add(nbrbuttons, item);
            nbrbuttons++;
        }

        if (nbrbuttons == 0)
        {
            return;
        }

        Color[] colors = null;
        if (setDefaultColors)
        {
            colors = SetColors(nbrbuttons, randomColors, distributeColors, 0.8f);
        }

        Font arial = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;

        foreach (RingButton_EditorMode item in a.butons_on_ring.Values)
        {
            if (setDefaultColors)
            {
                item.button_color = colors[item.button_index_on_ring_int];
            }

            item.label.label_font = arial;
        }

        if (setDefaultColors)
        {
            setDefaultColors = false;
        }

        if (ringMenu_Manager != null)
        {
            DestroyImmediate(ringMenu);
        }

        Dictionary <int, Anneau> anneaux = new Dictionary <int, Anneau>();

        anneaux.Add(a.index, a);

        //C'est parti :
        ringMenu                         = RingMenu._DrawRingMenu(anneaux, angle_initial, sens_horaire);
        ringMenu.name                    = "menu";
        ringMenu.transform.parent        = gameObject.transform;
        ringMenu.transform.localPosition = Vector3.zero;
        ringMenu_Manager                 = ringMenu.GetComponent <RingMenu_Manager>();

        foreach (var item in a.butons_on_ring.Values)
        {
            item.ringButtonManager._SetNormalColor(item.ringButtonManager.gameObject);
        }
    }
コード例 #6
0
        void Update()
        {
            if (!photonView.IsMine)
            {
                RefreshMultiplayerState();
                return;
            }

            float tHmove = Input.GetAxisRaw("Horizontal");
            float tVmove = Input.GetAxisRaw("Vertical");

            bool sprint = Input.GetKey(KeyCode.LeftShift);
            bool jump   = Input.GetKeyDown(KeyCode.Space);
            bool crouch = Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl);

            bool isGrounded  = Physics.Raycast(GroundDetector.position, Vector3.down, 0.15f, Ground);
            bool isSprinting = sprint && tVmove > 0;
            bool isJumping   = jump && isGrounded;
            bool isCrouching = crouch && !isSprinting && !isJumping && isGrounded;

            if (isCrouching)
            {
                photonView.RPC("SetCrouch", RpcTarget.All, !crouched);
            }

            if (isJumping)
            {
                if (crouched)
                {
                    photonView.RPC("SetCrouch", RpcTarget.All, false);
                }
                Rig.AddForce(Vector3.up * JumpForce);
                Debug.Log("Is Jumping");
            }

            if (Input.GetKeyDown(KeyCode.U))
            {
                takeDamage(100);
            }


            if (sliding)
            {
                HeadBob(movementCounter, 0.09f, 0.05f);
                weaponParent.localPosition =
                    Vector3.Lerp(weaponParent.localPosition, targetWeaponBobPosition, Time.deltaTime * 10f);
            }
            else if (tHmove == 0 && tVmove == 0)
            {
                HeadBob(idleCounter, 0.025f, 0.025f);
                idleCounter += Time.deltaTime;
                weaponParent.localPosition =
                    Vector3.Lerp(weaponParent.localPosition, targetWeaponBobPosition, Time.deltaTime * 2f);
            }
            else if (!isSprinting && !crouched)
            {
                HeadBob(movementCounter, 0.035f, 0.035f);
                movementCounter           += Time.deltaTime * 3f;
                weaponParent.localPosition =
                    Vector3.Lerp(weaponParent.localPosition, targetWeaponBobPosition, Time.deltaTime * 6f);
            }
            else if (crouched)
            {
                HeadBob(movementCounter, 0.02f, 0.02f);
                movementCounter           += Time.deltaTime * 1.75f;
                weaponParent.localPosition =
                    Vector3.Lerp(weaponParent.localPosition, targetWeaponBobPosition, Time.deltaTime * 6f);
            }
            else
            {
                HeadBob(movementCounter, 0.09f, 0.05f);
                movementCounter           += Time.deltaTime * 3f;
                weaponParent.localPosition =
                    Vector3.Lerp(weaponParent.localPosition, targetWeaponBobPosition, Time.deltaTime * 10f);
            }


            refreshHealthbar();
            weapon.RefreshAmmo(uiAmmo);

            if (Input.GetKey(KeyCode.F) && !activeRingMenu)
            {
                Debug.Log("Key F pressed");
                time += Time.deltaTime;
                Debug.Log(time);
                if (time > timeSpan)
                {
                    Debug.Log("Pressed for 0.1 s");
                    Transform  tSpawn = transform.Find("Cameras/Player Camera");
                    RaycastHit tHit   = new RaycastHit();
                    if (Physics.Raycast(tSpawn.position, tSpawn.forward, out tHit, 1000f, isPing))
                    {
                        activeRingMenu              = true;
                        AnswerMenuInstance          = Instantiate(AnswerMenuPrefab, FindObjectOfType <Canvas>().transform);
                        AnswerMenuInstance.callback = AnswerClick;
                        Debug.Log("Created answerRingMenu");
                    }
                    else
                    {
                        activeRingMenu            = true;
                        MainMenuInstance          = Instantiate(MainMenuPrefab, FindObjectOfType <Canvas>().transform);
                        MainMenuInstance.callback = MenuClick;
                        Debug.Log("Created mainRingMenu");
                    }
                }
            }

            if (Input.GetKeyUp(KeyCode.F))
            {
                if (time < timeSpan)
                {
                    photonView.RPC("PingWaypoint", RpcTarget.All);
                }

                time = 0f;
            }
        }
コード例 #7
0
 void Start()
 {
     MyPlayer       = FindObjectOfType <PlayerController>();
     RingMenuScript = RingMenu.GetComponent <RingMenu>();
 }
コード例 #8
0
ファイル: Controller.cs プロジェクト: vivogd/unity_test
    // Update is called once per frame
    void Update()
    {
        if (Mode == ControllerMode.Build)
        {
            if (Input.GetKeyDown(KeyCode.Q))
            {
                SetMode(ControllerMode.Menu);
                MainMenuInstance          = Instantiate(MainMenuPrefab, FindObjectOfType <Canvas>().transform);
                MainMenuInstance.callback = MenuClick;
            }
        }

        if (Mode == ControllerMode.Play)
        {
            if (Input.GetKeyDown(KeyCode.Tab))
            {
                SetMode(ControllerMode.Build);
            }
        }
        else if (Mode == ControllerMode.Build || Mode == ControllerMode.Menu)
        {
            if (Input.GetKeyDown(KeyCode.Tab))
            {
                SetMode(ControllerMode.Play);
            }
        }

        if (Mode == ControllerMode.Build || Mode == ControllerMode.Play)
        {
            //scroll to zoom
            CameraDistance = Mathf.Clamp(CameraDistance + Input.mouseScrollDelta.y, 0, 10);

            //input
            InputRotationX = InputRotationX + Input.GetAxis("Mouse X") * RotationSpeed * Time.deltaTime % 360f;
            InputRotationY = Mathf.Clamp(InputRotationY - Input.GetAxis("Mouse Y") * RotationSpeed * Time.deltaTime, -88f, 88f);

            //left and forward
            var characterForward = Quaternion.AngleAxis(InputRotationX, Vector3.up) * Vector3.forward;
            var characterLeft    = Quaternion.AngleAxis(InputRotationX + 90, Vector3.up) * Vector3.forward;

            //look and run direction
            var runDirection = characterForward * Input.GetAxisRaw("Vertical") + characterLeft * Input.GetAxisRaw("Horizontal");
            LookDirection = Quaternion.AngleAxis(InputRotationY, characterLeft) * characterForward;

            //set player values
            Player.Input.RunX  = runDirection.x;
            Player.Input.RunZ  = runDirection.z;
            Player.Input.LookX = LookDirection.x;
            Player.Input.LookZ = LookDirection.z;
            Player.Input.Jump  = Input.GetKey(KeyCode.Space);

            CharacterPivot = Quaternion.AngleAxis(InputRotationX, Vector3.up) * CameraPivot;
        }
        else
        {
            //set player values
            Player.Input.RunX  = 0;
            Player.Input.RunZ  = 0;
            Player.Input.LookX = 0;
            Player.Input.LookZ = 0;
            Player.Input.Jump  = false;
        }
    }