コード例 #1
0
            public void Bind(UnityEvent @event)
            {
#if UNITY_EDITOR
                if (value == null)
                {
                    System.Reflection.MethodInfo targetinfo = UnityEvent.GetValidMethodInfo(target, setMethodName, new Type[0]);
                    if (targetinfo == null)
                    {
                        Debug.LogError("no method " + setMethodName + "() in " + target.ToString());
                    }
                    UnityAction action = Delegate.CreateDelegate(typeof(UnityAction), target, targetinfo, false) as UnityAction;
                    UnityEventTools.AddVoidPersistentListener(@event, action);
                }
                else if (value is int)
                {
                    UnityEventTools.AddIntPersistentListener(@event, GetAction <int>(target, setMethodName), (int)value);
                }
                else if (value is float)
                {
                    UnityEventTools.AddFloatPersistentListener(@event, GetAction <float>(target, setMethodName), (float)value);
                }
                else if (value is string)
                {
                    UnityEventTools.AddStringPersistentListener(@event, GetAction <string>(target, setMethodName), (string)value);
                }
                else if (value is bool)
                {
                    UnityEventTools.AddBoolPersistentListener(@event, GetAction <bool>(target, setMethodName), (bool)value);
                }
                else if (value is GameObject)
                {
                    Bind <GameObject>(@event);
                }
                else if (value is Transform)
                {
                    Bind <Transform>(@event);
                }
                else
                {
                    Debug.LogError("unable to assign " + value.GetType());
                }
#else
                System.Reflection.MethodInfo targetinfo = UnityEvent.GetValidMethodInfo(target, setMethodName, new Type[0]);
                @event.AddListener(() => targetinfo.Invoke(target, new object[] { value }));
#endif
            }
    private void ConfigKeyPad()
    {
        var buttons = keyPadGameObject.GetComponentsInChildren <InGameSimpleButtonBolt>();

        foreach (var button in buttons)
        {
            CleanPersistentListeners(button.onEventReceived);

            var tweenMove = button.GetComponent <TweenMove>();

            UnityEventTools.AddPersistentListener(button.onEventReceived, tweenMove.Play);

            var inGameInputReceiver = keyPadGameObject.GetComponent <InGameInputReceiver>();

            UnityEventTools.AddStringPersistentListener(button.onEventReceived, inGameInputReceiver.ReceiveInput, button.Id.ToString());

            EditorUtility.SetDirty(button);
        }
    }
コード例 #3
0
        private static void CreateAdsButton(string placementId)
        {
            EditorApplication.ExecuteMenuItem("GameObject/UI/Button");
            var buttonGameObject = Selection.activeGameObject;
            var rectTransform    = buttonGameObject.transform as RectTransform;

            if (rectTransform != null)
            {
                rectTransform.anchoredPosition = Vector2.zero;
                rectTransform.sizeDelta        = new Vector2(200, 50);
            }
            var        button         = buttonGameObject.GetComponent <Button>();
            var        unityAdsHelper = Object.FindObjectOfType <UnityAdsHelper>();
            GameObject helperGameObject;

            if (unityAdsHelper == null)
            {
                helperGameObject = new GameObject("UnityAdsHelper");
                unityAdsHelper   = helperGameObject.AddComponent <UnityAdsHelper>();
            }
            else
            {
                helperGameObject = unityAdsHelper.gameObject;
            }
            var targetInfo = UnityEventBase.GetValidMethodInfo(
                unityAdsHelper, "ShowVideoAds",
                new Type[] { typeof(string) }
                );
            var action = Delegate.CreateDelegate(
                typeof(UnityAction <string>),
                unityAdsHelper,
                targetInfo,
                false
                ) as UnityAction <string>;

            UnityEventTools.AddStringPersistentListener(button.onClick, action, placementId);

            // Change button text
            buttonGameObject.GetComponentInChildren <Text>().text = $"Show {placementId} ads";

            // Set selection
            Selection.activeGameObject = helperGameObject;
        }
コード例 #4
0
        //
        void createToggle()
        {
            t = PrefabUtility.InstantiatePrefab(w.prefabs[0]) as GameObject;
            // add name to new weapon
            string ttt = toggleName;

            t.name = ttt;
            toggles.Add(t.name); // add new toggle to "Weapons" ScriptableObject.
                                 //t = new
            GameObject WeaponsPanel = GameObject.Find("WeaponsPanel");

            t.transform.SetParent(WeaponsPanel.transform);
            WeaponsPanel.GetComponent <MyToggleGroup>().toggles.Add(t.GetComponent <Toggle>());
            int       chc = t.transform.childCount;
            Transform Chc = t.transform.GetChild(chc - 1);

            Chc.GetComponent <Image>().sprite = ToggleWeaponImage;
            Toggle               tuggen  = t.GetComponent <Toggle>();
            SelectionMenu        SelMenu = FindObjectOfType <SelectionMenu>();
            UnityAction <string> action  = new UnityAction <string>(SelMenu.SelectWeapon);

            UnityEventTools.AddStringPersistentListener(tuggen.onValueChanged, action, WeaponToggleNumber);
            PrefabUtility.DisconnectPrefabInstance(t);
        }
