Beispiel #1
0
    public void ChangeAnimLength(float newLength)
    {
        //Update the file settings

        guiTimeline.totalValue = newLength;

        List <TagarelaTimelineUI.TLkeyframe> keySet = new List <TagarelaTimelineUI.TLkeyframe>(guiTimeline.keyframeSet);

        keySet.RemoveAll(item => item.value > newLength);


        guiTimeline.keyframeSet = keySet;

        settings = TagarelaFileManager.UpdateSettings(tagarela.smrTotal, guiTimeline.keyframeSet, 0, "", guiTimeline.totalValue);

        //guiTimeline.UpdateSelection();
        guiTimelineSegment.totalValue           = newLength;
        guiTimelineSegment.KeyframeSet[0].Value = 0;
        guiTimelineSegment.KeyframeSet[1].Value = newLength;
        guiTimelineSegment.UpdateSelection();

        settings.animationTime = newLength;

        Repaint();
        tagarela.settings = settings;
        tagarela.BuildTimeline();
        updateTimeline = true;

        Repaint();
        Update();
        playMode = PlayMode.currentTime;
    }
Beispiel #2
0
    public void CreateNewAnimation(bool isAudioBased, int audioFileIndex, string newAnimFileName, float newTime)
    {
        if (newAnimFileName != "")
        {
            string newAudioName = "";
            if (isAudioBased)
            {
                newAudioName = tagarela.audioFiles[audioFileIndex].name;
            }

            TagarelaMorphTarget _MorphTarget = new TagarelaMorphTarget();
            _MorphTarget.Populate(tagarela.smrTotal);

            guiTimeline = new TagarelaTimelineUI(newTime);
            guiTimeline.AddKeyframe(0f, _MorphTarget);

            guiTimelineSegment = new TagarelaTimelineSegmentUI(newTime);

            if (TagarelaFileManager.Save(newAnimFileName, tagarela.smrTotal, guiTimeline.keyframeSet, 0, newAudioName, newTime))
            {
                TextAsset newFile = AssetDatabase.LoadMainAssetAtPath("Assets/Tagarela/System/Animations/" + newAnimFileName + ".xml") as TextAsset;
                AssetDatabase.Refresh();
                tagarela.Clean();
                tagarela.animationFiles.Add(newFile);

                CleanVars();
                dialog = ScreenDialog.InitialScreen;
                Repaint();
                Update();

                LoadAnimationFile(tagarela.animationFiles[tagarela.animationFiles.Count - 1]);
            }
        }
    }
Beispiel #3
0
    public void OnEnable()
    {
        tagarela = target as Tagarela;
        tagarela.Repair();

        if (!Selection.activeGameObject.GetComponent(typeof(AudioSource)))
        {
            Selection.activeGameObject.AddComponent(typeof(AudioSource));
        }

        logo_inspector           = TagarelaFileManager.LoadImageResource("logoInspector.png");
        logo_inspector.hideFlags = HideFlags.DontSave;

        bg_inspector           = TagarelaFileManager.LoadImageResource("bgInspector.png");
        bg_inspector.hideFlags = HideFlags.DontSave;
        bg_inspector.wrapMode  = TextureWrapMode.Clamp;

        filelist_animation_loader = Resources.LoadAll("animations", typeof(TextAsset));
        filelist_animation        = new ArrayList();
        if (filelist_animation_loader.Length > 0)
        {
            for (int i = 0; i < filelist_animation_loader.Length; i++)
            {
                if ((filelist_animation_loader[i] as TextAsset).text.Contains("<MeshVertexCount>" + (Selection.activeGameObject.GetComponent(typeof(MeshFilter)) as MeshFilter).sharedMesh.vertexCount + "</MeshVertexCount>"))
                {
                    filelist_animation.Add(filelist_animation_loader[i].name);
                }
            }
        }
        setStyles = true;
    }
Beispiel #4
0
    public TagarelaTimelineSegmentUI(float TotalValue)
    {
        TimeLineRect    = new Rect(0, 0, 100, 20);
        this.totalValue = TotalValue;

        icoA           = TagarelaFileManager.LoadImageResource("icoSegmentA.png");
        icoA.hideFlags = HideFlags.DontSave;

        icoB           = TagarelaFileManager.LoadImageResource("icoSegmentB.png");
        icoB.hideFlags = HideFlags.DontSave;

        KeyframeSet.Add(new TLkeyframe(0f, TotalValue, TimeLineRect, new Rect(0, 0, icoA.width, icoA.height)));
        KeyframeSet.Add(new TLkeyframe(TotalValue, TotalValue, TimeLineRect, new Rect(0, 0, icoA.width, icoA.height)));
    }
