예제 #1
0
        private void OnCreateEntity(object e)
        {
            CEntity emptyEntity = new CEntity();

            emptyEntity.Name = "Entity";
            CEntityAsset <CEntity> .CreateFromEntity(emptyEntity, ActiveDirectory);

            UpdateShownAssets();
        }
        private void OnCreateAssetFromEntity(object e)
        {
            // We need the asset browser to get the active path where we want to save the entity asset
            CAssetBrowserViewModel assetBrowser = CWorkspace.Instance.GetTool <CAssetBrowserViewModel>();
            string assetPath = assetBrowser.ActiveDirectory;

            CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
            {
                CEntity entity = EntityId.GetEntity();
                CEntityAsset <CEntity> .CreateFromEntity(entity, assetPath);
                Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
                {
                    assetBrowser.UpdateShownAssets();
                }));
            });
        }
예제 #3
0
 public void OpenAsset(CEntityAsset <CEntity> asset)
 {
     Entity = asset.GetEntity();
     OnAssetOpened?.Invoke(asset, Entity);
 }
예제 #4
0
        public void HandleDrop(object dropData)
        {
            CEntityAsset <CEntity> entityAsset = (CEntityAsset <CEntity>)dropData;

            CEngine.Instance.CurrentWorld.InitWithWorld(entityAsset.GetEntity());
        }
예제 #5
0
        private void InitializeEntityMenues()
        {
            List <CAddComponentEntryViewModel> tempList = new List <CAddComponentEntryViewModel>(128);
            Dictionary <string, List <CAddComponentEntryViewModel> > components = new Dictionary <string, List <CAddComponentEntryViewModel> >(12);

            foreach (var type in CKlaxScriptRegistry.Instance.Types)
            {
                if (type.Type.IsSubclassOf(typeof(CEntityComponent)))
                {
                    KlaxComponentAttribute attribute = type.Type.GetCustomAttribute <KlaxComponentAttribute>();

                    if (attribute.HideInEditor)
                    {
                        continue;
                    }

                    CAddComponentEntryViewModel vm = new CAddComponentEntryViewModel(type.Name, type.Type);

                    if (components.TryGetValue(attribute.Category, out List <CAddComponentEntryViewModel> list))
                    {
                        list.Add(vm);
                    }
                    else
                    {
                        List <CAddComponentEntryViewModel> newList = new List <CAddComponentEntryViewModel>(8);
                        components.Add(attribute.Category, newList);

                        newList.Add(vm);
                    }
                }
            }

            List <CAddComponentCategoryViewModel> orderedList = new List <CAddComponentCategoryViewModel>(components.Count);

            foreach (var entry in components)
            {
                CAddComponentCategoryViewModel vm = new CAddComponentCategoryViewModel(entry.Key, entry.Value);
                orderedList.Add(vm);
            }

            orderedList = orderedList.OrderBy(p => p.Name).ToList();
            //Always show Common on top
            for (int i = 0, count = orderedList.Count; i < count; i++)
            {
                if (orderedList[i].Name == "Common")
                {
                    ContainerUtilities.Swap(orderedList, i, 0);
                    break;
                }
            }

            m_addComponentMenuCategories = new ObservableCollection <CAddComponentCategoryViewModel>(orderedList);

            m_entityCommands = new ObservableCollection <CEntityCommandViewModel>();
            m_entityCommands.Add(new CEntityCommandViewModel("Save as Asset", new CRelayCommand((obj) =>
            {
                EntityCommandsMenuOpen = false;

                CAssetBrowserViewModel assetBrowser = CWorkspace.Instance.GetTool <CAssetBrowserViewModel>();
                string assetPath = assetBrowser.ActiveDirectory;
                SEntityId id     = m_selectedObject.GetTargetEntityId();

                CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
                {
                    CEntity entity = id.GetEntity();
                    CEntityAsset <CEntity> .CreateFromEntity(entity, assetPath);
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
                    {
                        assetBrowser.UpdateShownAssets();
                    }));
                });
            })));
        }