This commit is contained in:
2024-01-11 16:38:19 +01:00
parent 4e63a46dc6
commit 7c3aa27c71
10 changed files with 375 additions and 10 deletions

View File

@ -78,6 +78,6 @@ Material:
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 0, b: 0, a: 1}
- _Color: {r: 0, g: 0, b: 0, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
m_BuildTextureStacks: []

View File

@ -0,0 +1,98 @@
{
"molecules": {
"O2": {
"name": "Dioxygène",
"formula": "O2",
"atoms": [
{
"element": "O",
"geometry": [0.0, 0.0, 0.0]
},
{
"element": "O",
"geometry": [1.2, 0.0, 0.0]
}
],
"bonds": [
{"atoms": [0, 1], "order": 2}
],
"properties": {
"molecularMass": 32.0,
"meltingPoint": -218.8,
"boilingPoint": -183.0
}
},
"O3": {
"name": "Ozone",
"formula": "O3",
"atoms": [
{"element": "O", "geometry": [0.0, 0.0, 0.0]},
{"element": "O", "geometry": [0.7, 0.0, 0.0]},
{"element": "O", "geometry": [1.4, 0.0, 0.0]}
],
"bonds": [
{"atoms": [0, 1], "order": 1},
{"atoms": [1, 2], "order": 1}
],
"properties": {
"molecularMass": 47.9982,
"meltingPoint": -192.5,
"boilingPoint": -110.0
}
},
"CO2": {
"name": "Dioxyde de carbone",
"formula": "CO2",
"atoms": [
{"element": "C", "geometry": [0.0, 0.0, 0.0]},
{"element": "O", "geometry": [1.2, 0.0, 0.0]},
{"element": "O", "geometry": [-1.2, 0.0, 0.0]}
],
"bonds": [
{"atoms": [0, 1], "order": 2},
{"atoms": [0, 2], "order": 2}
],
"properties": {
"molecularMass": 44.0095,
"meltingPoint": -56.6,
"boilingPoint": -78.5
}
},
"C4H10": {
"name": "Butane",
"formula": "C4H10",
"atoms": [
{"element": "C", "geometry": [0.0, 0.0, 0.0]},
{"element": "C", "geometry": [1.5, 0.0, 0.0]},
{"element": "C", "geometry": [3.0, 0.0, 0.0]},
{"element": "C", "geometry": [4.5, 0.0, 0.0]},
{"element": "H", "geometry": [0.0, 1.5, 0.0]},
{"element": "H", "geometry": [0.0, -1.5, 0.0]},
{"element": "H", "geometry": [1.5, 1.5, 0.0]},
{"element": "H", "geometry": [1.5, -1.5, 0.0]},
{"element": "H", "geometry": [3.0, 1.5, 0.0]},
{"element": "H", "geometry": [3.0, -1.5, 0.0]},
{"element": "H", "geometry": [4.5, 1.5, 0.0]},
{"element": "H", "geometry": [4.5, -1.5, 0.0]}
],
"bonds": [
{"atoms": [0, 1], "order": 1},
{"atoms": [1, 2], "order": 1},
{"atoms": [2, 3], "order": 1},
{"atoms": [0, 4], "order": 1},
{"atoms": [0, 5], "order": 1},
{"atoms": [1, 6], "order": 1},
{"atoms": [1, 7], "order": 1},
{"atoms": [2, 8], "order": 1},
{"atoms": [2, 9], "order": 1},
{"atoms": [3, 10], "order": 1},
{"atoms": [3, 11], "order": 1}
],
"properties": {
"molecularMass": 58.1222,
"meltingPoint": -138.3,
"boilingPoint": -0.5
}
}
}
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 865ef6336b8f164428ff661758efffd1
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using UnityEngine;
public class MoleculeFactory : MonoBehaviour{
public TextAsset jsonFile;
private static MoleculeFactory instance;
private Molecules moleculesInJson;
private Dictionary<string, Molecule> moleculesDictionary;
public MoleculeFactory(TextAsset jsonFile){
MoleculeFactory.instance = this;
moleculesInJson = JsonUtility.FromJson<List<Molecule>>(jsonFile.text);
Debug.Log(jsonFile.text);
moleculesDictionary = BuildMoleculesDictionary(moleculesInJson);
}
public static MoleculeFactory getInstrance(){
if(MoleculeFactory.instance == null){
Debug.LogError("no Json file");
}
return MoleculeFactory.instance;
}
public static MoleculeFactory getInstrance(TextAsset jsonFile){
if(MoleculeFactory.instance == null){
MoleculeFactory.instance = new MoleculeFactory(jsonFile);
}
return MoleculeFactory.instance;
}
public GameObject createMolecule (string formula){
Debug.Log(moleculesInJson);
// Molecule molecule = molecules[formula];
foreach(var item in moleculesInJson.molecules){
Debug.Log("pouet2");
Debug.Log(item.Key);
Debug.Log(item.Value);
}
// Debug.Log(molecule);
// make your shit
//return GO
return null;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 68834abede8b8d14d93f46876f40df3e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,17 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
class MoleculeFactoryTester: MonoBehaviour {
public TextAsset jsonFile;
void Start(){
MoleculeFactory factory = MoleculeFactory.getInstrance(this.jsonFile);
GameObject mol = factory.createMolecule("O2");
// mol.transform.position = new Vector3(10,0,0);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 617b4ba049dacfb4da7aa525641f8371
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,12 +1,11 @@
using System.Collections.Generic;
using System;
[System.Serializable]
public class Molecule
{
// nom molécules
public string name;
// formule melécule
public string formula;
// liste des atoms
public Atom[] atoms;
@ -21,5 +20,5 @@ public class Molecule
public class Molecules
{
// liste des liason entre les atoms
public Molecule[] molecules;
public Dictionary<string,Molecule> molecules;
}

View File

@ -6,8 +6,7 @@ public class ReadMolecule : MonoBehaviour
{
public TextAsset jsonFile;
void Start()
{
void Start(){
Molecules moleculesInJson = JsonUtility.FromJson<Molecules>(jsonFile.text);
int molNum = 0;