-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathEditorLoader.cs
More file actions
133 lines (117 loc) · 4.63 KB
/
Copy pathEditorLoader.cs
File metadata and controls
133 lines (117 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using System;
using System.IO;
using Toolbox.Core;
using MapStudio.UI;
using OpenTK;
using GLFrameworkEngine;
using Toolbox.Core.IO;
using System.Collections.Generic;
using UIFramework;
namespace SampleMapEditor
{
/// <summary>
/// Represents a class used for loading files into the editor.
/// IFileFormat determines what files to use. FileEditor is used to store all the editor information.
/// </summary>
public class EditorLoader : FileEditor, IFileFormat
{
/// <summary>
/// The description of the file extension of the plugin.
/// </summary>
public string[] Description => new string[] { "Map Data" };
/// <summary>
/// The extension of the plugin. This should match whatever file you plan to open.
/// </summary>
public string[] Extension => new string[] { "*.szs" };
/// <summary>
/// Determines if the plugin can save or not.
/// </summary>
public bool CanSave { get; set; } = true;
/// <summary>
/// File info of the loaded file format.
/// </summary>
public File_Info FileInfo { get; set; }
/// <summary>
/// Determines when to use the map editor from a given file.
/// You can check from file extension or check the data inside the file stream.
/// The file stream is always decompressed if the given file has a supported ICompressionFormat like Yaz0.
/// </summary>
public bool Identify(File_Info fileInfo, Stream stream)
{
//For the sake of a demo, always load the plugin
return true;
//Example for loading as extension check
return fileInfo.Extension == ".szs";
//Example for checking inside the file for magic
//NOTE you must use "true" in arguments to keep stream open
using (var reader = new FileReader(stream, true))
{
return reader.CheckSignature(4, "MODL");
}
}
/// <summary>
/// Loads the given file data from a stream.
/// </summary>
public void Load(Stream stream)
{
//For this example I will show loading 3D objects into the scene
MapScene scene = new MapScene();
scene.Setup(this);
//Animation test
Root.AddChild(new Toolbox.Core.ViewModels.NodeBase("AnimationTest")
{
Tag = new AnimationController(),
});
}
/// <summary>
/// Saves the given file data to a stream.
/// </summary>
public void Save(Stream stream)
{
}
//Extra overrides for FileEditor you can use for custom UI
/// <summary>
/// Draws the viewport menu bar usable for custom tools.
/// </summary>
public override void DrawViewportMenuBar()
{
}
/// <summary>
/// When an asset item from the asset windows gets dropped into the editor.
/// You can configure your own asset category from the asset window and make custom asset items to drop into.
/// </summary>
public override void AssetViewportDrop(AssetItem item, Vector2 screenPosition)
{
//viewport context
var context = GLContext.ActiveContext;
//Screen coords can be converted into 3D space
//By default it will spawn in the mouse position at a distance
Vector3 position = context.ScreenToWorld(screenPosition.X, screenPosition.Y, 100);
//Collision dropping can be used to drop these assets to the ground from CollisionCaster
if (context.EnableDropToCollision)
{
Quaternion rot = Quaternion.Identity;
CollisionDetection.SetObjectToCollision(context, context.CollisionCaster, screenPosition, ref position, ref rot);
}
}
/// <summary>
/// Checks for dropped files to use for the editor.
/// If the value is true, the file will not be loaded as an editor if supported.
/// </summary>
public override bool OnFileDrop(string filePath)
{
return false;
}
public override List<DockWindow> PrepareDocks()
{
List<DockWindow> windows = new List<DockWindow>();
windows.Add(Workspace.Outliner);
windows.Add(Workspace.PropertyWindow);
windows.Add(Workspace.ConsoleWindow);
windows.Add(Workspace.ViewportWindow);
windows.Add(Workspace.TimelineWindow);
windows.Add(Workspace.GraphWindow);
return windows;
}
}
}