private void UpdateProperties() { List <string> props = new List <string>(); foreach (var propEditor in m_propertyEditors) { if (m_subProperties.ContainsKey(propEditor.Key)) { props.Add("\"" + propEditor.Key + "\""); } } string query = "{ \"getProperty\": [ { \"id\": " + m_subProperties["id"] + ", \"properties\": [ " + string.Join(", ", props) + "] } ] }"; var result = SceneViewPlugin.QueryAssets <Dictionary <string, string> >(m_assetType, query); foreach (var item in result) { foreach (var data in item) { if (m_propertyEditors.Exists(e => e.Key == data.Key) && m_subProperties.ContainsKey(data.Key)) { m_subProperties[data.Key] = data.Value; } } } foreach (var item in m_propertyEditors) { item.Value.UpdateEditorValue(); } }
public bool OpenSceneBackup() { if (string.IsNullOrEmpty(m_scenePath)) { return(false); } string path = m_scenePath + ".backup"; if (!File.Exists(path)) { return(false); } MainForm mainForm = FindForm() as MainForm; if (mainForm != null) { SceneViewPlugin.SetAssetsFileSystemRoot(mainForm.ProjectModel.WorkingDirectory + @"\" + mainForm.ProjectModel.ActiveTargetWorkingDirectory); } string json = File.ReadAllText(path); m_renderer.RebuildSceneView(json); RebuildSceneTree(); return(true); }
private void applyButton_Click(object sender, EventArgs e) { string freeQuery = "\"free\": [ \"" + m_lastId + "\" ], "; List <string> setList = new List <string>(); foreach (var item in m_propertyEditors) { if (m_subProperties.ContainsKey(item.Key)) { setList.Add(String.Format("\"{0}\": {1}", item.Key, m_subProperties[item.Key])); } } string setQuery = "{ \"id\": \"" + m_lastId + "\", " + String.Join(", ", setList) + " }"; string query = "{ " + (string.IsNullOrEmpty(m_lastId) ? "" : freeQuery) + "\"load\": [ " + JsonValue + " ], \"setProperty\": [ " + setQuery + " ] }"; if (SceneViewPlugin.QueryAssets(m_assetType, query) != null) { MainForm mainForm = FindForm() as MainForm; if (mainForm != null) { mainForm.ExploreAssetsProperties(m_assetType); mainForm.RefreshSceneView(); } } UpdateProperties(); }
private void UpdateGameObjectNode(TreeNodeCollection nodes, int handle) { if (nodes == null || handle == 0) { return; } foreach (TreeNode node in nodes) { if (node.Tag.Equals(handle)) { Dictionary <string, string> info = SceneViewPlugin.QueryGameObject( handle, IsGameObjectsPrefabsMode, "{ \"get\": { \"properties\": [ \"Id\" ] } }" ); string id; if (info != null && info.ContainsKey("properties/Id")) { id = Newtonsoft.Json.JsonConvert.DeserializeObject <string>(info["properties/Id"]); } else { id = handle.ToString(); } node.Text = id; } UpdateGameObjectNode(node.Nodes, handle); } }
public void CloseScene() { m_renderer.RebuildSceneView(null); m_scenePath = null; SceneViewPlugin.SetAssetsFileSystemRoot(""); RebuildSceneTree(); }
private void RendererSurfaceControl_Resize(object sender, EventArgs e) { if (SceneViewPlugin.IsLoaded) { SceneViewPlugin.SetSceneViewSize(Width, Height); } }
private void RendererSurfaceControl_MouseDown(object sender, MouseEventArgs e) { if (!SceneViewPlugin.IsLoaded) { return; } if (e.Button == MouseButtons.Left) { int handle = SceneViewPlugin.FindGameObjectHandleAtScreenPosition(e.X, e.Y); if (handle != m_lastClickedGameObject) { MainForm mainForm = FindForm() as MainForm; if (mainForm != null) { mainForm.ExploreGameObjectProperties(handle, false); } } m_lastClickedGameObject = handle; m_isDraggingGameObject = handle; m_lastDragPosition = e.Location; } else if (e.Button == MouseButtons.Right) { m_isDragging = true; m_lastCameraZoom = m_cameraZoom; m_lastDragPosition = e.Location; } }
public void UpdateEditorsValues() { Dictionary <string, string> result = SceneViewPlugin.QueryGameObject(m_goHandle, m_goIsPrefab, "{ \"get\": null }"); m_goData.Clear(); foreach (string key in result.Keys) { m_goData.Add(key, result[key]); } bool irc; foreach (IEditorJsonValue e in m_editors) { if (result.ContainsKey(e.PropertyName)) { irc = e.IsRaisingEditorJsonValueChangedCallback; e.IsRaisingEditorJsonValueChangedCallback = false; e.UpdateEditorValue(); e.IsRaisingEditorJsonValueChangedCallback = irc; } } MainForm mainForm = FindForm() as MainForm; if (mainForm != null) { mainForm.RefreshSceneView(); } }
private void addComponentButton_Click(object sender, EventArgs e) { MetroButton btn = sender as MetroButton; if (btn == null) { return; } List <string> components = SceneViewPlugin.ListComponents(); if (components == null || components.Count == 0) { return; } MetroContextMenu menu = new MetroContextMenu(null); MetroSkinManager.ApplyMetroStyle(menu); ToolStripMenuItem menuItem; foreach (string c in components) { menuItem = new ToolStripMenuItem(c); menuItem.Click += new EventHandler(menuItem_addNewComponent_Click); menu.Items.Add(menuItem); } menu.Show(btn, new Point(0, btn.Height)); }
public bool ReinitializeRenderer() { if (SceneViewPlugin.Initialize(Handle.ToInt64())) { SceneViewPlugin.SetSceneViewSize(Width, Height); SceneViewPlugin.SetSceneViewCenter(m_cameraCenter.X, m_cameraCenter.Y); SceneViewPlugin.SetSceneViewZoom(m_cameraZoom); return(true); } return(false); }
public bool SaveScene(string path) { string json = SceneViewPlugin.ConvertSceneToJson(); File.WriteAllText(path, json); if (File.Exists(path)) { m_scenePath = path; return(true); } return(false); }
public bool SaveSceneBackup() { if (string.IsNullOrEmpty(m_scenePath)) { return(false); } string path = m_scenePath + ".backup"; string json = SceneViewPlugin.ConvertSceneToJson(); File.WriteAllText(path, json); return(File.Exists(path)); }
private void RemoveGameObject(int handle, bool isPrefab) { if (string.IsNullOrEmpty(m_scenePath)) { return; } if (SceneViewPlugin.DestroyGameObject(handle, isPrefab)) { RebuildSceneTree(); RefreshSceneView(); } }
private void RemoveAllGameObjects(bool isPrefab) { if (string.IsNullOrEmpty(m_scenePath)) { return; } if (SceneViewPlugin.ClearSceneGameObjects(isPrefab)) { RebuildSceneTree(); RefreshSceneView(); } }
private void removeButton_Click(object sender, EventArgs e) { string query = "{ \"free\": [ \"" + m_lastId + "\" ] }"; if (SceneViewPlugin.QueryAssets(m_assetType, query) != null) { MainForm mainForm = FindForm() as MainForm; if (mainForm != null) { mainForm.ExploreAssetsProperties(m_assetType); mainForm.RefreshSceneView(); } } }
public void RebuildSceneView(string json) { if (!SceneViewPlugin.IsLoaded) { return; } SceneViewPlugin.ClearScene(); if (!string.IsNullOrEmpty(json)) { SceneViewPlugin.ApplyJsonToScene(json); } Invalidate(); }
private void triggerFunctionality_Click(object sender, EventArgs e) { MetroButton btn = sender as MetroButton; if (btn == null || !(btn.Tag is string)) { return; } if (SceneViewPlugin.TriggerGameObjectComponentFunctionality(m_goHandle, m_goIsPrefab, btn.Tag as string, btn.Text)) { UpdateEditorsValues(); } }
private void applyToPrefabButton_Click(object sender, EventArgs e) { MainForm mainForm = FindForm() as MainForm; MetroButton button = sender as MetroButton; if (mainForm != null && button != null && button.Tag is string) { int handle = SceneViewPlugin.FindGameObjectHandleById(button.Tag as string, true, 0); if (handle != 0) { SceneViewPlugin.DuplicateGameObject(m_goHandle, m_goIsPrefab, handle, true); } } }
private void selectPrefabButton_Click(object sender, EventArgs e) { MainForm mainForm = FindForm() as MainForm; MetroButton button = sender as MetroButton; if (mainForm != null && button != null && button.Tag is string) { int handle = SceneViewPlugin.FindGameObjectHandleById(button.Tag as string, true, 0); if (handle != 0) { mainForm.ExploreGameObjectProperties(handle, true); } } }
private void BuildSceneTreeNodes(TreeNodeCollection nodes, List <SceneViewPlugin.GameObjectData> list = null) { if (list == null) { list = SceneViewPlugin.ListGameObjects(IsGameObjectsPrefabsMode); } if (list != null && list.Count > 0) { foreach (var item in list) { TreeNode node = nodes.Add(item.id); node.Tag = item.handle; BuildSceneTreeNodes(node.Nodes, item.childs); } } }
protected void UpdateValuesSource() { List <string> values = SceneViewPlugin.ListAssets(m_assetType); values = OnUpdateValuesSource(values); if (values != null) { values.Insert(0, NONE); ValuesSource = values.ToArray(); UpdateEditorValue(); } else { ValuesSource = new string[] {}; UpdateEditorValue(); } }
private void menuItem_addNewComponent_Click(object sender, EventArgs e) { ToolStripMenuItem menuItem = sender as ToolStripMenuItem; if (menuItem == null) { return; } string query = "{ \"set\": { \"components\": { \"" + menuItem.Text + "\": 0 } } }"; Dictionary <string, string> result = SceneViewPlugin.QueryGameObject(m_goHandle, m_goIsPrefab, query); MainForm mainForm = FindForm() as MainForm; if (mainForm != null) { mainForm.ExploreGameObjectProperties(m_goHandle, m_goIsPrefab); mainForm.RefreshSceneView(); } }
override protected List <string> OnUpdateValuesSource(List <string> ids) { if (ids == null || string.IsNullOrEmpty(m_type)) { return(ids); } List <string> result = new List <string>(); List <Info> assets = SceneViewPlugin.GetAssets <Info>(AssetsType, ids); foreach (Info info in assets) { if (info.type == m_type) { result.Add(info.id); } } return(result); }
protected override void OnPaint(PaintEventArgs e) { if (SceneViewPlugin.IsLoaded && SceneViewPlugin.IsInitialized) { SceneViewPlugin.ProcessEvents(); SceneViewPlugin.ProcessUpdate(0, true); SceneViewPlugin.ProcessRender(); } else { Brush brushBg = new SolidBrush(Color.FromArgb(255, 64, 64, 64)); Brush brush = new SolidBrush(Color.White); e.Graphics.FillRectangle(brushBg, e.ClipRectangle); string text = SceneViewPlugin.IsInitialized ? "Scene View Plugin is not loaded..." : "Scene View Plugin is not initialized..."; StringFormat format = new StringFormat(); format.LineAlignment = StringAlignment.Center; format.Alignment = StringAlignment.Center; e.Graphics.DrawString(text, Font, brush, e.ClipRectangle, format); } }
public GameObjectPropertiesControl(int handle, bool isPrefab) { if (handle == 0) { throw new ArgumentException("Game Object handle cannot be 0!"); } m_goHandle = handle; m_goIsPrefab = isPrefab; m_goData = SceneViewPlugin.QueryGameObject(handle, isPrefab, "{ \"get\": null }"); MetroSkinManager.ApplyMetroStyle(this); int y = DEFAULT_SEPARATOR; y = InitializePrefabSection(y); y = InitializePropertiesSection(y); y = InitializeComponentsSection(y); Height = y; }
private void AddNewGameObject(bool isPrefab, int parent, string prefabSource = "") { if (string.IsNullOrEmpty(m_scenePath)) { return; } MetroPromptBox prompt = new MetroPromptBox(); prompt.Title = "New Game Object"; prompt.Message = "Enter new Game Object id:"; DialogResult result = prompt.ShowDialog(); if (result == DialogResult.OK && !string.IsNullOrEmpty(prompt.Value)) { int handle = SceneViewPlugin.CreateGameObject(isPrefab, parent, prefabSource, prompt.Value); if (handle != 0) { RebuildSceneTree(); RefreshSceneView(); } } }
public void OnEditorValueChanged(IEditorJsonValue editor, string property, string jsonValue) { string query = PrepareSetQuery(property, jsonValue); Dictionary <string, string> result = SceneViewPlugin.QueryGameObject(m_goHandle, m_goIsPrefab, query); m_goData.Clear(); foreach (var kv in result) { m_goData.Add(kv.Key, kv.Value); } bool irc; foreach (IEditorJsonValue e in m_editors) { if (e.PropertyName != property && result.ContainsKey(e.PropertyName)) { irc = e.IsRaisingEditorJsonValueChangedCallback; e.IsRaisingEditorJsonValueChangedCallback = false; e.UpdateEditorValue(); e.IsRaisingEditorJsonValueChangedCallback = irc; } } MainForm mainForm = FindForm() as MainForm; if (mainForm != null) { if (result != null) { mainForm.RefreshSceneView(); } if (property == "properties/Id") { mainForm.DoAction(new MainForm.Action("GameObjectIdChanged", m_goHandle)); } } }
private int InitializeAssets(ProjectModel projectModel, int y) { Asset_PropertyEditor temp; List <string> assets = SceneViewPlugin.ListAssets(m_type); var data = SceneViewPlugin.GetAssetsInfo(m_type, assets); foreach (var d in data) { y = AddAsset(d.id, d.meta, d.tags == null ? "" : string.Join("|", d.tags.ToArray()), projectModel, out temp, y); } m_addAssetButton = new MetroButton(); MetroSkinManager.ApplyMetroStyle(m_addAssetButton); m_addAssetButton.Text = "Add New Asset"; m_addAssetButton.FontWeight = MetroButtonWeight.Bold; m_addAssetButton.Top = y; m_addAssetButton.Width = Width; m_addAssetButton.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; m_addAssetButton.Click += new EventHandler(addAssetButton_Click); Controls.Add(m_addAssetButton); y = m_addAssetButton.Bottom; return(y); }
private void RendererSurfaceControl_MouseMove(object sender, MouseEventArgs e) { if (!SceneViewPlugin.IsLoaded) { return; } if (m_isDragging) { float dx = (float)(m_lastDragPosition.X - e.X); float dy = (float)(m_lastDragPosition.Y - e.Y); if (ModifierKeys.HasFlag(Keys.Control)) { float dz = 1.0f + (Math.Abs(0.01f * dy) * (ModifierKeys.HasFlag(Keys.Shift) ? 10.0f : 1.0f)); if (dy > 0.0f) { m_cameraZoom = m_lastCameraZoom * dz; } else if (dy < 0.0f) { m_cameraZoom = m_lastCameraZoom / dz; } else { m_cameraZoom = m_lastCameraZoom; } m_cameraZoom = Math.Max(m_cameraZoom, 0.001f); if (ZoomChanged != null) { ZoomChanged(this, m_cameraZoom); } SceneViewPlugin.SetSceneViewZoom(m_cameraZoom); Invalidate(); } else { m_lastDragPosition = e.Location; m_cameraCenter.X += dx * m_cameraZoom; m_cameraCenter.Y += dy * m_cameraZoom; SceneViewPlugin.SetSceneViewCenter(m_cameraCenter.X, m_cameraCenter.Y); Invalidate(); m_lastCameraZoom = m_cameraZoom; } } else if (m_isDraggingGameObject != 0) { string query = "{ \"get\": { \"components\": { \"Transform\": [ \"Position\" ] } } }"; Dictionary <string, string> result = SceneViewPlugin.QueryGameObject(m_isDraggingGameObject, false, query); if (result != null && result.Count > 0) { float[] pos = null; try { pos = Newtonsoft.Json.JsonConvert.DeserializeObject <float[]>(result["components/Transform/Position"]); } catch { } if (pos != null && pos.Length >= 2) { float lx, ly; SceneViewPlugin.ConvertPointFromScreenToWorldSpace(m_lastDragPosition.X, m_lastDragPosition.Y, out lx, out ly); m_lastDragPosition = e.Location; float cx, cy; SceneViewPlugin.ConvertPointFromScreenToWorldSpace(m_lastDragPosition.X, m_lastDragPosition.Y, out cx, out cy); string scx = (pos[0] + (cx - lx)).ToString(Settings.DEFAULT_STRING_FORMAT, Settings.DefaultFormatProvider); string scy = (pos[1] + (cy - ly)).ToString(Settings.DEFAULT_STRING_FORMAT, Settings.DefaultFormatProvider); query = "{ \"set\": { \"components\": { \"Transform\": { \"Position\": [ " + scx + ", " + scy + " ] } } } }"; result = SceneViewPlugin.QueryGameObject(m_isDraggingGameObject, false, query); Invalidate(); MainForm mainForm = FindForm() as MainForm; if (mainForm != null) { mainForm.UpdateGameObjectProperties(); } } } } }
private void RendererSurfaceControl_Disposed(object sender, EventArgs e) { SceneViewPlugin.Release(); ZoomChanged = null; }