microsoft / RoomAliveToolkit

Other
714 stars 191 forks source link

Error : "Can't add script behaviour CallbackExecutor. The script needs to derive from Monobehaviour" #90

Open Hellbolato opened 4 years ago

Hellbolato commented 4 years ago

I'm stuck at the step 7 of "scene setup" : "Add the following two components (scripts) to the MyRoom object (you can use Add Component->RoomAliveToolkit->{ScriptName} in the Inspector to quickly find the scripts from the toolkit): RATCalibrationData RATSceneSetup"

I work with Unity 2018.4.18f1 (64-bit) and Visual Studio 2019

first of all, i can't add the script via the "Add component" button of my empty object named MyRoom in the inspector because i can't find it when i type the first letters, even though i imported the RoomAliveToolkit package (Assets > import packages > custom package). So i simply drag'N'drop the RATCalibrationData and RATSceneSetup scripts from my assets folder into my empty object but then i get this "needs to derive from Monobehavior" error.

1-The public class name is the same as the script name so the error doesn't seem to come from here. 2- I tried to Reset the script in the inspector but that didn't work either... 3 - I tried to add "using System.Collections; using UnityEditor; under "using UnityEngine" as it appears when i create an empty script but that didn't solved my problem either..

I didn't do anything to the script so it's pretty much still the same :

using UnityEngine;

namespace RoomAliveToolkit { ///

/// Calibration data asset. This is a component of the scene where the XML calibration file is read that is acquired by the room calibration routines. /// To obtain a Kinect calibration XML file see CalibrateEnsamble example in RoomAlive Toolkit ProCamCalibration /// https://github.com/Kinect/RoomAliveToolkit/tree/master/ProCamCalibration /// [AddComponentMenu("RoomAliveToolkit/RATCalibrationData")] [ExecuteInEditMode] public class RATCalibrationData : MonoBehaviour { /// /// Flag to signal whether calibration is loaded. /// public bool IsLoaded { get { return loaded; } }

    /// <summary>
    /// XML file containing calibration data. 
    /// </summary>
    public TextAsset calibration = null;

    private ProjectorCameraEnsemble ensemble;
    private bool loaded = false;

    public void LoadAsset()
    {
        if(calibration!=null)
            ensemble = ProjectorCameraEnsemble.ReadCalibration(calibration.text);
        loaded = true;
    }

    void Update()
    {

    }

    public ProjectorCameraEnsemble GetEnsemble()
    {
        if (!loaded)
            LoadAsset();
        return ensemble;
    }

    public bool IsValid()
    {
        return GetEnsemble() != null;
    }

    void OnValidate()
    {
        if(IsValid())
        {
            RATKinectClient[] cameras = GetComponentsInChildren<RATKinectClient>();
            RATProjector[] projectors = GetComponentsInChildren<RATProjector>();

            foreach(RATKinectClient camera in cameras) 
            {
                if (camera.calibrationData == null)
                    camera.calibrationData = this;
                if(camera.calibrationData==this)
                {
                    camera.LoadCalibrationData();
                }
            }
            foreach (RATProjector projector in projectors)
            {
                if (projector.calibrationData == null)
                    projector.calibrationData = this;
                if (projector.calibrationData == this)
                {
                    projector.LoadCalibrationData();
                }
            }
        }
    }
}

}