Beispiel #5
0
    public TagarelaTimelineUI(float totalValue)
    {
        timeLineRect = new Rect(0, 0, 100, 20);
        //TimeLineRect = new Rect(0, 0, 100, 40);
        this.totalValue = totalValue;

        imgTimeline                     = TagarelaFileManager.LoadImageResource("timeline.png");
        imgTimeline.hideFlags           = HideFlags.DontSave;
        styleTimeline                   = new GUIStyle();
        styleTimeline.normal.background = imgTimeline;
        styleTimeline.border            = new RectOffset(2, 2, 2, 2);
        styleTimeline.padding           = new RectOffset(0, 0, 0, 0);
        styleTimeline.margin            = new RectOffset(0, 0, 0, 0);
    }
Beispiel #6
0
 public void OnDestroy()
 {
     if (dialog == ScreenDialog.Timeline)
     {
         if (EditorUtility.DisplayDialog("Close animation", "Do you want to save?        ", "Yes", "No"))
         {
             string audioName = SelectedAudioclip != null ? SelectedAudioclip.name : "";
             TagarelaFileManager.Save(fileName, tagarela.smrTotal, guiTimeline.keyframeSet, 0, audioName, tagarela.settings.animationTime);
         }
     }
     SelectedAudioclip = null;
     if (tagarela != null)
     {
         tagarela.Clean();
     }
     CleanVars();
 }
Beispiel #7
0
    public void LoadAnimationFile(TextAsset file)
    {
        RefreshAudiolist();
        tagarela.Clean();
        CleanVars();

        settings = TagarelaFileManager.Load(file);
        lastSelectionGameObjectEditing = Selection.activeGameObject;
        fileName             = file.name;
        guiTimeline          = new TagarelaTimelineUI(settings.animationTime);
        audioPreviewSpectrum = null;
        SelectedAudioclip    = null;
        tagarela.audio.clip  = null;
        tagarela.isPlaying   = false;
        playMode             = PlayMode.stopped;


        if (settings.audioFile != null)
        {
            for (int i = 0; i < tagarela.audioFiles.Count; i++)
            {
                if (settings.audioFile == tagarela.audioFiles[i].name)
                {
                    SelectedAudioclip              = tagarela.audioFiles[i];
                    tagarela.audio.clip            = tagarela.audioFiles[i];
                    audioPreviewSpectrum           = TagarelaAudioSpectrum.CreatePreview(SelectedAudioclip, 1024, 64, new Color(150f / 255f, 200f / 255f, 25f / 255f, 0.8f), TagarelaAudioSpectrum.PreviewType.both);
                    audioPreviewSpectrum.hideFlags = HideFlags.DontSave;
                }
            }
        }

        //  CARREGA O ARQUIVO XML
        //configurações principais

        if (settings.meshList.id != null)
        {
            guiTimeline.keyframeSet = new List <TagarelaTimelineUI.TLkeyframe>();

            for (int i = 0; i < settings.keyframes.values.Length; i++)
            {
                TagarelaMorphTarget _MorphTarget = new TagarelaMorphTarget();
                _MorphTarget.Populate(tagarela.smrTotal);

                for (int j = 0; j < settings.keyframes.sliderSettings[i].Length; j++)
                {
                    float[] sliders = settings.keyframes.sliderSettings[i];

                    if (j < tagarela.smrTotalBlendShapesCount)
                    {
                        //tagarela.morphTargets[j].hideFlags = HideFlags.DontSave;
                        _MorphTarget.sliderValue[j] = sliders[j];
                    }
                }
                guiTimeline.AddKeyframe(settings.keyframes.values[i], _MorphTarget);
            }
        }
        else
        {
            guiTimeline.keyframeSet = new List <TagarelaTimelineUI.TLkeyframe>();
            TagarelaMorphTarget _MorphTarget = new TagarelaMorphTarget();
            _MorphTarget.Populate(tagarela.smrTotal);
            guiTimeline.AddKeyframe(0f, _MorphTarget);
        }

        //Update the file settings
        settings           = TagarelaFileManager.UpdateSettings(tagarela.smrTotal, guiTimeline.keyframeSet, 0, settings.audioFile, guiTimeline.totalValue);
        guiTimelineSegment = new TagarelaTimelineSegmentUI(settings.animationTime);

        tagarela.OpenFile(file);

        timeNormalized       = 0f;
        playMode             = PlayMode.stopped;
        lastKeyframeSelected = -1;

        lastKeyframeSelected = guiTimeline.selectedIndex;
        updateMorphValue     = guiTimeline.selectedValue;

        updateTimeline = true;

        if (settings != null && Selection.objects.Length == 1)
        {
            dialog = ScreenDialog.Timeline;
        }
    }
