void OnSlidesceneCreated(string val)
 {
     uAdventure.Core.Animation newAnim = new uAdventure.Core.Animation(val.Split('/').Last());
     newAnim.getFrame(0).setUri(EMPTY + "_01.png");
     AnimationWriter.WriteAnimation(val, newAnim);
     AssetDatabase.ImportAsset("Assets/uAdventure/Resources/CurrentGame/" + val);
     Path = val;
 }
Ejemplo n.º 2
0
        protected void OnGUI()
        {
            if (workingAnimation == null)
            {
                this.Close();
                return;
            }

            switch (Event.current.type)
            {
            case EventType.DragUpdated:
                if (DragAndDrop.paths != null && DragAndDrop.paths.Length > 0)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    Debug.Log("Dragging (" + Event.current.type + "):" + System.String.Join("\n", DragAndDrop.paths));
                }
                break;

            case EventType.DragPerform:
                if (DragAndDrop.paths != null && DragAndDrop.paths.Length > 0)
                {
                    DragAndDrop.AcceptDrag();
                    foreach (var path in DragAndDrop.paths)
                    {
                        var uri   = AssetsController.AddSingleAsset(AssetsConstants.CATEGORY_ANIMATION_IMAGE, path);
                        var frame = workingAnimation.addFrame(selectedFrame, null);
                        frame.setUri(uri);
                    }
                }
                break;
            }

            EditorGUILayout.PrefixLabel(TC.get("Animation.GeneralInfo"), GUIStyle.none, titleStyle);
            EditorGUI.BeginChangeCheck();
            var documentationTextContent = EditorGUILayout.TextField(TC.get("Animation.Documentation"), workingAnimation.getDocumentation());

            if (EditorGUI.EndChangeCheck())
            {
                workingAnimation.setDocumentation(documentationTextContent);
            }

            EditorGUI.BeginChangeCheck();
            var useTransitions = EditorGUILayout.Toggle(TC.get("Animation.UseTransitions"), workingAnimation.isUseTransitions());

            if (EditorGUI.EndChangeCheck())
            {
                workingAnimation.setUseTransitions(useTransitions);
            }

            EditorGUI.BeginChangeCheck();
            var isSlides = EditorGUILayout.Toggle(TC.get("Animation.Slides"), workingAnimation.isSlides());

            if (EditorGUI.EndChangeCheck())
            {
                workingAnimation.setSlides(isSlides);
            }

            /*
             * Transition panel
             */
            EditorGUILayout.PrefixLabel(TC.get("Animation.Timeline"), GUIStyle.none, titleStyle);

            using (var scroll = new EditorGUILayout.ScrollViewScope(scrollPosition, true, false, GUILayout.Height(125)))
                using (new EditorGUILayout.HorizontalScope())
                    using (new GUIUtil.SkinScope(noBackgroundSkin))
                    {
                        scrollPosition = scroll.scrollPosition;
                        for (int i = 0, frameCount = workingAnimation.getFrames().Count; i < frameCount; i++)
                        {
                            if (selectedFrame == i)
                            {
                                GUI.skin = selectedFrameSkin;
                            }

                            var frame        = workingAnimation.getFrame(i);
                            var image        = Controller.ResourceManager.getImage(frame.getUri());
                            var frameContent = new GUIContent(frame.getTime().ToString(), image);
                            if (GUILayout.Button(frameContent, GUILayout.Height(100), GUILayout.Width(80)))
                            {
                                selectedFrame = (i == selectedFrame) ? -1 : i;
                                GUI.FocusControl(null);
                            }
                            if (useTransitions && i != workingAnimation.getFrames().Count - 1)
                            {
                                var transition        = workingAnimation.getTranstionForFrame(i);
                                var transitionContent = new GUIContent(transition.getTime().ToString(), transitionTypeTexture[(int)transition.getType()]);
                                if (GUILayout.Button(transitionContent, GUILayout.Height(100), GUILayout.Width(80)))
                                {
                                    selectedFrame = (i == selectedFrame) ? -1 : i;
                                    GUI.FocusControl(null);
                                }
                            }
                            GUI.skin = noBackgroundSkin;
                        }
                    }

            /*
             * Transition button panel
             */
            using (new EditorGUILayout.HorizontalScope())
                using (new GUIUtil.SkinScope(noBackgroundSkin))
                {
                    GUILayout.FlexibleSpace();
                    using (new EditorGUI.DisabledScope(selectedFrame < 0))
                    {
                        if (GUILayout.Button(moveLeft))
                        {
                            workingAnimation.moveLeft(selectedFrame);
                            selectedFrame--;
                        }
                    }
                    using (new EditorGUI.DisabledScope(selectedFrame < 0 || workingAnimation.getFrames().Count < 2))
                    {
                        if (GUILayout.Button(clearImg))
                        {
                            workingAnimation.removeFrame(selectedFrame);
                            selectedFrame--;
                        }
                    }

                    if (GUILayout.Button(addTexture))
                    {
                        var frame = workingAnimation.addFrame(selectedFrame, null);
                        frame.setUri(SpecialAssetPaths.ASSET_EMPTY_ANIMATION + "_01.png");
                    }

                    using (new EditorGUI.DisabledScope(selectedFrame < 0))
                    {
                        if (GUILayout.Button(duplicateImg))
                        {
                            workingAnimation.addFrame(selectedFrame, workingAnimation.getFrame(selectedFrame));
                        }
                    }

                    using (new EditorGUI.DisabledScope(selectedFrame >= workingAnimation.getFrames().Count - 1))
                    {
                        if (GUILayout.Button(moveRight))
                        {
                            workingAnimation.moveRight(selectedFrame);
                            selectedFrame++;
                        }
                    }
                    GUILayout.FlexibleSpace();
                }


            using (new EditorGUI.DisabledScope(selectedFrame == -1))
            {/*
              * Frame info panel
              */
                var frame = selectedFrame >= 0 ? workingAnimation.getFrame(selectedFrame): emptyFrame;

                EditorGUILayout.PrefixLabel(TC.get("Animation.Details"), GUIStyle.none, titleStyle);

                EditorGUI.BeginChangeCheck();
                var frameDocumentation = EditorGUILayout.TextField(TC.get("Animation.Documentation"), frame.getDocumentation());
                if (EditorGUI.EndChangeCheck())
                {
                    frame.setDocumentation(frameDocumentation);
                }

                EditorGUI.BeginChangeCheck();
                var frameDuration = System.Math.Max(0, EditorGUILayout.LongField(TC.get("Animation.Duration"), frame.getTime()));
                if (EditorGUI.EndChangeCheck())
                {
                    frame.setTime(frameDuration);
                }

                EditorGUI.BeginChangeCheck();
                imageChooser.Path = frame.getUri();
                imageChooser.DoLayout();
                if (EditorGUI.EndChangeCheck())
                {
                    frame.setUri(imageChooser.Path);
                }

                EditorGUI.BeginChangeCheck();
                soundChooser.Path = frame.getSoundUri();
                soundChooser.DoLayout();
                if (EditorGUI.EndChangeCheck())
                {
                    frame.setSoundUri(soundChooser.Path);
                }

                var editTransition = useTransitions && selectedFrame.InRange(-1, workingAnimation.getFrames().Count - 1);
                var transition     = editTransition ? workingAnimation.getTranstionForFrame(selectedFrame) : emptyTransition;

                using (new EditorGUI.DisabledScope(!editTransition))
                {
                    EditorGUILayout.PrefixLabel(TC.get("NextScene.Transition"), GUIStyle.none, titleStyle);
                    EditorGUI.BeginChangeCheck();
                    var transitionDuration = EditorGUILayout.LongField(TC.get("Animation.Duration"), transition.getTime());
                    if (EditorGUI.EndChangeCheck())
                    {
                        transition.setTime(transitionDuration);
                    }

                    EditorGUI.BeginChangeCheck();
                    var transitionType = EditorGUILayout.Popup(TC.get("Conditions.Type"), (int)transition.getType(), transitionTypeName);
                    if (EditorGUI.EndChangeCheck())
                    {
                        transition.setType((TransitionType)transitionType);
                    }
                }
            }

            var lastEditorRect = GUILayoutUtility.GetLastRect();


            // Ending buttons
            GUILayout.FlexibleSpace();
            using (new EditorGUILayout.HorizontalScope())
            {
                if (GUILayout.Button("OK"))
                {
                    // If it doesnt have an extension its because its an old animation
                    if (!Path.HasExtension(cutscenePath))
                    {
                        cutscenePath = cutscenePath + ".eaa.xml";
                    }

                    AnimationWriter.WriteAnimation(cutscenePath, workingAnimation);
                    AssetDatabase.Refresh(ImportAssetOptions.Default);
                    if (reference != null)
                    {
                        reference.OnDialogOk(cutscenePath, this);
                    }
                    this.Close();
                }
                if (GUILayout.Button(TC.get("GeneralText.Cancel")))
                {
                    if (reference != null)
                    {
                        reference.OnDialogCanceled();
                    }
                    this.Close();
                }
            }

            if (Event.current.type == EventType.Repaint)
            {
                var lastButtonRect = GUILayoutUtility.GetLastRect();
                var minheight      = lastEditorRect.y + lastEditorRect.height + lastEditorRect.height + 10;
                minSize = new Vector2(400, minheight);
            }
        }