コード例 #5
0
    static void GenerateUdonMenu()
    {
        //Declare some variables + settings.
        Navigation no_nav = new Navigation();

        no_nav.mode = Navigation.Mode.None;

        //declare toggle resource settings
        DefaultControls.Resources toggleresources = new DefaultControls.Resources();
        //Set the Toggle Background Image someBgSprite;
        toggleresources.standard = AssetDatabase.GetBuiltinExtraResource <Sprite> ("UI/Skin/InputFieldBackground.psd");
        //Set the Toggle Checkmark Image someCheckmarkSprite;
        toggleresources.checkmark = AssetDatabase.GetBuiltinExtraResource <Sprite> ("UI/Skin/Checkmark.psd");
        DefaultControls.Resources rootpanelresources = new DefaultControls.Resources();
        rootpanelresources.background = AssetDatabase.GetBuiltinExtraResource <Sprite> ("UI/Skin/Background.psd");
        DefaultControls.Resources txtresources = new DefaultControls.Resources();

        int layer = 8;
        //int rowoffset=860;
        int columnoffset = 200;

        int rowseperation    = 100;
        int columnseperation = 1000;
        //int togglesizedelta=80;
        int     numberpercolumn     = 14;
        int     menusizex           = 5300;
        int     menusizey           = 1600;
        int     headersizey         = 60;
        int     textpadding         = 10;
        int     headerbuttonspacing = 100;
        int     buttonsizey         = 100;
        int     buttonsizex         = 900;
        int     menubuttonystart    = textpadding + headersizey + buttonsizey + 80;
        Vector2 backbuttonsize      = new Vector2(menusizey - headersizey - textpadding - headerbuttonspacing, buttonsizey);

        Vector2 buttonsize       = new Vector2(buttonsizex, buttonsizey);
        Vector2 menusize         = new Vector2(menusizex, menusizey);
        Vector3 menurootposition = new Vector3(1.5f, 0, 16);
        Vector3 canvasscale      = new Vector3(.001f, .001f, .001f);
        Vector2 zerovector2      = new Vector2(0, 0);
        Vector3 zerovector3      = new Vector3(0, 0, 0);

        /*****************************************
        *  START OF PROGRAM
        *****************************************/

        GameObject menuroot = new GameObject("Udon Menu System");         //creates a new "Menu Root gameobject which will be the parent of all newly created objects in the script.

        menuroot.transform.position = menurootposition;
        menuroot.GetOrAddComponent <UdonBehaviour>().programSource = AssetDatabase.LoadAssetAtPath <AbstractUdonProgramSource>("Assets/UdonSharpSourceCode/MenuControl.asset");
        //menuroot.transform.SetParent(parent.transform, false);
        menuroot.layer = layer;


        GameObject videocontainer = GameObject.Find("/VideoCanvas");

/*
 *              GameObject videocontainer = new GameObject("Video Container"); //container go to hold all videos. Allows a world option that turns on/off videos completely.
 *              videocontainer.transform.position = new Vector3(-3.75f, 1, 0);
 *              videocontainer.transform.SetParent(menuroot.transform, false);
 *              videocontainer.layer = layer;
 */

        GameObject rootcanvas = new GameObject("Root Canvas");

        rootcanvas.transform.SetParent(menuroot.transform, false);
        rootcanvas.layer = layer;
        rootcanvas.transform.localScale = canvasscale;
        rootcanvas.AddComponent <RectTransform> ();
        rootcanvas.GetComponent <RectTransform> ().localPosition = zerovector3;
        rootcanvas.GetComponent <RectTransform> ().sizeDelta     = menusize;
        rootcanvas.GetComponent <RectTransform> ().anchorMax     = zerovector2;
        rootcanvas.GetComponent <RectTransform> ().anchorMin     = zerovector2;
        rootcanvas.GetComponent <RectTransform> ().pivot         = zerovector2;
        rootcanvas.AddComponent <Canvas> ();        //adds canvas to root canvas gameobject
        rootcanvas.GetComponent <Canvas> ().renderMode = RenderMode.WorldSpace;
        rootcanvas.AddComponent <CanvasScaler>();
        rootcanvas.AddComponent <GraphicRaycaster>();
        rootcanvas.AddComponent <VRCUiShape>();        //wtf
        ToggleGroup rootcanvastogglegroup = rootcanvas.AddComponent <ToggleGroup>();

        rootcanvastogglegroup.allowSwitchOff = true;
        GameObject rootpanel = DefaultControls.CreatePanel(rootpanelresources);

        rootpanel.transform.SetParent(rootcanvas.transform, false);
        rootpanel.layer = layer;
        rootpanel.GetComponent <RectTransform> ().sizeDelta = menusize;
        rootpanel.GetComponent <RectTransform> ().anchorMax = zerovector2;
        rootpanel.GetComponent <RectTransform> ().anchorMin = zerovector2;
        rootpanel.GetComponent <RectTransform> ().pivot     = zerovector2;
        rootpanel.GetComponent <Image> ().color             = new Color(0.07f, 0.07f, 0.07f, 1); //gets rid of transparency - also can change panel color if I want here. 1=255.

        /*
         * if(mode=="Global"){
         *      rootpanel.GetComponent<Image> ().color = new Color(1,.90f,.90f,1); //gets rid of transparency - also can change panel color if I want here. 1=255.
         * }else{
         *      rootpanel.GetComponent<Image> ().color = new Color(.90f,.90f,1,1); //gets rid of transparency - also can change panel color if I want here. 1=255.
         * }
         *
         */
        GameObject menubuttons = new GameObject("Menu Buttons");

        menubuttons.transform.SetParent(rootcanvas.transform, false);
        menubuttons.layer = layer;

        GameObject menubuttonsheader = DefaultControls.CreateText(txtresources);

        menubuttonsheader.transform.SetParent(rootcanvas.transform, false);
        menubuttonsheader.name  = "Menu Header";
        menubuttonsheader.layer = layer;
        menubuttonsheader.GetComponent <Text> ().text                      = "Header";
        menubuttonsheader.GetComponent <Text> ().font                      = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
        menubuttonsheader.GetComponent <Text> ().fontStyle                 = FontStyle.Bold;
        menubuttonsheader.GetComponent <Text> ().fontSize                  = 50;
        menubuttonsheader.GetComponent <Text> ().color                     = Color.white;
        menubuttonsheader.GetComponent <Text> ().alignment                 = TextAnchor.MiddleLeft;
        menubuttonsheader.GetComponent <RectTransform> ().sizeDelta        = new Vector2(menusizex, headersizey);
        menubuttonsheader.GetComponent <RectTransform> ().anchoredPosition = new Vector2(textpadding, menusizey - headersizey - textpadding);
        menubuttonsheader.GetComponent <RectTransform> ().anchorMax        = zerovector2;
        menubuttonsheader.GetComponent <RectTransform> ().anchorMin        = zerovector2;
        menubuttonsheader.GetComponent <RectTransform> ().pivot            = zerovector2;

        GameObject menubuttonssubheader = DefaultControls.CreateText(txtresources);

        menubuttonssubheader.transform.SetParent(rootcanvas.transform, false);
        menubuttonssubheader.name  = "SubHeader";
        menubuttonssubheader.layer = layer;
        menubuttonssubheader.GetComponent <Text> ().text                      = "SubHeader";
        menubuttonssubheader.GetComponent <Text> ().font                      = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
        menubuttonssubheader.GetComponent <Text> ().fontStyle                 = FontStyle.Bold;
        menubuttonssubheader.GetComponent <Text> ().fontSize                  = 50;
        menubuttonssubheader.GetComponent <Text> ().color                     = Color.white;
        menubuttonssubheader.GetComponent <Text> ().alignment                 = TextAnchor.MiddleLeft;
        menubuttonssubheader.GetComponent <RectTransform> ().sizeDelta        = new Vector2(menusizex, headersizey);
        menubuttonssubheader.GetComponent <RectTransform> ().anchoredPosition = new Vector2(textpadding, menusizey - (headersizey * 2) - textpadding);
        menubuttonssubheader.GetComponent <RectTransform> ().anchorMax        = zerovector2;
        menubuttonssubheader.GetComponent <RectTransform> ().anchorMin        = zerovector2;
        menubuttonssubheader.GetComponent <RectTransform> ().pivot            = zerovector2;

/*
 *              GameObject menubuttonsheader = new GameObject("Menu Header");
 *              menubuttonsheader.transform.SetParent (rootcanvas.transform, false);
 *              menubuttonsheader.layer = layer;
 *              menubuttonsheader.AddComponent<CanvasRenderer>();
 *              menubuttonsheader.AddComponent<TextMeshProUGUI> ().text="Header";
 *              menubuttonsheader.GetComponent<TextMeshProUGUI> ().fontStyle = FontStyles.Bold;
 *              menubuttonsheader.GetComponent<TextMeshProUGUI> ().fontSize = 50;
 *              menubuttonsheader.GetComponent<TextMeshProUGUI> ().color = Color.white;
 *              menubuttonsheader.GetComponent<TextMeshProUGUI> ().alignment = TextAlignmentOptions.Left;
 *              menubuttonsheader.GetComponent<TextMeshProUGUI> ().autoSizeTextContainer=true;
 *              menubuttonsheader.GetComponent<TextMeshProUGUI> ().fontSizeMax=50;
 *              menubuttonsheader.GetComponent<TextMeshProUGUI> ().fontSizeMin=18;
 *              menubuttonsheader.GetComponent<RectTransform> ().sizeDelta = new Vector2 (menusizex, headersizey);
 *              menubuttonsheader.GetComponent<RectTransform> ().anchoredPosition = new Vector2 (textpadding, menusizey-headersizey-textpadding);
 *              menubuttonsheader.GetComponent<RectTransform> ().anchorMax = zerovector2;
 *              menubuttonsheader.GetComponent<RectTransform> ().anchorMin = zerovector2;
 *              menubuttonsheader.GetComponent<RectTransform> ().pivot = zerovector2;
 *
 * GameObject menubuttonssubheader = DefaultControls.CreateText(txtresources);
 *              menubuttonssubheader.transform.SetParent (rootcanvas.transform, false);
 *              menubuttonssubheader.name="Menu SubHeader";
 *              menubuttonssubheader.layer = layer;
 *              DestroyImmediate(menubuttonssubheader.GetComponent<Text> ());
 *              menubuttonssubheader.GetOrAddComponent<TextMeshProUGUI> ().text="SubHeader";
 *              menubuttonssubheader.GetComponent<TextMeshProUGUI> ().text = "SubHeader";
 *              //menubuttonssubheader.GetComponent<TextMesh> ().font = Resources.GetBuiltinResource (typeof(Font), "Arial.ttf") as Font;
 *              menubuttonssubheader.GetComponent<TextMeshProUGUI> ().font = Resources.Load("LiberationSans SDF", typeof(TMP_FontAsset)) as TMP_FontAsset;
 *              menubuttonssubheader.GetComponent<TextMeshProUGUI> ().fontStyle = FontStyles.Bold;
 *              menubuttonssubheader.GetComponent<TextMeshProUGUI> ().fontSize = 50;
 *              menubuttonssubheader.GetComponent<TextMeshProUGUI> ().color = Color.white;
 *              menubuttonssubheader.GetComponent<TextMeshProUGUI> ().alignment = TextAlignmentOptions.Left;
 *              menubuttonssubheader.GetComponent<TextMeshProUGUI> ().autoSizeTextContainer=true;
 *              menubuttonssubheader.GetComponent<TextMeshProUGUI> ().fontSizeMax=50;
 *              menubuttonssubheader.GetComponent<TextMeshProUGUI> ().fontSizeMin=18;
 *              menubuttonssubheader.GetComponent<RectTransform> ().sizeDelta = new Vector2 (menusizex, headersizey);
 *              menubuttonssubheader.GetComponent<RectTransform> ().anchoredPosition = new Vector2 (textpadding, menusizey-(headersizey*2)-textpadding);
 *              menubuttonssubheader.GetComponent<RectTransform> ().anchorMax = zerovector2;
 *              menubuttonssubheader.GetComponent<RectTransform> ().anchorMin = zerovector2;
 *              menubuttonssubheader.GetComponent<RectTransform> ().pivot = zerovector2;
 */
/*****************************************
*  Regenerates Next/Prev Button Events
*****************************************/

        GameObject prevbutton = GameObject.Find("/Signing Avatars/Canvas/PrevButton");
        GameObject nextbutton = GameObject.Find("/Signing Avatars/Canvas/NextButton");

        prevbutton.GetComponent <Button>().onClick = new Button.ButtonClickedEvent();
        nextbutton.GetComponent <Button>().onClick = new Button.ButtonClickedEvent();
        UnityEventTools.AddStringPersistentListener(prevbutton.GetOrAddComponent <Button>().onClick,                                                          //the button/toggle that triggers the action
                                                    System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>() //the target of the action
                                                                                   , "SendCustomEvent") as UnityAction <string>, "PrevB");

        UnityEventTools.AddStringPersistentListener(nextbutton.GetOrAddComponent <Button>().onClick,                                                          //the button/toggle that triggers the action
                                                    System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>() //the target of the action
                                                                                   , "SendCustomEvent") as UnityAction <string>, "NextB");


