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

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

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

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

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

            action._optionalAnimator = (Animator)EditorGUILayout.ObjectField(new GUIContent("Animator"), action._optionalAnimator, typeof(Animator), true);
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Handle:");
            action._uiSliderHandlePrefix  = EditorGUILayout.TextField(action._uiSliderHandlePrefix);
            action._uiSliderHandleText    = (Text)EditorGUILayout.ObjectField(action._uiSliderHandleText, typeof(Text), true);
            action._uiSliderHandlePostfix = EditorGUILayout.TextField(action._uiSliderHandlePostfix);
            EditorGUILayout.EndHorizontal();

            /*Really neat code, which is why i am leaving it in, but not really needed anymore
             * action._useCurve = EditorGUILayout.Toggle("Use Curve", action._useCurve);
             * if (action._useCurve)
             * {
             *  if (action._curve == null)
             *  {
             *      action._curve = AnimationCurve.Linear(0, 0, 1, 1);
             *      action._reverseCurve = ReverseCurve(action._curve);
             *  }
             *  EditorGUI.BeginChangeCheck();
             *  action._curve = EditorGUILayout.CurveField("Float Transformation Curve", action._curve);
             *  if (EditorGUI.EndChangeCheck()) action._reverseCurve = ReverseCurve(action._curve);
             *  //EditorGUILayout.CurveField("Reverse Curve", action._reverseCurve);
             * }*/
        }
示例#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));
                    }
                }
            }
        }