コード例 #1
0
    // Use this for initialization
    void Start()
    {
        var mat = new Material(Shader.Find("Particles/Alpha Blended"));

        mat.SetColor("_TintColor", new Color32(0xFF, 0x00, 0x00, 0x22));
        Camera.main.transform.position = new Vector3(0.04f, -0.057f, -0.14f);
        Camera.main.nearClipPlane      = 0.0001f;
        _cam = Camera.main;
        _cam.transform.position         = new Vector3(0, 0.223f, -0.096f) * RopeLength * 10;
        _cam.transform.localEulerAngles = new Vector3(30.2f, 0, 0);
        Destroy(GameObject.Find("Directional Light").GetComponent <Light>());
        // 设置
        var rope = new GameObject("TestRope");

        rope.transform.position = Vector3.up * RopeLength * 1.2f;
        var ctrl = rope.AddComponent <ControllableRope>();

        ctrl.TightenAmend = true;
        ctrl.Width        = RopeWidth;
        ctrl.Length       = RopeLength;
        ctrl.Segment      = Seg;
        ctrl.GenAxis      = Vector3.left;
        ctrl.Mass         = RopeMass;
        ctrl.AngularDrag  = 10;
        ctrl.IterCount    = 255;
        ctrl.RenderScale  = RopeRenderScale;
        ctrl.SetRenderInterplate(true, RenderInterplateCount);
        ctrl.Mat = mat;
        ctrl.Recalc();
        ctrl.ManualHead(true, false);
        ctrl.ManualTail(true, false);
        _rope = ctrl;
    }
コード例 #2
0
    private void Start()
    {
        Debug.Log("操作说明:鼠标左键拖动来拉动绳子,tab键切换拉动绳子哪一端,1键切换绳首是否挂物体,2键切换绳尾是否挂物体");
        var mat = new Material(Shader.Find("Particles/Alpha Blended"));

        mat.SetColor("_TintColor", new Color32(0xFF, 0x00, 0x00, 0x22));
        _cam = Camera.main;
        _cam.nearClipPlane              = 0.0001f;
        _cam.fieldOfView                = 30;
        _cam.transform.position         = new Vector3(0, 0.223f, -0.35f) * RopeLength * 10;
        _cam.transform.localEulerAngles = new Vector3(30.2f, 0, 0);
        Destroy(GameObject.Find("Directional Light").GetComponent <Light>());
        // 设置
        var rope = new GameObject("TestRope");

        rope.transform.position = Vector3.up * RopeLength * 1.2f;
        var ctrl = rope.AddComponent <ControllableRope>();

        ctrl.Width       = 0.05f * RopeLength;
        ctrl.Length      = RopeLength;
        ctrl.Segment     = 12;
        ctrl.GenAxis     = Vector3.up * -1; // 竖直向下创建
        ctrl.Mass        = RopeMass;
        ctrl.AngularDrag = 10;
        ctrl.IterCount   = 255;
        ctrl.RenderScale = 0.5f;
        ctrl.Mat         = mat;
        ctrl.Recalc();
        ctrl.Auto();
        _rope = ctrl;
        // 创建地面
        var floor = GameObject.CreatePrimitive(PrimitiveType.Plane);

        floor.transform.position         = Vector3.zero;
        floor.transform.localEulerAngles = Vector3.zero;
        _floorLayerMask = 1 << 6;
        floor.layer     = 6;
        // 创建挂接物
        _obj1 = GameObject.CreatePrimitive(PrimitiveType.Cube);
        var rig1 = _obj1.AddComponent <Rigidbody>();

        rig1.freezeRotation = true;
        _obj1.GetComponent <Renderer>().material.color = Color.red;
        _obj1.transform.position   = Vector3.zero;
        _obj1.transform.localScale = Vector3.one * 0.01f;

        _obj2 = GameObject.CreatePrimitive(PrimitiveType.Cube);
        var rig2 = _obj2.AddComponent <Rigidbody>();

        rig2.freezeRotation = true;
        _obj2.GetComponent <Renderer>().material.color = Color.blue;
        _obj2.transform.position   = Vector3.left * 0.05f;
        _obj2.transform.localScale = Vector3.one * 0.01f;

        _rope.HangHead(_obj1.GetComponent <Rigidbody>());
        _rope.HangTail(_obj2.GetComponent <Rigidbody>());
    }
コード例 #3
0
    // Use this for initialization
    void Start()
    {
        Debug.Log("操作说明:鼠标左键拖动来拉动绳子,tab键切换拉动绳子哪一端");
        var mat = new Material(Shader.Find("Particles/Alpha Blended"));

        mat.SetColor("_TintColor", new Color32(0xFF, 0x00, 0x00, 0x22));
        Camera.main.transform.position = new Vector3(0.04f, -0.057f, -0.14f);
        Camera.main.nearClipPlane      = 0.0001f;
        _cam = Camera.main;
        _cam.transform.position         = new Vector3(0, 0.223f, -0.096f) * RopeLength * 10;
        _cam.transform.localEulerAngles = new Vector3(30.2f, 0, 0);
        Destroy(GameObject.Find("Directional Light").GetComponent <Light>());
        // 设置
        var rope = new GameObject("TestRope");

        rope.transform.position = Vector3.up * RopeLength * 1.2f;
        var ctrl = rope.AddComponent <ControllableRope>();

        ctrl.Width       = 0.05f * RopeLength;
        ctrl.Length      = RopeLength;
        ctrl.Segment     = 12;
        ctrl.GenAxis     = Vector3.up * -1; // 竖直向下创建
        ctrl.Mass        = RopeMass;
        ctrl.AngularDrag = 10;
        ctrl.IterCount   = 255;
        ctrl.RenderScale = 0.5f;
        ctrl.Mat         = mat;
        ctrl.Recalc();
        ctrl.ManualHead(true);
        _rope = ctrl;
        // 创建地面
        var floor = GameObject.CreatePrimitive(PrimitiveType.Plane);

        floor.transform.position         = Vector3.zero;
        floor.transform.localEulerAngles = Vector3.zero;
        _floorLayerMask = 1 << 6;
        floor.layer     = 6;
    }