/*****************************************
*  Regenerates Quiz Button Events
*****************************************/

        GameObject quizbuttona   = GameObject.Find("/Signing Avatars/Canvas/QuizPanel/A");
        GameObject quizbuttonb   = GameObject.Find("/Signing Avatars/Canvas/QuizPanel/B");
        GameObject quizbuttonc   = GameObject.Find("/Signing Avatars/Canvas/QuizPanel/C");
        GameObject quizbuttond   = GameObject.Find("/Signing Avatars/Canvas/QuizPanel/D");
        GameObject quizbuttonbig = GameObject.Find("/Signing Avatars/Canvas/QuizPanel/BigButton");

        quizbuttona.GetComponent <Button>().onClick   = new Button.ButtonClickedEvent();
        quizbuttonb.GetComponent <Button>().onClick   = new Button.ButtonClickedEvent();
        quizbuttonc.GetComponent <Button>().onClick   = new Button.ButtonClickedEvent();
        quizbuttond.GetComponent <Button>().onClick   = new Button.ButtonClickedEvent();
        quizbuttonbig.GetComponent <Button>().onClick = new Button.ButtonClickedEvent();
        UnityEventTools.AddStringPersistentListener(quizbuttona.GetOrAddComponent <Button>().onClick,                                                         //the button/toggle that triggers the action
                                                    System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>() //the target of the action
                                                                                   , "SendCustomEvent") as UnityAction <string>, "QuizA");
        UnityEventTools.AddStringPersistentListener(quizbuttonb.GetOrAddComponent <Button>().onClick,                                                         //the button/toggle that triggers the action
                                                    System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>() //the target of the action
                                                                                   , "SendCustomEvent") as UnityAction <string>, "QuizB");
        UnityEventTools.AddStringPersistentListener(quizbuttonc.GetOrAddComponent <Button>().onClick,                                                         //the button/toggle that triggers the action
                                                    System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>() //the target of the action
                                                                                   , "SendCustomEvent") as UnityAction <string>, "QuizC");
        UnityEventTools.AddStringPersistentListener(quizbuttond.GetOrAddComponent <Button>().onClick,                                                         //the button/toggle that triggers the action
                                                    System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>() //the target of the action
                                                                                   , "SendCustomEvent") as UnityAction <string>, "QuizD");
        UnityEventTools.AddStringPersistentListener(quizbuttonbig.GetOrAddComponent <Button>().onClick,                                                       //the button/toggle that triggers the action
                                                    System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>() //the target of the action
                                                                                   , "SendCustomEvent") as UnityAction <string>, "QuizBigButtonPushed");



