Hi,
I'm trying to create a class to handle when a ball lands in a saucer. Looking through the supplied table code I'm thinking I need to do something like the following:
Create the class:
public class TW : BxSolenoid {
SetLamp(70,true);
float timer = 300f;
void Update(){ timer -= Time.deltaTime; if (timer <= 0) { SetLamp(70,false); } } }
In the table manager class, find the object on the FP table, and make it an object of the TW class: (What do I replace the "Toys/Toy1" with to find the kicker?
GameObject.Find ("Toys/Toy1").AddComponent<TW>();
Am I heading in the correct direction?
Here is the code I'm working with atm:
using UnityEngine;
using System.Collections;
public class Script{
public void Init(){
GameObject table = GameObject.Find("TABLE");
test_TableManager behaviour = table.AddComponent<test_TableManager>();
behaviour.PreInit(); // Call pre-initialization steps
behaviour.Init(); // Script initialization
behaviour.PostInit(); // Call poste-initialization steps
}
}
public class test_TableManager : BxTableManager{
bool m_autokick = true;
public override void Init (){
base.Init(); // Call BxVPMTableManager Start (Display version and default controller options
InitArrays(255,255,10,255); // 89 Lamps, 65 Solenoids/Flashers (10 by default for GIs) and 255 Switches...)
//SetDMDObject("DMD","BxVPMDMD"); // Link the Vpm driven Dmd Update Component to the object "DMD"
InitSubwaySystem(); // Initialize Subway System
PrepareElements();
AddSwitchCallBack(70, KLKickout);
AddSwitchCallBack(71, TWKickout);
Global.Physics.g_GeneralForceMultiplier = 1;
Global.Physics.g_PlungerForceMultiplier = 15f;
Global.Physics.g_AutoPlungerForceMultiplier = 45f;
Global.Physics.g_FlipperForceMultiplier = 350f;
Global.Physics.g_FlipperSpeedTargetMultiplier = 10000f;
Global.Physics.g_VerticalKickerForceMultiplier = 300;
Global.Physics.g_OrientedKickerForceMultiplier = 400f;
Global.Physics.g_BumperKickForceMultiplier = 500f;
Global.Physics.g_SlingshotForceMultiplier = 180f;
Global.Physics.g_SlingshotThresholdForce = 20;
Global.Physics.g_NudgeForceMultiplierX = 0.6f;
Global.Physics.g_NudgeForceMultiplierY = 0.3F;
Global.Physics.g_DiverterForceMultiplier = 1500;
Global.Physics.g_DebugShotForceMultiplier = 200;
Global.Physics.g_CoilMagnetForceMultiplier = 5.5f;
Global.Physics.SetBallDiameter(26.987f); // Set the balls diameter
Global.Physics.g_AirBall = false;
//BxBumperKick.s_AutoKickBumperMode = false; // Bumpers automatically kick
//GameObject ball=GameObject.Find("Shop/ball");
//ball.renderer.material.mainTexture=Resources.Load("BITMAP/amigaball") as Texture;////affect amigaball
//ball.renderer.material.color=Color.white; //// so that amigaball can be seen
}
void PrepareElements(){
/*
for (int l = 0; l < 200; l++) {
try {
GameObject.Find("Playfield/Lamps").transform.GetChild(l).FindChild("decal").Translate(new Vector3(0f, 0f, -0.09f));
Material mat = GameObject.Find("Playfield/Lamps").transform.GetChild(l).FindChild("decal").renderer.material;///find decal object
mat.shader = Shader.Find("PU3D/Managed/TexBackTrans"); ///// change its shader to textured backlit transparent
mat.color = new Color(mat.color.r / 3f, mat.color.r / 3f, mat.color.b / 3f, 0.9f); //// lowering its color by 3(texture used is really bright)
mat.SetFloat("_BackLightingStrength", 9f); ///// setting its backlighting strength(you need to test)
mat.color = new Color(mat.color.r, mat.color.r, mat.color.r, 0.9f);
}
catch { }
}
*/
/*
GameObject.Find("Playfield/Lamps/Light1").transform.FindChild("decal").Translate(new Vector3(0f, 0f, -0.09f));
Material mat = GameObject.Find("Playfield/Lamps/Light1").transform.FindChild("decal").renderer.material;///find decal object
mat.shader = Shader.Find("PU3D/Managed/TexBackTrans"); ///// change its shader to textured backlit transparent
mat.color = new Color(mat.color.r / 30f, mat.color.r / 30f, mat.color.b / 30f, 0.9f); //// lowering its color by 3(texture used is really bright)
mat.SetFloat("_BackLightingStrength", 0f); ///// setting its backlighting strength(you need to test)
mat.color = new Color(mat.color.r, mat.color.r, mat.color.r, 0.9f);
*/
//GameObject.Find("Playfield/Lamps/bulbInLaneBottomLeft").transform.FindChild("decal").Translate(new Vector3(0f, 0f, -0.09f));;
//GameObject.Find("Playfield/Lamps/Light55");
//GameObject.Find("Playfield/Lamps/bulbInLaneBottomLeft/decal").renderer.material.SetFloat("_BackLightingStrength",30f); ///// setting its backlighting strength
}
//! Initialize table driver
/*
public override void InitDriver(){
m_driver = new BxDriver_wpc();
}
*/
public override void LateUpdate (){
base.LateUpdate();
if(Input.GetKeyDown(KeyCode.K)){
SetSolenoid(4, true); // todo => switch off (will not work when not using changedSolenoidsCallback)
}
if(Input.GetKeyDown(KeyCode.L)){
//SetSolenoid(69, true);
launchBall(true);
}
}
//! Initialize Subway System (redefinition)
public override void InitSubwaySystem(){
base.InitSubwaySystem();
GameObject subway = GameObject.Find ("TABLE/SUBWAY");
if(subway==null){
Debug.LogError("Unable to find SUBWAY object");
return;
}
BxSwManager subManager = (BxSwManager)subway.GetComponent("BxSwManager");
if(subManager==null) subManager = (BxSwManager)subway.GetComponent("BxSwVisualManager");
if(subManager==null){
Debug.LogError("Unable to find the Subway manager component in SUBWAY object");
return;
}
float swL = Global.Physics.g_BallDiameter; // length of switches in mm
BxSwNode drain = subManager.AddEntrance("Drain",5); // Main drain node used as subway entrance
BxSwNode pkick = subManager.AddExit("PlungerKicker",4); // Exit GoT_ kicker Node
pkick.m_swicthSlot = 52; // Node switch number
BxSwEdge mainThrough = subManager.LinkNodes(drain,pkick,1.5f); // main Through edge link (1.5 seconds for a ball to cross it)
mainThrough.AddSwitch(50, mainThrough.m_length-swL*1.5f, swL*0.9f); // First switch on the edge
mainThrough.AddSwitch(51, mainThrough.m_length-swL*0.5f , swL*0.9f); // Second switch on the edge (making 3 in total with the pkick node switch)
BxSwNode KLSaucer = subManager.AddEntrance("KLSaucerKicker",70, false); // switch #70, kill ball = false
KLSaucer = subManager.AddExit("KLSaucerKicker",70, 10f); // solenoid #70
BxSwNode TWSaucer = subManager.AddEntrance("TWSaucerKicker",71, false); // switch #71, kill ball = false
TWSaucer = subManager.AddExit("TWSaucerKicker",71, 10f); // solenoid #71
subManager.Build();
for(int i=0;i<10;i++){
BxSwVirtualBall b = new BxSwVirtualBall();
drain.InsertBall(b);
subManager.ReportNewBall(b);
subManager.DoStep();
}
//BxSwNode thingSaucer = subManager.AddEntrance("Kicker1",87,false); // Intput kicker with switch 87 NOT destroying the ball (Saucer)
//thingSaucer = subManager.AddExit("Kicker1",26,0f); // Output kicker driven by solenoid 26 (SHOULD be the same as above because of the same name) => No animation for kicking (releaseTime=0)
}
//! Link lamp array to Unity objects (called by InitArrays)
public override void InitLampsObjects(){
base.InitLampsObjects(); // call ancestor's function
AddLamp("bulbInLaneBottomLeft",2);
SetLamp (2,true);
AddLamp("bulbInLaneTopLeft",3);
AddLamp("KLLamp",70);
AddLamp("TWLamp",71);
//SetLamp (3,true);
}
//! Link solenoid array to Unity objects (called by InitArrays)
public override void InitSolenoidsObjects(){
base.InitSolenoidsObjects(); // call ancestor's function
AddSolenoid("Bumper1" , 61 , "BxBumperKick");
AddSolenoid("Bumper1/cap" , 62 , "BxBasicLamp");
BxBasicLamp BumperLight1=GameObject.Find("Bumper1/cap").GetComponentInChildren<BxBasicLamp>();
BumperLight1.m_onTime=0f;
BumperLight1.m_offTime=0.5f;
AddSolenoid("Bumper2" , 63 , "BxBumperKick");
AddSolenoid("Bumper2/cap" , 64 , "BxBasicLamp");
BxBasicLamp BumperLight2=GameObject.Find("Bumper2/cap").GetComponentInChildren<BxBasicLamp>();
BumperLight2.m_onTime=0f;
BumperLight2.m_offTime=0.5f;
AddSolenoid("Bumper3" , 65 , "BxBumperKick");
AddSolenoid("Bumper3/cap" , 66 , "BxBasicLamp");
BxBasicLamp BumperLight3=GameObject.Find("Bumper3/cap").GetComponentInChildren<BxBasicLamp>();
BumperLight3.m_onTime=0f;
BumperLight3.m_offTime=0.5f;
AddSolenoid("LeftSlingshotRubber" , 67 , "BxSlingshotKick");
AddSolenoid("RightSlingshotRubber" , 68 , "BxSlingshotKick");
AddSolenoid("Flippers/RightFlipper" , 69 , "BxBasicFlip"); // Right Flipper
// #70 KLSaucerKicker set in InitSubwaySystem
// #71 TWSaucerKicker set in InitSubwaySystem
AddSolenoid("Flippers/LeftFlipper" , 72 , "BxBasicFlip"); // Left Flipper
AddSolenoid("Flippers/UpperRightFlipper" , 73 , "BxBasicFlip"); // URight Flipper
AddSolenoid("rightAutoPlunger" , 74 , "BxAutoPlunger"); //
}
public override void InitSwitchesObjects(){
base.InitSwitchesObjects(); // call ancestor's function
AddSwitch("Bumper1" , 61);
AddSwitch("Bumper2" , 63);
AddSwitch("Bumper3" , 65);
AddSwitch("LeftSlingshotRubber" , 67 ,"BxSlingshotSwitch");
AddSwitch("RightSlingshotRubber" , 68 ,"BxSlingshotSwitch");
// #70 KLSaucerKicker set in InitSubwaySystem
// #71 TWSaucerKicker set in InitSubwaySystem
AddSwitch("rightLaunchTrigger" , 74 ,"BxTriggerSwitch");
}
public override void SetSwitch (int slot, bool state){
base.SetSwitch (slot, state);
switch(slot){
case 61:
SetSolenoid(61,state);
SetSolenoid(62,state);
break;
case 63:
SetSolenoid(63,state);
SetSolenoid(64,state);
break;
case 65:
SetSolenoid(65,state);
SetSolenoid(66,state);
break;
case 67:
case 68:
if(state) {
SetSolenoid(slot,state);
}
break;
}
}
void KLKickout(int slot, bool state){
SetSolenoid(70, true);
}
void TWKickout(int slot, bool state){
SetSolenoid(71, true);
}
public void launchBall(bool state){
//SetSolenoid(69, state);
SetSolenoid(74, state);
}
}
Edited by nath2099, 31 July 2014 - 07:56 AM.



Top











are all trademarks of VPFORUMS.