CREATE YOUR WORLD
Scripting
ScriptableObject
5min
zepetoscriptableobject supports unity scriptableobject zepetoscriptableobject is a data container that saves large amounts of data, such as world data settings and character options to create a new zepetoscriptableobject file, click the \[+] icon in the top left corner of the project panel, or click assets → create → zepeto → scriptableobject the newly created zepetoscriptableobject needs to be connected by creating scripts with a defined data class make a new zepetoscript file, and declare the data you will use as the member variables here are some sample codes that can be used as data typescript import { vector3, quaternion } from 'unityengine'; export default class playerscriptobjectdef { public name string; public hp number; public position vector3; public rotation vector3; } when you link the zepetoscript with the defined data class to zepetoscriptableobjects, you will see those data in the inspector window, as shown below create a zepetoscript file to call data from the zepetoscriptableobject import the zepetoscriptableobject from the zepetoscript and import the data type you have declared as well typescript import { zepetoscriptableobject } from 'zepeto script'; import playerscriptobjectdef from ' /playerdefine/playerscriptobjectdef'; declare the zepetoscriptableobject’s as properties in the zepetoscript typescript public player zepetoscriptableobject\<playerscriptobjectdef>; public enemy zepetoscriptableobject\<playerscriptobjectdef>; open the inspector window in zepetoscript assign values for the zepetoscriptableobject properties, as shown below this sample shows how you can use the zepetoscriptableobject and access it’s values typescript // direct access by name console log(`play name ${this player\["name"]}`); console log(`play hp ${this player\["hp"]}`); console log(`play position (${this player\["position"] x}, ${this player\["position"] y}, ${this player\["position"] z})`); console log(`play rotation (${this player\["rotation"] x}, ${this player\["rotation"] y}, ${this player\["rotation"] z})`); // generic data call let monsterstate = this enemy targetobject; console log(`enemy name ${monsterstate name}`); console log(`enemy hp ${monsterstate hp}`); console log(`enemy position (${monsterstate position x}, ${monsterstate position y}, ${monsterstate position z})`); console log(`enemy rotation (${monsterstate rotation x}, ${monsterstate rotation y}, ${monsterstate rotation z})`); to access a primitive type of member variable, declare it as a generic type or covert it using type casting, like the example shown below typescript // type casting let playerposition = this player\["position"] as vector3; console log(`player position (x ${playerposition x}, y ${playerposition y}, z ${playerposition z})`); // generic type can access class member console log(`enemy position (x ${monsterstate position x}, y ${monsterstate position y}, z ${monsterstate position z})`); check the full code example for scriptableobject typescript import { vector3 } from 'unityengine'; import { zepetoscriptbehaviour, zepetoscriptableobject } from 'zepeto script'; // import scriptable object type definition import playerscriptobjectdef from ' /playerdefine/playerscriptobjectdef'; export default class scriptableobjectsample extends zepetoscriptbehaviour { public player zepetoscriptableobject; // generic type call public enemy zepetoscriptableobject\<playerscriptobjectdef>; awake() { // direct access by name console log(`play name ${this player\["name"]}`); console log(`play hp ${this player\["hp"]}`); console log(`play position (${this player\["position"] x}, ${this player\["position"] y}, ${this player\["position"] z})`); console log(`play rotation (${this player\["rotation"] x}, ${this player\["rotation"] y}, ${this player\["rotation"] z})`); // generic data call let monsterstate = this enemy targetobject; console log(`enemy name ${monsterstate name}`); console log(`enemy hp ${monsterstate hp}`); console log(`enemy position (${monsterstate position x}, ${monsterstate position y}, ${monsterstate position z})`); console log(`enemy rotation (${monsterstate rotation x}, ${monsterstate rotation y}, ${monsterstate rotation z})`); // type casting let playerposition = this player\["position"] as vector3; console log(`player position (${playerposition x}, ${playerposition y}, ${playerposition z})`); // generic type can access class member console log(`enemy position (${monsterstate position x}, ${monsterstate position y}, ${monsterstate position z})`); } }