I have the following problem:
I have a 3D engine that has their scenes, but they are not compatible with Unity.
But I have the metadata of this another 3D engine about everything on the scene, like: position, lights, models, light probes, physics, cameras etc...
I'd like to recreate this scene on Unity, but programmatically doing a parser onto this metadata I have, but not using the Unity Editor. (In the end I would have a .scene file and some created prefabs)
But in the same time I'd like to be able to load this created scene (from the metadata) inside the the Unity Editor (since I created it for Unity now)
I would like to have all the models and things created as prefabs to be able to use addressable in the future.
Is this feasible?
Maybe is there a way to create UnityYAML scene files?
It looks like this would sort of be a 2 step process:
Parse your existing data structure and create them as GameObjects/Components in a scene. You should be able to do this with a regular ol' script attached to a regular GameObject. For me, I would call it something like "CustomSceneLoader". On start, read your data file, parse it, and instantiate GameObjects with that data.
From there, it looks like you can use the PrefabUtility to create new Prefabs based on the GameObjects in the scene. Maybe as part of step 1 you attach a custom Component that adds a button to the inspector that would create a Prefab from the GameObject.
For example:
PrefabUtility.SaveAsPrefabAssetAndConnect(gameObject, localPath, InteractionMode.UserAction, out prefabSuccess);
As Retired Ninja mentions in the comments
UnityYAML is just based on YAML which is a raw text file format (similar to JSON)
=> Of course in theory you can generate such a file and all your content prefab and .meta files and GUIDs from scratch completely without Unity.
Which basically would mean you have to replicate this entire part of the Unity Editor.
Is this feasible?
In theory yes, but the question is, is this really worth the time and struggle? I would doubt that.
Instead depending on your exact file formats I would rather
Search for any plugins / external libraries that maybe already exist for this file format
If really non exists you again have multiple options
From your other engine which already understands your existing file formats export the content into a format Unity understands built-in
For example
Export all meshes as FBX (-> already supports embedded materials, textures and hierarchy)
Export the hierarchy e.g. as a JSON or whatever text file
Then in Unity reconstruct the scene according to those
Implement your own custom Scripted Importer which can directly parse your original file(s) and convert it(them) into a scene directly within Unity.
Related
I'm making a visual novel and my game uses some custom classes that store important data.
Example:
public class Speech
{
public Sprite CharacterHead; // Holds a reference to a sprite which is the "head" of who's currently speaking
public LocalizedString SpeechOrigin; // Holds a reference to a localizedstring that is what that character is saying based on the language. (Uses Unity.Localization)
public string Name; // the name of the character that is speaking
}
This "Speech" class should never be changed during runtime and only needs to be read during dialogues.
My question is: what is a general good-practice way to store this type of data? I'm fairly new to unity and the only way i found to do this yet is through declaring a List on monobehaviour classes and editing them through the Inspector but this does not seems to be a effective way of handling this in a game that's going to have 1000+ different "Speech".
Ps:Don't mind all the variables being public, they are this way right now to make some parts of development easier, i will change the necessary ones when the time comes.
Why don't you just use ScriptableObject? It's the default way for Unity to store data in the game. You can also edit it from the Unity Editor instead of using another external editor. You can also drag-and-drop any resource from the game project's folder into it (eg. the texture of the head, the whole localized sting as data, the dialog audio clips, etc)
https://docs.unity3d.com/Manual/class-ScriptableObject.html
https://youtu.be/aPXvoWVabPY
There are a few good ways to store this information, especially if you are localising them too. Essentially, you would store an ID that you refer to the various strings with, which would be constant across language files.
CSV format files
Basically, you can use some spreadsheet software (like Google Sheets) and have all your speech there; a column for the ID of the string, and a column for the actual value. You can export the sheet as a CSV file and load into Unity.
You can then write some simple parsing code to read each line from the file, and split out the ID and the value and store it in a dictionary.
JSON format files
With JSON, if you architect it correctly, you can use Unity's built in JSON utility, or other better ones, to read the data directly into C# object classes.
A decent video explaining this can be found here.
YAML format files
YAML is basically the same as JSON, but with less brackets. It is also the format that Unity uses for its serialisation. However, you can only use this format by writing your own parser, or using a third party one, because there is no built in parser.
JSON files are generally industry standard for data storage these days, but eventually it is up to you which format you find easiest to work with. I've tried to list these in the order of how easy it is to add and remove strings from the file.
You should not store a lot of data in c# code use external files that are designed for data by creating a JSON file, XML file, or any other type of both human and computer readable format.
XML should be the perfect choise for your usecase, it is widely used for dialogue trees
Here is an example of what you can do with XML in your usecase
<npcs>
<npc name="Oren">
<dialogue>
<text>Hi #{PlayerName} do you want to eat falafel? </text>
<options>
<option action="yes">yes, I would like</option>
<option action="no">no...</option>
</options>
</dialogue>
</npc>
</npcs>
it's fairly simple to use XML, and it fits dialogues perfectly
Using Model derivative API I am able to get geometric properties of 3d dwg file but for 2d dwg I am facing the issue(Unrecoverable exit code from extractor: -1073741831) on extracting geometric properties.
I also understand that model derivative API doesn't provide a support for extracting 2d geometries.
Is any other way to extract geometry of 2d file using programming API(c#)?
EDIT
I have added ObjectTree JSON file and POST URL of "Extract Geometry for Selected Objects into an OBJ File" in the following GitHub link.
https://github.com/Jothipandiyan-jp1/Autodesk
From the error, it seems that your 2D drawing is somehow broken, or not uploaded right. Or is it a vertical file, like Plant 3D or Map 3D?
The Model Derivative should extract the 2D View, you can try the file on A360 Viewer or via API at this sample (C# source).
EDIT
From the comments, it seems you are trying to extract the .obj from a single objectId in the 2D DWG. This should not trigger errors, but it may return empty file as the OBJ format is intended for 3D shapes. Can you update your question with the full POST job used on your code? Make sure the modelGuid and objectIds parameters are correct.
I am quite new in game development with Unity and was wondering how the "export game" function of unity works. I not yet used this function in unity, but I've read that it will generate some .exe file from your complete game. I also read that it will create a "data" folder or something like that.
My question is: What exactly is stored in this "data" folder? And how can I write logic to save my own files (e.g. files which contain save states, settings, configurations, etc.) in some file inside this directory (which is then shipped with the complete game / created in the local game directory after the user e.g. saved his game the first time? Can i e.g. save those files in a relative path (e.g. ./MyGame/data/savegames)?
And which types of files can I create? Text / Binary? Or can I even use some relational Database (some small one like HSQLDB)?
And how are things like models, sounds, animations and other assets treated? Are they all packaged within the .exe file which is my complete game? Or do i have some seperate folders with the shipped game for them?
Thank you!
The data folder (named the same as the exe file, but _Data on the end instead of .exe, which can be safely renamed to just Data) contains all of the dlls that actually run the game (even a blank Unity project will have them! The unity engine itself compiles to several dlls) as well as any Resources you might have (tip: stop using resources and use Asset Bundles instead).
Omitting this folder would be very bad indeed!
As for reading/writing other data from the hard disk (which is not possible on all platforms--looking at you web deployment) I would recommend using your own folder, eg. RuntimeData which could contain external audio, image, or video files as well as mutable data such as save games or screenshots. Pretty much anything you'd be ok with your users modifying without seriously breaking stuff (modding is "in" these days).
As for the types of file: well, that's up to you, really! Creating text files (of any extension: xml, html, dat, qqq...) is very easy. Images tend to be done through a 3rd party script (do you really want to write your own JPG converter? Video, same thing). You can also create binary files following a format of your own choosing. The only difficulty is writing the serializer and deserializer for the data, which would scale in difficulty as the complexity of the data scales.
You have full file system access* so you can realistically read or write anywhere. This is C# we're talking about. But with great power comes great responsibility.
*Note: Mobile devices heavily frown on that sort of thing and will deny access to folders outside the one explicitly given to that application.
I'm now reading this example. I see there is one FBX file and a few texture files in the content project, and that in the code you can choose which "take" to play. In the code it is "Take_001". Please tell me: When I create and animate my own 3D model in 3DS Max, how can I define those takes? plus, are any configurations need to be made when exporting FBX from 3DS Max to XNA?
You don't. The model artist does. In his modeling software he can name every bone or animation sequence, and then you can activate it from code.
The built-in FBX pipeline in XNA supports animation only partially, but it doesn't need any pre-configuration. So does the pipeline you linked to.
I'm working on an application that uses the XNA framework to do it's 3D rendering. I now want to load a texture from file. I've found two methods so far:
Texture2D.FromStream(GraphicsDevice, Stream) The problem with this approach is that it only loads gif, png and jpg and I also need support for tga images.
Create a ContentManager object. The problem with this approach is that it seems like all the textures need to be statically added to the project, from the documentation: "Before a ContentManager can load an asset, you need to add the asset to your game project". The program in question is a level editor and which textures are needed isn't known in advance.
Is there any other easy way to load the texture, I'm thinking about using some other class to load the image (although I don't know which, I'm not very familiar with C#) and then perhaps use the Texture2D.SetData method?
Is there any other easy way to achieve what I'm trying to achieve?
There are a few ways to achieve what you want:
You could invoke the content pipeline from within your editor, dynamically creating your content project. How to do this is described in the WinForms Series 2 Sample. This is probably the "best" way, because it allows you to keep using the content pipeline.
You could, as you say, decode the TGA file yourself and use SetData. There are lots of results for C# TGA readers on Google. This is the first one.
I've used Texture2D.FromFile(device, path) before, and it works well. However occasionally I'll encounter problems and will also have to specify TextureCreationParameters and pass them in. Keep in mind that you'll need to dispose the loaded Texture2D manually.