Esempio n. 1
0
    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());
        }
    }
Esempio n. 2
0
        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");
        }