Пример #1
0
    public static QuickRope2 Create(GameObject pointA, GameObject pointB, List <Vector3> curvePoints, BasicRopeTypes ropeType)
    {
        QuickRope2 qr = pointA.AddComponent <QuickRope2>();

        qr.ropeEnd = pointB;

        switch (ropeType)
        {
        case BasicRopeTypes.NONE:
            break;

        case BasicRopeTypes.Line:
            qr.gameObject.AddComponent <QuickRope2Line>();
            break;

        case BasicRopeTypes.Prefab:
            qr.gameObject.AddComponent <QuickRope2Prefab>();
            break;

        case BasicRopeTypes.Mesh:
            qr.gameObject.AddComponent <QuickRope2Mesh>();
            break;

        case BasicRopeTypes.Cloth:
            qr.gameObject.AddComponent <QuickRope2Cloth>();
            break;
        }

        qr.ApplyRopeSettings();

        return(qr);
    }
Пример #2
0
    static void AddBasicLineRope()
    {
        QuickRope2 r = QuickRope2.Create(new Vector3(-5, 0, 0), new Vector3(5, 0, 0), BasicRopeTypes.Line);

        r.gameObject.name          = "Line_Rope_Start";
        r.ropeEnd.name             = "Line_Rope_End";
        Selection.activeGameObject = r.gameObject;
    }
Пример #3
0
    void OnEnable()
    {
        rope = GetComponent<QuickRope2>();

        if (prefab == null)
            prefab = (GameObject)Resources.Load("Link", typeof(GameObject));

        rope.OnInitializeMesh += OnInitializeMesh;
    }
Пример #4
0
    void Start()
    {
        rope = QuickRope2.Create(Vector3.zero, new Vector3(0, -10, 0), BasicRopeTypes.Mesh);
        rope.enablePhysics        = true;
        rope.enableRopeController = true;
        rope.ApplyRopeSettings();

        rope.rigidbody.isKinematic = true;
    }
    void Start()
    {
        rope = QuickRope2.Create(Vector3.zero, new Vector3(0, -10, 0), BasicRopeTypes.Mesh);
        rope.enablePhysics = true;
        rope.enableRopeController = true;
        rope.ApplyRopeSettings();

        rope.rigidbody.isKinematic = true;
    }
Пример #6
0
    void OnEnable()
    {
        rope = GetComponent <QuickRope2>();

        if (prefab == null)
        {
            prefab = (GameObject)Resources.Load("Link", typeof(GameObject));
        }

        rope.OnInitializeMesh += OnInitializeMesh;
    }
Пример #7
0
    void OnEnable()
    {
        r = (QuickRope2)target;

        if (Application.isPlaying)
        {
            return;
        }

        CleanupObject();
        r.ApplyRopeSettings(); //r.SetControlPoints(r.ControlPoints);
    }
Пример #8
0
    void OnEnable()
    {
        rope = GetComponent<QuickRope2>();

        if (gameObject.GetComponent<LineRenderer>() == null)
            line = gameObject.AddComponent<LineRenderer>();
        else
            line = gameObject.GetComponent<LineRenderer>();

        if (line.sharedMaterial == null)
            line.sharedMaterial = (Material)Resources.Load("Materials/RopeLineMaterial", typeof(Material));

        rope.OnInitializeMesh += OnInitializeMesh;
    }
Пример #9
0
    void OnEnable()
    {
        rope = GetComponent <QuickRope2>();

        if (gameObject.GetComponent <LineRenderer>() == null)
        {
            line = gameObject.AddComponent <LineRenderer>();
        }
        else
        {
            line = gameObject.GetComponent <LineRenderer>();
        }

        if (line.sharedMaterial == null)
        {
            line.sharedMaterial = (Material)Resources.Load("Materials/RopeLineMaterial", typeof(Material));
        }

        rope.OnInitializeMesh += OnInitializeMesh;
    }
Пример #10
0
    static void CleanupObject()
    {
        QuickRope2 r = Selection.activeGameObject.GetComponent <QuickRope2>();

        if (r.GetComponent <QuickRope2Line>())
        {
            DestroyImmediate(r.GetComponent <QuickRope2Line>());
        }

        if (r.GetComponent <QuickRope2Mesh>())
        {
            DestroyImmediate(r.GetComponent <QuickRope2Mesh>());
        }

        if (r.GetComponent <QuickRope2Cloth>())
        {
            DestroyImmediate(r.GetComponent <QuickRope2Cloth>());
        }

        if (r.GetComponent <QuickRope2Prefab>())
        {
            DestroyImmediate(r.GetComponent <QuickRope2Prefab>());
        }
    }
