Exemple #1
0
 internal void DrawErrorTextAreas()
 {
     UdonSharpGUI.DrawCompileErrorTextArea(this);
     DrawAssemblyErrorTextArea();
 }
Exemple #2
0
 public override void OnInspectorGUI()
 {
     UdonSharpGUI.DrawDefaultUdonSharpBehaviourHeader(target);
     DrawDefaultInspector();
 }
Exemple #3
0
        public override void OnInspectorGUI()
        {
            t = (UdonSharpBehaviour)target;

            showUdonSettings = (bool)(UTUtils.GetUTSetting("showUdonSettings", UTUtils.UTSettingType.Bool) ?? false);

            // we force-disable collision transfer for toolkit driven behaviours as it is not applicable
            if (!nonUBChecked)
            {
                nonUBMode    = t.gameObject.GetComponent <UdonBehaviour>() == null;
                nonUBChecked = true;
            }

            if (!nonUBMode)
            {
                if (UdonSharpEditorUtility.GetBackingUdonBehaviour(t).AllowCollisionOwnershipTransfer)
                {
                    UdonSharpEditorUtility.GetBackingUdonBehaviour(t).AllowCollisionOwnershipTransfer = false;
                }
            }

            var headerExited = false;

            EditorGUI.BeginChangeCheck();
            showUdonSettings = GUILayout.Toggle(showUdonSettings, "Udon Settings", UTStyles.smallButton);
            if (EditorGUI.EndChangeCheck())
            {
                UTUtils.SetUTSetting("showUdonSettings", UTUtils.UTSettingType.Bool, showUdonSettings);
            }

            if (showUdonSettings)
            {
                headerExited = UdonSharpGUI.DrawDefaultUdonSharpBehaviourHeader(t, true);
            }

            if (headerExited)
            {
                return;
            }

            #region Caching

            if (!cacheBuilt)
            {
                tT           = t.GetType();
                programAsset = UdonSharpEditorUtility.GetUdonSharpProgramAsset(t);
                behInfo      = new UTBehaviourInfo(t);

                var prop = serializedObject.GetIterator();
                var next = prop.NextVisible(true);

                if (next)
                {
                    do
                    {
                        if (prop.name == "m_Script")
                        {
                            continue;
                        }

                        if (!fieldCache.ContainsKey(prop.name))
                        {
                            var newField = new UTField(prop);
                            fieldCache.Add(prop.name, newField);
                            if (newField.isInTabGroup)
                            {
                                if (!tabs.ContainsKey(newField.tabGroupName))
                                {
                                    tabs.Add(newField.tabGroupName, new Dictionary <string, UTFieldType>());
                                    // we only support one tab group per behaviour right now
                                    if (!tabsExist)
                                    {
                                        fieldOrder.Add(newField.tabGroupName, UTFieldType.Tab);
                                        tabsExist = true;
                                    }
                                }

                                // since tabs can host foldouts - we need to explicitly retarget them
                                // this logic could be generalized if i ever want to make all of this recursive
                                if (newField.isInFoldout)
                                {
                                    if (!foldouts.ContainsKey(newField.foldoutName))
                                    {
                                        foldouts.Add(newField.foldoutName, new Dictionary <string, UTFieldType>());
                                        tabs[newField.tabGroupName].Add(newField.foldoutName, UTFieldType.Foldout);
                                    }

                                    AddToFieldOrder(newField, prop, true);
                                    continue;
                                }

                                AddToFieldOrder(newField, prop, addToTabGroup: true);
                                continue;
                            }

                            if (newField.isInFoldout)
                            {
                                if (!foldouts.ContainsKey(newField.foldoutName))
                                {
                                    foldouts.Add(newField.foldoutName, new Dictionary <string, UTFieldType>());
                                    fieldOrder.Add(newField.foldoutName, UTFieldType.Foldout);
                                }

                                AddToFieldOrder(newField, prop, true);
                                continue;
                            }

                            AddToFieldOrder(newField, prop);
                        }
                    } while (prop.NextVisible(false));
                }

                cacheBuilt = true;
                return;
            }

            var e = Event.current;
            if (e.type == EventType.Repaint)
            {
                if (firstRepaint)
                {
                    firstRepaint = false;
                    return;
                }
            }

            #endregion

            if (behInfo.customName != null || behInfo.helpUrl != null)
            {
                EditorGUILayout.BeginHorizontal();
                UTStyles.RenderHeader(behInfo.customName != null ? behInfo.customName : behInfo.name);
                if (behInfo.helpUrl != null)
                {
                    if (GUILayout.Button("?", GUILayout.Height(26), GUILayout.Width(26)))
                    {
                        Application.OpenURL(behInfo.helpUrl);
                    }
                }
                EditorGUILayout.EndHorizontal();
            }

            if (behInfo.helpMsg != null)
            {
                UTStyles.RenderNote(behInfo.helpMsg);
            }

            if (behInfo.onBeforeEditor != null)
            {
                behInfo.onBeforeEditor.Invoke(t, new object[] { serializedObject });
            }

            // handle jagged arrays
            Undo.RecordObject(t, "Change Properties");

            EditorGUI.BeginChangeCheck();
            droppedObjects = false;

            // this method is overrideable by custom code
            DrawGUI();

            if (EditorGUI.EndChangeCheck() || droppedObjects || shouldReserialize)
            {
                if (behInfo.onValuesChanged != null)
                {
                    behInfo.onValuesChanged.Invoke(t, new object[] { serializedObject });
                }
                serializedObject.ApplyModifiedProperties();
            }

            if (droppedObjects)
            {
                return;
            }

            if (behInfo.onAfterEditor != null)
            {
                behInfo.onAfterEditor.Invoke(t, new object[] { serializedObject });
            }

            #region Buttons
            if (behInfo.buttons != null && !Application.isPlaying && behInfo.buttons.Length > 0)
            {
                buttonsExpanded = UTStyles.FoldoutHeader("Editor Methods", buttonsExpanded);
                if (buttonsExpanded)
                {
                    EditorGUILayout.BeginVertical(new GUIStyle("helpBox"));
                    foreach (var button in behInfo.buttons)
                    {
                        if (GUILayout.Button(button.Name))
                        {
                            button.Invoke(t, new object[] {});
                        }
                    }
                    EditorGUILayout.EndVertical();
                }
            }
            if (Application.isPlaying && behInfo.udonCustomEvents.Length > 0 && !nonUBMode)
            {
                methodsExpanded = UTStyles.FoldoutHeader("Udon Events", methodsExpanded);
                if (methodsExpanded)
                {
                    EditorGUILayout.BeginVertical(new GUIStyle("helpBox"));
                    var rowBreak = Mathf.Max(1, Mathf.Min(3, behInfo.udonCustomEvents.Length - 1));
                    var rowEndI  = -100;
                    foreach (var(button, i) in behInfo.udonCustomEvents.WithIndex())
                    {
                        if (i == rowEndI && i != behInfo.udonCustomEvents.Length - 1)
                        {
                            EditorGUILayout.EndHorizontal();
                        }
                        if (i % rowBreak == 0 && i != behInfo.udonCustomEvents.Length - 1)
                        {
                            EditorGUILayout.BeginHorizontal();
                            rowEndI = Math.Min(i + rowBreak, behInfo.udonCustomEvents.Length - 1);
                        }
                        if (GUILayout.Button(button))
                        {
                            UdonSharpEditorUtility.GetBackingUdonBehaviour(t).SendCustomEvent(button);
                            UdonSharpEditorUtility.CopyUdonToProxy(t);
                        }
                        if (i == behInfo.udonCustomEvents.Length - 1 && rowEndI != -100)
                        {
                            EditorGUILayout.EndHorizontal();
                        }
                    }
                    EditorGUILayout.EndVertical();
                }
            }
            #endregion
        }
        public override void OnInspectorGUI()
        {
            //base.OnInspectorGUI();

            if (!T23_EditorUtility.GuideJoinMaster(master, body, body.groupID, 1))
            {
                return;
            }

            UdonSharpProgramAsset programAsset = UdonSharpEditorUtility.GetUdonSharpProgramAsset((UdonSharpBehaviour)target);

            UdonSharpGUI.DrawCompileErrorTextArea(programAsset);

            serializedObject.Update();

            T23_EditorUtility.ShowTitle("Trigger");

            if (master)
            {
                GUILayout.Box("[#" + body.groupID.ToString() + "] " + body.title, T23_EditorUtility.HeadlineStyle());
            }
            else
            {
                body.groupID = EditorGUILayout.IntField("Group ID", body.groupID);
            }

            prop = serializedObject.FindProperty("passive");
            EditorGUILayout.PropertyField(prop);
            if (!body.passive)
            {
                prop = serializedObject.FindProperty("allowContinuity");
                EditorGUILayout.PropertyField(prop);
            }

            GUILayout.Space(10);
            EditorGUILayout.LabelField("Base", EditorStyles.boldLabel);
            serializedObject.FindProperty("basePropertyBox").objectReferenceValue = EditorGUILayout.ObjectField("PropertyBox", body.basePropertyBox, typeof(T23_PropertyBox), true);

            if (body.basePropertyBox)
            {
                GUILayout.Space(10);
                EditorGUILayout.LabelField("Comparison", EditorStyles.boldLabel);
                serializedObject.FindProperty("compOperator").intValue      = EditorGUILayout.Popup("Operator", body.compOperator, (body.basePropertyBox.valueType == 1 || body.basePropertyBox.valueType == 2) ? CompOperator_a : CompOperator_b);
                serializedObject.FindProperty("compParameterType").intValue = (int)(CompParameterType)EditorGUILayout.EnumPopup("Parameter Type", (CompParameterType)body.compParameterType);
                if (body.compParameterType == 0)
                {
                    switch (body.basePropertyBox.valueType)
                    {
                    case 0:
                        serializedObject.FindProperty("comp_b").boolValue = EditorGUILayout.Toggle("Value", body.comp_b);
                        break;

                    case 1:
                        serializedObject.FindProperty("comp_i").intValue = EditorGUILayout.IntField("Value", body.comp_i);
                        break;

                    case 2:
                        serializedObject.FindProperty("comp_f").floatValue = EditorGUILayout.FloatField("Value", body.comp_f);
                        break;

                    case 4:
                        serializedObject.FindProperty("comp_s").stringValue = EditorGUILayout.TextField("Value", body.comp_s);
                        break;
                    }
                }
                if (body.compParameterType == 1)
                {
                    serializedObject.FindProperty("compPropertyBox").objectReferenceValue = EditorGUILayout.ObjectField("PropertyBox", body.compPropertyBox, typeof(T23_PropertyBox), true);
                    if (body.compPropertyBox)
                    {
                        if (body.compPropertyBox.valueType != body.basePropertyBox.valueType)
                        {
                            EditorGUILayout.HelpBox("PropertyBox の ValueType が不適合です", MessageType.Error);
                        }
                    }
                }
            }

            serializedObject.ApplyModifiedProperties();
        }
