Parent class for all joints that have anchor points.

Inheritance: Joint2D
示例#1
0
 static public int get_connectedAnchor(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.AnchoredJoint2D self = (UnityEngine.AnchoredJoint2D)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.connectedAnchor);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
 public void OnSceneGUI()
 {
   this.anchorJoint2D = (AnchoredJoint2D) this.target;
   if (!this.anchorJoint2D.enabled)
     return;
   Vector3 position1 = Joint2DEditor.TransformPoint(this.anchorJoint2D.transform, (Vector3) this.anchorJoint2D.anchor);
   Vector3 position2 = (Vector3) this.anchorJoint2D.connectedAnchor;
   if ((bool) ((Object) this.anchorJoint2D.connectedBody))
     position2 = Joint2DEditor.TransformPoint(this.anchorJoint2D.connectedBody.transform, position2);
   Vector3 vector3 = position1 + (position2 - position1).normalized * HandleUtility.GetHandleSize(position1) * 0.1f;
   Handles.color = Color.green;
   Handles.DrawAAPolyLine(new Vector3[2]
   {
     vector3,
     position2
   });
   if (this.HandleAnchor(ref position2, true))
   {
     position2 = this.SnapToSprites(position2);
     position2 = Joint2DEditor.SnapToPoint(position2, position1, 0.13f);
     if ((bool) ((Object) this.anchorJoint2D.connectedBody))
       position2 = Joint2DEditor.InverseTransformPoint(this.anchorJoint2D.connectedBody.transform, position2);
     Undo.RecordObject((Object) this.anchorJoint2D, "Move Connected Anchor");
     this.anchorJoint2D.connectedAnchor = (Vector2) position2;
   }
   if (!this.HandleAnchor(ref position1, false))
     return;
   Vector3 point = Joint2DEditor.SnapToPoint(this.SnapToSprites(position1), position2, 0.13f);
   Undo.RecordObject((Object) this.anchorJoint2D, "Move Anchor");
   this.anchorJoint2D.anchor = (Vector2) Joint2DEditor.InverseTransformPoint(this.anchorJoint2D.transform, point);
 }
示例#3
0
        /// <summary>
        /// Read the data into the specified value.
        /// </summary>
        /// <param name="value">Value.</param>
        /// <param name="reader">Reader.</param>
        public override void ReadInto(object value, ISaveGameReader reader)
        {
            UnityEngine.AnchoredJoint2D anchoredJoint2D = (UnityEngine.AnchoredJoint2D)value;
            foreach (string property in reader.Properties)
            {
                switch (property)
                {
                case "anchor":
                    anchoredJoint2D.anchor = reader.ReadProperty <UnityEngine.Vector2> ();
                    break;

                case "connectedAnchor":
                    anchoredJoint2D.connectedAnchor = reader.ReadProperty <UnityEngine.Vector2> ();
                    break;

                case "autoConfigureConnectedAnchor":
                    anchoredJoint2D.autoConfigureConnectedAnchor = reader.ReadProperty <System.Boolean> ();
                    break;

                case "connectedBody":
                    if (anchoredJoint2D.connectedBody == null)
                    {
                        anchoredJoint2D.connectedBody = reader.ReadProperty <UnityEngine.Rigidbody2D> ();
                    }
                    else
                    {
                        reader.ReadIntoProperty <UnityEngine.Rigidbody2D> (anchoredJoint2D.connectedBody);
                    }
                    break;

                case "enableCollision":
                    anchoredJoint2D.enableCollision = reader.ReadProperty <System.Boolean> ();
                    break;

                case "breakForce":
                    anchoredJoint2D.breakForce = reader.ReadProperty <System.Single> ();
                    break;

                case "breakTorque":
                    anchoredJoint2D.breakTorque = reader.ReadProperty <System.Single> ();
                    break;

                case "enabled":
                    anchoredJoint2D.enabled = reader.ReadProperty <System.Boolean> ();
                    break;

                case "tag":
                    anchoredJoint2D.tag = reader.ReadProperty <System.String> ();
                    break;

                case "name":
                    anchoredJoint2D.name = reader.ReadProperty <System.String> ();
                    break;

                case "hideFlags":
                    anchoredJoint2D.hideFlags = reader.ReadProperty <UnityEngine.HideFlags> ();
                    break;
                }
            }
        }
 public void OnSceneGUI()
 {
     this.anchorJoint2D = (AnchoredJoint2D) base.target;
     if (this.anchorJoint2D.enabled)
     {
         Vector3 position = Joint2DEditor.TransformPoint(this.anchorJoint2D.transform, (Vector3) this.anchorJoint2D.anchor);
         Vector3 connectedAnchor = (Vector3) this.anchorJoint2D.connectedAnchor;
         if (this.anchorJoint2D.connectedBody != null)
         {
             connectedAnchor = Joint2DEditor.TransformPoint(this.anchorJoint2D.connectedBody.transform, connectedAnchor);
         }
         Vector3 vector4 = connectedAnchor - position;
         Vector3 vector3 = position + ((Vector3) ((vector4.normalized * HandleUtility.GetHandleSize(position)) * 0.1f));
         Handles.color = Color.green;
         Vector3[] points = new Vector3[] { vector3, connectedAnchor };
         Handles.DrawAAPolyLine(points);
         if (base.HandleAnchor(ref connectedAnchor, true))
         {
             connectedAnchor = Joint2DEditor.SnapToPoint(this.SnapToSprites(connectedAnchor), position, 0.13f);
             if (this.anchorJoint2D.connectedBody != null)
             {
                 connectedAnchor = Joint2DEditor.InverseTransformPoint(this.anchorJoint2D.connectedBody.transform, connectedAnchor);
             }
             Undo.RecordObject(this.anchorJoint2D, "Move Connected Anchor");
             this.anchorJoint2D.connectedAnchor = connectedAnchor;
         }
         if (base.HandleAnchor(ref position, false))
         {
             position = Joint2DEditor.SnapToPoint(this.SnapToSprites(position), connectedAnchor, 0.13f);
             Undo.RecordObject(this.anchorJoint2D, "Move Anchor");
             this.anchorJoint2D.anchor = Joint2DEditor.InverseTransformPoint(this.anchorJoint2D.transform, position);
         }
     }
 }
