using System;
using UnityEngine;
using Random = UnityEngine.Random;
namespace UnityEditor.TreeViewExamples
{
[Serializable]
internal class MyTreeElement : TreeElement
{
public float floatValue1, floatValue2, floatValue3;
public Material material;
public string text = "";
public bool enabled;
public MyTreeElement (string name, int depth, int id) : base (name, depth, id)
{
floatValue1 = Random.value;
floatValue2 = Random.value;
floatValue3 = Random.value;
enabled = false;
}
}
}
And I want to save/load this variables values from this script :
using UnityEngine;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
public class SaveData
{
public static void Save()
{
}
public static void Load()
{
}
}
But when trying to type MyTreeElement in the Save() like this :
The problem is that when I’m doing in the SaveData class at the top :
using UnityEditor.
There is no TreeViewExamples the TreeViewExamples is not exist.
Same if I’m doing inside the Save method :
public SaveData(UnityEditor.TreeViewExamples.MyTreeElement)
The MyTreeElement not exist.
But I saw in another script no my one that the MyTreeElement does exist and can be accessed :
using System.Collections.Generic;
using UnityEngine;
namespace UnityEditor.TreeViewExamples
{
[CreateAssetMenu (fileName = "TreeDataAsset", menuName = "Tree Asset", order = 1)]
public class MyTreeAsset : ScriptableObject
{
[SerializeField] List<MyTreeElement> m_TreeElements = new List<MyTreeElement> ();
I can’t figure out why it’s exist can be access here but on in my class.
I tried to change the SaveData class to add to it the namespace namespace UnityEditor.TreeViewExamples but it didn’t help. I tried to make the internal class to be public without internal but not working.
Tried to make the SaveData class to be type ScriptableObject it should not be ScriptableObject but for testing but it’s not working either.
Nothing I can’t access the MyTreeElement from my SaveData class can’t figure out why bot and in other scripts it can be accessed.
I just moved the script SaveData into the folder of the of the other Tree…scripts in the Assets in the editor.
Now I have access to all the variables in MyTreeElement
But I still can’t figure out why after moving the script to the folder make it working.
Where was this script located before you moved it?
All scripts have to be in the asset folders so that Unity takes them into account. You cannot just have them anywhere else on your development device.
Sometimes they have to be in a special subfolder, but that’s another topic.