J'ai créé une node personnalisée en Visual Sripting pour sauvegarder mes variables en une seule fois au lieu de plusieurs.(C'est pour la partie Setting, je vais en faire d'autres plus longues pour mes GameObjects.)
Je vous donne tout en bas plus d'explications sur le projet.
Voci mon problème : J'aimerais faire l'inverse (un Get) pour récupérer les lignes du tableau séparément par index.
Pour le moment je n'arrive qu'à récupérer le tableau entier sans pouvoir sélectionner une ligne précise.
Code : Tout sélectionner
Variable = File.ReadAllText(Application.persistentDataPath + "/" + Folder + "/" + File + ".txt");
La node va convertir les int, float et bool directement en string pour le fichier txt.
Voci ce que donne le résultat de la node Set :
Donc pour la "Get" je vais mettre des "Parse" pour reconvertir les types, mais surtout split les variables pour ne récupérer que la partie variable, sans sa désigantion.
Si quelqu'un peut m'aider pour identifier l'index de chaque ligne dans un tableau
La je galère à trouver.
Et voici le script de ma node:
Code : Tout sélectionner
using System;
using System.IO;
using UnityEngine;
using Unity.VisualScripting;
[UnitTitle("Set Settings")]
[UnitCategory("[Variables ]")]
[TypeIcon(typeof(GameObject))]
public class Set_Settings : Unit
{
[DoNotSerialize]
[PortLabelHidden]
public ControlInput Entrance_Flux;
[DoNotSerialize]
[PortLabelHidden]
public ControlOutput Exit_Flux;
[DoNotSerialize]
public ValueInput Entrance_Folder;
[DoNotSerialize]
public ValueInput Entrance_File;
[DoNotSerialize]
public ValueInput Entrance_Variable_1;
[DoNotSerialize]
public ValueInput Entrance_Variable_2;
[DoNotSerialize]
public ValueInput Entrance_Variable_3;
[DoNotSerialize]
public ValueInput Entrance_Variable_4;
[DoNotSerialize]
public ValueInput Entrance_Variable_5;
[DoNotSerialize]
public ValueInput Entrance_Variable_6;
[DoNotSerialize]
public ValueInput Entrance_Variable_7;
[DoNotSerialize]
public ValueInput Entrance_Variable_8;
[DoNotSerialize]
public ValueInput Entrance_Variable_9;
[DoNotSerialize]
public ValueInput Entrance_Variable_10;
[DoNotSerialize]
public ValueInput Entrance_Variable_11;
[DoNotSerialize]
public ValueInput Entrance_Variable_12;
[DoNotSerialize]
public ValueInput Entrance_Variable_13;
[DoNotSerialize]
public ValueInput Entrance_Variable_14;
[DoNotSerialize]
public ValueInput Entrance_Variable_15;
[DoNotSerialize]
public ValueInput Entrance_Variable_16;
[DoNotSerialize]
public ValueInput Entrance_Variable_17;
[DoNotSerialize]
public ValueInput Entrance_Variable_18;
[DoNotSerialize]
public ValueInput Entrance_Variable_19;
[DoNotSerialize]
public ValueInput Entrance_Variable_20;
[DoNotSerialize]
public ValueInput Entrance_Variable_21;
private string Variable_Folder;
private string Variable_File;
private bool Variable_1_bool;
private int Variable_2_int;
private string Variable_3;
private int Variable_4_int;
private int Variable_5_int;
private int Variable_6_int;
private int Variable_7_int;
private int Variable_8_int;
private int Variable_9_int;
private int Variable_10_int;
private int Variable_11_int;
private bool Variable_12_bool;
private float Variable_13_float;
private float Variable_14_float;
private float Variable_15_float;
private float Variable_16_float;
private float Variable_17_float;
private float Variable_18_float;
private float Variable_19_float;
private float Variable_20_float;
private float Variable_21_float;
protected override void Definition()
{
Entrance_Flux = ControlInput("Entrance_Flux", (flow) =>
{
Variable_Folder = flow.GetValue<string>(Entrance_Folder);
Variable_File = flow.GetValue<string>(Entrance_File);
Variable_1_bool = flow.GetValue<bool>(Entrance_Variable_1);
string Variable_1 = Variable_1_bool.ToString();
Variable_2_int = flow.GetValue<int>(Entrance_Variable_2);
string Variable_2 = Variable_2_int.ToString();
Variable_3 = flow.GetValue<string>(Entrance_Variable_3);
Variable_4_int = flow.GetValue<int>(Entrance_Variable_4);
string Variable_4 = Variable_4_int.ToString();
Variable_5_int = flow.GetValue<int>(Entrance_Variable_5);
string Variable_5 = Variable_5_int.ToString();
Variable_6_int = flow.GetValue<int>(Entrance_Variable_6);
string Variable_6 = Variable_6_int.ToString();
Variable_7_int = flow.GetValue<int>(Entrance_Variable_7);
string Variable_7 = Variable_7_int.ToString();
Variable_8_int = flow.GetValue<int>(Entrance_Variable_8);
string Variable_8 = Variable_8_int.ToString();
Variable_9_int = flow.GetValue<int>(Entrance_Variable_9);
string Variable_9 = Variable_9_int.ToString();
Variable_10_int = flow.GetValue<int>(Entrance_Variable_10);
string Variable_10 = Variable_10_int.ToString();
Variable_11_int = flow.GetValue<int>(Entrance_Variable_11);
string Variable_11 = Variable_11_int.ToString();
Variable_12_bool = flow.GetValue<bool>(Entrance_Variable_12);
string Variable_12 = Variable_12_bool.ToString();
Variable_13_float = flow.GetValue<float>(Entrance_Variable_13);
string Variable_13 = Variable_13_float.ToString();
Variable_14_float = flow.GetValue<float>(Entrance_Variable_14);
string Variable_14 = Variable_14_float.ToString();
Variable_15_float = flow.GetValue<float>(Entrance_Variable_15);
string Variable_15 = Variable_15_float.ToString();
Variable_16_float = flow.GetValue<float>(Entrance_Variable_16);
string Variable_16 = Variable_16_float.ToString();
Variable_17_float = flow.GetValue<float>(Entrance_Variable_17);
string Variable_17 = Variable_17_float.ToString();
Variable_18_float = flow.GetValue<float>(Entrance_Variable_18);
string Variable_18 = Variable_18_float.ToString();
Variable_19_float = flow.GetValue<float>(Entrance_Variable_19);
string Variable_19 = Variable_19_float.ToString();
Variable_20_float = flow.GetValue<float>(Entrance_Variable_20);
string Variable_20 = Variable_20_float.ToString();
Variable_21_float = flow.GetValue<float>(Entrance_Variable_21);
string Variable_21 = Variable_21_float.ToString();
Directory.CreateDirectory(Application.persistentDataPath + "/" + Variable_Folder);
string[] List = {
null,
"-Initialization-",
"Setup: " + Variable_1,
"GameObject: " + Variable_2,
"Select: " + Variable_3,
"Music: " + Variable_4,
null,
"-Time-",
"Hour: " + Variable_5,
"Minute: " + Variable_6,
"Second :" + Variable_7,
"Day: " + Variable_8,
"Month: " + Variable_9,
"Year: " + Variable_10,
"Leap Year: " + Variable_11,
null,
"-Camera-",
"Camera: " + Variable_12,
"Position X: " + Variable_13,
"Position Y: " + Variable_14,
"Position Z: " + Variable_15,
"Rotation X: " + Variable_16,
"Rotation Y: " + Variable_17,
"Rotation Z: " + Variable_18,
"Scale X: " + Variable_19,
"Scale Y: " + Variable_20,
"Scale Z: " + Variable_21,
};
File.WriteAllLines(Application.persistentDataPath + "/" + Variable_Folder + "/" + Variable_File + ".txt", List);
return Exit_Flux;
});
Exit_Flux = ControlOutput("Exit_Flux");
Entrance_Folder = ValueInput<string>("Folder", string.Empty);
Entrance_File = ValueInput<string>("File", string.Empty);
Entrance_Variable_1 = ValueInput<bool>("Setup");
Entrance_Variable_2 = ValueInput<int>("GameObject");
Entrance_Variable_3 = ValueInput<string>("Select", string.Empty);
Entrance_Variable_4 = ValueInput<int>("Music");
Entrance_Variable_5 = ValueInput<int>("Hour");
Entrance_Variable_6 = ValueInput<int>("Minute");
Entrance_Variable_7 = ValueInput<int>("Second");
Entrance_Variable_8 = ValueInput<int>("Day");
Entrance_Variable_9 = ValueInput<int>("Month");
Entrance_Variable_10 = ValueInput<int>("Year");
Entrance_Variable_11 = ValueInput<int>("Leap Year");
Entrance_Variable_12 = ValueInput<bool>("Camera");
Entrance_Variable_13 = ValueInput<float>("Position X");
Entrance_Variable_14 = ValueInput<float>("Position Y");
Entrance_Variable_15 = ValueInput<float>("Position Z");
Entrance_Variable_16 = ValueInput<float>("Rotation X");
Entrance_Variable_17 = ValueInput<float>("Rotation Y");
Entrance_Variable_18 = ValueInput<float>("Rotation Z");
Entrance_Variable_19 = ValueInput<float>("Scale X");
Entrance_Variable_20 = ValueInput<float>("Scale Y");
Entrance_Variable_21 = ValueInput<float>("Scale Z");
Succession(Entrance_Flux, Exit_Flux);
}
}
L'idée dans mes codes VS est de placer en début la node Get pour que je puisse tirer une ligne d'une variable de cette node que j'ai besoin vers les nodes de mon code.
La node Set seras placer en bout de code pour récupérer directement toutes les variables mises à jour.
Pour les variables non utilisée je vais dans un premier temps relier toutes les variables de la Get à la Set avant de déplacer la node set sur la droite de mon code.
Comme ça au lieu qu'elle m'enregistre une ligne vide j'aurais réécrit la variable avec son actuel contenu.
(Oui je ne pense pas que ça soit possible d'écrire une ligne ignorée).