Exemple #1
0
        public bool RegisterMetaComponent(MetaComponent meta)
        {
            if (meta == null || m_metaComponents.Exists(item => item.Name == meta.Name))
            {
                return(false);
            }

            m_metaComponents.Add(meta);
            return(true);
        }
Exemple #2
0
        public List <MetaProperty> GetFlattenPropertiesOf(MetaComponent component)
        {
            if (component == null)
            {
                return(null);
            }

            List <MetaProperty> result = new List <MetaProperty>();

            MetaComponent       baseMeta;
            List <MetaProperty> baseProps;

            if (component.BaseClasses != null && component.BaseClasses.Count > 0)
            {
                foreach (string baseClass in component.BaseClasses)
                {
                    baseMeta = FindMetaComponent(baseClass);
                    if (baseMeta == null)
                    {
                        continue;
                    }

                    baseProps = GetFlattenPropertiesOf(baseMeta);
                    if (baseProps == null || baseProps.Count == 0)
                    {
                        continue;
                    }

                    foreach (MetaProperty p in baseProps)
                    {
                        if (!result.Exists(item => item.Name == p.Name))
                        {
                            result.Add(p);
                        }
                    }
                }
            }

            if (component.Properties != null && component.Properties.Count > 0)
            {
                foreach (MetaProperty p in component.Properties)
                {
                    if (!result.Exists(item => item.Name == p.Name))
                    {
                        result.Add(p);
                    }
                }
            }

            return(result);
        }
