I really gotta get my new version out… Its so much simpler…
Within a script component class, to reference another component attached to the same transform, you would call GetComponent and to access an arbitrary class on any transform from anywhere else you would use SceneManager.FindScriptComponent
Note: I thinks its called FindSceneComponent in the legacy toolkit you are currently working with
But basically its like Unity: Unity - Scripting API: GameObject.GetComponent
In Unity, you would do something like this to get a reference to a component:
using UnityEngine;
public class GetComponentExample : MonoBehaviour
{
void Start()
{
HingeJoint hinge = gameObject.GetComponent(typeof(HingeJoint)) as HingeJoint;
if (hinge != null)
hinge.useSpring = false;
}
}
Same exact usage in Babylon:
module PROJECT {
export class GetComponentExample extends BABYLON.ScriptComponent {
public constructor(transform: BABYLON.TransformNode, scene: BABYLON.Scene, properties: any = {}) {
super(transform, scene, properties);
}
protected start(): void {
var hinge:PROJECT.HingeJoint = this.getComponent("PROJECT.HingeJoint");
if (hinge != null)
hinge.useSpring = false;
}
}
}
Here is an example helper function from my speedway demo used to instantiate a prefab of a fully scripted and setup mustang vehicle object (Hierarchy of models with various scripts attached) that can be called from anywhere… Even the Playgraound
protected static CreateMustangVehicle(scene:BABYLON.Scene, container:BABYLON.AssetContainer, prefab:string, name:string, player:BABYLON.PlayerNumber, startPosition:BABYLON.AbstractMesh, heightOffset:number, enableInput:boolean, attachCamera:boolean, topSpeed:number, powerRatio:number, skillLevel:number, bodyColor:BABYLON.Color3, wheelColor:BABYLON.Color3 = null, wheelType:number = 0, decalIndex:number = 0):BABYLON.TransformNode {
const mustangVehicle:BABYLON.TransformNode = BABYLON.SceneManager.InstantiatePrefab(container, prefab, name);
if (mustangVehicle != null) {
mustangVehicle.rotationQuaternion = startPosition.rotationQuaternion.clone();
mustangVehicle.position = startPosition.position.clone();
mustangVehicle.position.y += heightOffset;
const autoBodyShop:PROJECT.AutoBodyGarage = BABYLON.SceneManager.FindScriptComponent(mustangVehicle, "PROJECT.AutoBodyGarage");
const inputController:PROJECT.VehicleInputController = BABYLON.SceneManager.FindScriptComponent(mustangVehicle, "PROJECT.VehicleInputController");
const cameraManager:PROJECT.VehicleCameraManager = BABYLON.SceneManager.FindScriptComponent(mustangVehicle, "PROJECT.VehicleCameraManager");
const carController:PROJECT.StandardCarController = BABYLON.SceneManager.FindScriptComponent(mustangVehicle, "PROJECT.StandardCarController");
if (autoBodyShop != null) autoBodyShop.setupVehicleMaterials(bodyColor, wheelColor, wheelType, decalIndex);
if (carController != null) {
carController.lowSpeedAngle = (player === 0) ? 20 : 10;
carController.highSpeedAngle = (player === 0) ? 10 : 1;
carController.topEngineSpeed = topSpeed;
carController.powerCoefficient = powerRatio;
}
if (inputController != null) {
inputController.enableInput = false;
inputController.playerNumber = player;
inputController.driverSkillLevel = skillLevel;
}
if (cameraManager != null && attachCamera === true) {
cameraManager.enableCamera = true;
cameraManager.followBehind = true;
cameraManager.attachPlayerCamera(player);
}
} else {
BABYLON.Tools.Warn("===> Failed to instantiate mustang prefab: " + name);
}
return mustangVehicle;
}
The SceneManager Extension is Unity Style Micro Framework i created to provide Babylon Developers with same kind of Unity Workflow And Game Mechanics
I am trying to get the new version out as best i can… But its just me… Lots of functionality to re-produce by myself