Exemplo n.º 1
0
        public override void OnInspectorGUI()
        {
            EditorGUILayout.LabelField("<size=20><color=#f542da>Toggle Adapter</color></size>", new GUIStyle(EditorStyles.label)
            {
                richText = true, alignment = TextAnchor.MiddleCenter
            }, GUILayout.Height(50));

            serializedObject.Update();
            TA_Toggle action = (TA_Toggle)target;

            if (!ThryActionEditor.MakeSureItsAnUdonBehaviour(action))
            {
                return;
            }

            action.action    = (ThryAction)EditorGUILayout.ObjectField(new GUIContent("Thry Action"), action.action, typeof(ThryAction), true);
            action._uiToggle = (Toggle)EditorGUILayout.ObjectField(new GUIContent("Toggle"), action._uiToggle, typeof(Toggle), true);

            EditorGUILayout.LabelField("Optional", EditorStyles.boldLabel);

            action._optionalAnimator = (Animator)EditorGUILayout.ObjectField(new GUIContent("Animator"), action._optionalAnimator, typeof(Animator), true);
        }
Exemplo n.º 2
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));
                    }
                }
            }
        }