Exemple #3
0
        private void OnAction(Action action)
        {
            if (action == null)
            {
                return;
            }

            if (action.Id == "CbpChanged")
            {
                Console.WriteLine("CBP project file changed!");
                if (ProjectModel != null)
                {
                    ProjectModel.UpdateFromCbp();
                    MetaComponentsManager.Instance.UnregisterAllMetaComponents();
                    Parallel.Invoke(
                        () => LoadSdkMetaFiles(),
                        () => GenerateProjectMetaFiles()
                        );
                    if (m_buildPage != null)
                    {
                        m_buildPage.RefreshContent();
                    }
                    if (m_projectManagerPanel != null)
                    {
                        m_projectManagerPanel.RebuildList();
                    }
                }
            }
            else if (action.Id == "EditorCbpChanged")
            {
                Console.WriteLine("Editor CBP project file changed!");
                if (m_buildPage != null && !m_buildPage.IsBatchProcessRunning && ProjectModel != null && !string.IsNullOrEmpty(ProjectModel.EditorCbpPath))
                {
                    if (m_scenePage != null)
                    {
                        m_scenePage.SaveSceneBackup();
                    }
                    SceneViewPlugin.Unload();
                    m_buildPage.BatchOperationProject(
                        BuildPageControl.BatchOperationMode.Rebuild,
                        null,
                        ProjectModel.WorkingDirectory + @"\" + ProjectModel.EditorCbpPath
                        );
                }
            }
            else if (action.Id == "SceneViewPluginChanged")
            {
                Console.WriteLine("Editor components plugin changed!");
                if (ProjectModel != null && !string.IsNullOrEmpty(ProjectModel.EditorPluginPath))
                {
                    string pluginPath = ProjectModel.WorkingDirectory + @"\" + ProjectModel.EditorPluginPath;
                    SceneViewPlugin.Unload();
                    if (SceneViewPlugin.Load(pluginPath))
                    {
                        if (m_scenePage != null)
                        {
                            m_scenePage.ReinitializeRenderer();
                        }
                        List <string> clist = SceneViewPlugin.ListComponents();
                        if (clist != null && clist.Count > 0)
                        {
                            foreach (string c in clist)
                            {
                                Console.WriteLine("Registered component: " + c);
                            }
                        }
                        if (m_scenePage != null)
                        {
                            m_scenePage.OpenSceneBackup();
                        }
                    }
                }
            }
            else if (action.Id == "LoadMetaComponent" && action.Params != null && action.Params.Length > 0)
            {
                string path = action.Params[0] as string;
                if (!String.IsNullOrEmpty(path) && ProjectModel != null)
                {
                    Console.WriteLine("Load meta-component for: \"{0}\"", path);
                    string metaPath = path + ".meta";
                    if (File.Exists(metaPath))
                    {
                        string        json = File.ReadAllText(metaPath);
                        MetaComponent meta = Newtonsoft.Json.JsonConvert.DeserializeObject <MetaComponent>(json);
                        MetaComponentsManager.Instance.UnregisterMetaComponent(meta);
                        ProjectModel.MetaComponentPaths.Remove(path);
                        if (meta != null)
                        {
                            MetaComponentsManager.Instance.RegisterMetaComponent(meta);
                            ProjectModel.MetaComponentPaths.Add(path, meta);
                            if (meta.Properties != null && meta.Properties.Count > 0)
                            {
                                foreach (MetaProperty prop in meta.Properties)
                                {
                                    if (PropertyEditorsManager.Instance.FindPropertyEditor(prop.ValueType) == null)
                                    {
                                        Console.WriteLine("Property editor for type: \"{0}\" (component: \"{1}\", property: \"{2}\") not found!", prop.ValueType, meta.Name, prop.Name);
                                    }
                                }
                            }
                        }
                    }
                    if (m_projectManagerPanel != null)
                    {
                        m_projectManagerPanel.UpdateFile(path);
                    }
                    GenerateProjectCodeFiles();
                }
            }
            else if (action.Id == "RemoveMetaComponent" && action.Params != null && action.Params.Length > 0)
            {
                string path = action.Params[0] as string;
                if (!String.IsNullOrEmpty(path) && ProjectModel != null && ProjectModel.MetaComponentPaths.ContainsKey(path))
                {
                    Console.WriteLine("Remove meta-component for: \"{0}\"", path);
                    MetaComponentsManager.Instance.UnregisterMetaComponent(ProjectModel.MetaComponentPaths[path]);
                    ProjectModel.MetaComponentPaths.Remove(path);
                    if (m_projectManagerPanel != null)
                    {
                        m_projectManagerPanel.UpdateFile(path);
                    }
                    GenerateProjectCodeFiles();
                }
            }
            else if (action.Id == "LoadMetaAsset" && action.Params != null && action.Params.Length > 0)
            {
                string path = action.Params[0] as string;
                if (!String.IsNullOrEmpty(path) && ProjectModel != null)
                {
                    Console.WriteLine("Load meta-asset for: \"{0}\"", path);
                    string metaPath = path + ".meta";
                    if (File.Exists(metaPath))
                    {
                        string    json = File.ReadAllText(metaPath);
                        MetaAsset meta = Newtonsoft.Json.JsonConvert.DeserializeObject <MetaAsset>(json);
                        MetaAssetsManager.Instance.UnregisterMetaAsset(meta);
                        ProjectModel.MetaAssetsPaths.Remove(path);
                        if (meta != null)
                        {
                            MetaAssetsManager.Instance.RegisterMetaAsset(meta);
                            ProjectModel.MetaAssetsPaths.Add(path, meta);
                        }
                    }
                    if (m_projectManagerPanel != null)
                    {
                        m_projectManagerPanel.UpdateFile(path);
                    }
                    GenerateProjectCodeFiles();
                }
            }
            else if (action.Id == "RemoveMetaAsset" && action.Params != null && action.Params.Length > 0)
            {
                string path = action.Params[0] as string;
                if (!String.IsNullOrEmpty(path) && ProjectModel != null && ProjectModel.MetaAssetsPaths.ContainsKey(path))
                {
                    Console.WriteLine("Remove meta-asset for: \"{0}\"", path);
                    MetaAssetsManager.Instance.UnregisterMetaAsset(ProjectModel.MetaAssetsPaths[path]);
                    ProjectModel.MetaAssetsPaths.Remove(path);
                    if (m_projectManagerPanel != null)
                    {
                        m_projectManagerPanel.UpdateFile(path);
                    }
                    GenerateProjectCodeFiles();
                }
            }
            else if (action.Id == "GameObjectIdChanged" && action.Params != null && action.Params.Length > 0)
            {
                if (m_scenePage != null)
                {
                    m_scenePage.SceneTreeChangeGameObjectId((int)action.Params[0]);
                }
            }
        }
        private int InitializeComponentFragment(string component, int y)
        {
            if (string.IsNullOrEmpty(component))
            {
                return(y);
            }

            MetaComponent meta = MetaComponentsManager.Instance.FindMetaComponent(component);

            if (meta == null)
            {
                return(y);
            }

            MetroButton componentButton = new MetroButton();

            MetroSkinManager.ApplyMetroStyle(componentButton);
            componentButton.Text       = component;
            componentButton.FontWeight = MetroButtonWeight.Bold;
            componentButton.Top        = y + DEFAULT_SEPARATOR + DEFAULT_SEPARATOR + DEFAULT_SEPARATOR;
            componentButton.Width      = Width;
            componentButton.Anchor     = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            componentButton.Click     += new EventHandler(componentButton_Click);
            Controls.Add(componentButton);
            y = componentButton.Bottom + DEFAULT_SEPARATOR;

            if (meta.FunctionalityTriggers != null && meta.FunctionalityTriggers.Count > 0)
            {
                MetroLabel label = new MetroLabel();
                MetroSkinManager.ApplyMetroStyle(label);
                label.Text       = "Functionality Triggers";
                label.FontWeight = MetroLabelWeight.Bold;
                label.FontSize   = MetroLabelSize.Small;
                label.Top        = y;
                label.Width      = Width;
                label.Anchor     = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                Controls.Add(label);
                y = label.Bottom;

                foreach (string func in meta.FunctionalityTriggers)
                {
                    MetroButton btn = new MetroButton();
                    MetroSkinManager.ApplyMetroStyle(btn);
                    btn.Tag    = meta.Name;
                    btn.Text   = func;
                    btn.Top    = y;
                    btn.Width  = Width - 20;
                    btn.Left   = 10;
                    btn.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                    btn.Click += new EventHandler(triggerFunctionality_Click);
                    Controls.Add(btn);
                    y = btn.Bottom + DEFAULT_SEPARATOR;
                }
            }

            List <MetaProperty> props = MetaComponentsManager.Instance.GetFlattenPropertiesOf(meta);

            if (props == null || props.Count == 0)
            {
                return(y);
            }

            foreach (MetaProperty p in props)
            {
                Type t = PropertyEditorsManager.Instance.FindPropertyEditor(p.ValueType);
                if (t == null)
                {
                    string msg = string.Format("Property editor for type: \"{0}\" not found!", p.ValueType);
                    ErrorPropertyEditor editor = new ErrorPropertyEditor(p.Name, msg);
                    editor.UpdateEditorValue();
                    editor.Top    = y;
                    editor.Width  = Width;
                    editor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                    Controls.Add(editor);
                    y = editor.Bottom + DEFAULT_SEPARATOR;
                }
                else
                {
                    y = InitializePropertyFragment(component, p, t, y);
                }
            }

            return(y);
        }
Exemple #5
0
 public bool UnregisterMetaComponent(MetaComponent meta)
 {
     return(m_metaComponents.Remove(meta));
 }