Beispiel #8
0
    void OnGUI()
    {
        updateWindow = false;

        GUI.color = Color.white;

        GUI.DrawTexture(new Rect(0, 0, Screen.width, bgEditor.height), bgEditor);
        GUI.DrawTexture(new Rect(13, 14, logoEditor.width, logoEditor.height), logoEditor);

        GUILayout.BeginVertical(styleHeader);
        {
            GUI.color = Color.white;
            switch (dialog)
            {
            case ScreenDialog.InvalidObject:
                GUILayout.Label(log_msg, EditorStyles.boldLabel);
                break;

            case ScreenDialog.AddComponent:
                GUILayout.Label("", EditorStyles.boldLabel);
                GUILayout.Space(15f);

                if (GUILayout.Button("Add LipSync Component!"))
                {
                    //Debug.Log("UnityLipSync -> LipSync Component created on " + LastSelected.name);
                    Selection.activeGameObject.AddComponent(typeof(Tagarela));
                }
                break;

            case ScreenDialog.InitialScreen:

                GUILayout.BeginHorizontal();

                GUILayout.Label("Select Animation", styleFileTitle, GUILayout.Height(22));

                if (GUILayout.Button("Create New Animation", styleBigButtons, new GUILayoutOption[] { GUILayout.Width(150), GUILayout.Height(18) }))
                {
                    TagarelaEditorPopupNewFile popupNewFile = CreateInstance <TagarelaEditorPopupNewFile>();
                    popupNewFile.parent = this;
                    RefreshAudiolist();
                    popupNewFile.audioList = audioList;
                    popupNewFile.tagarela  = tagarela;
                    popupNewFile.ShowAuxWindow();
                }
                GUILayout.Space(8f);
                GUILayout.EndHorizontal();

                scrollViewVector = GUILayout.BeginScrollView(scrollViewVector, styleScrollview);
                {
                    GUILayout.BeginVertical();
                    {
                        GUILayout.Space(15f);

                        if (tagarela.animationFiles.Count > 0)
                        {
                            GUILayout.BeginVertical(styleGrid);
                            {
                                for (int i = tagarela.animationFiles.Count - 1; i >= 0; i--)
                                {
                                    GUILayout.BeginHorizontal();
                                    {
                                        //CLICK TO OPEN FILE
                                        if (GUILayout.Button(tagarela.animationFiles[i].name.ToString(), styleButtonGrid, GUILayout.Height(20)))
                                        {
                                            LoadAnimationFile(tagarela.animationFiles[i]);
                                        }
                                    }
                                    GUILayout.EndHorizontal();
                                }
                            }
                            GUILayout.EndHorizontal();
                        }
                        GUI.color = Color.white;


                        GUILayout.FlexibleSpace();
                    }     //end vertical
                    GUILayout.EndVertical();
                }
                GUILayout.EndScrollView();
                break;

            case ScreenDialog.Timeline:

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label(fileName, styleFileTitle, GUILayout.Height(21));

                    if (GUILayout.Button("Save", styleBigButtons, GUILayout.Width(70)))
                    {
                        string audioName = SelectedAudioclip != null ? SelectedAudioclip.name : "";
                        TagarelaFileManager.Save(fileName, tagarela.smrTotal, guiTimeline.keyframeSet, 0, audioName, tagarela.settings.animationTime);
                    }
                    if (GUILayout.Button("Close", styleBigButtons, GUILayout.Width(70)))
                    {
                        switch (EditorUtility.DisplayDialogComplex("Close", "Do you want to save?        ", "Yes", "No", "Cancel"))
                        {
                        case 0:
                            updateTimeline = true;
                            string audioName = SelectedAudioclip != null ? SelectedAudioclip.name : "";
                            TagarelaFileManager.Save(fileName, tagarela.smrTotal, guiTimeline.keyframeSet, 0, audioName, tagarela.settings.animationTime);

                            if (tagarela != null)
                            {
                                tagarela.Clean();
                            }
                            CleanVars();

                            dialog = ScreenDialog.InitialScreen;
                            break;

                        case 1:
                            if (tagarela != null)
                            {
                                tagarela.Clean();
                            }
                            CleanVars();
                            dialog = ScreenDialog.InitialScreen;
                            break;
                        }
                    }
                }
                GUILayout.EndHorizontal();

                updateMorph = false;

                //######################################################################################

                GUILayout.BeginVertical(styleBgTimeline, GUILayout.Height(bgTimeline.height));
                {
                    GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false));
                    {
                        if (SelectedAudioclip != null)
                        {
                            GUILayout.Label(SelectedAudioclip.name);
                        }

                        GUILayout.FlexibleSpace();

                        GUILayout.Space(20);

                        GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false));
                        {
                            if (settings != null)
                            {
                                GUILayout.Label(guiTimeline.selectedValue.ToString("0.000") + " / " + settings.animationTime.ToString("0.000"));
                            }
                        }
                        GUILayout.EndHorizontal();

                        GUILayout.Space(5);
                    }
                    GUILayout.EndHorizontal();


                    //scrollViewTimelineVector = GUILayout.BeginScrollView(scrollViewTimelineVector, styleScrollviewTimeline);
                    //{

                    GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
                    //GUILayout.BeginHorizontal(new GUILayoutOption[] { GUILayout.Width(1040f) });
                    {
                        GUILayout.Box("", new GUIStyle(), GUILayout.ExpandWidth(true));

                        Rect lastRect = GUILayoutUtility.GetLastRect();

                        if (lastRect.width > 1)
                        {
                            guiTimeline.Draw(new Rect(lastRect.x, 124, lastRect.width, 57));
                            if (audioPreviewSpectrum != null)
                            {
                                GUI.DrawTexture(new Rect(lastRect.x, 125, lastRect.width, 40), audioPreviewSpectrum);
                            }
                            guiTimelineSegment.Draw(new Rect(lastRect.x + 2, 125, lastRect.width - 2, 130));
                        }

                        switch (playMode)
                        {
                        case PlayMode.all:
                            GUI.color = new Color(130f / 255f, 170f / 255f, 30f / 255f, 0.3f);
                            GUI.DrawTexture(new Rect(guiTimeline.timeLineRect.x + 1, guiTimeline.timeLineRect.y + 44, (guiTimeline.timeLineRect.width) * timeNormalized, 11), EditorGUIUtility.whiteTexture);
                            break;

                        case PlayMode.segment:
                            GUI.color = new Color(130f / 255f, 170f / 255f, 30f / 255f, 0.3f);
                            GUI.DrawTexture(new Rect(guiTimelineSegment.KeyframeSet[0].IconRect.x + 7, guiTimeline.timeLineRect.y + 44, (guiTimeline.timeLineRect.width - 18) * timeNormalized, 11), EditorGUIUtility.whiteTexture);
                            break;
                        }
                    }
                    GUILayout.EndHorizontal();

                    GUI.color = Color.white;

                    //}
                    //GUILayout.EndScrollView();

                    GUILayout.Space(67);

                    GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false));
                    {
                        GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false));
                        {
                            if (guiTimeline.keyframeSet.Count == 1 || disableGuiControls)
                            {
                                GUI.enabled = false;
                            }
                            if (GUILayout.Button(icoRemove, styleBtTimeline, new GUILayoutOption[] { GUILayout.Width(22), GUILayout.Height(20) }))     //btRemove
                            {
                                guiTimeline.RemoveKeyframe(guiTimeline.selectedIndex);
                            }
                            GUI.enabled = true;
                            if (disableGuiControls)
                            {
                                GUI.enabled = false;
                            }
                            if (GUILayout.Button(icoAdd, styleBtTimeline, new GUILayoutOption[] { GUILayout.Width(22), GUILayout.Height(20) }))     //btAdd
                            {
                                TagarelaMorphTarget _morphTargetList = new TagarelaMorphTarget();
                                _morphTargetList.Populate(tagarela.smrTotal);
                                guiTimeline.AddKeyframe(0.0f, _morphTargetList);
                                updateTimeline = true;
                                updateMorph    = true;
                            }
                        }
                        GUILayout.EndHorizontal();


                        GUILayout.FlexibleSpace();

                        if (GUILayout.Button("Sliders to zero", styleBtTimeline, new GUILayoutOption[] { GUILayout.Width(120), GUILayout.Height(20) }))     //btAdd
                        {
                            TagarelaMorphTarget _MorphTarget = guiTimeline.morphSliders;
                            if (_MorphTarget != null)
                            {
                                for (int i = 0; i < _MorphTarget.id.Count; i++)
                                {
                                    _MorphTarget.sliderValue[i] = 0;
                                }
                            }
                            updateTimeline = true;
                        }

                        GUILayout.FlexibleSpace();

                        GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false));
                        {
                            GUI.enabled = !disableGuiControls;

                            if (GUILayout.Button(icoPlay, styleBtTimeline, new GUILayoutOption[] { GUILayout.Width(22), GUILayout.Height(20) }))
                            {
                                //tagarela.setTimer(0);
                                playMode = PlayMode.all;
                            }

                            GUI.enabled = true;
                            if (!guiTimelineSegment.active || disableGuiControls)
                            {
                                GUI.enabled = false;
                            }
                            if (GUILayout.Button(icoPlaySegment, styleBtTimeline, new GUILayoutOption[] { GUILayout.Width(22), GUILayout.Height(20) }))
                            {
                                tagarela.setTimer(guiTimelineSegment.KeyframeSet[0].Value);
                                playMode = PlayMode.segment;
                            }

                            GUI.enabled = false;
                            if (!playMode.Equals(PlayMode.stopped))
                            {
                                GUI.enabled = true;
                            }
                            if (GUILayout.Button(icoStop, styleBtTimeline, new GUILayoutOption[] { GUILayout.Width(22), GUILayout.Height(20) }))
                            {
                                //tagarela.audio.loop = false;
                                tagarela.setTimer(0f);
                                //tagarela.audio.Stop();
                                playMode = PlayMode.stopped;
                                if (tagarela.audio.isPlaying)
                                {
                                    tagarela.audio.Stop();
                                }
                            }

                            //if don´t have any audio, is a time based animation
                            if (SelectedAudioclip == null)
                            {
                                GUI.enabled = !disableGuiControls;
                                GUILayout.Space(10);
                                if (GUILayout.Button(icoClock, styleBtTimeline, new GUILayoutOption[] { GUILayout.Width(22), GUILayout.Height(20) }))
                                {
                                    TagarelaEditorPopupTimeLength popupAnimLength = CreateInstance <TagarelaEditorPopupTimeLength>();
                                    popupAnimLength.parent        = this;
                                    popupAnimLength.title         = "Time Settings";
                                    popupAnimLength.currentLength = popupAnimLength.newLength = guiTimeline.totalValue;
                                    popupAnimLength.ShowAuxWindow();
                                }
                                ;
                            }

                            GUI.enabled = true;
                        }
                        GUILayout.EndHorizontal();
                    }
                    GUILayout.EndHorizontal();
                }
                GUILayout.EndVertical();

                GUI.enabled      = !disableGuiControls;
                scrollViewVector = GUILayout.BeginScrollView(scrollViewVector, styleScrollview);
                {
                    if (tagarela.smrTotal.Count > 0 && guiTimeline.selectedIndex != -1 && guiTimeline.keyframeSet.Count > 0)
                    {
                        EditorGUILayout.BeginVertical();
                        {
                            //seleciona a lista de acordo com o index selecionado
                            TagarelaMorphTarget _MorphTarget = guiTimeline.morphSliders;
                            GUI.color = GUI.contentColor;
                            if (_MorphTarget != null)
                            {
                                //GUILayout.Space(13f);
                                GUILayout.Space(14);     //space before slider list
                                for (int i = 0; i < _MorphTarget.id.Count; i++)
                                {
                                    EditorGUILayout.BeginHorizontal(styleBgSlider, GUILayout.ExpandWidth(true));
                                    {
                                        float temp_value = _MorphTarget.sliderValue[i];

                                        GUILayout.Label(_MorphTarget.id[i], GUILayout.Width(150));
                                        temp_value = GUILayout.HorizontalSlider(temp_value, 0, 100, GUILayout.ExpandWidth(true));
                                        if (_MorphTarget.sliderValue[i] != temp_value)
                                        {
                                            _MorphTarget.sliderValue[i] = temp_value;

                                            updateTimeline = true;
                                        }
                                    }
                                    EditorGUILayout.EndHorizontal();
                                }
                            }
                        }
                        EditorGUILayout.EndVertical();
                    }

                    if (guiTimeline.refresh)
                    {
                        updateWindow = true;
                    }
                    if (guiTimeline.isDragging)
                    {
                        guiTimelineSegment.isDragging = false;
                        guiTimelineSegment.enabled    = false;

                        if (updateMorphValue != guiTimeline.selectedValue && SelectedAudioclip != null)
                        {
                            playMode         = PlayMode.currentTime;
                            updateMorphValue = guiTimeline.selectedValue;
                        }
                    }

                    if (guiTimeline.enabled && (guiTimeline.selectedIndex == -1 || lastKeyframeSelected != guiTimeline.selectedIndex))
                    {
                        lastKeyframeSelected = guiTimeline.selectedIndex;
                        updateMorphValue     = guiTimeline.selectedValue;
                        updateTimeline       = true;
                    }

                    //if a new keyframe was create or cloned, call a update om mesh list
                    if (guiTimeline.isKeyframeSetChanged)
                    {
                        lastKeyframeSelected             = -1;
                        guiTimeline.isKeyframeSetChanged = false;
                        updateTimeline = true;
                        updateMorph    = true;
                    }

                    if (guiTimelineSegment.refresh)
                    {
                        updateWindow = true;
                    }
                    if (guiTimelineSegment.isDragging)
                    {
                        guiTimeline.isDragging = false;
                        guiTimeline.enabled    = false;

                        if (updateMorphValue != guiTimelineSegment.SelectedValue)
                        {
                            playMode         = PlayMode.currentTime;
                            updateMorphValue = guiTimelineSegment.SelectedValue;
                            updateMorph      = true;
                        }
                    }

                    if (!guiTimelineSegment.isDragging && !guiTimeline.isDragging)
                    {
                        guiTimelineSegment.enabled = true;
                        guiTimeline.enabled        = true;
                    }

                    if (playMode.Equals(PlayMode.all) || playMode.Equals(PlayMode.segment))
                    {
                        guiTimeline.enabled = false;
                    }
                }
                GUILayout.EndScrollView();
                GUI.enabled = true;
                break;
            }
        }
        GUILayout.EndVertical();

        if (updateWindow || tagarela != null && tagarela.isPlaying)
        {
            Repaint();
        }
    }
