コード例 #1
0
 public void RemoveAnchor()
 {
     if (_anchor != null)
     {
         _anchor.RemoveAnchor();
         _anchor = null;
     }
 }
コード例 #2
0
 public void RemoveAnchor()
 {
     if (Anchor != null)
     {
         Anchor.RemoveAnchor();
         Anchor   = null;
         Anchored = false;
     }
 }
コード例 #3
0
        public virtual PartialViewResult Anchor(AnchorComponent component)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }

            return(PartialView(component));
        }
コード例 #4
0
 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.");
 }
コード例 #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.");
 }
コード例 #6
0
        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);
        }
コード例 #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");
        }
    }
コード例 #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();
        }
    }
コード例 #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);
    }
コード例 #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);
    }
コード例 #11
0
 public void RegisterAnchor(AnchorComponent _component)
 {
     m_anchorComponentList.Add(_component);
 }
コード例 #12
0
 public void UnregisterAnchor(AnchorComponent _component)
 {
     m_anchorComponentList.Remove(_component);
 }
コード例 #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));
 }