Assign multiple Camera values to a single Scriptable Object
I have a situation where I need the camera to move around a Canvas when I play "Next" or "previous". So whenever I press "Next", for example, the Camera should change its position and Orthographic Size.
This is a structure to show a "Story" over a single image which has different "Scenes". Like this I have multiple Stories.
I have been experimenting doing something with Scriptable Objects, whereby I have a template of the Story having different Classes.
The Scriptable Object I'm working with:
public class StoryData : MonoBehaviour
{
public string StoryName;
public StorySceneData[] storySceneDatas;
}
[System.Serializable]
public class StorySceneData
{
public string SceneText;
public StorySceneCameraData StorySceneCameraData;
}
[System.Serializable]
public class StorySceneCameraData
{
public Vector3 CameraCoordinates;
public float CameraSize;
[Button]
public void SetCamera()
{
CameraCoordinates = Camera.main.transform.position;
CameraSize = Camera.main.orthographicSize;
}
}
I'm using Naughty Attributes asset to show the button on the inspector. Idea is to set the number of Scenes to an array, adjust the camera and get that value after clicking on the button.
But the button doesn't appear when placed inside the StorySceneCameraData. It's visible inside the main StoryData, which I can't use because I need individual Camera data.
I also tried building a Custom Inspector for this, it didn't work.
Any Ideas?
Answer by Jack-Mariani · May 09, 2019 at 12:23 PM
I think the answer is related to the Naughty Attributes, but I can't be sure because I've never used it.
It seems likely that the [Button] attribute works on the MonoBehaviour, but not on other classes.
BTW please note that StorySceneCameraData is not a Scriptable Object. If you want Scriptable Object you should derive it from Scriptable Object class.
If you want the [Button] attribute working also on a class not deriving from MonoBehaviour I would suggest you Odin Inspector.