Exemple #5
0
        public override void OnInspectorGUI()
        {
            //base.OnInspectorGUI();

            if (!UdonSharpEditorUtility.IsProxyBehaviour(body))
            {
                UdonSharpGUI.DrawConvertToUdonBehaviourButton(body);
                return;
            }

            serializedObject.Update();

            T23_EditorUtility.ShowTitle("Option");

            GUILayout.Box("AudioBank", T23_EditorUtility.HeadlineStyle());

            prop = serializedObject.FindProperty("source");
            EditorGUILayout.PropertyField(prop);
            serializedObject.FindProperty("playbackOrder").intValue = (int)(Order)EditorGUILayout.EnumPopup("Playback Order", (Order)body.playbackOrder);
            serializedObject.FindProperty("playbackStyle").intValue = (int)(Style)EditorGUILayout.EnumPopup("Playback Style", (Style)body.playbackStyle);
            prop = serializedObject.FindProperty("repeat");
            EditorGUILayout.PropertyField(prop);
            prop = serializedObject.FindProperty("minPitchRange");
            EditorGUILayout.PropertyField(prop);
            prop = serializedObject.FindProperty("maxPitchRange");
            EditorGUILayout.PropertyField(prop);

            EditorGUILayout.BeginHorizontal();
            prop = serializedObject.FindProperty("onPlay");
            EditorGUILayout.PropertyField(prop);

            /*
             * List<string> onPlayCustomNameList = new List<string>();
             * if (body.onPlay)
             * {
             *  onPlayCustomNameList = GetCustomNameList(body.onPlay);
             * }
             * if (onPlayCustomNameList.Count > 0)
             * {
             *  var index = EditorGUILayout.Popup(onPlayCustomNameList.IndexOf(body.onPlayCustomName), onPlayCustomNameList.ToArray());
             *  serializedObject.FindProperty("onPlayCustomName").stringValue = index >= 0 ? onPlayCustomNameList[index] : "";
             * }
             * else
             */
            {
                prop = serializedObject.FindProperty("onPlayCustomName");
                EditorGUILayout.PropertyField(prop, new GUIContent(""));
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            prop = serializedObject.FindProperty("onStop");
            EditorGUILayout.PropertyField(prop);

            /*
             * List<string> onStopCustomNameList = new List<string>();
             * if (body.onStop)
             * {
             *  onStopCustomNameList = GetCustomNameList(body.onStop);
             * }
             * if (onStopCustomNameList.Count > 0)
             * {
             *  var index = EditorGUILayout.Popup(onStopCustomNameList.IndexOf(body.onStopCustomName), onStopCustomNameList.ToArray());
             *  serializedObject.FindProperty("onStopCustomName").stringValue = index >= 0 ? onStopCustomNameList[index] : "";
             * }
             * else
             */
            {
                prop = serializedObject.FindProperty("onStopCustomName");
                EditorGUILayout.PropertyField(prop, new GUIContent(""));
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            prop = serializedObject.FindProperty("onChange");
            EditorGUILayout.PropertyField(prop);

            /*
             * List<string> onChangeCustomNameList = new List<string>();
             * if (body.onChange)
             * {
             *  onChangeCustomNameList = GetCustomNameList(body.onChange);
             * }
             * if (onChangeCustomNameList.Count > 0)
             * {
             *  var index = EditorGUILayout.Popup(onChangeCustomNameList.IndexOf(body.onChangeCustomName), onChangeCustomNameList.ToArray());
             *  serializedObject.FindProperty("onChangeCustomName").stringValue = index >= 0 ? onChangeCustomNameList[index] : "";
             * }
             * else
             */
            {
                prop = serializedObject.FindProperty("onChangeCustomName");
                EditorGUILayout.PropertyField(prop, new GUIContent(""));
            }
            EditorGUILayout.EndHorizontal();

            SerializedProperty recieverProp = serializedObject.FindProperty("clips");

            if (recieverReorderableList == null)
            {
                recieverReorderableList                     = new ReorderableList(serializedObject, recieverProp);
                recieverReorderableList.draggable           = true;
                recieverReorderableList.displayAdd          = true;
                recieverReorderableList.drawHeaderCallback  = rect => EditorGUI.LabelField(rect, "Clips");
                recieverReorderableList.drawElementCallback = (rect, index, isActive, isFocused) =>
                {
                    rect.height       = EditorGUIUtility.singleLineHeight;
                    body.clips[index] = (AudioClip)EditorGUI.ObjectField(rect, body.clips[index], typeof(AudioClip), false);
                };
            }
            recieverReorderableList.DoLayoutList();

            serializedObject.ApplyModifiedProperties();
        }