/*****************************************
*  Regenerates Preferences Items
*****************************************/

        Toggle HandToggle = GameObject.Find("/Preferencesv2/Canvas/Left Panel/Hand Toggle").GetComponent <Toggle>();

        HandToggle.onValueChanged = new Toggle.ToggleEvent();
        UnityEventTools.AddStringPersistentListener(HandToggle.onValueChanged, System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>()
                                                                                                              , "SendCustomEvent") as UnityAction <string>, "ToggleHand");

        Toggle GlobalToggle = GameObject.Find("/Preferencesv2/Canvas/Left Panel/Global Mode").GetComponent <Toggle>();

        GlobalToggle.onValueChanged = new Toggle.ToggleEvent();
        UnityEventTools.AddStringPersistentListener(GlobalToggle.onValueChanged, System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>()
                                                                                                                , "SendCustomEvent") as UnityAction <string>, "ToggleGlobal");

        Toggle QuizToggle = GameObject.Find("/Preferencesv2/Canvas/Left Panel/Quiz Mode").GetComponent <Toggle>();

        QuizToggle.onValueChanged = new Toggle.ToggleEvent();
        UnityEventTools.AddStringPersistentListener(QuizToggle.onValueChanged, System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>()
                                                                                                              , "SendCustomEvent") as UnityAction <string>, "ToggleQuiz");

        Slider avatarscaleslider = GameObject.Find("/Preferencesv2/Canvas/Left Panel/Avatar Scale Slider").GetComponent <Slider>();

        avatarscaleslider.onValueChanged = new Slider.SliderEvent();
        UnityEventTools.AddStringPersistentListener(avatarscaleslider.onValueChanged, System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>()
                                                                                                                     , "SendCustomEvent") as UnityAction <string>, "AvatarScaleSliderValueChanged");

        Toggle DarkToggle = GameObject.Find("/Preferencesv2/Canvas/Right Panel/Dark Mode").GetComponent <Toggle>();

        DarkToggle.onValueChanged = new Toggle.ToggleEvent();
        UnityEventTools.AddStringPersistentListener(DarkToggle.onValueChanged, System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>()
                                                                                                              , "SendCustomEvent") as UnityAction <string>, "ToggleDark");



