private void OnSaveCompleted(ISaveAssetDialog sender, UnityObject asset)
        {
            sender.SaveCompleted -= OnSaveCompleted;

            if (asset == null)
            {
                return;
            }

            RuntimeAnimationClip clip = (RuntimeAnimationClip)asset;
            GameObject           go   = TargetGameObject;

            ExposeToEditor exposeToEditor = go.GetComponent <ExposeToEditor>();

            if (exposeToEditor != null)
            {
                Editor.Undo.BeginRecord();
                if (!exposeToEditor.GetComponent <RuntimeAnimation>())
                {
                    Editor.Undo.AddComponent(exposeToEditor, typeof(RuntimeAnimation));
                }
                Editor.Undo.CreateRecord(redoRecord =>
                {
                    SetAnimationClip(clip, go);
                    return(true);
                },
                                         undoRecord =>
                {
                    RuntimeAnimation animation = exposeToEditor.GetComponent <RuntimeAnimation>();
                    if (animation != null)
                    {
                        animation.Clips = null;
                    }
                    UpdateTargetAnimation();
                    m_propertiesView.Target = null;
                    m_timelineView.Target   = null;
                    UpdateCreateViewState();
                    return(true);
                });
                Editor.Undo.EndRecord();
            }
            else
            {
                if (!go.GetComponent <RuntimeAnimation>())
                {
                    go.AddComponent <RuntimeAnimation>();
                }
            }

            SetAnimationClip(clip, go);
        }
예제 #2
0
        private void SetAnimationClip(RuntimeAnimationClip clip, ExposeToEditor exposeToEditor)
        {
            RuntimeAnimation animation = exposeToEditor.GetComponent <RuntimeAnimation>();

            animation.Clips = new List <RuntimeAnimationClip> {
                clip
            };
            animation.ClipIndex = 0;

            UpdateTargetAnimation();
            m_propertiesView.Target = animation;
            m_timelineView.Target   = animation;

            CurrentClip = clip;

            if (exposeToEditor != null && animation != null)
            {
                exposeToEditor.ReloadComponentEditor(animation, true);
            }

            animation.Refresh();
            UpdateCreateViewState();
        }
예제 #3
0
        private void Start()
        {
            m_parentDialog                 = GetComponentInParent <Dialog>();
            m_parentDialog.IsOkVisible     = true;
            m_parentDialog.IsCancelVisible = true;
            m_parentDialog.OkText          = m_localization.GetString("ID_RTEditor_SelectObjectDialog_Select", "Select");
            m_parentDialog.CancelText      = m_localization.GetString("ID_RTEditor_SelectObjectDialog_Cancel", "Cancel");
            m_parentDialog.Ok             += OnOk;

            m_toggleAssets.onValueChanged.AddListener(OnAssetsTabSelectionChanged);

            m_project       = IOC.Resolve <IProject>();
            m_windowManager = IOC.Resolve <IWindowManager>();

            IResourcePreviewUtility resourcePreview = IOC.Resolve <IResourcePreviewUtility>();

            AssetItem[] assetItems = m_project.Root.Flatten(true, false).Where(item =>
            {
                Type type = m_project.ToType((AssetItem)item);
                if (type == null)
                {
                    return(false);
                }
                return(type == ObjectType || type.IsSubclassOf(ObjectType));
            }).OfType <AssetItem>().ToArray();

            m_treeView.SelectionChanged += OnSelectionChanged;
            m_treeView.ItemDataBinding  += OnItemDataBinding;
            Editor.IsBusy = true;
            m_parentDialog.IsOkInteractable = false;
            m_project.GetAssetItems(assetItems, (error, assetItemsWithPreviews) =>
            {
                if (error.HasError)
                {
                    Editor.IsBusy = false;
                    m_windowManager.MessageBox(m_localization.GetString("ID_RTEditor_SelectObjectDialog_CantGetAssets", "Can't GetAssets"), error.ToString());
                    return;
                }

                AssetItem none = new AssetItem();
                none.Name      = m_localization.GetString("ID_RTEditor_SelectObjectDialog_None", "None");
                none.TypeGuid  = m_noneGuid;

                assetItemsWithPreviews = new[] { none }.Union(assetItemsWithPreviews).ToArray();

                m_previewsCreated = false;
                StartCoroutine(ProjectItemView.CoCreatePreviews(assetItemsWithPreviews, m_project, resourcePreview, () =>
                {
                    m_previewsCreated = true;
                    HandleSelectionChanged((AssetItem)m_treeView.SelectedItem);
                    m_treeView.ItemDoubleClick     += OnItemDoubleClick;
                    m_parentDialog.IsOkInteractable = m_previewsCreated && m_treeView.SelectedItem != null;
                    Editor.IsBusy = false;

                    if (m_filter != null)
                    {
                        if (!string.IsNullOrEmpty(m_filter.text))
                        {
                            ApplyFilter(m_filter.text);
                        }
                        m_filter.onValueChanged.AddListener(OnFilterValueChanged);
                    }
                }));

                m_assetsCache    = assetItemsWithPreviews;
                m_treeView.Items = m_assetsCache;

                List <AssetItem> sceneCache = new List <AssetItem>();
                sceneCache.Add(none);

                m_sceneObjects = new Dictionary <long, UnityObject>();
                ExposeToEditor[] sceneObjects = Editor.Object.Get(false, true).ToArray();
                for (int i = 0; i < sceneObjects.Length; ++i)
                {
                    ExposeToEditor exposeToEditor = sceneObjects[i];
                    UnityObject obj = null;
                    if (ObjectType == typeof(GameObject))
                    {
                        obj = exposeToEditor.gameObject;
                    }
                    else if (ObjectType.IsSubclassOf(typeof(Component)))
                    {
                        obj = exposeToEditor.GetComponent(ObjectType);
                    }

                    if (obj != null)
                    {
                        AssetItem assetItem = new AssetItem()
                        {
                            ItemID = m_project.ToID(exposeToEditor),
                            Name   = exposeToEditor.name,
                        };
                        assetItem.TypeGuid = m_project.ToGuid(typeof(GameObject));
                        assetItem.Preview  = new Preview {
                            ItemID = assetItem.ItemID, PreviewData = new byte[0]
                        };
                        sceneCache.Add(assetItem);
                        m_sceneObjects.Add(assetItem.ItemID, obj);
                    }
                }
                m_sceneCache = sceneCache.ToArray();
            });
        }