Пример #11
0
    void OnSceneGUI()
    {
        r = (QuickRope2)target;
        if (Application.isPlaying || r.ropeEnd == null)
        {
            return;
        }

        if (EditorApplication.isCompiling)
        {
            rebuildAfterCompile = true;
        }
        else if (rebuildAfterCompile)
        {
            rebuildAfterCompile = false;
            UpdateRope();
            //return;
        }

        Quaternion camLookAt = SceneView.currentDrawingSceneView.camera.transform.rotation;
        Vector3    camNormal = SceneView.currentDrawingSceneView.camera.transform.forward;


        //==============  Add Control Point Button ==================

        if (r.ControlPoints.Count == 0 && PlusButton(r.transform.position + (r.ropeEnd.transform.position - r.transform.position) / 2, camLookAt))
        {
            r.ControlPoints.Add(r.transform.position + (r.ropeEnd.transform.position - r.transform.position) / 2);
        }

        if (r.ControlPoints.Count > 0)
        {
            // First Add Button
            if (PlusButton(r.transform.position + (r.ControlPoints[0] - r.transform.position) / 2, camLookAt))
            {
                r.ControlPoints.Insert(0, r.transform.position + (r.ControlPoints[0] - r.transform.position) / 2);
                currentActiveHandle = 0;
            }

            // Last Add Button
            if (PlusButton(r.ControlPoints[r.ControlPoints.Count - 1] + (r.ropeEnd.transform.position - r.ControlPoints[r.ControlPoints.Count - 1]) / 2, camLookAt))
            {
                r.ControlPoints.Insert(r.ControlPoints.Count, r.ControlPoints[r.ControlPoints.Count - 1] + (r.ropeEnd.transform.position - r.ControlPoints[r.ControlPoints.Count - 1]) / 2);
                currentActiveHandle = r.ControlPoints.Count - 1;
            }

            for (int i = 0; i < r.ControlPoints.Count - 1; i++)
            {
                Vector3 btnPos = r.ControlPoints[i] + ((r.ControlPoints[i + 1] - r.ControlPoints[i]) / 2);

                if (PlusButton(btnPos, camLookAt))
                {
                    r.ControlPoints.Insert(i + 1, btnPos);
                    currentActiveHandle = i + 1;
                }
            }
        }

        // ==================
        if (r.ControlPoints == null)
        {
            UpdateRope();
            return;
        }

        // =================
        for (int i = 0; i < r.ControlPoints.Count; i++)
        {
            Handles.color = new Color(0, 0, 0, 1);
            if (Handles.Button(r.ControlPoints[i], camLookAt, 0.5f * guiScale, 0.5f * guiScale, Handles.CircleCap))
            {
                currentActiveHandle = i;
            }

            if (i == currentActiveHandle)
            {
                Handles.color = new Color(0.3f, 0.3f, 0.8f);
                Handles.DrawSolidDisc(r.ControlPoints[i], camNormal, 0.4f * guiScale);

                Handles.color      = Color.white;
                r.ControlPoints[i] = Handles.PositionHandle(r.ControlPoints[i], Quaternion.identity);

                if (Event.current.type == EventType.keyDown)
                {
                    if (Event.current.keyCode == KeyCode.P)
                    {
                        if (i > 0 && i < r.ControlPoints.Count - 2)
                        {
                            r.ControlPoints.Insert(i + 1, r.ControlPoints[i] + ((r.ControlPoints[i + 1] - r.ControlPoints[i]) / 2));
                        }
                        //UpdateRope();
                    }

                    if (Event.current.keyCode == KeyCode.Backspace)
                    {
                        r.ControlPoints.RemoveAt(currentActiveHandle);

                        currentActiveHandle--;
                        if (currentActiveHandle == -1 && r.ControlPoints.Count != 0)
                        {
                            currentActiveHandle = 0;
                        }

                        r.ControlPoints.TrimExcess();
                        UpdateRope();
                        return;
                    }
                }
            }
            else
            {
                Handles.color = new Color(0.2f, 0.2f, 0.4f, 0.8f);
                Handles.DrawSolidDisc(r.ControlPoints[i], camNormal, 0.4f * guiScale);
            }
        }

        //Deal with rope end
        {
            Handles.color = new Color(0, 0, 0, 1);
            if (Handles.Button(r.ropeEnd.transform.position, camLookAt, 0.5f * guiScale, 0.5f * guiScale, Handles.CircleCap))
            {
                currentActiveHandle = 5000;
            }

            if (currentActiveHandle == 5000)

            {
                Handles.color = new Color(0.3f, 0.3f, 0.8f);
                Handles.DrawSolidDisc(r.ropeEnd.transform.position, camNormal, 0.4f * guiScale);

                Handles.color = Color.white;
                r.ropeEnd.transform.position = Handles.PositionHandle(r.ropeEnd.transform.position, Quaternion.identity);
            }
            else
            {
                Handles.color = new Color(0.2f, 0.2f, 0.4f, 0.8f);
                Handles.DrawSolidDisc(r.ropeEnd.transform.position, camNormal, 0.4f * guiScale);
            }
        }

        foreach (RopeAttachedObject ao in r.attachedObjects)
        {
            if (ao.go == null)
            {
                continue;
            }

            if (ao.jointIndex > r.Joints.Count - 1)
            {
                ao.jointIndex = r.Joints.Count - 1;
            }

            Handles.color = new Color(0.8f, 0.4f, 0f, 0.8f);
            Handles.DrawSolidDisc(ao.go.transform.position, camNormal, 0.2f * guiScale);
            Handles.DrawSolidDisc(r.Joints[ao.jointIndex].transform.position, camNormal, 0.2f * guiScale);

            float dist = Vector3.Distance(r.Joints[ao.jointIndex].transform.position, ao.go.transform.position);

            if (dist > 0.5f)
            {
                Handles.ArrowCap(0, ao.go.transform.position, Quaternion.LookRotation((r.Joints[ao.jointIndex].transform.position - ao.go.transform.position).normalized), dist * 0.8f);
            }

            Handles.color = new Color(0.8f, 0f, 0f, 0.8f);
            if (ao.jointType == RopeAttachmentJointType.Hinge && (ao.hingeAxis != Vector3.zero))
            {
                Handles.ArrowCap(0, ao.go.transform.position, ao.go.transform.rotation * Quaternion.LookRotation(ao.hingeAxis), 1);
            }
        }

        winRect = GUI.Window(0, winRect, EditWindowFunc, "Edit Selected Control Point");

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
            UpdateRope();
        }
        else if (QuickRope2Helper.HasMoved(ref prevRopePos, r.transform.position))
        {
            UpdateRope();
        }
    }