/*
 *
 *                                      GameObject prevbutton=createbutton2(parent:menubuttons, name:"PrevButton",
 *                                      sizedelta:new Vector2(625,100),localPosition:new Vector3 (-2125,600,-2000),
 *                                      text:"Previous Sign",txtsizedelta:new Vector2 (625, 100),txtanchoredPosition:new Vector2 (0,0), alignment:TextAnchor.MiddleCenter,
 *                                      nav:no_nav,layer:layer);
 *
 *                                              UnityEventTools.AddStringPersistentListener(prevbutton.GetOrAddComponent<Button>().onClick, //the button/toggle that triggers the action
 *                                              System.Delegate.CreateDelegate(typeof(UnityAction<string>), menuroot.GetOrAddComponent<UdonBehaviour>()//the target of the action
 *                                              , "SendCustomEvent") as UnityAction<string>,"PrevB");
 *
 *                                      GameObject nextbutton=createbutton2(parent:menubuttons, name:"NextButton",
 *                                      sizedelta:new Vector2(625,100),localPosition:new Vector3 (-1500,600,-2000),
 *                                      text:"Next Sign",txtsizedelta:new Vector2 (625, 100),txtanchoredPosition:new Vector2 (0,0), alignment:TextAnchor.MiddleCenter,
 *                                      nav:no_nav,layer:layer);
 *
 *                                              UnityEventTools.AddStringPersistentListener(nextbutton.GetOrAddComponent<Button>().onClick, //the button/toggle that triggers the action
 *                                              System.Delegate.CreateDelegate(typeof(UnityAction<string>), menuroot.GetOrAddComponent<UdonBehaviour>()//the target of the action
 *                                              , "SendCustomEvent") as UnityAction<string>,"NextB");
 *
 */

/*****************************************
*  Create the main array of buttons here
*****************************************/

        int menucolumn = 0;
        int menurow    = 0;

        for (int x = 0; x < 70; x++)
        {
            if (x != 0)
            {
                if (x % numberpercolumn == 0)                          //display 9 items per column
                {
                    menucolumn++;
                    menurow = 0;
                }
            }
            GameObject buttongo = createbutton2(parent: menubuttons, name: "Button " + (x), sizedelta: buttonsize,
                                                localPosition: new Vector2(columnoffset + (menucolumn * columnseperation), (menusizey - headersizey - textpadding - buttonsizey - 100 - (menurow * rowseperation))),
                                                text: "   Button " + (x), txtsizedelta: new Vector2(750, 100), txtanchoredPosition: new Vector2(32, 0),
                                                alignment: TextAnchor.MiddleLeft, nav: no_nav, layer: layer);
            //alignment:TextAlignmentOptions.Left


            UnityEventTools.AddStringPersistentListener(buttongo.GetOrAddComponent <Button>().onClick,                                                            //the button/toggle that triggers the action
                                                        System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>() //the target of the action
                                                                                       , "SendCustomEvent") as UnityAction <string>, "B" + (x));
            //var targetBehaviour = GameObject.Find("MyObject").GetComponent<UdonBehaviour>();
//						menuroot.GetOrAddComponent<UdonBehaviour>().publicVariables.TrySetVariableValue("",);
            //colors the buttons to indicate what's working and what's not.

            /*
             * if(x<2){
             *      var colors = b.colors;
             *      colors.normalColor = new Color32( 0xFF, 0xFF, 0x98, 0xFF ); //FF9898FF light yellow
             *      b.colors = colors;
             * }
             * if(x>=2){
             *      var colors = b.colors;
             *      colors.normalColor = new Color32( 0xFF, 0x98, 0x98, 0xFF ); //FF9898FF light red
             *      b.colors = colors;
             * }*/


//Don't forget to create the "selected" button with checkmark (optional)
//Use color-changing buttons to indicated currently selected.

