/// <summary> /// Sets up the physics world and the bodies, particle systems and joints in it. /// This is called on Awake() so you can implement your code on Start() and the liquidfun stuff will be ready</summary> void Awake() { //Always turn off debug messages in a build (Debug.Log writes to a log file and costs performance) if (!Application.isEditor && !Debug.isDebugBuild) { DebugMessages = false; } //Check for duplicate LPmanagers if (GameObject.FindObjectsOfType <LPManager>().Length > 1) { Debug.LogError("There is more than one LiquidFunManager in your scene. There can be only one!"); } else { //Create contact listener c# object ContactListener = new LPContactListener(); //Create World worldPtr = LPAPIWorld.CreateWorld(Gravity.x, Gravity.y); if (DebugMessages) { Debug.Log("World Created at: 0x" + worldPtr.ToInt64()); } //Initialise Contact Listener if (UseContactListener) { ContactListener.Initialise(worldPtr); } //Create bodies LPBody[] bodies = GameObject.FindObjectsOfType <LPBody>(); foreach (LPBody bod in bodies) { if (bod.SpawnOnPlay) { bod.Initialise(this); } } if (DebugMessages) { Debug.Log(bodies.Length + " Bodies created"); } //Create Joints foreach (LPJoint joint in GameObject.FindObjectsOfType <LPJoint>()) { if (joint.GetType() != typeof(LPJointGear)) { if (joint.SpawnOnPlay) { joint.Initialise(this); } } } foreach (LPJoint joint in GameObject.FindObjectsOfType <LPJointGear>()) { if (joint.SpawnOnPlay) { joint.Initialise(this); } } //Create Particles ParticleSystems = GameObject.FindObjectsOfType <LPParticleSystem>(); for (int i = 0; i < ParticleSystems.Length; i++) { ParticleSystems[i].Initialise(worldPtr, DebugMessages, i); } //Set or Determine recommended number of particle iterations if (OverrideParticleIterations) { m_particleIterations = ParticleIterationsOverride; } else { m_particleIterations = LPAPIParticleSystems.GetParticleIterations(Gravity.magnitude, ParticleSystems[0].ParticleRadius, TimeStep); if (DebugMessages) { Debug.Log("Recommended number of particle iterations is " + m_particleIterations.ToString()); } } } }
/// <summary> /// Sets up the physics world and the bodies, particle systems and joints in it. /// This is called on Awake() so you can implement your code on Start() and the liquidfun stuff will be ready</summary> void Awake() { //Always turn off debug messages in a build (Debug.Log writes to a log file and costs performance) if ( !Application.isEditor && !Debug.isDebugBuild) { DebugMessages = false; } //Check for duplicate LPmanagers if(GameObject.FindObjectsOfType<LPManager>().Length > 1) { Debug.LogError("There is more than one LiquidFunManager in your scene. There can be only one!"); } else { //Create contact listener c# object ContactListener = new LPContactListener(); //Create World worldPtr = LPAPIWorld.CreateWorld(Gravity.x,Gravity.y); if (DebugMessages) Debug.Log("World Created at: 0x" + worldPtr.ToInt64()); //Initialise Contact Listener if (UseContactListener) { ContactListener.Initialise(worldPtr); } //Create bodies LPBody[] bodies = GameObject.FindObjectsOfType<LPBody>(); foreach (LPBody bod in bodies) { if (bod.SpawnOnPlay) { bod.Initialise(this); } } if (DebugMessages) Debug.Log(bodies.Length + " Bodies created"); //Create Joints foreach (LPJoint joint in GameObject.FindObjectsOfType<LPJoint>()) { if (joint.GetType() != typeof(LPJointGear)) { joint.Initialise(this); } } foreach (LPJoint joint in GameObject.FindObjectsOfType<LPJointGear>()) { joint.Initialise(this); } //Create Particles ParticleSystems = GameObject.FindObjectsOfType<LPParticleSystem>(); for (int i = 0; i < ParticleSystems.Length; i++) { ParticleSystems[i].Initialise(worldPtr,DebugMessages,i); } //Set or Determine recommended number of particle iterations if (OverrideParticleIterations) { m_particleIterations = ParticleIterationsOverride; } else { m_particleIterations = LPAPIParticleSystems.GetParticleIterations(Gravity.magnitude,ParticleSystems[0].ParticleRadius,TimeStep); if (DebugMessages) Debug.Log("Recommended number of particle iterations is "+ m_particleIterations.ToString()); } } }