Compare commits
4 Commits
cb0396e23c
...
91e3d2e28a
Author | SHA1 | Date | |
---|---|---|---|
91e3d2e28a | |||
27ce4e14a8 | |||
9b7b156d7b | |||
f7a2cc4c88 |
8
Assets/script/Atome.meta
Normal file
8
Assets/script/Atome.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d277baeb8e7f7794fb44493815552a02
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
134
Assets/script/Atome/AtomeFactory.cs
Normal file
134
Assets/script/Atome/AtomeFactory.cs
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class AtomeFactory : MonoBehaviour{
|
||||||
|
|
||||||
|
public TextAsset jsonFile;
|
||||||
|
|
||||||
|
private static AtomeFactory instance;
|
||||||
|
|
||||||
|
private AtomesInformation atomeInJson;
|
||||||
|
|
||||||
|
private Dictionary<string, AtomeInformation> AtomeDictionary;
|
||||||
|
|
||||||
|
public AtomeFactory(TextAsset jsonFile){
|
||||||
|
AtomeFactory.instance = this;
|
||||||
|
AtomeDictionary = new Dictionary<string, AtomeInformation>();
|
||||||
|
atomeInJson = JsonUtility.FromJson<AtomesInformation>(jsonFile.text);
|
||||||
|
foreach (var atome in atomeInJson.atomes){
|
||||||
|
AtomeDictionary.Add(atome.symbol, atome);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AtomeFactory getInstrance(){
|
||||||
|
if(AtomeFactory.instance == null){
|
||||||
|
Debug.LogError("no Json file");
|
||||||
|
}
|
||||||
|
return AtomeFactory.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AtomeFactory getInstrance(TextAsset jsonFile){
|
||||||
|
if(AtomeFactory.instance == null){
|
||||||
|
AtomeFactory.instance = new AtomeFactory(jsonFile);
|
||||||
|
}
|
||||||
|
return AtomeFactory.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AtomeInformation createAtome(string symbol){
|
||||||
|
if(!AtomeDictionary.ContainsKey(symbol)){
|
||||||
|
Debug.LogError("Atome does not existe in json");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
AtomeInformation atome = AtomeDictionary[symbol];
|
||||||
|
|
||||||
|
return atome;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameObject createAnimatedAtome(string symbol) {
|
||||||
|
if(!AtomeDictionary.ContainsKey(symbol)){
|
||||||
|
Debug.LogError("Atome does not existe in json");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
AtomeInformation atomeinfo = AtomeDictionary[symbol];
|
||||||
|
GameObject Parent = new GameObject(atomeinfo.name);
|
||||||
|
int ElectronsNumber = atomeinfo.protons;
|
||||||
|
|
||||||
|
//Symbol
|
||||||
|
GameObject atome = CreateSymbolAnimation(atomeinfo);
|
||||||
|
atome.transform.parent = Parent.transform;
|
||||||
|
|
||||||
|
//Electrons
|
||||||
|
for (int i = 1; ElectronsNumber > 0; i++) {
|
||||||
|
int nbrElectronLayer = 2 * (i * i);
|
||||||
|
GameObject electrons = CreateElectronsAnimation(Mathf.Min(ElectronsNumber, nbrElectronLayer), (float)i);
|
||||||
|
electrons.transform.parent = Parent.transform;
|
||||||
|
ElectronsNumber -= nbrElectronLayer;
|
||||||
|
}
|
||||||
|
//rajouter electron == protons
|
||||||
|
return Parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
private GameObject DrawCircle(float orbitRadius)
|
||||||
|
{
|
||||||
|
GameObject orbitCircle = new GameObject("Orbit Circle");
|
||||||
|
LineRenderer lineRenderer = orbitCircle.AddComponent<LineRenderer>();
|
||||||
|
lineRenderer.useWorldSpace = false;
|
||||||
|
lineRenderer.widthMultiplier = 0.05f; // Ajustez l'épaisseur de la ligne si nécessaire.
|
||||||
|
lineRenderer.positionCount = 100 + 1;
|
||||||
|
//Add Color
|
||||||
|
Color myColor = new Color(0, 0, 1, 1);
|
||||||
|
ColorUtility.TryParseHtmlString("#7F7F7F", out myColor);
|
||||||
|
orbitCircle.GetComponent<Renderer>().material.color = myColor;
|
||||||
|
|
||||||
|
for (int i = 0; i <= 100; i++)
|
||||||
|
{
|
||||||
|
float angle = i * 2 * Mathf.PI / 100;
|
||||||
|
float x = Mathf.Cos(angle) * orbitRadius;
|
||||||
|
float y = Mathf.Sin(angle) * orbitRadius;
|
||||||
|
|
||||||
|
lineRenderer.SetPosition(i, new Vector3(x, 0f, y));
|
||||||
|
}
|
||||||
|
return orbitCircle;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private GameObject CreateSymbolAnimation(AtomeInformation info) {
|
||||||
|
//Create GameObject
|
||||||
|
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
||||||
|
//Add information
|
||||||
|
sphere.name = info.symbol;
|
||||||
|
sphere.transform.position = new Vector3(0, 0, 0);
|
||||||
|
//Add Color
|
||||||
|
Color myColor = new Color(0, 0, 1, 1);
|
||||||
|
ColorUtility.TryParseHtmlString(info.representation.color, out myColor);
|
||||||
|
sphere.GetComponent<Renderer>().material.color = myColor;
|
||||||
|
|
||||||
|
return sphere;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private GameObject CreateElectronsAnimation(int electrons, float layer) {
|
||||||
|
GameObject ParentLayer = new GameObject("Electrons");
|
||||||
|
|
||||||
|
for (int i = 0; i < electrons; i++) {
|
||||||
|
float angle = i * Mathf.PI * 2 / electrons;
|
||||||
|
float x = Mathf.Cos(angle) * layer;
|
||||||
|
float z = Mathf.Sin(angle) * layer;
|
||||||
|
float y = 0f;
|
||||||
|
|
||||||
|
GameObject electron = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
||||||
|
electron.name = "Electron" + i;
|
||||||
|
electron.transform.position = new Vector3(x, y, z);
|
||||||
|
electron.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
|
||||||
|
electron.transform.parent = ParentLayer.transform;
|
||||||
|
}
|
||||||
|
GameObject orbit = DrawCircle(layer);
|
||||||
|
orbit.transform.parent = ParentLayer.transform;
|
||||||
|
|
||||||
|
return ParentLayer;
|
||||||
|
}
|
||||||
|
}
|
@ -1,49 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class AtomeFactory : MonoBehaviour{
|
|
||||||
|
|
||||||
public TextAsset jsonFile;
|
|
||||||
|
|
||||||
private static AtomeFactory instance;
|
|
||||||
|
|
||||||
private AtomesInformation atomeInJson;
|
|
||||||
|
|
||||||
private Dictionary<string, AtomeInformation> AtomeDictionary;
|
|
||||||
|
|
||||||
public AtomeFactory(TextAsset jsonFile){
|
|
||||||
AtomeFactory.instance = this;
|
|
||||||
AtomeDictionary = new Dictionary<string, AtomeInformation>();
|
|
||||||
atomeInJson = JsonUtility.FromJson<AtomesInformation>(jsonFile.text);
|
|
||||||
foreach (var atome in atomeInJson.atomes){
|
|
||||||
AtomeDictionary.Add(atome.symbol, atome);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static AtomeFactory getInstrance(){
|
|
||||||
if(AtomeFactory.instance == null){
|
|
||||||
Debug.LogError("no Json file");
|
|
||||||
}
|
|
||||||
return AtomeFactory.instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static AtomeFactory getInstrance(TextAsset jsonFile){
|
|
||||||
if(AtomeFactory.instance == null){
|
|
||||||
AtomeFactory.instance = new AtomeFactory(jsonFile);
|
|
||||||
}
|
|
||||||
return AtomeFactory.instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AtomeInformation createAtome(string symbol){
|
|
||||||
if(!AtomeDictionary.ContainsKey(symbol)){
|
|
||||||
Debug.LogError("Atome does not existe in json");
|
|
||||||
}
|
|
||||||
AtomeInformation atome = AtomeDictionary[symbol];
|
|
||||||
|
|
||||||
return atome;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
8
Assets/script/Molecule.meta
Normal file
8
Assets/script/Molecule.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: daab5552b7014024c9b81a31c7eb0b12
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
53
Assets/script/New Animation.anim
Normal file
53
Assets/script/New Animation.anim
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!74 &7400000
|
||||||
|
AnimationClip:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_Name: New Animation
|
||||||
|
serializedVersion: 7
|
||||||
|
m_Legacy: 0
|
||||||
|
m_Compressed: 0
|
||||||
|
m_UseHighQualityCurve: 1
|
||||||
|
m_RotationCurves: []
|
||||||
|
m_CompressedRotationCurves: []
|
||||||
|
m_EulerCurves: []
|
||||||
|
m_PositionCurves: []
|
||||||
|
m_ScaleCurves: []
|
||||||
|
m_FloatCurves: []
|
||||||
|
m_PPtrCurves: []
|
||||||
|
m_SampleRate: 60
|
||||||
|
m_WrapMode: 0
|
||||||
|
m_Bounds:
|
||||||
|
m_Center: {x: 0, y: 0, z: 0}
|
||||||
|
m_Extent: {x: 0, y: 0, z: 0}
|
||||||
|
m_ClipBindingConstant:
|
||||||
|
genericBindings: []
|
||||||
|
pptrCurveMapping: []
|
||||||
|
m_AnimationClipSettings:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_AdditiveReferencePoseClip: {fileID: 0}
|
||||||
|
m_AdditiveReferencePoseTime: 0
|
||||||
|
m_StartTime: 0
|
||||||
|
m_StopTime: 1
|
||||||
|
m_OrientationOffsetY: 0
|
||||||
|
m_Level: 0
|
||||||
|
m_CycleOffset: 0
|
||||||
|
m_HasAdditiveReferencePose: 0
|
||||||
|
m_LoopTime: 0
|
||||||
|
m_LoopBlend: 0
|
||||||
|
m_LoopBlendOrientation: 0
|
||||||
|
m_LoopBlendPositionY: 0
|
||||||
|
m_LoopBlendPositionXZ: 0
|
||||||
|
m_KeepOriginalOrientation: 0
|
||||||
|
m_KeepOriginalPositionY: 1
|
||||||
|
m_KeepOriginalPositionXZ: 0
|
||||||
|
m_HeightFromFeet: 0
|
||||||
|
m_Mirror: 0
|
||||||
|
m_EditorCurves: []
|
||||||
|
m_EulerEditorCurves: []
|
||||||
|
m_HasGenericRootTransform: 0
|
||||||
|
m_HasMotionFloatCurves: 0
|
||||||
|
m_Events: []
|
8
Assets/script/New Animation.anim.meta
Normal file
8
Assets/script/New Animation.anim.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3f4a98ccdd3a2514495ffff7ef525aa7
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 7400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
12
Assets/script/New Animator Controller.controller
Normal file
12
Assets/script/New Animator Controller.controller
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!91 &9100000
|
||||||
|
AnimatorController:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_Name: New Animator Controller
|
||||||
|
serializedVersion: 5
|
||||||
|
m_AnimatorParameters: []
|
||||||
|
m_AnimatorLayers: []
|
8
Assets/script/New Animator Controller.controller.meta
Normal file
8
Assets/script/New Animator Controller.controller.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 825a7187bec92284dbce290965de4dba
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 9100000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
19
Assets/script/Testor.cs
Normal file
19
Assets/script/Testor.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
|
||||||
|
class MoleculeFactoryTester: MonoBehaviour {
|
||||||
|
|
||||||
|
public TextAsset moleculeJson;
|
||||||
|
public TextAsset atomJson;
|
||||||
|
|
||||||
|
void Start(){
|
||||||
|
MoleculeFactory factory = MoleculeFactory.getInstrance(this.moleculeJson);
|
||||||
|
AtomeFactory atomeFactory = AtomeFactory.getInstrance(this.atomJson);
|
||||||
|
GameObject mol = atomeFactory.createAnimatedAtome("Na");
|
||||||
|
//mol.transform.position = new Vector3(0,1,0);
|
||||||
|
//GameObject bon = GameOject.CreatePrimitive(PrimitiveType.)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
11
Assets/script/Testor.cs.meta
Normal file
11
Assets/script/Testor.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7d15c31ec91cb674fac22415c1ceff75
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
x
Reference in New Issue
Block a user