Пример #12
0
 void OnEnable()
 {
     rope = GetComponent<QuickRope2>();
     rope.OnInitializeMesh += OnInitializeMesh;
 }
Пример #13
0
 void OnEnable()
 {
     rope = GetComponent <QuickRope2>();
     rope.OnInitializeMesh += OnInitializeMesh;
 }
Пример #14
0
    void OnSceneGUI()
    {
        r = (QuickRope2)target;
        if (Application.isPlaying || r.ropeEnd == null)
            return;

        if (EditorApplication.isCompiling)
        {
            rebuildAfterCompile = true;
        }
        else if (rebuildAfterCompile)
        {
            rebuildAfterCompile = false;
            UpdateRope();
            //return;
        }

        Quaternion camLookAt = SceneView.currentDrawingSceneView.camera.transform.rotation;
        Vector3 camNormal = SceneView.currentDrawingSceneView.camera.transform.forward;

        //==============  Add Control Point Button ==================

        if (r.ControlPoints.Count == 0 && PlusButton(r.transform.position + (r.ropeEnd.transform.position - r.transform.position) / 2, camLookAt))
        {
            r.ControlPoints.Add(r.transform.position + (r.ropeEnd.transform.position - r.transform.position) / 2);
        }

        if(r.ControlPoints.Count > 0)
        {
            // First Add Button
            if (PlusButton(r.transform.position + (r.ControlPoints[0] - r.transform.position)/2, camLookAt))
            {
                r.ControlPoints.Insert(0, r.transform.position + (r.ControlPoints[0] - r.transform.position) / 2);
                currentActiveHandle = 0;
            }

            // Last Add Button
            if (PlusButton(r.ControlPoints[r.ControlPoints.Count - 1] + (r.ropeEnd.transform.position - r.ControlPoints[r.ControlPoints.Count-1])/2, camLookAt))
            {
                r.ControlPoints.Insert(r.ControlPoints.Count, r.ControlPoints[r.ControlPoints.Count - 1] + (r.ropeEnd.transform.position - r.ControlPoints[r.ControlPoints.Count - 1]) / 2);
                currentActiveHandle = r.ControlPoints.Count - 1;
            }

            for (int i = 0; i < r.ControlPoints.Count - 1; i++)
            {
                Vector3 btnPos = r.ControlPoints[i] + ((r.ControlPoints[i + 1] - r.ControlPoints[i]) / 2);

                if (PlusButton(btnPos, camLookAt))
                {
                    r.ControlPoints.Insert(i + 1, btnPos);
                    currentActiveHandle = i + 1;
                }
            }
        }

        // ==================
        if (r.ControlPoints == null)
        {
            UpdateRope();
            return;
        }

        // =================
        for (int i = 0; i < r.ControlPoints.Count; i++)
        {
            Handles.color = new Color(0, 0, 0, 1);
            if (Handles.Button(r.ControlPoints[i], camLookAt, 0.5f * guiScale, 0.5f * guiScale, Handles.CircleCap))
                currentActiveHandle = i;

            if (i == currentActiveHandle)
            {
                Handles.color = new Color(0.3f, 0.3f, 0.8f);
                Handles.DrawSolidDisc(r.ControlPoints[i], camNormal, 0.4f * guiScale);

                Handles.color = Color.white;
                r.ControlPoints[i] = Handles.PositionHandle(r.ControlPoints[i], Quaternion.identity);

                if (Event.current.type == EventType.keyDown)
                {
                    if (Event.current.keyCode == KeyCode.P)
                    {
                        if (i > 0 && i < r.ControlPoints.Count - 2)
                            r.ControlPoints.Insert(i + 1, r.ControlPoints[i] + ((r.ControlPoints[i + 1] - r.ControlPoints[i]) / 2));
                        //UpdateRope();
                    }

                    if (Event.current.keyCode == KeyCode.Backspace)
                    {
                        r.ControlPoints.RemoveAt(currentActiveHandle);

                        currentActiveHandle--;
                        if (currentActiveHandle == -1 && r.ControlPoints.Count != 0)
                            currentActiveHandle = 0;

                        r.ControlPoints.TrimExcess();
                        UpdateRope();
                        return;
                    }
                }
            }
            else
            {
                Handles.color = new Color(0.2f, 0.2f, 0.4f, 0.8f);
                Handles.DrawSolidDisc(r.ControlPoints[i], camNormal, 0.4f * guiScale);
            }
        }

        //Deal with rope end
        {
            Handles.color = new Color(0, 0, 0, 1);
            if (Handles.Button(r.ropeEnd.transform.position, camLookAt, 0.5f * guiScale, 0.5f * guiScale, Handles.CircleCap))
                currentActiveHandle = 5000;

            if (currentActiveHandle == 5000)

            {
                Handles.color = new Color(0.3f, 0.3f, 0.8f);
                Handles.DrawSolidDisc(r.ropeEnd.transform.position, camNormal, 0.4f * guiScale);

                Handles.color = Color.white;
                r.ropeEnd.transform.position = Handles.PositionHandle(r.ropeEnd.transform.position, Quaternion.identity);
            }
            else
            {
                Handles.color = new Color(0.2f, 0.2f, 0.4f, 0.8f);
                Handles.DrawSolidDisc(r.ropeEnd.transform.position, camNormal, 0.4f * guiScale);
            }
        }

        foreach (RopeAttachedObject ao in r.attachedObjects)
        {
            if (ao.go == null)
                continue;

            if (ao.jointIndex > r.Joints.Count - 1)
                ao.jointIndex = r.Joints.Count - 1;

            Handles.color = new Color(0.8f, 0.4f, 0f, 0.8f);
            Handles.DrawSolidDisc(ao.go.transform.position, camNormal, 0.2f * guiScale);
            Handles.DrawSolidDisc(r.Joints[ao.jointIndex].transform.position, camNormal, 0.2f * guiScale);

            float dist = Vector3.Distance(r.Joints[ao.jointIndex].transform.position, ao.go.transform.position);

            if (dist > 0.5f)
                Handles.ArrowCap(0, ao.go.transform.position, Quaternion.LookRotation((r.Joints[ao.jointIndex].transform.position - ao.go.transform.position).normalized), dist * 0.8f);

            Handles.color = new Color(0.8f, 0f, 0f, 0.8f);
            if (ao.jointType == RopeAttachmentJointType.Hinge && (ao.hingeAxis != Vector3.zero))
                Handles.ArrowCap(0, ao.go.transform.position, ao.go.transform.rotation * Quaternion.LookRotation(ao.hingeAxis), 1);
        }

        winRect = GUI.Window(0, winRect, EditWindowFunc, "Edit Selected Control Point");

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
            UpdateRope();
        }
        else if (QuickRope2Helper.HasMoved(ref prevRopePos, r.transform.position))
            UpdateRope();
    }
Пример #15
0
    void OnEnable()
    {
        r = (QuickRope2)target;

        if (Application.isPlaying)
            return;

        CleanupObject();
        r.ApplyRopeSettings(); //r.SetControlPoints(r.ControlPoints);
    }