develop #12
@ -14,26 +14,37 @@ public class ActiveScoppedElements : MonoBehaviour
|
||||
public GameObject obj;
|
||||
}
|
||||
|
||||
public enum AnimationState
|
||||
{
|
||||
IDLE,
|
||||
GORIGHT,
|
||||
GOLEFT
|
||||
}
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
public TextAsset jsonFile;
|
||||
public TextAsset atomJsonFile;
|
||||
public HashSet<String> actives = new HashSet<String>();
|
||||
public HashSet<GameObject> InstantiatesObject = new HashSet<GameObject>();
|
||||
public TextMeshProUGUI textToUpdate;
|
||||
public TextMeshProUGUI objectInstantiateText;
|
||||
/*public ObjectToInstantiate[] objectToInstantiates;*/
|
||||
public HashSet<GameObject> DisableGameObjects = new HashSet<GameObject>();
|
||||
public GameObject[] InformationObjs;
|
||||
public GameObject[] DebugObjs;
|
||||
public Button button;
|
||||
private AnimationState _animationState = AnimationState.IDLE;
|
||||
private float _animationSpeed = 1.0f;
|
||||
|
||||
private AtomeFactory _atomFactory;
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (button != null)
|
||||
_atomFactory = new AtomeFactory(this.atomJsonFile);
|
||||
Debug.Log("AtomFactory created !");
|
||||
/*if (button != null)
|
||||
{
|
||||
button.onClick.AddListener(this.Center);
|
||||
}
|
||||
}*/
|
||||
if (this.textToUpdate != null)
|
||||
{
|
||||
textToUpdate.text = "Scanner des Markers...";
|
||||
@ -56,6 +67,10 @@ public class ActiveScoppedElements : MonoBehaviour
|
||||
Debug.Log("Center called !");
|
||||
foreach (var obj in InstantiatesObject)
|
||||
{
|
||||
if (Camera.main == null)
|
||||
{
|
||||
throw new Exception("NO MAIN CAMERA DEFINED ");
|
||||
}
|
||||
Vector3 cameraPosition = Camera.main.transform.position;
|
||||
|
||||
// Obtenez la rotation de la caméra sans inclure la rotation autour de l'axe Y
|
||||
@ -72,6 +87,60 @@ public class ActiveScoppedElements : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void onClickStopAnimation()
|
||||
{
|
||||
Quaternion cameraRotation = Quaternion.Euler(0, Camera.main.transform.rotation.eulerAngles.y, 0);
|
||||
this._animationState = AnimationState.IDLE;
|
||||
foreach (var obj in InstantiatesObject)
|
||||
{
|
||||
obj.transform.rotation = cameraRotation;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void onClickPauseAnimation()
|
||||
{
|
||||
this._animationState = AnimationState.IDLE;
|
||||
}
|
||||
|
||||
public void onClickStartAnimation()
|
||||
{
|
||||
this._animationState = AnimationState.GORIGHT;
|
||||
}
|
||||
|
||||
public void onClickRightAnimation()
|
||||
{
|
||||
this._animationState = AnimationState.GORIGHT;
|
||||
}
|
||||
|
||||
public void onClickGoLeftAnimation()
|
||||
{
|
||||
this._animationState = AnimationState.GOLEFT;
|
||||
}
|
||||
|
||||
public void onClickSpeedUp()
|
||||
{
|
||||
this._animationSpeed += 0.5f;
|
||||
}
|
||||
|
||||
public void onClickSpeedDown()
|
||||
{
|
||||
this._animationSpeed -= 0.5f;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (this._animationState == AnimationState.GORIGHT)
|
||||
{
|
||||
foreach (var obj in InstantiatesObject)
|
||||
{
|
||||
obj.transform.Rotate(0, this._animationSpeed, 0, Space.Self);
|
||||
/*Vector3 position = obj.GetComponent<SphereCollider>().bounds.center;
|
||||
obj.transform.RotateAround(position, new Vector3(0, 0.1f, 0), 30 * Time.deltaTime);*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshText()
|
||||
{
|
||||
if (this.textToUpdate != null)
|
||||
@ -125,6 +194,7 @@ public class ActiveScoppedElements : MonoBehaviour
|
||||
private GameObject FindGameObjectWithFormula()
|
||||
{
|
||||
var factory = MoleculeFactory.getInstrance(this.jsonFile);
|
||||
factory.setAtomFactory(this._atomFactory);
|
||||
Debug.Log("ACTIVES ELEMENTS:");
|
||||
Debug.Log(this.actives);
|
||||
foreach (var formula in GetPermutations(this.actives.ToList()))
|
||||
@ -137,21 +207,35 @@ public class ActiveScoppedElements : MonoBehaviour
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String GetFormula()
|
||||
{
|
||||
var factory = MoleculeFactory.getInstrance(this.jsonFile);
|
||||
factory.setAtomFactory(this._atomFactory);
|
||||
foreach (var formula in GetPermutations(this.actives.ToList()))
|
||||
{
|
||||
Debug.Log("FORMULA: " + String.Join("", formula));
|
||||
if (factory.hasMolecule(String.Join("", formula)))
|
||||
{
|
||||
return String.Join("", formula);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void RefreshAtom()
|
||||
{
|
||||
var objToFind = FindGameObjectWithFormula();
|
||||
if (objToFind != null)
|
||||
{
|
||||
Debug.Log("Object to instantiate found !");
|
||||
if (Camera.main == null)
|
||||
{
|
||||
throw new Exception("NO MAIN CAMERA DEFINED ");
|
||||
}
|
||||
Vector3 cameraPosition = Camera.main.transform.position;
|
||||
|
||||
// Obtenez la rotation de la caméra sans inclure la rotation autour de l'axe Y
|
||||
Quaternion cameraRotation = Quaternion.Euler(0, Camera.main.transform.rotation.eulerAngles.y, 0);
|
||||
|
||||
// Calculez la position finale en ajoutant la direction vers l'avant multipliée par la distance désirée
|
||||
Vector3 position = cameraPosition + cameraRotation * Vector3.forward * 0.35f;
|
||||
|
||||
//var instantiatedObj = Instantiate(objt.obj, position, cameraRotation);
|
||||
|
||||
objToFind.transform.position = position;
|
||||
objToFind.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f);
|
||||
@ -180,76 +264,39 @@ public class ActiveScoppedElements : MonoBehaviour
|
||||
InstantiatesObject.Clear();
|
||||
EnableAllMarkerModel();
|
||||
}
|
||||
/*foreach (var objt in objectToInstantiates)
|
||||
{
|
||||
if (objt.elements.TrueForAll((s => actives.Contains(s))))
|
||||
{
|
||||
foreach (var objName in objt.elements)
|
||||
{
|
||||
var a = GameObject.Find("OBJ_" + objName);
|
||||
if (a != null)
|
||||
{
|
||||
a.SetActive(false);
|
||||
DisableGameObjects.Add(a);
|
||||
}
|
||||
}
|
||||
|
||||
// Obtenez la position de la caméra
|
||||
Vector3 cameraPosition = Camera.main.transform.position;
|
||||
|
||||
// Obtenez la rotation de la caméra sans inclure la rotation autour de l'axe Y
|
||||
Quaternion cameraRotation = Quaternion.Euler(0, Camera.main.transform.rotation.eulerAngles.y, 0);
|
||||
|
||||
// Calculez la position finale en ajoutant la direction vers l'avant multipliée par la distance désirée
|
||||
Vector3 position = cameraPosition + cameraRotation * Vector3.forward * 0.35f;
|
||||
|
||||
//var instantiatedObj = Instantiate(objt.obj, position, cameraRotation);
|
||||
|
||||
var obj = MoleculeFactory.getInstrance(this.jsonFile).createMolecule("CO2");
|
||||
obj.transform.position = position;
|
||||
obj.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f);
|
||||
obj.transform.rotation = cameraRotation;
|
||||
Debug.Log("RefreshAtom(): Created " + obj.name);
|
||||
|
||||
obj.name = "[N] " + objt.obj.name;
|
||||
InstantiatesObject.Add(obj);
|
||||
this.OnInstantiateObject(obj);
|
||||
Debug.Log("Instantiate " + obj.name);
|
||||
}
|
||||
else
|
||||
{
|
||||
var a = InstantiatesObject.FirstOrDefault(s => s.name == ("[N] " + objt.obj.name));
|
||||
if (a != null)
|
||||
{
|
||||
Debug.Log("Destroy " + a.name);
|
||||
InstantiatesObject.Remove(a);
|
||||
OnDestroyObject(a);
|
||||
Destroy(a);
|
||||
foreach (var disableGameObject in DisableGameObjects)
|
||||
{
|
||||
disableGameObject.SetActive(true);
|
||||
}
|
||||
DisableGameObjects.Clear();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
if (InstantiatesObject.Count > 0)
|
||||
{
|
||||
|
||||
if (InstantiatesObject.Count > 0 && objectInstantiateText != null) {
|
||||
objectInstantiateText.text = String.Join(", ", InstantiatesObject.Select((s) => s.name));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else if (objectInstantiateText != null) {
|
||||
objectInstantiateText.text = "En attente...";
|
||||
}
|
||||
}
|
||||
|
||||
private void SetMoleculeInfo(String formula)
|
||||
{
|
||||
if (formula == null) {
|
||||
return;
|
||||
}
|
||||
var factory = MoleculeFactory.getInstrance(this.jsonFile);
|
||||
factory.setAtomFactory(this._atomFactory);
|
||||
Molecule mol = factory.GetMoleculeByFormula(formula);
|
||||
var descriptionGO = GameObject.Find("TXT_DESC").GetComponent<TextMeshProUGUI>();
|
||||
var atomNbGO = GameObject.Find("TXT_ATOM_NB").GetComponent<TextMeshProUGUI>();
|
||||
var symGO = GameObject.Find("TXT_SYM").GetComponent<TextMeshProUGUI>();
|
||||
var nameGO = GameObject.Find("TXT_NAME").GetComponent<TextMeshProUGUI>();
|
||||
nameGO.text = mol.name;
|
||||
symGO.text = mol.formula;
|
||||
descriptionGO.text = "Masse moleculaire: ";
|
||||
atomNbGO.text = mol.atoms.Length + " Atomes";
|
||||
}
|
||||
|
||||
private void OnInstantiateObject(GameObject obj)
|
||||
{
|
||||
foreach (var informationObj in InformationObjs)
|
||||
{
|
||||
informationObj.SetActive(true);
|
||||
}
|
||||
SetMoleculeInfo(GetFormula());
|
||||
foreach (var debugObj in DebugObjs)
|
||||
{
|
||||
debugObj.SetActive(false);
|
||||
@ -275,9 +322,4 @@ public class ActiveScoppedElements : MonoBehaviour
|
||||
RefreshText();
|
||||
RefreshAtom();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@ -38,7 +38,7 @@ RenderSettings:
|
||||
m_ReflectionIntensity: 1
|
||||
m_CustomReflection: {fileID: 0}
|
||||
m_Sun: {fileID: 0}
|
||||
m_IndirectSpecularColor: {r: 0.37311918, g: 0.3807398, b: 0.35872716, a: 1}
|
||||
m_IndirectSpecularColor: {r: 0.3708985, g: 0.37837005, b: 0.3572253, a: 1}
|
||||
m_UseRadianceAmbientProbe: 0
|
||||
--- !u!157 &3
|
||||
LightmapSettings:
|
||||
@ -332,52 +332,6 @@ CanvasRenderer:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 136169417}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!1 &524575261
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 524575263}
|
||||
- component: {fileID: 524575262}
|
||||
m_Layer: 0
|
||||
m_Name: GameObject
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &524575262
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 524575261}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 8c2433f4f2c3ba343851fdf3c660c21e, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
moleculeJson: {fileID: 4900000, guid: 3a11d0f923ae50c4d82ee1dda0f629a3, type: 3}
|
||||
atomJson: {fileID: 4900000, guid: ab8f44086e6af6f48a38b7d7d595e9a2, type: 3}
|
||||
--- !u!4 &524575263
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 524575261}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: -0.5532938, y: -1.3569599, z: -4.0075746}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &534669303
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -388,7 +342,7 @@ GameObject:
|
||||
m_Component:
|
||||
- component: {fileID: 534669306}
|
||||
- component: {fileID: 534669305}
|
||||
- component: {fileID: 534669304}
|
||||
- component: {fileID: 534669307}
|
||||
m_Layer: 0
|
||||
m_Name: EventSystem
|
||||
m_TagString: Untagged
|
||||
@ -396,26 +350,6 @@ GameObject:
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &534669304
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 534669303}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 4f231c4fb786f3946a6b90b886c48677, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_SendPointerHoverToParent: 1
|
||||
m_HorizontalAxis: Horizontal
|
||||
m_VerticalAxis: Vertical
|
||||
m_SubmitButton: Submit
|
||||
m_CancelButton: Cancel
|
||||
m_InputActionsPerSecond: 10
|
||||
m_RepeatDelay: 0.5
|
||||
m_ForceModuleActive: 0
|
||||
--- !u!114 &534669305
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -446,6 +380,36 @@ Transform:
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &534669307
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 534669303}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 01614664b831546d2ae94a42149d80ac, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_SendPointerHoverToParent: 1
|
||||
m_MoveRepeatDelay: 0.5
|
||||
m_MoveRepeatRate: 0.1
|
||||
m_XRTrackingOrigin: {fileID: 0}
|
||||
m_ActionsAsset: {fileID: -944628639613478452, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
|
||||
m_PointAction: {fileID: -1654692200621890270, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
|
||||
m_MoveAction: {fileID: -8784545083839296357, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
|
||||
m_SubmitAction: {fileID: 392368643174621059, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
|
||||
m_CancelAction: {fileID: 7727032971491509709, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
|
||||
m_LeftClickAction: {fileID: 3001919216989983466, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
|
||||
m_MiddleClickAction: {fileID: -2185481485913320682, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
|
||||
m_RightClickAction: {fileID: -4090225696740746782, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
|
||||
m_ScrollWheelAction: {fileID: 6240969308177333660, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
|
||||
m_TrackedDevicePositionAction: {fileID: 6564999863303420839, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
|
||||
m_TrackedDeviceOrientationAction: {fileID: 7970375526676320489, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
|
||||
m_DeselectOnBackgroundClick: 1
|
||||
m_PointerBehavior: 0
|
||||
m_CursorLockBehavior: 0
|
||||
--- !u!1 &693850225
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -1296,4 +1260,3 @@ SceneRoots:
|
||||
- {fileID: 693850230}
|
||||
- {fileID: 732397232}
|
||||
- {fileID: 534669306}
|
||||
- {fileID: 524575263}
|
||||
|
@ -23,7 +23,7 @@ public class AtomeFactory : MonoBehaviour{
|
||||
}
|
||||
}
|
||||
|
||||
public static AtomeFactory getInstrance(){
|
||||
public static AtomeFactory getInstrance() {
|
||||
if(AtomeFactory.instance == null){
|
||||
Debug.LogError("no Json file");
|
||||
}
|
||||
|
@ -27,28 +27,6 @@
|
||||
"boilingPoint": -183.0
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Eau",
|
||||
"formula": "H2O",
|
||||
"atoms": [
|
||||
{
|
||||
"element": "H2",
|
||||
"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
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Dioxygène",
|
||||
"formula": "O2",
|
||||
|
@ -2,8 +2,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
|
||||
public class MoleculeFactory : MonoBehaviour{
|
||||
|
||||
public TextAsset jsonFile;
|
||||
@ -76,6 +74,32 @@ public class MoleculeFactory : MonoBehaviour{
|
||||
return sortie;
|
||||
}
|
||||
|
||||
public Molecule GetMoleculeByFormula(String formula)
|
||||
{
|
||||
if (!hasMolecule(formula))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Molecule molecule = moleculesDictionary[formula];
|
||||
return molecule;
|
||||
}
|
||||
|
||||
public Dictionary<String, AtomeInformation> GetAtomsInfoByFormula(String formula)
|
||||
{
|
||||
if (!hasMolecule(formula))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Dictionary<String, AtomeInformation> dictionary = new Dictionary<string, AtomeInformation>();
|
||||
Molecule molecule = moleculesDictionary[formula];
|
||||
foreach (var atom in molecule.atoms)
|
||||
{
|
||||
dictionary.Add(atom.element, atomeFactory.createAtome(atom.element));
|
||||
}
|
||||
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
public void setAtomFactory(AtomeFactory atomeFactory){
|
||||
this.atomeFactory = atomeFactory;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user