示例#5
0
    private AnchoredJoint2D getJoint()
    {
        if (joint == null) {
            if (GetComponent<DistanceJoint2D>() != null)
            {
                joint = GetComponent<DistanceJoint2D>();
            }
            if (GetComponent<HingeJoint2D>() != null)
            {
                joint = GetComponent<HingeJoint2D>();
            }
            if (GetComponent<SliderJoint2D>() != null)
            {
                joint = GetComponent<SliderJoint2D>();
            }
            if (GetComponent<SpringJoint2D>() != null)
            {
                joint = GetComponent<SpringJoint2D>();
            }
            if (GetComponent<WheelJoint2D>() != null)
            {
                joint = GetComponent<WheelJoint2D>();
            }
        }

        return joint;
    }
		public void OnSceneGUI()
		{
			this.anchorJoint2D = (AnchoredJoint2D)this.target;
			Vector3 vector = Joint2DEditorBase.TransformPoint(this.anchorJoint2D.transform, this.anchorJoint2D.anchor);
			Vector3 vector2 = this.anchorJoint2D.connectedAnchor;
			if (this.anchorJoint2D.connectedBody)
			{
				vector2 = Joint2DEditorBase.TransformPoint(this.anchorJoint2D.connectedBody.transform, vector2);
			}
			Vector3 vector3 = vector + (vector2 - vector).normalized * HandleUtility.GetHandleSize(vector) * 0.1f;
			Handles.color = Color.green;
			Handles.DrawAAPolyLine(new Vector3[]
			{
				vector3,
				vector2
			});
			if (base.HandleAnchor(ref vector2, true))
			{
				vector2 = this.SnapToSprites(vector2);
				vector2 = Joint2DEditorBase.SnapToPoint(vector2, vector, 0.13f);
				if (this.anchorJoint2D.connectedBody)
				{
					vector2 = Joint2DEditorBase.InverseTransformPoint(this.anchorJoint2D.connectedBody.transform, vector2);
				}
				Undo.RecordObject(this.anchorJoint2D, "Move Connected Anchor");
				this.anchorJoint2D.connectedAnchor = vector2;
			}
			if (base.HandleAnchor(ref vector, false))
			{
				vector = this.SnapToSprites(vector);
				vector = Joint2DEditorBase.SnapToPoint(vector, vector2, 0.13f);
				Undo.RecordObject(this.anchorJoint2D, "Move Anchor");
				this.anchorJoint2D.anchor = Joint2DEditorBase.InverseTransformPoint(this.anchorJoint2D.transform, vector);
			}
		}
 static public int constructor(IntPtr l)
 {
     UnityEngine.AnchoredJoint2D o;
     o = new UnityEngine.AnchoredJoint2D();
     pushObject(l, o);
     return(1);
 }
 public static Vector2 GetConnectedAnchorPosition(AnchoredJoint2D joint2D)
 {
     if (joint2D.connectedBody) {
         return Helpers2D.TransformPoint(joint2D.connectedBody.transform, joint2D.connectedAnchor);
     }
     return joint2D.connectedAnchor;
 }
 static public int set_connectedAnchor(IntPtr l)
 {
     UnityEngine.AnchoredJoint2D o = (UnityEngine.AnchoredJoint2D)checkSelf(l);
     UnityEngine.Vector2         v;
     checkType(l, 2, out v);
     o.connectedAnchor = v;
     return(0);
 }
    public static Vector2 GetTargetPosition(AnchoredJoint2D joint2D, AnchorBias bias = AnchorBias.Either)
    {
        var transform = GetTargetTransform(joint2D, bias);

        if (transform == null) {
            return Vector2.zero;
        }
        return transform.position;
    }
 public static Vector2 GetAnchorPosition(AnchoredJoint2D joint2D, AnchorBias bias = AnchorBias.Either)
 {
     switch (bias) {
         case AnchorBias.Connected:
             return GetConnectedAnchorPosition(joint2D);
         default:
             return GetMainAnchorPosition(joint2D);
     }
 }
    public static float GetTargetRotation(AnchoredJoint2D joint2D, AnchorBias bias = AnchorBias.Either)
    {
        var transform = GetTargetTransform(joint2D, bias);

        if (transform == null) {
            return 0;
        }

        return transform.rotation.eulerAngles.z;
    }