/*
 *                                                      GameObject homeicongo = new GameObject("Home Icon");
 *                                                      homeicongo.transform.SetParent(buttongo.transform, false);
 *                                                      homeicongo.layer=layer;
 *                                                      homeicongo.AddComponent<RectTransform> ();
 *                                                      homeicongo.GetComponent<RectTransform> ().localPosition = new Vector3(450,68,0);
 *                                                      homeicongo.GetComponent<RectTransform> ().sizeDelta = new Vector2(64,64);
 *                                                      homeicongo.GetComponent<RectTransform> ().anchorMax = zerovector2;
 *                                                      homeicongo.GetComponent<RectTransform> ().anchorMin = zerovector2;
 *                                                      homeicongo.GetComponent<RectTransform> ().pivot = zerovector2;
 *                                                      Image homeicon= homeicongo.AddComponent<Image>();
 *                                                      homeicon.sprite = AssetDatabase.LoadAssetAtPath<Sprite>("Assets/Icons/homeicon3.png");
 */

            //5th value is VR index or regular 0=indexonly , 1=generalvr,2=both

            GameObject indexicongo = new GameObject("Index VR Icon");
            indexicongo.transform.SetParent(buttongo.transform, false);
            indexicongo.layer = layer;
            indexicongo.AddComponent <RectTransform> ();
            indexicongo.GetComponent <RectTransform> ().localPosition = new Vector3(450, 68, 0);
            indexicongo.GetComponent <RectTransform> ().sizeDelta     = new Vector2(64, 64);
            indexicongo.GetComponent <RectTransform> ().anchorMax     = zerovector2;
            indexicongo.GetComponent <RectTransform> ().anchorMin     = zerovector2;
            indexicongo.GetComponent <RectTransform> ().pivot         = zerovector2;
            Image indexicon = indexicongo.AddComponent <Image>();
            indexicon.sprite = AssetDatabase.LoadAssetAtPath <Sprite>("Assets/Icons/left_index_controllerdark.png");


            GameObject vricongo = new GameObject("Regular VR Icon");
            vricongo.transform.SetParent(buttongo.transform, false);
            vricongo.layer = layer;
            vricongo.AddComponent <RectTransform> ();
            vricongo.GetComponent <RectTransform> ().localPosition = new Vector3(450, 68, 0);
            vricongo.GetComponent <RectTransform> ().sizeDelta     = new Vector2(64, 64);
            vricongo.GetComponent <RectTransform> ().anchorMax     = zerovector2;
            vricongo.GetComponent <RectTransform> ().anchorMin     = zerovector2;
            vricongo.GetComponent <RectTransform> ().pivot         = zerovector2;
            Image vricon = vricongo.AddComponent <Image>();
            vricon.sprite = AssetDatabase.LoadAssetAtPath <Sprite>("Assets/Icons/left_htc_controllerdark.png");

            GameObject allvricongo = new GameObject("Both VR Icon");
            allvricongo.transform.SetParent(buttongo.transform, false);
            allvricongo.layer = layer;
            allvricongo.AddComponent <RectTransform> ();
            allvricongo.GetComponent <RectTransform> ().localPosition = new Vector3(450, 68, 0);
            allvricongo.GetComponent <RectTransform> ().sizeDelta     = new Vector2(64, 64);
            allvricongo.GetComponent <RectTransform> ().anchorMax     = zerovector2;
            allvricongo.GetComponent <RectTransform> ().anchorMin     = zerovector2;
            allvricongo.GetComponent <RectTransform> ().pivot         = zerovector2;
            Image allvricon = allvricongo.AddComponent <Image>();
            allvricon.sprite = AssetDatabase.LoadAssetAtPath <Sprite>("Assets/Icons/bothvricondark.png");
//indexicongo.SetActive(false);
//vricongo.SetActive(false);
//allvricongo.SetActive(false);

            menurow++;
        }

        //Create back button
        GameObject backtolessongo = createbutton2(parent: menubuttons, name: "Left Back Button", sizedelta: backbuttonsize,
                                                  localPosition: new Vector2(buttonsizey, 0),
                                                  text: "Back to Previous Menu", fontSize: 50, txtsizedelta: backbuttonsize, txtanchoredPosition: new Vector2(20, 0),
                                                  alignment: TextAnchor.MiddleCenter, nav: no_nav, rotatez: 90, layer: layer);

        //alignment:TextAlignmentOptions.Center,


        //backtolessongo.GetOrAddComponent<Button>().onClick=new Button.ButtonClickedEvent();
        UnityEventTools.AddStringPersistentListener(backtolessongo.GetOrAddComponent <Button>().onClick,                                                      //the button/toggle that triggers the action
                                                    System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>() //the target of the action
                                                                                   , "SendCustomEvent") as UnityAction <string>, "BackB");

        //Create back button
        GameObject backtolessongo2 = createbutton2(parent: menubuttons, name: "Right Back Button", sizedelta: backbuttonsize,
                                                   localPosition: new Vector2(menusizex, 0),
                                                   text: "Back to Previous Menu", fontSize: 50, txtsizedelta: backbuttonsize, txtanchoredPosition: new Vector2(20, 0),
                                                   alignment: TextAnchor.MiddleCenter, nav: no_nav, rotatez: 90, layer: layer);

        //alignment:TextAlignmentOptions.Center,

        //backtolessongo.GetOrAddComponent<Button>().onClick=new Button.ButtonClickedEvent();
        UnityEventTools.AddStringPersistentListener(backtolessongo2.GetOrAddComponent <Button>().onClick,                                                     //the button/toggle that triggers the action
                                                    System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>() //the target of the action
                                                                                   , "SendCustomEvent") as UnityAction <string>, "BackB");


/*****************************************
*  Update menu system to point to newly created objects.
*****************************************/
//recreate toggle to fix reference?

