/// <summary> /// -This operation sets the attribute "state" in the Context class. /// </summary> /// <summary> /// -This operation implements the logic for returning the unique instance of the Singleton pattern. /// </summary> public static BehaviourModifier GetUniqueInstance() { if (uniqueInstance == null) { uniqueInstance = new BehaviourModifier(); } return(uniqueInstance); }
private void createMaterialInController() { //set preview item to right controller GameObject prefab = Resources.Load("newBall") as GameObject; if (prefab == null) { Debug.LogError("Prefab not found"); return; } try { GameObject ball = Instantiate(prefab, Menu.getGrabbedObjectHolder().transform); ball.GetComponent <Rigidbody>().isKinematic = true; ball.GetComponent <TxSoftBody>().enabled = false; ball.transform.position = Menu.getGrabbedObjectHolder().transform.position; ball.transform.SetParent(Menu.getGrabbedObjectHolder().transform); //pass needed objects to modifier BehaviourModifier mod = ball.GetComponent <BehaviourModifier>(); if (!SceneManager.GetActiveScene().name.Equals("Phys1")) { mod.IsSoftbody = true; } mod.RightController = gameObject; mod.LeftController = LeftController; mod.sliderHandler = sliderHandler; mod.formulaController = formulaController; mod.grabHandler = gameObject.GetComponent <grabThrowable>(); //modify behaviour based on slider settings mod.initSliderSettings(sliderHandler.getSliderSettings()); mod.updateBehaviour(); this.grabbedGo = ball; } catch (Exception e) { Debug.LogError("Error during creating Ball in controller\n" + e.Message.ToString()); } }
private void OnCollisionEnter(Collision collision) { if (collision.gameObject.tag.Equals("Ball")) { GameObject go = collision.gameObject; BehaviourModifier mod = null; if (mod = go.GetComponent <BehaviourModifier>()) { if (mod.IsSoftbody) { if (double.IsNaN(mod.calcWeight())) { Sign.GetComponent <Text>().text = mod.fakeWeight.ToString(); weight = mod.fakeWeight; } else { Sign.GetComponent <Text>().text = mod.calcWeight().ToString(); weight = (float)mod.calcWeight(); } } } } if (comparator != null) { ScaleDisplay scd = comparator.GetComponent <ScaleDisplay>(); //float delta = scd.weight - this.weight; if (scd.weight == this.weight) { if (!this.IsComparator) { checkAsCorrect(); } } } }
private void UnSnapObject(object sender, ControllerInteractionEventArgs e) { try { BehaviourModifier mod = this.touchingObject.GetComponent <BehaviourModifier>(); if (mod.IsSoftbody) { TxSoftBody softRB = this.touchingObject.GetComponent <TxSoftBody>(); softRB.enabled = true; softRB.ApplyImpulse(formulaController.Direction * throwMultiplyer); } else { Rigidbody rb = this.touchingObject.GetComponent <Rigidbody>(); rb.velocity = formulaController.Direction * throwMultiplyer; } OnReleased(this.touchingObject, transform.position - lastPosition); } catch { Debug.LogWarning("touching object is null"); } this.touchingObject = null; }
public void handlePush(object sender, Control3DEventArgs e) { Transform oldPos = this.position.transform; try { foreach (Transform child in this.position.transform) { Destroy(child.gameObject); } GameObject newSim = Instantiate(Prefab, this.position.transform, false); BehaviourModifier mod = newSim.GetComponent <BehaviourModifier>(); newSim.GetComponent <TxSoftBody>().enabled = false; if (useLocation == true) { newSim.transform.position = Location; } else { this.position.transform.position = oldPos.position; } if (Prefab == null) { Debug.LogError("Prefab not found"); return; } //pass needed objects to modifier if (!SceneManager.GetActiveScene().name.Equals("Phys1")) { mod.IsSoftbody = true; } mod.RightController = RightController; mod.LeftController = LeftController; mod.sliderHandler = LeftController.GetComponent <SliderHandler>(); mod.formulaController = RightController.GetComponent <FormulaController>(); mod.grabHandler = RightController.GetComponent <grabThrowable>(); //modify behaviour based on slider settings float[] settings = new float[5]; settings[0] = 800; settings[1] = 0.01643762f; settings[2] = UnityEngine.Random.value * 50; settings[3] = 1000000; settings[4] = 0.08f; mod.initSliderSettings(settings); mod.fakeWeight = UnityEngine.Random.value * 20; mod.updateBehaviour(); } catch (Exception err) { Debug.LogError("Error restarting sim softbodies \n " + err.Message.ToString() + err.StackTrace.ToString()); } Debug.Log("Hit"); }