示例#13
0
 static public int get_connectedAnchor(IntPtr l)
 {
     try {
         UnityEngine.AnchoredJoint2D self = (UnityEngine.AnchoredJoint2D)checkSelf(l);
         pushValue(l, self.connectedAnchor);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
	static public int constructor(IntPtr l) {
		try {
			UnityEngine.AnchoredJoint2D o;
			o=new UnityEngine.AnchoredJoint2D();
			pushValue(l,true);
			pushValue(l,o);
			return 2;
		}
		catch(Exception e) {
			return error(l,e);
		}
	}
示例#15
0
 static public int get_autoConfigureConnectedAnchor(IntPtr l)
 {
     try {
         UnityEngine.AnchoredJoint2D self = (UnityEngine.AnchoredJoint2D)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.autoConfigureConnectedAnchor);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.AnchoredJoint2D o;
         o = new UnityEngine.AnchoredJoint2D();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int constructor(IntPtr l)
 {
     LuaDLL.lua_remove(l, 1);
     UnityEngine.AnchoredJoint2D o;
     if (matchType(l, 1))
     {
         o = new UnityEngine.AnchoredJoint2D();
         pushObject(l, o);
         return(1);
     }
     LuaDLL.luaL_error(l, "New object failed.");
     return(0);
 }
示例#18
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.AnchoredJoint2D o;
         o = new UnityEngine.AnchoredJoint2D();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.AnchoredJoint2D o;
         o=new UnityEngine.AnchoredJoint2D();
         pushValue(l,o);
         return 1;
     }
     catch(Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return 0;
     }
 }
示例#20
0
 static public int set_connectedAnchor(IntPtr l)
 {
     try {
         UnityEngine.AnchoredJoint2D self = (UnityEngine.AnchoredJoint2D)checkSelf(l);
         UnityEngine.Vector2         v;
         checkType(l, 2, out v);
         self.connectedAnchor = v;
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
示例#21
0
 static public int set_autoConfigureConnectedAnchor(IntPtr l)
 {
     try {
         UnityEngine.AnchoredJoint2D self = (UnityEngine.AnchoredJoint2D)checkSelf(l);
         bool v;
         checkType(l, 2, out v);
         self.autoConfigureConnectedAnchor = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
示例#22
0
 static public int set_anchor(IntPtr l)
 {
     try {
         UnityEngine.AnchoredJoint2D self = (UnityEngine.AnchoredJoint2D)checkSelf(l);
         UnityEngine.Vector2         v;
         checkType(l, 2, out v);
         self.anchor = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
示例#23
0
 static void AnchoredJoint2D_connectedAnchor(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.AnchoredJoint2D _this = (UnityEngine.AnchoredJoint2D)vc.csObj;
         var result = _this.connectedAnchor;
         JSApi.setVector2S((int)JSApi.SetType.Rval, result);
     }
     else
     {
         UnityEngine.Vector2         arg0  = (UnityEngine.Vector2)JSApi.getVector2S((int)JSApi.GetType.Arg);
         UnityEngine.AnchoredJoint2D _this = (UnityEngine.AnchoredJoint2D)vc.csObj;
         _this.connectedAnchor = arg0;
     }
 }
示例#24
0
 /// <summary>
 /// Write the specified value using the writer.
 /// </summary>
 /// <param name="value">Value.</param>
 /// <param name="writer">Writer.</param>
 public override void Write(object value, ISaveGameWriter writer)
 {
     UnityEngine.AnchoredJoint2D anchoredJoint2D = (UnityEngine.AnchoredJoint2D)value;
     writer.WriteProperty("anchor", anchoredJoint2D.anchor);
     writer.WriteProperty("connectedAnchor", anchoredJoint2D.connectedAnchor);
     writer.WriteProperty("autoConfigureConnectedAnchor", anchoredJoint2D.autoConfigureConnectedAnchor);
     writer.WriteProperty("connectedBody", anchoredJoint2D.connectedBody);
     writer.WriteProperty("enableCollision", anchoredJoint2D.enableCollision);
     writer.WriteProperty("breakForce", anchoredJoint2D.breakForce);
     writer.WriteProperty("breakTorque", anchoredJoint2D.breakTorque);
     writer.WriteProperty("enabled", anchoredJoint2D.enabled);
     writer.WriteProperty("tag", anchoredJoint2D.tag);
     writer.WriteProperty("name", anchoredJoint2D.name);
     writer.WriteProperty("hideFlags", anchoredJoint2D.hideFlags);
 }
 static void AnchoredJoint2D_autoConfigureConnectedAnchor(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.AnchoredJoint2D _this = (UnityEngine.AnchoredJoint2D)vc.csObj;
         var result = _this.autoConfigureConnectedAnchor;
         JSApi.setBooleanS((int)JSApi.SetType.Rval, (System.Boolean)(result));
     }
     else
     {
         System.Boolean arg0 = (System.Boolean)JSApi.getBooleanS((int)JSApi.GetType.Arg);
         UnityEngine.AnchoredJoint2D _this = (UnityEngine.AnchoredJoint2D)vc.csObj;
         _this.autoConfigureConnectedAnchor = arg0;
     }
 }
		public override void OnEnter()
		{
			var go = Fsm.GetOwnerDefaultTarget(gameObject);
			
			if (go != null)
			{
				_anchoredJoint2d = go.GetComponent<AnchoredJoint2D>();
			}
			
			SetProperty();

			if(!everyFrame)
			{
				Finish();
			}
		}
    public static Type GetEditorType(AnchoredJoint2D joint2D)
    {
        Type editorType = null;

        if (joint2D is HingeJoint2D) {
            editorType = typeof (HingeJoint2DEditor);
        } else if (joint2D is DistanceJoint2D) {
            editorType = typeof (DistanceJoint2DEditor);
        } else if (joint2D is SliderJoint2D) {
            editorType = typeof (SliderJoint2DEditor);
        } else if (joint2D is SpringJoint2D) {
            editorType = typeof (SpringJoint2DEditor);
        } else if (joint2D is WheelJoint2D) {
            editorType = typeof (WheelJoint2DEditor);
        }
        return editorType;
    }
    protected void AnchorGUI(AnchoredJoint2D joint2D)
    {
        var jointSettings = SettingsHelper.GetOrCreate(joint2D);

        var anchorLock = WantsLocking() && jointSettings.lockAnchors;

        var playing = EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPaused;
        var worldAnchor = JointHelpers.GetMainAnchorPosition(joint2D);
        var worldConnectedAnchor = JointHelpers.GetConnectedAnchorPosition(joint2D);

        var overlapping = Vector2.Distance(worldConnectedAnchor, worldAnchor) <= AnchorEpsilon;

        var changed = false;

        AnchorInfo main = new AnchorInfo(controlNames),
                   connected = new AnchorInfo(controlNames),
                   locked = new AnchorInfo(controlNames);

        if (jointAnchorInfos.ContainsKey(joint2D)) {
            jointAnchorInfos[joint2D].Clear();
        } else {
            jointAnchorInfos[joint2D] = new List<AnchorInfo>();
        }

        jointAnchorInfos[joint2D].AddRange(new[] {
            main, connected, locked
        });

        var otherAnchors = GetAllAnchorsInSelection(joint2D);

        if (anchorLock && DragBothAnchorsWhenLocked()) {
            if (playing || overlapping) {
                if (AnchorDraggingWidgetGUI(joint2D, locked, otherAnchors, JointHelpers.AnchorBias.Either)) {
                    changed = true;
                }
            } else {
                //draw the locks instead, force them to show
                if (ToggleLockButton(main.GetControlID("lock"), joint2D, JointHelpers.AnchorBias.Main)) {
                    changed = true;
                }
                if (ToggleLockButton(connected.GetControlID("lock"), joint2D, JointHelpers.AnchorBias.Connected)) {
                    changed = true;
                }
            }

            if (!changed) {
                changed = PostAnchorGUI(joint2D, locked, otherAnchors, JointHelpers.AnchorBias.Either);
            }
        } else {
            if (AnchorDraggingWidgetGUI(joint2D, connected, otherAnchors, JointHelpers.AnchorBias.Connected)) {
                changed = true;
                if (anchorLock) {
                    ReAlignAnchors(joint2D, JointHelpers.AnchorBias.Connected);
                }
            }

            if (AnchorDraggingWidgetGUI(joint2D, main, otherAnchors, JointHelpers.AnchorBias.Main)) {
                changed = true;
                if (anchorLock) {
                    ReAlignAnchors(joint2D, JointHelpers.AnchorBias.Main);
                }
            }

            if (!changed) {
                changed = PostAnchorGUI(joint2D, main, otherAnchors, JointHelpers.AnchorBias.Main)
                          || PostAnchorGUI(joint2D, connected, otherAnchors, JointHelpers.AnchorBias.Connected);
            }
        }

        if (changed) {
            EditorUtility.SetDirty(joint2D);
        }
    }
    private void DrawDefaultSceneGUI(AnchoredJoint2D joint2D)
    {
        Editor defaultEditor = null;
        if (defaultEditors.ContainsKey(joint2D)) {
            defaultEditor = defaultEditors[joint2D];
        } else {
            var editorType = GetEditorType(joint2D);
            if (editorType != null) {
                defaultEditor = CreateEditor(joint2D, editorType);
                defaultEditors[joint2D] = defaultEditor;
            }
        }

        if (defaultEditor == null) {
            return;
        }

        var method = defaultEditor.GetType()
                                  .GetMethod("OnSceneGUI",
                                      BindingFlags.Instance
                                      | BindingFlags.Public
                                      | BindingFlags.NonPublic
                                      | BindingFlags.FlattenHierarchy);

        if (method != null) {
            method.Invoke(defaultEditor, null);
        }
    }
 protected virtual Vector2 GetTargetPosition(AnchoredJoint2D joint2D, JointHelpers.AnchorBias bias)
 {
     return JointHelpers.GetTargetPosition(joint2D, bias);
 }
示例#31
0
 /// <summary>
 /// Read the data using the reader.
 /// </summary>
 /// <param name="reader">Reader.</param>
 public override object Read(ISaveGameReader reader)
 {
     UnityEngine.AnchoredJoint2D anchoredJoint2D = SaveGameType.CreateComponent <UnityEngine.AnchoredJoint2D> ();
     ReadInto(anchoredJoint2D, reader);
     return(anchoredJoint2D);
 }
 protected virtual void ExtraMenuItems(GenericMenu menu, AnchoredJoint2D joint)
 {
 }
    protected Vector2 AnchorSlider(int controlID, float handleScale, IEnumerable<Vector2> snapPositions,
        JointHelpers.AnchorBias bias, AnchoredJoint2D joint, AnchorInfo anchorInfo)
    {
        var sliderState = StateObject.Get<AnchorSliderState>(controlID);

        var anchorPosition = JointHelpers.GetAnchorPosition(joint, bias);
        var handleSize = HandleUtility.GetHandleSize(anchorPosition) * handleScale;
        EditorGUI.BeginChangeCheck();
        Vector2 targetPosition;
        var connectedBody = joint.connectedBody;
        if (bias == JointHelpers.AnchorBias.Connected) {
            if (connectedBody) {
                targetPosition = connectedBody.transform.position;
            } else {
                targetPosition = anchorPosition;
            }
        } else {
            targetPosition = joint.gameObject.transform.position;
        }

        var originalAngle = JointHelpers.AngleFromAnchor(anchorPosition, targetPosition,
            joint.gameObject.transform.rotation.eulerAngles.z);

        if (GUIUtility.hotControl == controlID) {
            using (var drawer = CreateHotDrawer(originalAngle)) {
                drawer.alwaysVisible = true;
                drawer.DrawSquare(anchorPosition, Quaternion.identity, handleSize);
            }
        }

        var hovering = HandleUtility.nearestControl == controlID;

        var hoveringOrHot = (hovering && GUIUtility.hotControl == 0) || controlID == GUIUtility.hotControl;

        if (hoveringOrHot && _hoverControlID != controlID) {
            _hoverControlID = controlID;

            HandleUtility.Repaint();
        } else if (!hoveringOrHot && _hoverControlID == controlID) {
            _hoverControlID = 0;
            HandleUtility.Repaint();
        }

        var joint2DSettings = SettingsHelper.GetOrCreate(joint);

        HandleAnchorContext(controlID, bias, joint, joint2DSettings, anchorPosition, connectedBody);

        HandleSliderEvents(controlID, joint, sliderState, anchorPosition, hoveringOrHot, handleSize);

        HandleDragDrop(controlID, joint, joint2DSettings);

        var result = HandleSliding(controlID, bias, originalAngle, anchorPosition, handleSize);

        result = HandleSnapping(controlID, snapPositions, bias, joint, anchorInfo, result, handleSize);

        return result;
    }
    protected void HandleDragDrop(int controlID, AnchoredJoint2D joint, Joint2DSettingsBase joint2DSettings)
    {
        var current = Event.current;

        if (HandleUtility.nearestControl == controlID) {
            switch (current.GetTypeForControl(controlID)) {
                case EventType.DragPerform:
                    foreach (var o in DragAndDrop.objectReferences) {
                        var gameObject = o as GameObject;
                        if (gameObject == null) {
                            continue;
                        }
                        var go = gameObject;
                        var rigidbody2D = go.GetComponent<Rigidbody2D>();
                        if (go.Equals(joint.gameObject) || rigidbody2D == null || rigidbody2D == joint.connectedBody) {
                            continue;
                        }
                        var wantsLock = joint2DSettings.lockAnchors;

                        EditorHelpers.RecordUndo("Drag Onto Anchor", joint);
                        var connectedBodyPosition = JointHelpers.GetConnectedAnchorPosition(joint);

                        var previousConnectedBody = joint.connectedBody;
                        joint.connectedBody = rigidbody2D;

                        JointHelpers.SetWorldConnectedAnchorPosition(joint, connectedBodyPosition);

                        if (wantsLock) {
                            ReAlignAnchors(joint, JointHelpers.AnchorBias.Main);
                        }

                        if (isCreatedByTarget) {
                            EditorHelpers.SelectObject(rigidbody2D.gameObject, true);
                            Selection.objects = Selection.objects.Where(o1 => o1 != previousConnectedBody.gameObject)
                                                         .ToArray();
                        }

                        EditorUtility.SetDirty(joint);
                        DragAndDrop.AcceptDrag();
                        break;
                    }
                    break;
                case EventType.DragUpdated:
                    if (DragAndDrop.objectReferences.OfType<GameObject>()
                                   .Any(go => {
                                       var rigidbody2D = go.GetComponent<Rigidbody2D>();
                                       return !go.Equals(joint.gameObject) && rigidbody2D != null &&
                                              rigidbody2D != joint.connectedBody;
                                   })) {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Link;
                        Event.current.Use();
                    }
                    break;
                case EventType.DragExited:
                    break;
            }
        }
    }
 protected virtual IEnumerable<Vector2> GetSnapPositions(AnchoredJoint2D joint2D,
     AnchorInfo anchorInfo,
     JointHelpers.AnchorBias bias,
     Vector2 anchorPosition)
 {
     return null;
 }
 protected virtual bool PostAnchorGUI(AnchoredJoint2D joint2D, AnchorInfo info, List<Vector2> otherAnchors,
     JointHelpers.AnchorBias bias)
 {
     return false;
 }
    private void HandleAnchorContext(int controlID, JointHelpers.AnchorBias bias, AnchoredJoint2D joint,
        Joint2DSettingsBase joint2DSettings, Vector2 anchorPosition,
        Rigidbody2D connectedBody)
    {
        EditorHelpers.ContextClick(controlID, () => {
            var menu = new GenericMenu();
            menu.AddDisabledItem(new GUIContent(joint.GetType()
                                                     .Name));
            menu.AddSeparator("");
            if (WantsLocking()) {
                menu.AddItem(new GUIContent("Lock Anchors", GetAnchorLockTooltip()),
                    joint2DSettings.lockAnchors, () => {
                        EditorHelpers.RecordUndo(
                            joint2DSettings.lockAnchors ? "Unlock Anchors" : "Lock Anchors", joint2DSettings,
                            joint);
                        if (!joint2DSettings.lockAnchors) {
                            ReAlignAnchors(joint, bias);
                        }
                        joint2DSettings.lockAnchors = !joint2DSettings.lockAnchors;
                        EditorUtility.SetDirty(joint2DSettings);
                        EditorUtility.SetDirty(joint);
                    });
            }
            {
                var otherBias = JointHelpers.GetOppositeBias(bias);
                var otherPosition = JointHelpers.GetAnchorPosition(joint, otherBias);
                if (Vector2.Distance(otherPosition, anchorPosition) <= AnchorEpsilon) {
                    menu.AddDisabledItem(new GUIContent("Bring other anchor here"));
                } else {
                    menu.AddItem(new GUIContent("Bring other anchor here"), false, () => {
                        EditorHelpers.RecordUndo("Move Joint Anchor", joint);
                        JointHelpers.SetWorldAnchorPosition(joint, anchorPosition, otherBias);
                        EditorUtility.SetDirty(joint);
                    });
                }
            }

            menu.AddItem(new GUIContent("Enable Collision",
                "Should rigid bodies connected with this joint collide?"), joint.enableCollision,
                () => {
                    EditorHelpers.RecordUndo("Move Joint Anchor", joint);
                    joint.enableCollision = !joint.enableCollision;
                    EditorUtility.SetDirty(joint);
                });

            menu.AddSeparator("");

            var itemCount = menu.GetItemCount();

            ExtraMenuItems(menu, joint);

            if (itemCount != menu.GetItemCount()) {
                menu.AddSeparator("");
            }

            if (connectedBody) {
                var connectedBodyName = connectedBody.name;
                var selectConnectedBodyContent = new GUIContent(string.Format("Select '{0}'", connectedBodyName));
                if (isCreatedByTarget) {
                    menu.AddDisabledItem(selectConnectedBodyContent);
                } else {
                    menu.AddItem(selectConnectedBodyContent, false,
                        () => { Selection.activeGameObject = connectedBody.gameObject; });
                }
                menu.AddItem(new GUIContent(string.Format("Move ownership to '{0}'", connectedBodyName)), false, () => {
                    var connectedObject = connectedBody.gameObject;

                    var cloneJoint =
                        Undo.AddComponent(connectedObject, joint.GetType()) as AnchoredJoint2D;
                    if (!cloneJoint) {
                        return;
                    }
                    EditorUtility.CopySerialized(joint, cloneJoint);
                    cloneJoint.connectedBody = joint.GetComponent<Rigidbody2D>();

                    JointHelpers.SetWorldAnchorPosition(cloneJoint,
                        JointHelpers.GetAnchorPosition(joint, JointHelpers.AnchorBias.Main),
                        JointHelpers.AnchorBias.Connected);
                    JointHelpers.SetWorldAnchorPosition(cloneJoint,
                        JointHelpers.GetAnchorPosition(joint, JointHelpers.AnchorBias.Connected),
                        JointHelpers.AnchorBias.Main);

                    var jointSettings = SettingsHelper.GetOrCreate(joint);
                    var cloneSettings =
                        Undo.AddComponent(connectedObject, jointSettings.GetType()) as Joint2DSettingsBase;

                    if (cloneSettings == null) {
                        return;
                    }
                    cloneSettings.hideFlags = HideFlags.HideInInspector;

                    EditorUtility.CopySerialized(jointSettings, cloneSettings);
                    cloneSettings.Setup(cloneJoint);

                    cloneSettings.SetOffset(JointHelpers.AnchorBias.Main,
                        jointSettings.GetOffset(JointHelpers.AnchorBias.Connected));
                    cloneSettings.SetOffset(JointHelpers.AnchorBias.Connected,
                        jointSettings.GetOffset(JointHelpers.AnchorBias.Main));

                    if (!Selection.Contains(connectedObject)) {
                        var selectedObjects = new List<Object>(Selection.objects) {connectedObject};

                        if (selectedObjects.Contains(joint.gameObject)) {
                            selectedObjects.Remove(joint.gameObject);
                        }

                        Selection.objects = selectedObjects.ToArray();
                    }

                    Undo.DestroyObjectImmediate(joint);

                    OwnershipMoved(cloneJoint);
                });
                menu.AddItem(new GUIContent("Disconnect from '" + connectedBodyName + "'"), false, () => {
                    var worldConnectedPosition = JointHelpers.GetConnectedAnchorPosition(joint);

                    using (new Modification("Disconnect from connected body", joint)) {
                        joint.connectedBody = null;
                        JointHelpers.SetWorldConnectedAnchorPosition(joint, worldConnectedPosition);
                    }
                });
            } else {
                menu.AddDisabledItem(new GUIContent("Select connected body"));
                menu.AddDisabledItem(new GUIContent("Move ownership to connected body"));
                menu.AddDisabledItem(new GUIContent("Disconnect from connected body"));
            }

            menu.AddItem(new GUIContent("Delete " + joint.GetType()
                                                         .Name), false,
                () => Undo.DestroyObjectImmediate(joint));
            menu.ShowAsContext();
        });
    }
 protected virtual void ReAlignAnchors(AnchoredJoint2D joint2D, JointHelpers.AnchorBias alignmentBias)
 {
     var oppositeBias = JointHelpers.GetOppositeBias(alignmentBias);
     JointHelpers.SetWorldAnchorPosition(joint2D, GetWantedAnchorPosition(joint2D, oppositeBias), oppositeBias);
 }
    private static Type GetEditorType(AnchoredJoint2D joint2D)
    {
        Type editorType = null;

        var assembly = typeof (Editor).Assembly;

        if (joint2D is HingeJoint2D) {
            editorType = assembly.GetType("UnityEditor.HingeJoint2DEditor", true);
        } else if (joint2D is DistanceJoint2D) {
            editorType = assembly.GetType("UnityEditor.DistanceJoint2DEditor", true);
        } else if (joint2D is SliderJoint2D) {
            editorType = assembly.GetType("UnityEditor.SliderJoint2DEditor", true);
        } else if (joint2D is SpringJoint2D) {
            editorType = assembly.GetType("UnityEditor.SpringJoint2DEditor", true);
        } else if (joint2D is WheelJoint2D) {
            editorType = assembly.GetType("UnityEditor.WheelJoint2DEditor", true);
        }
        return editorType;
    }
    protected bool ToggleLockButton(int controlID, AnchoredJoint2D joint2D, JointHelpers.AnchorBias bias)
    {
        Vector3 center = JointHelpers.GetAnchorPosition(joint2D, bias);

        var lockPressed = EditorHelpers.CustomHandleButton(controlID,
            center,
            HandleUtility.GetHandleSize(center) * editorSettings.lockButtonScale,
            editorSettings.unlockButtonTexture, editorSettings.lockButtonTexture,
            GetAdjustedColor(Color.white));

        if (lockPressed) {
            var jointSettings = SettingsHelper.GetOrCreate(joint2D);

            EditorHelpers.RecordUndo("Lock Anchors", jointSettings, joint2D);
            jointSettings.lockAnchors = true;
            EditorUtility.SetDirty(jointSettings);

            ReAlignAnchors(joint2D, bias);
        }

        return lockPressed;
    }
    protected virtual void ToggleIndividualAnchorLock(bool wantsLock, AnchoredJoint2D joint2D,
        JointHelpers.AnchorBias alignmentBias)
    {
        var jointSettings = SettingsHelper.GetOrCreate(joint2D);

        var action = wantsLock ? "Lock Anchors" : "Unlock Anchors";
        EditorHelpers.RecordUndo(action, jointSettings);
        jointSettings.lockAnchors = wantsLock;
        EditorUtility.SetDirty(jointSettings);

        if (wantsLock) {
            EditorHelpers.RecordUndo(action, joint2D);
            ReAlignAnchors(joint2D, alignmentBias);
            EditorUtility.SetDirty(joint2D);
        }
    }
 protected virtual bool SingleAnchorGUI(AnchoredJoint2D joint2D, AnchorInfo anchorInfo, JointHelpers.AnchorBias bias)
 {
     return false;
 }
    private void DrawLineToBody(AnchoredJoint2D joint2D, JointHelpers.AnchorBias bias)
    {
        if (bias == JointHelpers.AnchorBias.Connected && !joint2D.connectedBody) {
            return;
        }

        if (editorSettings.drawLinesToBodies || isCreatedByTarget) {
            Color lineColor;

            if (bias == JointHelpers.AnchorBias.Main) {
                lineColor = editorSettings.anchorsToMainBodyColor;
            } else {
                lineColor = editorSettings.anchorsToConnectedBodyColor;
            }

            using (new HandleColor(GetAdjustedColor(lineColor))) {
                Vector3 bodyPosition = JointHelpers.GetTargetPosition(joint2D, bias);
                var anchorPosition = JointHelpers.GetAnchorPosition(joint2D, bias);

                if (Vector2.Distance(bodyPosition, anchorPosition) > AnchorEpsilon) {
                    Handles.DrawLine(bodyPosition, anchorPosition);
                }
            }
        }
    }
 static public int get_connectedAnchor(IntPtr l)
 {
     UnityEngine.AnchoredJoint2D o = (UnityEngine.AnchoredJoint2D)checkSelf(l);
     pushValue(l, o.connectedAnchor);
     return(1);
 }
 protected virtual void OwnershipMoved(AnchoredJoint2D cloneJoint)
 {
 }
 protected virtual Vector2 GetWantedAnchorPosition(AnchoredJoint2D anchoredJoint2D, JointHelpers.AnchorBias bias)
 {
     var oppositeBias = JointHelpers.GetOppositeBias(bias);
     return JointHelpers.GetAnchorPosition(anchoredJoint2D, oppositeBias);
 }
    protected bool SliderGUI(AnchoredJoint2D joint2D, AnchorInfo anchorInfo, IEnumerable<Vector2> otherAnchors,
        JointHelpers.AnchorBias bias)
    {
        var sliderID = anchorInfo.GetControlID("slider");
        List<Vector2> snapPositions = null;
        if (EditorGUI.actionKey) {
            snapPositions = new List<Vector2> {
                GetTargetPosition(joint2D, JointHelpers.AnchorBias.Main),
                JointHelpers.GetTargetTransform(joint2D, JointHelpers.AnchorBias.Main)
                            .position
            };

            if (joint2D.connectedBody) {
                snapPositions.Add(GetTargetPosition(joint2D, JointHelpers.AnchorBias.Connected));
                snapPositions.Add(JointHelpers.GetTargetTransform(joint2D, JointHelpers.AnchorBias.Connected)
                                              .position);
            }

            switch (bias) {
                case JointHelpers.AnchorBias.Main:
                    snapPositions.Add(JointHelpers.GetAnchorPosition(joint2D,
                        JointHelpers.AnchorBias.Connected));
                    break;
                case JointHelpers.AnchorBias.Connected:
                    snapPositions.Add(JointHelpers.GetAnchorPosition(joint2D, JointHelpers.AnchorBias.Main));
                    break;
            }

            snapPositions.AddRange(otherAnchors);
        }
        EditorGUI.BeginChangeCheck();
        var position = AnchorSlider(sliderID, editorSettings.anchorScale, snapPositions, bias, joint2D, anchorInfo);

        var changed = false;
        if (EditorGUI.EndChangeCheck()) {
            EditorHelpers.RecordUndo("Anchor Move", joint2D);
            changed = true;

            JointHelpers.SetWorldAnchorPosition(joint2D, position, bias);
        }
        return changed;
    }