void OnSceneGUI()
    {
        myTarget = (ConnectViaDuplication)target;
        if (myTarget.startPoint == Vector3.zero && myTarget.endPoint == Vector3.zero)
        {
            myTarget.startPoint = myTarget.transform.position;
            myTarget.endPoint   = myTarget.transform.position;
            myTarget.startPoint = Handles.PositionHandle(myTarget.transform.position, Quaternion.identity);
            myTarget.endPoint   = Handles.PositionHandle(myTarget.transform.position, Quaternion.identity);
        }
        if (myTarget.connector != null)
        {
            Handles.color       = Color.blue;
            myTarget.startPoint = Handles.PositionHandle(myTarget.startPoint, Quaternion.identity);
            Handles.Disc(Quaternion.identity, myTarget.startPoint, new Vector3(0, 0, 1), 1, false, 1);
            Handles.Label(myTarget.startPoint, "Start Point");
            myTarget.endPoint = Handles.PositionHandle(myTarget.endPoint, Quaternion.identity);
            Handles.Disc(Quaternion.identity, myTarget.endPoint, new Vector3(0, 0, 1), 1, false, 1);
            Handles.Label(myTarget.endPoint, "EndPoint");

            angle = Mathf.Atan(Mathf.Abs((myTarget.endPoint.y - myTarget.startPoint.y) / (myTarget.endPoint.x - myTarget.startPoint.x)));

            if (myTarget.endPoint.x > myTarget.startPoint.x)
            {
                if (myTarget.endPoint.y > myTarget.startPoint.y)
                {
                    //quad 1
                }
                else
                {
                    //quad 4
                    angle = (Mathf.PI) - angle + (Mathf.PI);
                }
            }
            else
            {
                if (myTarget.endPoint.y > myTarget.startPoint.y)
                {
                    //quad 2
                    angle = (Mathf.PI / 2) - angle + (Mathf.PI / 2);
                }
                else
                {
                    //quad 3
                    angle = Mathf.PI + angle;
                }
            }
        }
    }
    void OnSceneGUI() {


        myTarget=(ConnectViaDuplication)target;
        if (myTarget.startPoint==Vector3.zero&&myTarget.endPoint==Vector3.zero) {
            myTarget.startPoint=myTarget.transform.position;
            myTarget.endPoint=myTarget.transform.position;
            myTarget.startPoint=Handles.PositionHandle(myTarget.transform.position, Quaternion.identity);
            myTarget.endPoint=Handles.PositionHandle(myTarget.transform.position, Quaternion.identity);
        }
        if (myTarget.connector!=null) {



            Handles.color=Color.blue;
            myTarget.startPoint=Handles.PositionHandle(myTarget.startPoint, Quaternion.identity);
            Handles.Disc(Quaternion.identity, myTarget.startPoint, new Vector3(0, 0, 1), 1, false, 1);
            Handles.Label(myTarget.startPoint, "Start Point");
            myTarget.endPoint=Handles.PositionHandle(myTarget.endPoint, Quaternion.identity);
            Handles.Disc(Quaternion.identity, myTarget.endPoint, new Vector3(0, 0, 1), 1, false, 1);
            Handles.Label(myTarget.endPoint, "EndPoint");

            angle=Mathf.Atan(Mathf.Abs((myTarget.endPoint.y-myTarget.startPoint.y)/(myTarget.endPoint.x-myTarget.startPoint.x)));

            if (myTarget.endPoint.x>myTarget.startPoint.x) {
                if (myTarget.endPoint.y>myTarget.startPoint.y) {
                    //quad 1
                }
                else {
                    //quad 4
                    angle=(Mathf.PI)-angle+(Mathf.PI);
                }
            }
            else {
                if (myTarget.endPoint.y>myTarget.startPoint.y) {
                    //quad 2
                    angle=(Mathf.PI/2)-angle+(Mathf.PI/2);
                }
                else {
                    //quad 3
                    angle=Mathf.PI+angle;

                }
            }

        }


    }
 void Start()
 {
     myTarget = (ConnectViaDuplication)target;
     createPool();
     Debug.Log("STARTED");
 }
    public override void OnInspectorGUI()
    {
        myTarget = (ConnectViaDuplication)target;

        bool changed = false;

        if (oldAngle != angle)
        {
            changed  = true;
            oldAngle = angle;
        }
        ConnectViaDuplication.mode old = myTarget.modeChoice;
        myTarget.modeChoice = (ConnectViaDuplication.mode)EditorGUILayout.EnumPopup("Mode of creation: ", myTarget.modeChoice);
        if (myTarget.modeChoice != old)
        {
            changed = true;
        }
        if (myTarget.modeChoice == ConnectViaDuplication.mode.chooseSpacing)
        {
            myTarget.fillChoice = (ConnectViaDuplication.fillOption)EditorGUILayout.EnumPopup("Mode of creation: ", myTarget.fillChoice);
        }

        int oldNum = myTarget.number;

        EditorGUILayout.Space();
        EditorGUILayout.Space();
        myTarget.connector = (GameObject)EditorGUILayout.ObjectField("Connector", myTarget.connector, typeof(GameObject), true);
        float origScale = myTarget.objScale;

        myTarget.objScale = Mathf.Abs(EditorGUILayout.FloatField("Scale: ", myTarget.objScale));
        if (myTarget.objScale != origScale)
        {
            Debug.Log("TRUE");
            changed = true;
        }
        float spacing = myTarget.spacing;

        myTarget.spacing = Mathf.Abs(EditorGUILayout.FloatField("Spacing: ", myTarget.spacing));
        if (spacing != myTarget.spacing)
        {
            changed = true;
        }
        if (myTarget.modeChoice == ConnectViaDuplication.mode.chooseNumber)
        {
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            myTarget.number = EditorGUILayout.IntField("Number of objects: ", myTarget.number);
            if (myTarget.number > 10)
            {
                myTarget.number = EditorGUILayout.IntSlider("Number of objects: ", myTarget.number, myTarget.number - 10, myTarget.number + 10);
            }
            else
            {
                myTarget.number = EditorGUILayout.IntSlider("Number of objects: ", myTarget.number, 0, myTarget.number + 10);
            }
        }
        if (oldNum != myTarget.number)
        {
            createPool();
            changed = true;
        }
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        myTarget.delChildren = EditorGUILayout.Toggle("Delete Children: ", myTarget.delChildren);
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        myTarget.hingeJointSetup = EditorGUILayout.Toggle("Set up hinge joints: ", myTarget.hingeJointSetup);
        if (myTarget.hingeJointSetup)
        {
            myTarget.collideWithConnected = EditorGUILayout.Toggle("Collide with hinge: ", myTarget.collideWithConnected);
            if (myTarget.connector.GetComponent <DistanceJoint2D>())
            {
                myTarget.jointDist = EditorGUILayout.FloatField("Distance: ", myTarget.jointDist);
                if (myTarget.jointDist < 0)
                {
                    myTarget.jointDist = 0;
                }
            }
            if (myTarget.connector.GetComponent <SpringJoint2D>())
            {
                myTarget.jointDist    = EditorGUILayout.FloatField("Distance: ", myTarget.jointDist);
                myTarget.dampingRatio = EditorGUILayout.FloatField("Damping: ", myTarget.dampingRatio);
                myTarget.frequency    = EditorGUILayout.FloatField("Frequency: ", myTarget.frequency);
                if (myTarget.dampingRatio > 1)
                {
                    myTarget.dampingRatio = 1;
                }
                if (myTarget.dampingRatio < 0)
                {
                    myTarget.dampingRatio = 0;
                }
                if (myTarget.jointDist < 0)
                {
                    myTarget.jointDist = 0;
                }
                if (myTarget.frequency < 0)
                {
                    myTarget.frequency = 0;
                }
            }
            if (GUILayout.Button("Refresh hinges"))
            {
                setupHinges();
            }
        }
        myTarget.fixedEnds = EditorGUILayout.Toggle("Fix ends: ", myTarget.fixedEnds);
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        myTarget.startPoint = EditorGUILayout.Vector2Field("Start Point:", myTarget.startPoint);
        myTarget.endPoint   = EditorGUILayout.Vector2Field("End Point: ", myTarget.endPoint);
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        autoUpdate = EditorGUILayout.Toggle("Automatically refresh: ", autoUpdate);
        if (autoUpdate)
        {
            if (changed)
            {
                refresh();
            }
        }
        else
        {
            if (GUILayout.Button("Refresh"))
            {
                refresh();
                createPool();
            }
        }

        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Angle: " + angle * 180 / Mathf.PI);
        if (myTarget.modeChoice == ConnectViaDuplication.mode.chooseSpacing)
        {
            EditorGUILayout.LabelField("Number: " + myTarget.number);
        }
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        startAmount = EditorGUILayout.IntField("Objects in Pool ", startAmount);
        if (GUILayout.Button("Update Pool"))
        {
            createPool();
        }
        if (oldPos != myTarget.transform.position)
        {
            Vector3 change = myTarget.transform.position - oldPos;
            myTarget.endPoint   += change;
            myTarget.startPoint += change;
            oldPos = myTarget.transform.position;
        }
    }
 void Start() {
     myTarget=(ConnectViaDuplication)target;
     createPool();
     Debug.Log("STARTED");
 }
    public override void OnInspectorGUI() {
        myTarget=(ConnectViaDuplication)target;

        bool changed=false;
        if (oldAngle!=angle) {
            changed=true;
            oldAngle=angle;
        }
        ConnectViaDuplication.mode old=myTarget.modeChoice;
        myTarget.modeChoice=(ConnectViaDuplication.mode)EditorGUILayout.EnumPopup("Mode of creation: ", myTarget.modeChoice);
        if (myTarget.modeChoice!=old) {
            changed=true;
        }
        if (myTarget.modeChoice==ConnectViaDuplication.mode.chooseSpacing) {
            myTarget.fillChoice=(ConnectViaDuplication.fillOption)EditorGUILayout.EnumPopup("Mode of creation: ", myTarget.fillChoice);
        }

        int oldNum=myTarget.number;

        EditorGUILayout.Space();
        EditorGUILayout.Space();
        myTarget.connector=(GameObject)EditorGUILayout.ObjectField("Connector", myTarget.connector, typeof(GameObject), true);
        float origScale=myTarget.objScale;
        myTarget.objScale=Mathf.Abs(EditorGUILayout.FloatField("Scale: ", myTarget.objScale));
        if (myTarget.objScale!=origScale) {
            Debug.Log("TRUE");
            changed=true;
        }
        float spacing=myTarget.spacing;
        myTarget.spacing=Mathf.Abs(EditorGUILayout.FloatField("Spacing: ", myTarget.spacing));
        if (spacing!=myTarget.spacing) {
            changed=true;
        }
        if (myTarget.modeChoice==ConnectViaDuplication.mode.chooseNumber) {
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            myTarget.number=EditorGUILayout.IntField("Number of objects: ", myTarget.number);
            if (myTarget.number>10) {
                myTarget.number=EditorGUILayout.IntSlider("Number of objects: ", myTarget.number, myTarget.number-10, myTarget.number+10);
            }
            else {
                myTarget.number=EditorGUILayout.IntSlider("Number of objects: ", myTarget.number, 0, myTarget.number+10);
            }
        }
        if (oldNum!=myTarget.number) {
            createPool();
            changed=true;
        }
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        myTarget.delChildren=EditorGUILayout.Toggle("Delete Children: ", myTarget.delChildren);
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        myTarget.hingeJointSetup=EditorGUILayout.Toggle("Set up hinge joints: ", myTarget.hingeJointSetup);
        if (myTarget.hingeJointSetup) {
            myTarget.collideWithConnected=EditorGUILayout.Toggle("Collide with hinge: ", myTarget.collideWithConnected);
            if (myTarget.connector.GetComponent<DistanceJoint2D>()) {
                myTarget.jointDist=EditorGUILayout.FloatField("Distance: ", myTarget.jointDist);
                if (myTarget.jointDist<0) {
                    myTarget.jointDist=0;
                }
            }
            if (myTarget.connector.GetComponent<SpringJoint2D>()) {
                myTarget.jointDist=EditorGUILayout.FloatField("Distance: ", myTarget.jointDist);
                myTarget.dampingRatio=EditorGUILayout.FloatField("Damping: ", myTarget.dampingRatio);
                myTarget.frequency=EditorGUILayout.FloatField("Frequency: ", myTarget.frequency);
                if (myTarget.dampingRatio>1) {
                    myTarget.dampingRatio=1;
                }
                if (myTarget.dampingRatio<0) {
                    myTarget.dampingRatio=0;
                }
                if (myTarget.jointDist<0) {
                    myTarget.jointDist=0;
                }
                if(myTarget.frequency<0){
                    myTarget.frequency=0;
                }
            }
            if (GUILayout.Button("Refresh hinges")) {
                setupHinges();
            }
        }
        myTarget.fixedEnds=EditorGUILayout.Toggle("Fix ends: ", myTarget.fixedEnds);
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        myTarget.startPoint=EditorGUILayout.Vector2Field("Start Point:", myTarget.startPoint);
        myTarget.endPoint=EditorGUILayout.Vector2Field("End Point: ", myTarget.endPoint);
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        autoUpdate=EditorGUILayout.Toggle("Automatically refresh: ", autoUpdate);
        if (autoUpdate) {
            if (changed)
                refresh();
        }
        else {
            if (GUILayout.Button("Refresh")) {
                refresh();
                createPool();
            }



        }

        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Angle: "+angle*180/Mathf.PI);
        if (myTarget.modeChoice==ConnectViaDuplication.mode.chooseSpacing) {
            EditorGUILayout.LabelField("Number: "+myTarget.number);
        }
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        startAmount=EditorGUILayout.IntField("Objects in Pool ", startAmount);
        if (GUILayout.Button("Update Pool")) {

            createPool();
        }
        if (oldPos!=myTarget.transform.position) {
            Vector3 change=myTarget.transform.position-oldPos;
            myTarget.endPoint+=change;
            myTarget.startPoint+=change;
            oldPos=myTarget.transform.position;
        }
    }