Ejemplo n.º 3
0
        void OnGUI()
        {
            /*
             * Documentation area
             */
            GUILayout.BeginArea(animInfoRect);

            GUILayout.BeginVertical();
            GUILayout.Label(TC.get("Animation.Documentation"));
            GUILayout.Space(5);
            documentationTextContent = GUILayout.TextField(documentationTextContent);
            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            useTransitonFlag = GUILayout.Toggle(useTransitonFlag, TC.get("Animation.UseTransitions"));
            if (useTransitonFlag != useTransitonFlagLast)
            {
                OnUseTransitonFlagLastChanged(useTransitonFlag);
            }
            slidesAnimationFlag = GUILayout.Toggle(slidesAnimationFlag, TC.get("Animation.Slides"));
            if (slidesAnimationFlag != slidesAnimationFlagLast)
            {
                OnSlidesAnimationFlagLastChanged(slidesAnimationFlag);
            }
            GUILayout.EndVertical();

            GUILayout.EndArea();

            /*
             * Transition panel
             */
            GUILayout.BeginArea(timelineRect);
            scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(false), GUILayout.MaxHeight(0.25f * windowWidth));
            GUI.skin       = noBackgroundSkin;
            GUILayout.BeginHorizontal();
            for (int i = 0; i < workingAnimation.getFrames().Count; i++)
            {
                GUILayout.BeginHorizontal();
                if (selectedFrame == i)
                {
                    GUI.skin = selectedFrameSkin;
                }

                if (
                    GUILayout.Button(
                        workingAnimation.getFrames()[i].getImage(false, false, global::uAdventure.Core.Animation.ENGINE).texture, GUILayout.MaxHeight(0.2f * windowHeight), GUILayout.MaxWidth(0.2f * windowWidth)))
                {
                    OnFrameSelectionChanged(i);
                }
                GUI.skin = noBackgroundSkin;
                GUILayout.EndHorizontal();
            }
            GUI.skin = defaultSkin;
            GUILayout.EndHorizontal();
            GUILayout.EndScrollView();
            GUILayout.EndArea();


            /*
             * Transition button panel
             */
            GUILayout.BeginArea(timelineButtonsRect);
            GUILayout.BeginHorizontal();
            GUI.skin = noBackgroundSkin;
            if (GUILayout.Button(moveLeft))
            {
                workingAnimation.moveLeft(selectedFrame);
            }
            if (GUILayout.Button(clearImg))
            {
                if (selectedFrame >= 0)
                {
                    workingAnimation.removeFrame(selectedFrame);
                    selectedFrame--;
                }
            }
            if (GUILayout.Button(addTexture))
            {
                workingAnimation.addFrame(selectedFrame, null);
            }
            if (GUILayout.Button(duplicateImg))
            {
                workingAnimation.addFrame(selectedFrame, workingAnimation.getFrame(selectedFrame));
            }
            if (GUILayout.Button(moveRight))
            {
                workingAnimation.moveRight(selectedFrame);
            }
            GUI.skin = defaultSkin;
            GUILayout.EndHorizontal();
            GUILayout.EndArea();


            /*
             * Frame info panel
             */
            GUILayout.BeginArea(frameInfoRect);

            GUILayout.BeginHorizontal();
            GUILayout.Label(TC.get("Animation.Duration"));
            animationDurationString = GUILayout.TextField(animationDurationString);
            animationDurationString = (Regex.Match(animationDurationString, "^[0-9]{1,4}$").Success
                ? animationDurationString
                : animationDurationStringLast);
            if (!animationDurationString.Equals(animationDurationStringLast))
            {
                OnFrameDurationChanged(animationDurationString);
            }
            GUILayout.Space(5);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label(TC.get("Animation.Image"));
            GUILayout.Box(imagePath, GUILayout.MinWidth(0.3f * windowWidth));
            if (GUILayout.Button(TC.get("Buttons.Select")))
            {
                ImageFileOpenDialog imageDialog =
                    (ImageFileOpenDialog)ScriptableObject.CreateInstance(typeof(ImageFileOpenDialog));
                imageDialog.Init(this, BaseFileOpenDialog.FileType.FRAME_IMAGE);
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label(TC.get("Animation.Sound"));
            GUILayout.Space(5);
            if (GUILayout.Button(clearImg))
            {
            }
            GUILayout.Box(soundPath, GUILayout.MinWidth(0.3f * windowWidth));
            if (GUILayout.Button(TC.get("Buttons.Select")))
            {
                MusicFileOpenDialog musicDialog =
                    (MusicFileOpenDialog)ScriptableObject.CreateInstance(typeof(MusicFileOpenDialog));
                musicDialog.Init(this, BaseFileOpenDialog.FileType.FRAME_MUSIC);
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(20);
            GUILayout.BeginHorizontal();
            GUILayout.Label(TC.get("NextScene.Transition") + " " + TC.get("Animation.Duration"));
            transitionDurationString = GUILayout.TextField(transitionDurationString);
            transitionDurationString = (Regex.Match(transitionDurationString, "^[0-9]{1,4}$").Success
                ? transitionDurationString
                : transitionDurationStringLast);
            if (!transitionDurationString.Equals(transitionDurationStringLast))
            {
                OnTransitionDurationChanged(transitionDurationString);
            }
            GUILayout.EndHorizontal();
            GUILayout.EndArea();


            GUILayout.BeginArea(buttonRect);
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("OK"))
            {
                AnimationWriter.writeAnimation(cutscenePath, workingAnimation);
                reference.OnDialogOk("", this);
                this.Close();
            }
            if (GUILayout.Button(TC.get("GeneralText.Cancel")))
            {
                reference.OnDialogCanceled();
                this.Close();
            }
            GUILayout.EndHorizontal();
            GUILayout.EndArea();
        }