示例#1
0
        public override void OnFlowWindowGUI(FD.FlowWindow window)
        {
            var data = FlowSystem.GetData();

            if (data == null)
            {
                return;
            }

            if (data.modeLayer == ModeLayer.Audio)
            {
                if (window.IsContainer() == true ||
                    window.IsSmall() == true ||
                    window.IsShowDefault() == true)
                {
                    return;
                }

                var screen = window.GetScreen();
                if (screen != null)
                {
                    GUILayout.BeginHorizontal();
                    {
                        var playType = (int)screen.audio.playType;
                        playType = GUILayoutExt.Popup(playType, new string[2] {
                            "Keep Current", "Replace"
                        }, FlowSystemEditorWindow.defaultSkin.label, GUILayout.Width(EditorGUIUtility.labelWidth));
                        screen.audio.playType = (UnityEngine.UI.Windows.Audio.Window.PlayType)playType;

                        var rect = GUILayoutUtility.GetLastRect();

                        /*var newId = */ AudioPopupEditor.Draw(new Rect(rect.x + rect.width, rect.y, window.rect.width - EditorGUIUtility.labelWidth - 10f, rect.height), screen.audio.id, (result) => {
                            screen.audio.id    = result;
                            window.audioEditor = null;
                        }, screen.audio.clipType, screen.audio.flowData.audio, null);

                        /*if (newId != screen.audio.id) {
                         *
                         *      screen.audio.id = newId;
                         *      window.audioEditor = null;
                         *
                         * }*/
                    }
                    GUILayout.EndHorizontal();

                    var state = data.audio.GetState(screen.audio.clipType, screen.audio.id);
                    if (state != null && state.clip != null)
                    {
                        GUILayout.BeginVertical();
                        {
                            GUILayout.Box(string.Empty, FlowSystemEditorWindow.styles.layoutBoxStyle, GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true));
                            var rect = GUILayoutUtility.GetLastRect();

                            if (Event.current.type == EventType.MouseDown && rect.Contains(Event.current.mousePosition) == true)
                            {
                                window.audioEditor = null;
                            }

                            if (window.audioEditor == null)
                            {
                                EditorPrefs.SetBool("AutoPlayAudio", false);
                                window.audioEditor = Editor.CreateEditor(state.clip);
                                //System.Type.GetType("AudioUtil").InvokeMember("StopClip", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public, null, null, new object[] { state.clip });
                            }

                            if (Event.current.type != EventType.MouseDrag && Event.current.type != EventType.DragPerform)
                            {
                                window.audioEditor.OnPreviewGUI(rect, EditorStyles.helpBox);
                                GUILayout.BeginHorizontal();
                                window.audioEditor.OnPreviewSettings();
                                GUILayout.EndHorizontal();
                            }
                        }
                        GUILayout.EndVertical();
                    }
                }
            }
        }
示例#2
0
        public static void CreateTransition <T>(FD.FlowWindow windowWithScreen, FD.FlowWindow flowWindow, FD.FlowWindow toWindow, int attachIndex, string localPath, string namePrefix, System.Action <T> callback = null) where T : TransitionInputTemplateParameters
        {
            if (windowWithScreen.GetScreen() == null)
            {
                return;
            }

            var screenPath = AssetDatabase.GetAssetPath(windowWithScreen.GetScreen().Load <WindowBase>());

            screenPath = System.IO.Path.GetDirectoryName(screenPath);
            var splitted    = screenPath.Split(new string[] { "/" }, System.StringSplitOptions.RemoveEmptyEntries);
            var packagePath = string.Join("/", splitted, 0, splitted.Length - 1);
            var path        = packagePath + localPath;

            FlowChooserFilterWindow.Show <T>(
                root: null,
                onSelect: (element) => {
                // Clean up previous transitions if exists
                var attachItem = flowWindow.GetAttachItem(toWindow.id, (x) => x.index == attachIndex);
                if (attachItem != null)
                {
                    if (FlowSystem.GetData().modeLayer == ModeLayer.Flow)
                    {
                        if (attachItem.transitionParameters != null)
                        {
                            AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(attachItem.transitionParameters.gameObject));
                        }

                        attachItem.transition           = null;
                        attachItem.transitionParameters = null;
                    }
                    else if (FlowSystem.GetData().modeLayer == ModeLayer.Audio)
                    {
                        if (attachItem.audioTransitionParameters != null)
                        {
                            AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(attachItem.audioTransitionParameters.gameObject));
                        }

                        attachItem.audioTransition           = null;
                        attachItem.audioTransitionParameters = null;
                    }
                }

                if (System.IO.Directory.Exists(path) == false)
                {
                    System.IO.Directory.CreateDirectory(path);
                }

                if (element == null)
                {
                    return;
                }

                var prefix = string.Empty;
                if (FlowSystem.GetData().modeLayer == ModeLayer.Flow)
                {
                    prefix = "Transition-" + namePrefix;
                }
                else if (FlowSystem.GetData().modeLayer == ModeLayer.Audio)
                {
                    prefix = "AudioTransition-" + namePrefix;
                }

                var elementPath = AssetDatabase.GetAssetPath(element.gameObject);
                var targetName  = prefix + "-" + element.gameObject.name + "-" + (toWindow.IsFunction() == true ? FlowSystem.GetWindow(toWindow.functionId).directory : toWindow.directory);
                var targetPath  = path + "/" + targetName + ".prefab";

                if (AssetDatabase.CopyAsset(elementPath, targetPath) == true)
                {
                    AssetDatabase.ImportAsset(targetPath);

                    var newInstance        = AssetDatabase.LoadAssetAtPath <GameObject>(targetPath);
                    var instance           = newInstance.GetComponent <T>();
                    instance.useDefault    = false;
                    instance.useAsTemplate = false;
                    EditorUtility.SetDirty(instance);

                    if (FlowSystem.GetData().modeLayer == ModeLayer.Flow)
                    {
                        attachItem.transition           = instance.transition;
                        attachItem.transitionParameters = instance;
                    }
                    else if (FlowSystem.GetData().modeLayer == ModeLayer.Audio)
                    {
                        attachItem.audioTransition           = instance.transition;
                        attachItem.audioTransitionParameters = instance;
                    }

                    if (callback != null)
                    {
                        callback(instance);
                    }
                }
            },
                onEveryGUI: (element) => {
                // on gui

                var style      = new GUIStyle(GUI.skin.label);
                style.wordWrap = true;

                if (element != null)
                {
                    GUILayout.Label(element.name, style);
                }
                else
                {
                    GUILayout.Label("None", style);
                }
            },
                predicate: (element) => {
                var elementPath = AssetDatabase.GetAssetPath(element.gameObject);
                var isInPackage = FlowEditorUtilities.IsValidPackage(elementPath + "/../");

                if (element.transition != null && (isInPackage == true || element.useAsTemplate == true))
                {
                    var name     = element.GetType().FullName;
                    var baseName = name.Substring(0, name.IndexOf("Parameters"));

                    var type = System.Type.GetType(baseName + ", " + element.GetType().Assembly.FullName, throwOnError: true, ignoreCase: true);
                    if (type != null)
                    {
                        var attribute = type.GetCustomAttributes(inherit: true).OfType <TransitionCameraAttribute>().FirstOrDefault();
                        if (attribute != null)
                        {
                            return(true);
                        }
                        else
                        {
                            Debug.Log("No Attribute: " + baseName, element);
                        }
                    }
                    else
                    {
                        Debug.Log("No type: " + baseName);
                    }
                }

                return(false);
            },
                strongType: false,
                directory: null,
                useCache: false,
                drawNoneOption: true,
                updateRedraw: true);
        }