Beispiel #9
0
    void Awake()
    {
        logoEditor           = TagarelaFileManager.LoadImageResource("logoEditor.png");
        logoEditor.hideFlags = HideFlags.DontSave;

        bgEditor           = TagarelaFileManager.LoadImageResource("bgEditor.png");
        bgEditor.hideFlags = HideFlags.DontSave;

        bgTimeline           = TagarelaFileManager.LoadImageResource("bgTimeline.png");
        bgTimeline.hideFlags = HideFlags.DontSave;

        icoPlay           = TagarelaFileManager.LoadImageResource("icoPlay.png");
        icoPlay.hideFlags = HideFlags.DontSave;

        icoClock           = TagarelaFileManager.LoadImageResource("icoClock.png");
        icoClock.hideFlags = HideFlags.DontSave;

        icoPlaySegment           = TagarelaFileManager.LoadImageResource("icoPlaySegment.png");
        icoPlaySegment.hideFlags = HideFlags.DontSave;

        icoStop           = TagarelaFileManager.LoadImageResource("icoStop.png");
        icoStop.hideFlags = HideFlags.DontSave;

        icoAdd           = TagarelaFileManager.LoadImageResource("icoAdd.png");
        icoAdd.hideFlags = HideFlags.DontSave;

        icoRemove           = TagarelaFileManager.LoadImageResource("icoRemove.png");
        icoRemove.hideFlags = HideFlags.DontSave;

        styleHeader         = new GUIStyle();
        styleHeader.padding = new RectOffset(0, 0, 73, 0);

        styleScrollview         = new GUIStyle();
        styleScrollview.padding = new RectOffset(14, 14, 0, 10);

        styleScrollviewTimeline         = new GUIStyle();
        styleScrollviewTimeline.padding = new RectOffset(0, 0, 0, 0);

        styleFileTitle                  = new GUIStyle();
        styleFileTitle.fontStyle        = FontStyle.Bold;
        styleFileTitle.normal.textColor = Color.white;
        styleFileTitle.padding.left     = 14;
        styleFileTitle.fontSize         = 14;

        styleBgTimeline = new GUIStyle();
        styleBgTimeline.normal.background = bgTimeline;
        styleBgTimeline.padding           = new RectOffset(10, 10, 0, 11);

        styleBtTimeline              = new GUIStyle(GUI.skin.button);
        styleBtTimeline.padding      = new RectOffset(0, 0, 0, 0);
        styleBtTimeline.margin.left  = 0;
        styleBtTimeline.margin.right = 1;

        styleBigButtons = new GUIStyle(GUI.skin.button);
        styleBigButtons.padding.left = 0;
        styleBigButtons.margin.top   = 0;

        styleLabelGrid = new GUIStyle();
        styleLabelGrid.normal.background = EditorStyles.toolbarTextField.normal.background;
        styleLabelGrid.normal.textColor  = EditorStyles.toolbarTextField.normal.textColor;
        styleLabelGrid.fontStyle         = EditorStyles.toolbarTextField.fontStyle;
        styleLabelGrid.margin            = new RectOffset(0, 0, 0, 0);
        styleLabelGrid.border            = new RectOffset(2, 2, 3, 3);
        styleLabelGrid.padding           = new RectOffset(2, 2, 1, 2);

        styleBgSlider = new GUIStyle();
        styleBgSlider.normal.background = EditorStyles.toolbarTextField.normal.background;
        styleBgSlider.normal.textColor  = Color.yellow;
        styleBgSlider.border            = new RectOffset(3, 3, 3, 3);
        styleBgSlider.margin            = new RectOffset(13, 13, 3, 3);
        styleBgSlider.padding           = new RectOffset(10, 10, 4, 4);

        styleButtonGrid               = new GUIStyle(GUI.skin.button);
        styleButtonGrid.margin.top    = 0;
        styleButtonGrid.padding.top   = 2;
        styleButtonGrid.padding.left  = 4;
        styleButtonGrid.margin.right  = 0;
        styleButtonGrid.margin.bottom = 2;

        styleGrid         = new GUIStyle(GUI.skin.box);
        styleGrid.margin  = new RectOffset(0, 0, 10, 0);
        styleGrid.padding = new RectOffset(10, 10, 10, 10);

        SelectObject();
    }