/*
 *      Toggle oldvideotoggle = GameObject.Find("/Preferencesv2/Canvas/Left Panel/Video Toggle").GetOrAddComponent<Toggle>();
 *      DestroyImmediate(oldvideotoggle);
 *      Toggle newvideotoggle = GameObject.Find("/Preferencesv2/Canvas/Left Panel/Video Toggle").GetOrAddComponent<Toggle>();
 *      newvideotoggle.navigation = no_nav;
 *      newvideotoggle.isOn = true;
 *      newvideotoggle.graphic=newvideotoggle.transform.Find("Background").gameObject.transform.Find("Checkmark").GetComponent<Image>();
 *      newvideotoggle.transition= Selectable.Transition.None;
 *      newvideotoggle.toggleTransition= Toggle.ToggleTransition.None;
 *      newvideotoggle.onValueChanged = new Toggle.ToggleEvent();
 *      UnityEventTools.AddPersistentListener(newvideotoggle.onValueChanged, System.Delegate.CreateDelegate(typeof(UnityAction<bool>),
 *      videocontainer, "SetActive") as UnityAction<bool>);
 */
    }//End of main program
コード例 #6
0
        public static void CB_AddGlobalChatBox()
        {
            if (!FindObjectOfType <NetworkManager>())
            {
                if (EditorUtility.DisplayDialog("Missing Network Manager", "No NetworkManager object was found in this scene. In order for this component to work properly there must be a network manager in the scene. Please add a \"NetworkManager\" component to the scene.",
                                                "Okay"))
                {
                }
            }
            else if (FindObjectOfType <ChatBox>())
            {
                Selection.activeGameObject = FindObjectOfType <ChatBox>().gameObject;
                if (EditorUtility.DisplayDialog("Scene Already Has ChatBox", "This scene already contains a \"ChatBox\" component. You should never add more than one at a time to a scene.",
                                                "Okay"))
                {
                }
            }
            else
            {
                string     chatBoxPrefabPath = string.Format("Assets{0}InvectorMultiplayer{0}UI{0}ChatBox.prefab", Path.DirectorySeparatorChar);
                GameObject ChatBox           = E_Helpers.CreatePrefabFromPath(chatBoxPrefabPath);
                ChatBox.transform.SetParent(FindObjectOfType <NetworkManager>().transform);
                ChatBox.GetComponent <ChatBox>().nm = FindObjectOfType <NetworkManager>();
                ChatBox.GetComponent <ChatBox>().GetType().GetField("openChatWindowOnPress", E_Helpers.allBindings).SetValue(ChatBox.GetComponent <ChatBox>(), new List <string> {
                    "T"
                });
                ChatBox.GetComponent <ChatBox>().GetType().GetField("closeWindowOnPress", E_Helpers.allBindings).SetValue(ChatBox.GetComponent <ChatBox>(), new List <string> {
                    "Escape"
                });
                ChatBox.GetComponent <ChatBox>().GetType().GetField("sendChatOnPress", E_Helpers.allBindings).SetValue(ChatBox.GetComponent <ChatBox>(), new List <string> {
                    "KeypadEnter", "Return"
                });
                E_Helpers.SetObjectIcon(ChatBox, E_Core.h_textChatIcon);

                //Join Room Events
                if (!E_PlayerEvents.HasUnityEvent(FindObjectOfType <NetworkManager>().roomEvents._onJoinedRoom, "SetActiveRoomAsChannelName", ChatBox.GetComponent <ChatBox>()))
                {
                    UnityEventTools.AddPersistentListener(FindObjectOfType <NetworkManager>().roomEvents._onJoinedRoom, ChatBox.GetComponent <ChatBox>().SetActiveRoomAsChannelName);
                }
                if (!E_PlayerEvents.HasUnityEvent(FindObjectOfType <NetworkManager>().roomEvents._onJoinedRoom, "Connect", ChatBox.GetComponent <ChatBox>()))
                {
                    UnityEventTools.AddPersistentListener(FindObjectOfType <NetworkManager>().roomEvents._onJoinedRoom, ChatBox.GetComponent <ChatBox>().Connect);
                }
                if (E_PlayerEvents.HasUnityEvent(FindObjectOfType <NetworkManager>().roomEvents._onJoinedRoom, "EnableVisualBox", ChatBox.GetComponent <ChatBox>()))
                {
                    UnityEventTools.AddBoolPersistentListener(FindObjectOfType <NetworkManager>().roomEvents._onJoinedRoom, ChatBox.GetComponent <ChatBox>().EnableVisualBox, true);
                }

                //Left Room Events
                if (!E_PlayerEvents.HasUnityEvent(FindObjectOfType <NetworkManager>().roomEvents._onLeftRoom, "EnableVisualBox", ChatBox.GetComponent <ChatBox>()))
                {
                    UnityEventTools.AddBoolPersistentListener(FindObjectOfType <NetworkManager>().roomEvents._onLeftRoom, ChatBox.GetComponent <ChatBox>().EnableVisualBox, false);
                }

                //Joined Room Failed Events
                if (!E_PlayerEvents.HasUnityEvent(FindObjectOfType <NetworkManager>().roomEvents._onJoinRoomFailed, "SetActiveChannel", ChatBox.GetComponent <ChatBox>()))
                {
                    UnityEventTools.AddStringPersistentListener(FindObjectOfType <NetworkManager>().roomEvents._onJoinRoomFailed, ChatBox.GetComponent <ChatBox>().SetActiveChannel, "lobbyChat");
                }

                // Misc - OnDisconnect Events
                if (!E_PlayerEvents.HasUnityEvent(FindObjectOfType <NetworkManager>().otherEvents._onDisconnected, "Disconnect", ChatBox.GetComponent <ChatBox>()))
                {
                    UnityEventTools.AddStringPersistentListener(FindObjectOfType <NetworkManager>().otherEvents._onDisconnected, ChatBox.GetComponent <ChatBox>().Disconnect, "");
                }
                if (!E_PlayerEvents.HasUnityEvent(FindObjectOfType <NetworkManager>().otherEvents._onDisconnected, "EnableChat", ChatBox.GetComponent <ChatBox>()))
                {
                    UnityEventTools.AddBoolPersistentListener(FindObjectOfType <NetworkManager>().otherEvents._onDisconnected, ChatBox.GetComponent <ChatBox>().EnableChat, false);
                }
            }
        }
