I want to use a variable in the Unity editor source file to get it from a regular script.
I want to use a variable in the Unity editor source file to get it from a regular script.
TrackbarWindows.cs
using System.Collections; using System.Collections.Generic; using UnityEngine;
if UNITY_EDITOR
sing UnityEditor; #endif
public class TrackbarWindow : EditorWindow { public static TrackbarWindow Instance; private static Rect TitleRect; private static Rect MainRect;
// test Color
public float slider1Value = 0.0f;
public float slider2Value = 0.0f;
public float slider3Value = 0.0f;
public float slider4Value = 0.0f;
public float slider5Value = 0.0f;
public float slider6Value = 0.0f;
public static void Init()
{
Instance = GetWindow<TrackbarWindow>();
Instance.titleContent = new GUIContent("Node Editor");
Instance.maxSize = new Vector2(1000, 600);
Instance.minSize = Instance.maxSize;
TitleRect = new Rect(0, 0, Instance.maxSize.x, 50);
MainRect = new Rect(0, TitleRect.height + 5, Instance.maxSize.x, 500);
}
public void OnGUI()
{
GUILayout.BeginArea(TitleRect);
{
GUI.backgroundColor = Color.cyan;
GUI.Box(TitleRect, "");
GUILayout.BeginHorizontal();
{
GUILayout.Label("테스트용 Track Bar");
}
GUILayout.EndHorizontal();
GUI.backgroundColor = Color.white;
}
GUILayout.EndArea();
GUILayout.BeginArea(MainRect);
{
GUI.backgroundColor = Color.gray;
GUI.Box(new Rect(0, 0, MainRect.width, MainRect.height), "");
GUILayout.BeginHorizontal();
{
slider1Value = EditorGUILayout.Slider(slider1Value, 0, 100);
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
{
slider2Value = EditorGUILayout.Slider(slider2Value, 0, 100);
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
{
slider3Value = EditorGUILayout.Slider(slider3Value, 0, 100);
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
{
slider4Value = EditorGUILayout.Slider(slider4Value, 0, 100);
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
{
slider5Value = EditorGUILayout.Slider(slider5Value, 0, 100);
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
{
slider6Value = EditorGUILayout.Slider(slider6Value, 0, 100);
}
GUILayout.EndHorizontal();
GUI.backgroundColor = Color.white;
}
GUILayout.EndArea();
// Debug.Log (slider1Value);
}
}
TestTrackber.cs
using System.Collections; using System.Collections.Generic; using UnityEngine; #if UNITY_EDITOR using UnityEditor; #endif
namespace RPG.NodeEditor.Editor { public partial class TestTrackbar { [MenuItem("Tools/Trackbar")] public static void InitNodeEditor() { TrackbarWindow.Init(); } } }
Test.cs
using System.Collections.Generic; using UnityEngine;
public class TestNumbering : MonoBehaviour { public float num1; public float num2; public float num3; public TrackbarWindow trackbar;
// Use this for initialization
void Start () {
// trackbar = GetComponents<TrackbarWindow> ();
}
// Update is called once per frame
void Update () {
Debug.Log (trackbar.slider1Value);
}
}
is. In the Trackbarwindows source code, public float slider1Value = 0.0f; Set the value of the variable to public float num1; towards I want to use the value in the editor source code.
However, debug.log says that you can not get the value as NULL, Please help ...