Beispiel #10
0
    public override void OnInspectorGUI()
    {
        if (setStyles)
        {
            styleBoxStep         = new GUIStyle(GUI.skin.window);
            styleBoxStep.margin  = new RectOffset(6, 6, 0, 0);
            styleBoxStep.padding = new RectOffset(4, 4, 1, 4);

            styleBoxStepTitle          = new GUIStyle(EditorStyles.boldLabel);
            styleBoxStepTitle.margin   = new RectOffset(0, 0, 0, 0);
            styleBoxStepTitle.padding  = new RectOffset(0, 0, 1, 0);
            styleBoxStepTitle.wordWrap = true;

            styleBoxStepContent          = new GUIStyle(EditorStyles.wordWrappedLabel);
            styleBoxStepContent.margin   = new RectOffset(0, 0, 4, 0);
            styleBoxStepContent.padding  = new RectOffset(0, 0, 0, 0);
            styleBoxStepContent.wordWrap = true;

            styleBoxError        = new GUIStyle(styleBoxStep);
            styleBoxErrorTitle   = new GUIStyle(styleBoxStepTitle);
            styleBoxErrorContent = new GUIStyle(styleBoxStepContent);

            styleBoxErrorTitle = new GUIStyle();
            styleBoxErrorTitle.normal.textColor   = Color.white;
            styleBoxErrorContent.normal.textColor = Color.white;

            styleLabelGrid = new GUIStyle();
            styleLabelGrid.normal.background = EditorStyles.toolbarTextField.normal.background;
            styleLabelGrid.normal.textColor  = EditorStyles.toolbarTextField.normal.textColor;
            styleLabelGrid.fontStyle         = EditorStyles.toolbarTextField.fontStyle;
            styleLabelGrid.margin            = new RectOffset(0, 0, 0, 0);
            styleLabelGrid.border            = new RectOffset(2, 2, 3, 3);
            styleLabelGrid.padding           = new RectOffset(2, 2, 1, 2);

            styleButtonGrid               = new GUIStyle();
            styleButtonGrid               = EditorStyles.miniButtonRight;
            styleButtonGrid.margin.top    = 0;
            styleButtonGrid.padding.top   = 0;
            styleButtonGrid.padding.left  = 0;
            styleButtonGrid.margin.right  = 0;
            styleButtonGrid.margin.bottom = 2;

            styleGrid        = new GUIStyle();
            styleGrid.margin = new RectOffset(6, 4, 2, 2);

            styleMiniLabel           = new GUIStyle(EditorStyles.miniLabel);
            styleMiniLabel.alignment = TextAnchor.MiddleCenter;

            setStyles = false;
        }

        GUI.color = Color.white;

        GUILayout.Space(0);
        Rect lastRect = GUILayoutUtility.GetLastRect();

        GUI.DrawTexture(new Rect(0, lastRect.y + 4, Screen.width, bg_inspector.height), bg_inspector);

        GUILayout.Space(10);

        EditorGUILayout.BeginHorizontal();
        {
            GUILayout.Box(new GUIContent(logo_inspector), new GUIStyle(), new GUILayoutOption[] { GUILayout.Width(110), GUILayout.Height(35) });
            if (nextStepBox != 0 || messageError != "")
            {
                GUI.enabled = false;
                GUI.color   = Color.black;
            }

            if (GUILayout.Button("Open Editor", new GUILayoutOption[] { GUILayout.Height(22) }))
            {
                TagarelaEditor.GetWindow(typeof(TagarelaEditor)).Show();
            }
        }
        EditorGUILayout.EndHorizontal();
        GUI.color   = Color.white;
        GUI.enabled = true;
        EditorGUILayout.BeginVertical();
        {
            GUILayout.Space(4);
            GUI.enabled = true;

            nextStep     = true;
            nextStepBox  = 0;
            messageError = "";

            tagarela.FindBlendShapes();

            if (nextStepBox != 1)
            {
                EditorGUILayout.Separator();
                toolbar     = GUILayout.Toolbar(toolbar, toolbarContent);
                GUI.enabled = true;

                switch (toolbar)
                {
                case 0:     //Audio

                    EditorGUILayout.Separator();

                    EditorGUILayout.BeginHorizontal();
                    {
                        GUILayout.Label("Audio Clip:");
                        tempAudio = EditorGUILayout.ObjectField(tempAudio, typeof(AudioClip), false) as AudioClip;
                        if (tempAudio == null)
                        {
                            GUI.enabled = false;
                        }
                        if (GUILayout.Button("Add", new GUILayoutOption[] { GUILayout.Width(60), GUILayout.Height(16) }) && !tagarela.audioFiles.Find(delegate(AudioClip a)
                        {
                            return(a.name == tempAudio.name);
                        }))
                        {
                            tagarela.audioFiles.Add(tempAudio);
                            tempAudio = null;
                        }
                        GUI.enabled = true;
                    }
                    EditorGUILayout.EndHorizontal();


                    if (tagarela.audioFiles.Count > 0)
                    {
                        EditorGUILayout.BeginVertical(styleGrid);
                        {
                            tagarela.audioFiles.ForEach(delegate(AudioClip a)
                            {
                                EditorGUILayout.BeginHorizontal();

                                GUILayout.Box(a.name, styleLabelGrid, new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(16) });
                                if (GUILayout.Button("Remove", styleButtonGrid, new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(16), GUILayout.Width(59) }))
                                {
                                    //if (GUILayout.Button("X ", EditorStyles.toolbarButton, new GUILayoutOption[] { GUILayout.Height(20), GUILayout.Width(20) }))
                                    tagarela.audioFiles.Remove(a);
                                    tempAudio = null;
                                }

                                EditorGUILayout.EndHorizontal();
                            });
                        }
                        EditorGUILayout.EndVertical();
                    }
                    tempLipFilePreview = null;
                    break;

                case 1:     //lip files

                    EditorGUILayout.Separator();

                    //tempLipFile = EditorGUILayout.ObjectField("Lip Sync files", tempLipFile, typeof(TextAsset), false) as TextAsset;
                    if (GUILayout.Button("Add Animation from Assets"))
                    {
                        string path = EditorUtility.OpenFilePanel("Tagarela Animation Files", Application.dataPath + "/Tagarela/Animations/", "xml");
                        path        = path.Replace(Application.dataPath, "Assets");
                        tempLipFile = AssetDatabase.LoadMainAssetAtPath(path) as TextAsset;
                        if (tempLipFile != null)
                        {
                            tempLipFilePreview = TagarelaFileManager.Load(tempLipFile);
                            if (tempLipFilePreview.meshVertexCount == vertexCount)
                            {
                                if (tagarela.animationFiles.Find(delegate(TextAsset a)
                                {
                                    return(a.name == tempLipFile.name);
                                }) == null)
                                {
                                    tagarela.animationFiles.Add(tempLipFile);
                                    tempLipFile = null;
                                }
                                ;
                            }
                        }
                    }

                    if (tempLipFilePreview != null && tempLipFilePreview.meshVertexCount != vertexCount)
                    {
                        EditorGUILayout.Separator();
                        GUIErrorBox("The selected file has inconsistent data.");
                        EditorGUILayout.Separator();
                    }

                    if (tagarela.animationFiles.Count > 0)
                    {
                        EditorGUILayout.BeginVertical(styleGrid);
                        {
                            //int index = 0;

                            for (int index = tagarela.animationFiles.Count - 1; index >= 0; index--)
                            {
                                EditorGUILayout.BeginHorizontal();
                                TextAsset f = tagarela.animationFiles[index];
                                GUILayout.Box("(" + index + ") " + f.name, styleLabelGrid, new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(16) });

                                if (GUILayout.Button("Remove", styleButtonGrid, new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(16), GUILayout.Width(59) }))
                                {
                                    switch (EditorUtility.DisplayDialogComplex("Remove", "Do you want to delete completely the file?", "Yes", "No, Just remove", "Cancel"))
                                    {
                                    case 0:
                                        tagarela.animationFiles.Remove(f);
                                        TagarelaFileManager.Delete(f);
                                        tempLipFile = null;
                                        Repaint();
                                        break;

                                    case 1:
                                        tagarela.animationFiles.Remove(f);
                                        tempLipFile = null;
                                        break;
                                    }
                                }

                                EditorGUILayout.EndHorizontal();
                            }
                        }
                        EditorGUILayout.EndVertical();
                    }

                    break;
                }
            }

            GUI.enabled = true;

            if (!nextStep && messageError != "")
            {
                GUIErrorBox(messageError);
            }

            EditorGUILayout.Separator();

            switch (nextStepBox)
            {
            case 1:
                GUInextStepBox("Step 1 - Main Object", "Select in Scene or Hierarchy Window the Main Object that you want to control. This object must have a Mesh Renderer or Skinned Mesh Renderer Component. In some cases, this is the Main Object.");
                EditorGUILayout.Separator();
                break;

            case 2:
                GUInextStepBox("Step 2 - Neutral Mesh", "Select a Neutral Mesh in your Project Window.");
                EditorGUILayout.Separator();
                break;

            case 3:
                GUInextStepBox("Step 3 - Blend Shapes", "Select at least one Blend Shape in your Project Window and click in Add.");
                EditorGUILayout.Separator();
                break;
            }

            GUILayout.Label(versionNumber, styleMiniLabel, new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(16) });
            GUILayout.Label("Developed by Rodrigo Pegorari - 2014\nhttp://www.rodrigopegorari.net", styleMiniLabel, new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(26) });
            GUILayout.Space(4f);
        }
        EditorGUILayout.EndVertical();
    }