コード例 #7
0
        void AutoAddComponents()
        {
            MonoBehaviour    uiObjToAddCall  = null;
            SerializedObject serialUIObj     = null;
            UdonBehaviour    behaviourToCall = null;

            if (action.GetComponent <Slider>() != null)
            {
                TA_Slider adapter = (TA_Slider)GetAdapter <TA_Slider>(action.gameObject);

                uiObjToAddCall = action.GetComponent <Slider>();
                serialUIObj    = new SerializedObject(uiObjToAddCall);

                action.actionType = (int)ActionType.Float;

                adapter._uiSlider = action.GetComponent <Slider>();
                adapter.action    = action;

                behaviourToCall = UdonSharpEditorUtility.GetBackingUdonBehaviour(adapter);
                UdonSharpEditorUtility.CopyProxyToUdon(adapter);
            }
            else if (action.GetComponent <Toggle>() != null)
            {
                TA_Toggle adapter = (TA_Toggle)GetAdapter <TA_Toggle>(action.gameObject);

                uiObjToAddCall = action.GetComponent <Toggle>();
                serialUIObj    = new SerializedObject(uiObjToAddCall);

                action.actionType = (int)ActionType.Bool;

                adapter._uiToggle = action.GetComponent <Toggle>();
                adapter.action    = action;

                behaviourToCall = UdonSharpEditorUtility.GetBackingUdonBehaviour(adapter);
                UdonSharpEditorUtility.CopyProxyToUdon(adapter);
            }
            else if (action.GetComponent <Button>() != null)
            {
                action.actionType = 0;

                uiObjToAddCall = action.GetComponent <Button>();
                serialUIObj    = new SerializedObject(uiObjToAddCall);

                behaviourToCall = UdonSharpEditorUtility.GetBackingUdonBehaviour(action);
            }

            foreach (UdonBehaviour u in action.GetComponents <UdonBehaviour>())
            {
                u.SyncMethod = Networking.SyncType.Manual;
            }

            EditorUtility.SetDirty(target);

            //Add call
            if (serialUIObj != null && behaviourToCall != null)
            {
                bool hasCall = false;

                SerializedProperty serialPropCalls = null;
                if (uiObjToAddCall.GetType() == typeof(Slider))
                {
                    serialPropCalls = serialUIObj.FindProperty("m_OnValueChanged.m_PersistentCalls.m_Calls");
                }
                else if (uiObjToAddCall.GetType() == typeof(Toggle))
                {
                    serialPropCalls = serialUIObj.FindProperty("onValueChanged.m_PersistentCalls.m_Calls");
                }
                else if (uiObjToAddCall.GetType() == typeof(Button))
                {
                    serialPropCalls = serialUIObj.FindProperty("m_OnClick.m_PersistentCalls.m_Calls");
                }

                if (serialPropCalls != null)
                {
                    for (int i = 0; i < serialPropCalls.arraySize; i++)
                    {
                        SerializedProperty item = serialPropCalls.GetArrayElementAtIndex(i);
                        if (item.FindPropertyRelative("m_Target").objectReferenceValue == behaviourToCall &&
                            item.FindPropertyRelative("m_MethodName").stringValue == nameof(UdonBehaviour.SendCustomEvent) &&
                            item.FindPropertyRelative("m_Arguments") != null &&
                            item.FindPropertyRelative("m_Arguments.m_StringArgument").stringValue == nameof(action.OnInteraction))
                        {
                            hasCall = true;
                        }
                    }
                }
                if (!hasCall)
                {
                    UnityAction <string> methodDelegate = UnityAction.CreateDelegate(typeof(UnityAction <string>), behaviourToCall, typeof(UdonBehaviour).GetMethod(nameof(UdonBehaviour.SendCustomEvent))) as UnityAction <string>;
                    if (uiObjToAddCall.GetType() == typeof(Slider))
                    {
                        UnityEventTools.AddStringPersistentListener(((Slider)uiObjToAddCall).onValueChanged, methodDelegate, nameof(action.OnInteraction));
                    }
                    else if (uiObjToAddCall.GetType() == typeof(Toggle))
                    {
                        UnityEventTools.AddStringPersistentListener(((Toggle)uiObjToAddCall).onValueChanged, methodDelegate, nameof(action.OnInteraction));
                    }
                    else if (uiObjToAddCall.GetType() == typeof(Button))
                    {
                        UnityEventTools.AddStringPersistentListener(((Button)uiObjToAddCall).onClick, methodDelegate, nameof(action.OnInteraction));
                    }
                }
            }
        }
コード例 #8
0
 public static void AddPersistentListener(this UnityEventBase self, UnityAction <string> unityAction, string argument)
 {
     UnityEventTools.AddStringPersistentListener(self, unityAction, argument);
 }