Ejemplo n.º 1
0
 public void RemoveAnchor()
 {
     if (_anchor != null)
     {
         _anchor.RemoveAnchor();
         _anchor = null;
     }
 }
Ejemplo n.º 2
0
 public void RemoveAnchor()
 {
     if (Anchor != null)
     {
         Anchor.RemoveAnchor();
         Anchor   = null;
         Anchored = false;
     }
 }
Ejemplo n.º 3
0
        public virtual PartialViewResult Anchor(AnchorComponent component)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }

            return(PartialView(component));
        }
 public void AnchorTo(IAnchorable target, PositionType style, int offsetX = 0, int offsetY = 0, AnchorType anchorType = AnchorType.Bounds)
 {
     if (target != (IAnchorable)this)
     {
         RemoveAnchor();
         _anchor = new AnchorComponent(target, this, anchorType, style, new MonoGame.Extended.Size2(offsetX, offsetY));
         return;
     }
     Console.WriteLine("WARNING: Attempted to anchor this object to itself.");
 }
Ejemplo n.º 5
0
 public void AnchorTo(IAnchorable target, AnchorAlignment alignment, PositionOffset offset)
 {
     if (target.GetHashCode() != GetHashCode())
     {
         RemoveAnchor();
         Anchor   = new AnchorComponent(target, this, alignment, offset);
         Position = Anchor.AnchoredPosition;
         Anchored = true;
         return;
     }
     throw new NotSupportedException("Cannot anchor an object to itself.");
 }
        void OnSceneGUI()
        {
            AnchorComponent compontent = target as AnchorComponent;

            Handles.color = compontent.color;

            //绘制实心正方体
            //Handles.CubeCap(compontent.GetInstanceID(), compontent.transform.position, compontent.transform.rotation, 1.0f);

            //绘制线框正方体
            DrawWireframeBox(compontent.transform, compontent.isUserLossyScale, compontent.isUserHandlesSize);
        }
Ejemplo n.º 7
0
    public void AttachToNearestAnchor(IAnchorUser _anchorUser)
    {
        AnchorComponent nearestAnchor = FindNearestAnchorComponent(_anchorUser.GetRigidbody2D().transform.position);

        if (nearestAnchor != null)
        {
            nearestAnchor.AttachUser(_anchorUser);
        }
        else
        {
            Debug.LogWarning("No anchors found to attach the body");
        }
    }
Ejemplo n.º 8
0
    public void Detach(IAnchorUser _user)
    {
        AnchorComponent attachedAnchor = null;

        foreach (AnchorComponent _anchor in m_anchorComponentList)
        {
            if (_anchor.IsAttachedToUser(_user))
            {
                attachedAnchor = _anchor;
            }
        }
        if (attachedAnchor != null)
        {
            attachedAnchor.DetachUser();
        }
    }
Ejemplo n.º 9
0
    private AnchorComponent FindNearestAnchorComponent(Vector2 _position)
    {
        float           shortestDistance = int.MaxValue;
        AnchorComponent nearestAnchor    = null;

        foreach (AnchorComponent _component in m_anchorComponentList)
        {
            float distance = (_position - (Vector2)_component.transform.position).sqrMagnitude;

            if (distance < shortestDistance)
            {
                shortestDistance = distance;
                nearestAnchor    = _component;
            }
        }

        return(nearestAnchor);
    }
Ejemplo n.º 10
0
    public AnchorComponent FindNearestAnchorComponent(Vector2 _position)
    {
        float           shortestDistance = Mathf.Infinity;
        AnchorComponent nearestAnchor    = null;

        foreach (AnchorComponent _component in m_anchorComponentList)
        {
            float distance = (_position - (Vector2)_component.transform.position).sqrMagnitude;
            if (distance < shortestDistance)
            {
                foreach (var anchor in m_anchorComponentList)
                {
                    anchor.UnmarkAnchor();
                }
                shortestDistance = distance;
                nearestAnchor    = _component;
                nearestAnchor.MarkAnchor();
            }
        }

        return(nearestAnchor);
    }
Ejemplo n.º 11
0
 public void RegisterAnchor(AnchorComponent _component)
 {
     m_anchorComponentList.Add(_component);
 }
Ejemplo n.º 12
0
 public void UnregisterAnchor(AnchorComponent _component)
 {
     m_anchorComponentList.Remove(_component);
 }
Ejemplo n.º 13
0
 public void AnchorTo(IAnchorable target, PositionType style, int offsetX = 0, int offsetY = 0, AnchorType anchorType = AnchorType.Bounds)
 {
     RemoveAnchor();
     _anchor = new AnchorComponent(target, this, anchorType, style, new MonoGame.Extended.Size2(offsetX, offsetY));
 }