예제 #1
0
        public override AnchorInfo GetAnchorInfo(bool reverse)
        {
            int fixedWidth = GetFixedWidth();

            if (Minimum == 0)
            {
                return(new AnchorInfo(this, fixedWidth));
            }
            AnchorInfo anchorInfo = Expression.GetAnchorInfo(reverse);

            if (anchorInfo.IsPosition)
            {
                return(new AnchorInfo(this, anchorInfo.Offset, fixedWidth, anchorInfo.Position));
            }
            if (anchorInfo.IsSubstring)
            {
                if (anchorInfo.IsComplete)
                {
                    string        substring     = anchorInfo.Substring;
                    StringBuilder stringBuilder = new StringBuilder(substring);
                    for (int i = 1; i < Minimum; i++)
                    {
                        stringBuilder.Append(substring);
                    }
                    return(new AnchorInfo(this, 0, fixedWidth, stringBuilder.ToString(), anchorInfo.IgnoreCase));
                }
                return(new AnchorInfo(this, anchorInfo.Offset, fixedWidth, anchorInfo.Substring, anchorInfo.IgnoreCase));
            }
            return(new AnchorInfo(this, fixedWidth));
        }
예제 #2
0
    protected override bool SingleAnchorGUI(AnchoredJoint2D joint2D, AnchorInfo anchorInfo, JointHelpers.AnchorBias bias)
    {
        var hingeJoint2D = joint2D as HingeJoint2D;

        if (hingeJoint2D == null)
        {
            return(false);
        }

        if (bias == JointHelpers.AnchorBias.Either)
        {
            DrawLinesAndDiscs(hingeJoint2D, anchorInfo, JointHelpers.AnchorBias.Main);
            DrawLinesAndDiscs(hingeJoint2D, anchorInfo, JointHelpers.AnchorBias.Connected);
        }
        else
        {
            DrawLinesAndDiscs(hingeJoint2D, anchorInfo, bias);
        }

        var mainAnchorPosition      = JointHelpers.GetMainAnchorPosition(hingeJoint2D);
        var connectedAnchorPosition = JointHelpers.GetConnectedAnchorPosition(hingeJoint2D);

        if (bias == JointHelpers.AnchorBias.Main &&
            Vector2.Distance(mainAnchorPosition, connectedAnchorPosition) > AnchorEpsilon)
        {
            using (new HandleColor(GetAdjustedColor(Color.green))) {
                Handles.DrawLine(mainAnchorPosition, connectedAnchorPosition);
            }
        }
        return(false);
    }
예제 #3
0
 public override CustomObjectInfo SerializeObject()
 {
     AnchorInfo info=new AnchorInfo();
     info.BasicSerialization(this);
     info.showPicture=showPicture.name;
     return info;
 }
예제 #4
0
        private async void downloadAnchorFile()
        {
            try
            {
                Debug.Log("Check anchor file exist...");
                AnchorApi  api        = new AnchorApi("http://" + serverHost);
                AnchorInfo anchorInfo = await api.QueryAnchorInfo(appId, roomId);

                Debug.Log("--Check result=" + anchorInfo);


                if (anchorInfo != null && anchorInfo.fileSize > 0)
                {
                    downloadApi = new DownloadProgressAnchorApi(
                        "http://" + serverHost,
                        appId,
                        roomId,
                        anchorFilePath,
                        anchorFileName,
                        tempFilePath,
                        anchorInfo.fileSize
                        );

                    worker.SubmitWork(downloadApi);
                }
            }
            catch (Exception e)
            {
                downloadApi         = null;
                downloadErrorString = e.ToString();
                downloadFinish      = true;
            }
        }
    protected override bool SingleAnchorGUI(AnchoredJoint2D joint2D, AnchorInfo anchorInfo, JointHelpers.AnchorBias bias)
    {
        var jointWithDistance = joint2D as T;

        if (!jointWithDistance)
        {
            return(false);
        }

        var mainAnchorPosition      = JointHelpers.GetMainAnchorPosition(jointWithDistance);
        var connectedAnchorPosition = JointHelpers.GetConnectedAnchorPosition(jointWithDistance);

        if (Vector2.Distance(mainAnchorPosition, connectedAnchorPosition) > AnchorEpsilon)
        {
            using (new HandleColor(Color.green)) {
                Handles.DrawLine(mainAnchorPosition, connectedAnchorPosition);
            }
        }


        DrawDistance(jointWithDistance, anchorInfo, bias);

        Handles.DrawLine(mainAnchorPosition, connectedAnchorPosition);

        return(false);
    }
예제 #6
0
        /**
         * If there is a pending scroll position or saved states, updates the anchor info from that
         * data and returns true
         */
        private bool UpdateAnchorFromPendingData(AnchorInfo anchorInfo)
        {
            if (mPendingScrollPosition == NO_POSITION)
            {
                return(false);
            }
            // validate scroll position
            if (mPendingScrollPosition < 0 || mPendingScrollPosition >= ItemCount)
            {
                mPendingScrollPosition       = NO_POSITION;
                mPendingScrollPositionOffset = INVALID_OFFSET;
                return(false);
            }

            anchorInfo.Position = mPendingScrollPosition;

            if (mPendingScrollPositionOffset == INVALID_OFFSET)
            {
                anchorInfo.Coordinate = anchorInfo.LayoutFromEnd ? mOrientationHelper.GetEndAfterPadding() : mOrientationHelper.GetStartAfterPadding();
            }
            else
            {
                if (mShouldReverseLayout)
                {
                    anchorInfo.Coordinate = mOrientationHelper.GetEndAfterPadding()
                                            - mPendingScrollPositionOffset;
                }
                else
                {
                    anchorInfo.Coordinate = mOrientationHelper.GetStartAfterPadding()
                                            + mPendingScrollPositionOffset;
                }
            }
            return(true);
        }
예제 #7
0
        public static TrackableId UnityXRMock_attachAnchor(TrackableId trackableId, Pose pose)
        {
            if (trackableId == TrackableId.invalidId)
            {
                trackableId = s_trackableIdGenerator();
            }

            if (!s_anchors.ContainsKey(trackableId) || s_addedAnchors.ContainsKey(trackableId))
            {
                if (!s_anchors.ContainsKey(trackableId))
                {
                    s_anchors[trackableId] = new AnchorInfo()
                    {
                        id = trackableId
                    };
                }

                s_addedAnchors[trackableId] = s_anchors[trackableId];
            }
            else
            {
                s_updatedAnchors[trackableId] = s_anchors[trackableId];
            }

            var anchorInfo = s_anchors[trackableId];

            anchorInfo.pose          = pose;
            anchorInfo.trackingState = TrackingState.Tracking;
            return(anchorInfo.id);
        }
    public void CreateNewAnchorInManager()
    {
        List <Plant> plant       = new List <Plant>();
        PlantInfo    plantInfo1  = new PlantInfo(plant);
        AnchorInfo   anchorInfo1 = new AnchorInfo(plantInfo1);

        anchorInfo1.id = spaceId;
        //AnchorInfo anchorNew = CreateAnchor(anchorInfo1);
        UpdateAnchorData(anchorInfo1.id, e.ToArray());
        //anchorInfoManager.anchorInfoList.Add(anchorNew);
    }
예제 #9
0
    protected override bool PreSliderGUI(AnchoredJoint2D joint2D, AnchorInfo anchorInfo, JointHelpers.AnchorBias bias)
    {
        var hingeJoint2D = joint2D as HingeJoint2D;

        if (hingeJoint2D == null)
        {
            return(false);
        }

        return(DrawAngleLimits(hingeJoint2D, anchorInfo, bias));
    }
    public AnchorInfo CreateAnchor(AnchorInfo anchorInfo)
    {
        UploadHandlerRaw u = new UploadHandlerRaw(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(anchorInfo)));

        DownloadHandlerBuffer d = new DownloadHandlerBuffer();

        UnityWebRequest r = new UnityWebRequest(anchorStoreHost + GetSpaceId() + "/" + ANCHOR_STORE + "/" + anchorInfo.id, "PUT", d, u);

        r.SetRequestHeader("Content-Type", "application/json");
        r.SendWebRequest();
        return(ReadJSONResponse <AnchorInfo>(r));
    }
예제 #11
0
        private static void UpdateAnchorInfo(IArrangedElement element)
        {
            AnchorInfo anchorInfo = GetAnchorInfo(element);

            if (anchorInfo == null)
            {
                anchorInfo = new AnchorInfo();
                SetAnchorInfo(element, anchorInfo);
            }
            if (CommonProperties.GetNeedsAnchorLayout(element) && (element.Container != null))
            {
                GetCachedBounds(element);
                anchorInfo.Left   = element.Bounds.Left;
                anchorInfo.Top    = element.Bounds.Top;
                anchorInfo.Right  = element.Bounds.Right;
                anchorInfo.Bottom = element.Bounds.Bottom;
                Rectangle displayRectangle = element.Container.DisplayRectangle;
                int       width            = displayRectangle.Width;
                int       height           = displayRectangle.Height;
                anchorInfo.Left   -= displayRectangle.X;
                anchorInfo.Top    -= displayRectangle.Y;
                anchorInfo.Right  -= displayRectangle.X;
                anchorInfo.Bottom -= displayRectangle.Y;
                AnchorStyles anchor = GetAnchor(element);
                if (IsAnchored(anchor, AnchorStyles.Right))
                {
                    anchorInfo.Right -= width;
                    if (!IsAnchored(anchor, AnchorStyles.Left))
                    {
                        anchorInfo.Left -= width;
                    }
                }
                else if (!IsAnchored(anchor, AnchorStyles.Left))
                {
                    anchorInfo.Right -= width / 2;
                    anchorInfo.Left  -= width / 2;
                }
                if (IsAnchored(anchor, AnchorStyles.Bottom))
                {
                    anchorInfo.Bottom -= height;
                    if (!IsAnchored(anchor, AnchorStyles.Top))
                    {
                        anchorInfo.Top -= height;
                    }
                }
                else if (!IsAnchored(anchor, AnchorStyles.Top))
                {
                    anchorInfo.Bottom -= height / 2;
                    anchorInfo.Top    -= height / 2;
                }
            }
        }
예제 #12
0
        public static void ScaleAnchorInfo(IArrangedElement element, SizeF factor)
        {
            AnchorInfo anchorInfo = GetAnchorInfo(element);

            if (anchorInfo != null)
            {
                anchorInfo.Left   = (int)(anchorInfo.Left * factor.Width);
                anchorInfo.Top    = (int)(anchorInfo.Top * factor.Height);
                anchorInfo.Right  = (int)(anchorInfo.Right * factor.Width);
                anchorInfo.Bottom = (int)(anchorInfo.Bottom * factor.Height);
                SetAnchorInfo(element, anchorInfo);
            }
        }
예제 #13
0
        /**
         * Finds an anchor child from existing Views. Most of the time, this is the view closest to
         * start or end that has a valid position (e.g. not removed).
         * If a child has focus, it is given priority.
         */
        private bool UpdateAnchorFromChildren(FlexibleView.Recycler recycler, AnchorInfo anchorInfo)
        {
            if (GetChildCount() == 0)
            {
                return(false);
            }

            FlexibleView.ViewHolder anchorChild = FindFirstCompleteVisibleItemView();
            anchorInfo.Position   = anchorChild.LayoutPosition;
            anchorInfo.Coordinate = mOrientationHelper.GetViewHolderStart(anchorChild);

            return(true);
        }
예제 #14
0
        public static void ScaleAnchorInfo(IArrangedElement element, SizeF factor)
        {
            AnchorInfo anchorInfo = GetAnchorInfo(element);

            // some controls don't have AnchorInfo, i.e. Panels
            if (anchorInfo != null)
            {
                anchorInfo.Left   = (int)((float)anchorInfo.Left * factor.Width);
                anchorInfo.Top    = (int)((float)anchorInfo.Top * factor.Height);
                anchorInfo.Right  = (int)((float)anchorInfo.Right * factor.Width);
                anchorInfo.Bottom = (int)((float)anchorInfo.Bottom * factor.Height);

                SetAnchorInfo(element, anchorInfo);
            }
        }
예제 #15
0
        private void UpdateAnchorInfoForLayout(FlexibleView.Recycler recycler, AnchorInfo anchorInfo)
        {
            if (UpdateAnchorFromPendingData(anchorInfo))
            {
                return;
            }

            if (UpdateAnchorFromChildren(recycler, anchorInfo))
            {
                return;
            }

            anchorInfo.Position   = FocusPosition != NO_POSITION ? FocusPosition : 0;
            anchorInfo.Coordinate = anchorInfo.LayoutFromEnd ? mOrientationHelper.GetEndAfterPadding() : mOrientationHelper.GetStartAfterPadding();
        }
예제 #16
0
    protected override bool SingleAnchorGUI(AnchoredJoint2D joint2D, AnchorInfo anchorInfo, JointHelpers.AnchorBias bias)
    {
        var sliderJoint2D = (SliderJoint2D)joint2D;

        var mainAnchorPosition      = JointHelpers.GetMainAnchorPosition(sliderJoint2D);
        var connectedAnchorPosition = JointHelpers.GetConnectedAnchorPosition(sliderJoint2D);

        var sliderAngleControlID = anchorInfo.GetControlID("sliderAngle");

        if (bias != JointHelpers.AnchorBias.Connected &&
            (
                GUIUtility.hotControl == sliderAngleControlID ||
                GUIUtility.hotControl == anchorInfo.GetControlID("minLimit") ||
                GUIUtility.hotControl == anchorInfo.GetControlID("maxLimit") ||
                !Event.current.shift))
        {
            DrawAngleWidget(sliderJoint2D, sliderAngleControlID);

            if (sliderJoint2D.useLimits)
            {
                HandleLimits(sliderJoint2D, anchorInfo);
            }
        }

        if (GUIUtility.hotControl == anchorInfo.GetControlID("slider"))
        {
            var snap = GetWantedAnchorPosition(sliderJoint2D, bias);
            using (
                new HandleColor(new Color(1, 1, 1,
                                          isCreatedByTarget ? .5f * editorSettings.connectedJointTransparency : .5f))) {
                Handles.DrawLine(connectedAnchorPosition, snap);
                Handles.DrawLine(mainAnchorPosition, snap);
            }
        }

        using (
            new HandleColor(new Color(1, 1, 1,
                                      0.125f * (isCreatedByTarget ? editorSettings.connectedJointTransparency : 1.0f)))) {
            Handles.DrawLine(mainAnchorPosition, connectedAnchorPosition);
            if (sliderJoint2D.connectedBody && GUIUtility.hotControl == sliderAngleControlID)
            {
                Handles.DrawLine(mainAnchorPosition, GetTargetPosition(sliderJoint2D, JointHelpers.AnchorBias.Connected));
            }
        }
        return(false);
    }
    protected override bool PostAnchorGUI(AnchoredJoint2D joint2D, AnchorInfo info, List <Vector2> otherAnchors,
                                          JointHelpers.AnchorBias bias)
    {
        var wheelJoint2D = joint2D as WheelJoint2D;

        if (wheelJoint2D == null)
        {
            return(false);
        }


        var suspensionAngleControlID = info.GetControlID("suspensionAngle");

        if (Event.current.type == EventType.repaint)
        {
            if (EditorHelpers.IsWarm(suspensionAngleControlID) && DragAndDrop.objectReferences.Length == 0)
            {
                var suspensionAngle = wheelJoint2D.suspension.angle;

                var     labelContent       = new GUIContent(String.Format("{0:0.00}", suspensionAngle));
                Vector3 mainAnchorPosition = Helpers2D.GUIPointTo2DPosition(Event.current.mousePosition);

                var fontSize = HandleUtility.GetHandleSize(mainAnchorPosition) * (1f / 64f);

                var labelOffset = fontSize * EditorHelpers.FontWithBackgroundStyle.CalcSize(labelContent).y;

                EditorHelpers.OverlayLabel(mainAnchorPosition + (Camera.current.transform.up * labelOffset),
                                           labelContent,
                                           EditorHelpers.FontWithBackgroundStyle);
            }
        }
        else
        {
            if (EditorHelpers.IsWarm(suspensionAngleControlID) &&
                DragAndDrop.objectReferences.Length == 0)
            {
                if (SceneView.lastActiveSceneView)
                {
                    SceneView.lastActiveSceneView.Repaint();
                }
            }
        }

        return(false);
    }
예제 #18
0
        // Finds an anchor child from existing Views. Most of the time, this is the view closest to
        // start or end that has a valid position (e.g. not removed).
        // If a child has focus, it is given priority.
        private bool UpdateAnchorFromChildren(FlexibleView.Recycler recycler, AnchorInfo anchorInfo)
        {
            if (ChildCount == 0)
            {
                return(false);
            }

            FlexibleView.ViewHolder anchorChild = FindFirstVisibleItemView();
            if (anchorChild == null)
            {
                Log.Error("flexibleview", $"exception occurs when updating anchor information!");
                anchorChild = GetChildAt(0);
            }
            anchorInfo.Position   = anchorChild.LayoutPosition;
            anchorInfo.Coordinate = mOrientationHelper.GetViewHolderStart(anchorChild);

            return(true);
        }
예제 #19
0
        public override void Compile(ICompiler cmp, bool reverse)
        {
            GetWidth(out int min, out int max);
            cmp.EmitInfo(group_count, min, max);
            AnchorInfo anchorInfo = GetAnchorInfo(reverse);
            LinkRef    linkRef    = cmp.NewLink();

            cmp.EmitAnchor(reverse, anchorInfo.Offset, linkRef);
            if (anchorInfo.IsPosition)
            {
                cmp.EmitPosition(anchorInfo.Position);
            }
            else if (anchorInfo.IsSubstring)
            {
                cmp.EmitString(anchorInfo.Substring, anchorInfo.IgnoreCase, reverse);
            }
            cmp.EmitTrue();
            cmp.ResolveLink(linkRef);
            base.Compile(cmp, reverse);
            cmp.EmitTrue();
        }
    protected override bool SingleAnchorGUI(AnchoredJoint2D joint2D, AnchorInfo anchorInfo, JointHelpers.AnchorBias bias)
    {
        var wheelJoint2D = (WheelJoint2D)joint2D;

        var mainAnchorPosition      = JointHelpers.GetMainAnchorPosition(wheelJoint2D);
        var connectedAnchorPosition = JointHelpers.GetConnectedAnchorPosition(wheelJoint2D);

        var suspensionAngleControlID = anchorInfo.GetControlID("suspensionAngle");


        if (bias != JointHelpers.AnchorBias.Connected &&
            (GUIUtility.hotControl == suspensionAngleControlID || !Event.current.shift))
        {
            DrawAngleWidget(wheelJoint2D, suspensionAngleControlID);
        }

        var snapLineColor = GetAdjustedColor(new Color(1, 1, 1, .5f));

        //if the joint anchors are being moved, then show snap lines
        var sliderControlID = anchorInfo.GetControlID("slider");

        if (GUIUtility.hotControl == sliderControlID)
        {
            var snap = GetWantedAnchorPosition(wheelJoint2D, bias);
            using (new HandleColor(snapLineColor)) {
                Handles.DrawLine(connectedAnchorPosition, snap);
                Handles.DrawLine(mainAnchorPosition, snap);
            }
        }

        using (new HandleColor(snapLineColor))
        {
            Handles.DrawLine(mainAnchorPosition, connectedAnchorPosition);
            if (wheelJoint2D.connectedBody && GUIUtility.hotControl == suspensionAngleControlID)
            {
                Handles.DrawLine(mainAnchorPosition, GetTargetPosition(wheelJoint2D, JointHelpers.AnchorBias.Connected));
            }
        }
        return(false);
    }
예제 #21
0
    private BotBuilder[] buildBotArray(bool replaceSelected, HttpBotsWrapper bots)
    {
        BotBuilder[] botArrayTmp = new BotBuilder[3] {
            new BotBuilder(), new BotBuilder(), new BotBuilder()
        };

        foreach (HttpBots botInfo in bots.wrap)
        {
            int        id     = int.Parse(botInfo.botsSlot);
            BotBuilder botAct = botArrayTmp[id];
            botAct.platform      = botInfo.botsPlatform;
            botAct.botID         = botInfo.botsId;
            botAct.botsPrefered  = botInfo.botsPrefered;
            botAct.ownerID       = botInfo.ownerID;
            botAct.botsName      = botInfo.botsName;
            botAct.rotationSpeed = float.Parse(botInfo.botsRotationSpeed);
            botAct.speed         = float.Parse(botInfo.botsSpeed);
            string            jsonAnchorPrepared = "{\"botsAnchorInfo\":" + botInfo.botsAnchorInfo + "}";
            JsonAnchorWrapper listPartsJson      = JsonUtility.FromJson <JsonAnchorWrapper>(jsonAnchorPrepared);
            botAct.listParts = new AnchorInfo[listPartsJson.botsAnchorInfo.Length];
            int i = 0;
            foreach (JsonAnchor jsonAnchor in listPartsJson.botsAnchorInfo)
            {
                botAct.listParts[i] = new AnchorInfo();
                AnchorInfo AnchorAct = botAct.listParts[i];
                AnchorAct.anchorPos = jsonAnchor.anchorPos;
                AnchorAct.itemName  = jsonAnchor.itemName;
                i++;
            }
            if (replaceSelected)
            {
                if (botInfo.botsPrefered == "true")
                {
                    PlayerPrefs.SetInt("botsPrefered", id);
                    GameManager.instance.SelectedBotIndex = id;
                }
            }
        }
        return(botArrayTmp);
    }
예제 #22
0
    private void HandleLimits(SliderJoint2D sliderJoint2D, AnchorInfo anchorInfo)
    {
        var worldAngle = sliderJoint2D.transform.eulerAngles.z + sliderJoint2D.angle;

        var settings = SettingsHelper.GetOrCreate <SliderJoint2DSettings>(sliderJoint2D);

        JointHelpers.AnchorBias bias;
        switch (settings.anchorPriority)
        {
        case JointSettingsWithBias.AnchorPriority.Main:
            bias = JointHelpers.AnchorBias.Main;
            break;

        case JointSettingsWithBias.AnchorPriority.Connected:
            bias = JointHelpers.AnchorBias.Connected;
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }

        LimitWidget(sliderJoint2D, anchorInfo, bias, worldAngle);
    }
예제 #23
0
        internal override void EnsureAnchorReady(FlexibleView.Recycler recycler, AnchorInfo anchorInfo, int itemDirection)
        {
            bool layingOutInPrimaryDirection = (itemDirection == LayoutState.ITEM_DIRECTION_TAIL);
            int  span = anchorInfo.Position % mSpanCount;

            if (layingOutInPrimaryDirection)
            {
                // choose span 0
                while (span > 0 && anchorInfo.Position > 0)
                {
                    anchorInfo.Position--;
                    span = anchorInfo.Position;
                }
            }
            else
            {
                // choose the max span we can get. hopefully last one
                int indexLimit = ChildCount - 1;
                int pos        = anchorInfo.Position;
                int bestSpan   = span;
                while (pos < indexLimit)
                {
                    int next = (pos + 1) % mSpanCount;
                    if (next > bestSpan)
                    {
                        pos     += 1;
                        bestSpan = next;
                    }
                    else
                    {
                        break;
                    }
                }
                anchorInfo.Position = pos;
            }
        }
    protected override bool PostAnchorGUI(AnchoredJoint2D joint2D, AnchorInfo info, List<Vector2> otherAnchors,
        JointHelpers.AnchorBias bias)
    {
        var hingeJoint2D = joint2D as HingeJoint2D;
        if (hingeJoint2D == null) {
            return false;
        }

        if (!hingeJoint2D.useLimits) {
            return false;
        }

        var showAngle = false;
        float angle = 0;
        float displayAngle = 0;

        float jointAngle;
        if (EditorApplication.isPlayingOrWillChangePlaymode || Application.isPlaying) {
            jointAngle = hingeJoint2D.jointAngle;
        } else {
            jointAngle = 0;
        }

        var startPosition = JointHelpers.GetAnchorPosition(hingeJoint2D, bias);

        var mainBodyPosition = GetTargetPosition(hingeJoint2D, JointHelpers.AnchorBias.Main);

        var mainBodyAngle = JointHelpers.AngleFromAnchor(startPosition, mainBodyPosition,
            JointHelpers.GetTargetRotation(hingeJoint2D, JointHelpers.AnchorBias.Main));

        var connectedBodyPosition = GetTargetPosition(hingeJoint2D, JointHelpers.AnchorBias.Connected);

        float connectedBodyAngle;
        if (hingeJoint2D.connectedBody) {
            connectedBodyAngle = JointHelpers.AngleFromAnchor(startPosition, connectedBodyPosition,
                JointHelpers.GetTargetRotation(hingeJoint2D, JointHelpers.AnchorBias.Connected));
        } else {
            connectedBodyAngle = 0;
        }

        var angleDiff = jointAngle - (connectedBodyAngle - mainBodyAngle);

        var liveMainAngle = connectedBodyAngle + angleDiff;

        var minMainAngle = liveMainAngle - hingeJoint2D.limits.min;
        var maxMainAngle = liveMainAngle - hingeJoint2D.limits.max;

        var labelText = "";

        float angleOffset = 0;

        var settings = SettingsHelper.GetOrCreate<HingeJoint2DSettings>(hingeJoint2D);

        if (EditorHelpers.IsWarm(info.GetControlID("lowerMainAngle"))) {
            showAngle = true;
            angle = minMainAngle;
            displayAngle = hingeJoint2D.limits.min;
            labelText = "Lower: ";
            angleOffset = settings.mainAngleOffset;
        } else if (EditorHelpers.IsWarm(info.GetControlID("upperMainAngle"))) {
            showAngle = true;
            angle = maxMainAngle;
            displayAngle = hingeJoint2D.limits.max;
            labelText = "Upper: ";
            angleOffset = settings.mainAngleOffset;
        } else if (EditorHelpers.IsWarm(info.GetControlID("lowerConnectedAngle"))) {
            showAngle = true;
            angle = hingeJoint2D.limits.min;
            displayAngle = angle;
            labelText = "Lower: ";
            startPosition = JointHelpers.GetConnectedAnchorPosition(hingeJoint2D);
            angleOffset = settings.connectedAngleOffset;
        } else if (EditorHelpers.IsWarm(info.GetControlID("upperConnectedAngle"))) {
            showAngle = true;
            angle = hingeJoint2D.limits.max;
            labelText = "Upper: ";
            displayAngle = angle;
            startPosition = JointHelpers.GetConnectedAnchorPosition(hingeJoint2D);
            angleOffset = settings.connectedAngleOffset;
        }

        LimitContext(hingeJoint2D, info.GetControlID("lowerMainAngle"), Limit.Min);
        LimitContext(hingeJoint2D, info.GetControlID("upperMainAngle"), Limit.Max);
        LimitContext(hingeJoint2D, info.GetControlID("lowerConnectedAngle"), Limit.Min);
        LimitContext(hingeJoint2D, info.GetControlID("upperConnectedAngle"), Limit.Max);

        if (showAngle) {
            var distanceFromCenter = GetAngleSliderRadius(startPosition);

            var anglePosition = startPosition + Helpers2D.GetDirection(angle + angleOffset) * distanceFromCenter;

            var labelContent = new GUIContent(labelText + "\n" + String.Format("{0:0.00}", displayAngle));

            var fontSize = HandleUtility.GetHandleSize(anglePosition) * (1f / 64f);

            var labelOffset = fontSize * EditorHelpers.FontWithBackgroundStyle.CalcSize(labelContent).y;

            EditorHelpers.OverlayLabel((Vector3) anglePosition + (Camera.current.transform.up * labelOffset),
                labelContent,
                EditorHelpers.FontWithBackgroundStyle);
        }
        return false;
    }
    protected override bool PreSliderGUI(AnchoredJoint2D joint2D, AnchorInfo anchorInfo, JointHelpers.AnchorBias bias)
    {
        var hingeJoint2D = joint2D as HingeJoint2D;
        if (hingeJoint2D == null) {
            return false;
        }

        return DrawAngleLimits(hingeJoint2D, anchorInfo, bias);
    }
    protected override bool SingleAnchorGUI(AnchoredJoint2D joint2D, AnchorInfo anchorInfo, JointHelpers.AnchorBias bias)
    {
        var hingeJoint2D = joint2D as HingeJoint2D;

        if (hingeJoint2D == null) {
            return false;
        }

        if (bias == JointHelpers.AnchorBias.Either) {
            DrawLinesAndDiscs(hingeJoint2D, anchorInfo, JointHelpers.AnchorBias.Main);
            DrawLinesAndDiscs(hingeJoint2D, anchorInfo, JointHelpers.AnchorBias.Connected);
        } else {
            DrawLinesAndDiscs(hingeJoint2D, anchorInfo, bias);
        }

        var mainAnchorPosition = JointHelpers.GetMainAnchorPosition(hingeJoint2D);
        var connectedAnchorPosition = JointHelpers.GetConnectedAnchorPosition(hingeJoint2D);
        if (bias == JointHelpers.AnchorBias.Main &&
            Vector2.Distance(mainAnchorPosition, connectedAnchorPosition) > AnchorEpsilon) {
            using (new HandleColor(GetAdjustedColor(Color.green))) {
                Handles.DrawLine(mainAnchorPosition, connectedAnchorPosition);
            }
        }
        return false;
    }
예제 #27
0
        private static void UpdateAnchorInfo(IArrangedElement element)
        {
            Debug.Assert(!HasCachedBounds(element.Container), "Do not call this method with an active cached bounds list.");

            AnchorInfo anchorInfo = GetAnchorInfo(element);

            if (anchorInfo is null)
            {
                anchorInfo = new AnchorInfo();
                SetAnchorInfo(element, anchorInfo);
            }

            Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "Update anchor info");
            Debug.Indent();
            Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, element.Container is null ? "No parent" : "Parent");

            if (CommonProperties.GetNeedsAnchorLayout(element) && element.Container != null)
            {
                Rectangle  bounds        = GetCachedBounds(element);
                AnchorInfo oldAnchorInfo = new AnchorInfo
                {
                    Left   = anchorInfo.Left,
                    Top    = anchorInfo.Top,
                    Right  = anchorInfo.Right,
                    Bottom = anchorInfo.Bottom
                };

                anchorInfo.Left   = element.Bounds.Left;
                anchorInfo.Top    = element.Bounds.Top;
                anchorInfo.Right  = element.Bounds.Right;
                anchorInfo.Bottom = element.Bounds.Bottom;

                Rectangle parentDisplayRect = element.Container.DisplayRectangle;
                Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "Parent displayRectangle" + parentDisplayRect);
                int parentWidth  = parentDisplayRect.Width;
                int parentHeight = parentDisplayRect.Height;

                // The anchor is relative to the parent DisplayRectangle, so offset the anchor
                // by the DisplayRect origin
                anchorInfo.Left   -= parentDisplayRect.X;
                anchorInfo.Top    -= parentDisplayRect.Y;
                anchorInfo.Right  -= parentDisplayRect.X;
                anchorInfo.Bottom -= parentDisplayRect.Y;

                AnchorStyles anchor = GetAnchor(element);
                if (IsAnchored(anchor, AnchorStyles.Right))
                {
                    if (DpiHelper.IsScalingRequirementMet && (anchorInfo.Right - parentWidth > 0) && (oldAnchorInfo.Right < 0))
                    {
                        // parent was resized to fit its parent, or screen, we need to reuse old anchor info to prevent losing control beyond right edge
                        anchorInfo.Right = oldAnchorInfo.Right;
                        // control might have been resized, update Left anchor
                        anchorInfo.Left = oldAnchorInfo.Right - bounds.Width;
                    }
                    else
                    {
                        anchorInfo.Right -= parentWidth;

                        if (!IsAnchored(anchor, AnchorStyles.Left))
                        {
                            anchorInfo.Left -= parentWidth;
                        }
                    }
                }
                else if (!IsAnchored(anchor, AnchorStyles.Left))
                {
                    anchorInfo.Right -= (parentWidth / 2);
                    anchorInfo.Left  -= (parentWidth / 2);
                }

                if (IsAnchored(anchor, AnchorStyles.Bottom))
                {
                    if (DpiHelper.IsScalingRequirementMet && (anchorInfo.Bottom - parentHeight > 0) && (oldAnchorInfo.Bottom < 0))
                    {
                        // parent was resized to fit its parent, or screen, we need to reuse old anchor info to prevent losing control beyond bottom edge
                        anchorInfo.Bottom = oldAnchorInfo.Bottom;
                        // control might have been resized, update Top anchor
                        anchorInfo.Top = oldAnchorInfo.Bottom - bounds.Height;
                    }
                    else
                    {
                        anchorInfo.Bottom -= parentHeight;

                        if (!IsAnchored(anchor, AnchorStyles.Top))
                        {
                            anchorInfo.Top -= parentHeight;
                        }
                    }
                }
                else if (!IsAnchored(anchor, AnchorStyles.Top))
                {
                    anchorInfo.Bottom -= (parentHeight / 2);
                    anchorInfo.Top    -= (parentHeight / 2);
                }

                Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "anchor info (l,t,r,b): (" + anchorInfo.Left + ", " + anchorInfo.Top + ", " + anchorInfo.Right + ", " + anchorInfo.Bottom + ")");
            }

            Debug.Unindent();
        }
예제 #28
0
 public CalendarLayoutManager()
 {
     orientationHelper = OrientationHelper.CreateVerticalHelper(this);
     anchorInfo        = new AnchorInfo(orientationHelper, anchorCount);
     layoutState       = new LayoutState(anchorCount);
 }
예제 #29
0
    private void DrawLinesAndDiscs(HingeJoint2D hingeJoint2D, AnchorInfo anchorInfo, JointHelpers.AnchorBias bias)
    {
        var center = JointHelpers.GetAnchorPosition(hingeJoint2D, bias);

        var scale      = editorSettings.anchorScale;
        var handleSize = HandleUtility.GetHandleSize(center) * scale;

        var mainBodyPosition      = GetTargetPosition(hingeJoint2D, JointHelpers.AnchorBias.Main);
        var connectedBodyPosition = GetTargetPosition(hingeJoint2D, JointHelpers.AnchorBias.Connected);

        var settings = SettingsHelper.GetOrCreate <HingeJoint2DSettings>(hingeJoint2D);

        if (bias == JointHelpers.AnchorBias.Main)
        {
            float angleToMain;

            if (Vector2.Distance(mainBodyPosition, center) > AnchorEpsilon)
            {
                angleToMain = Helpers2D.GetAngle(mainBodyPosition - center);
            }
            else
            {
                angleToMain = JointHelpers.GetTargetRotation(hingeJoint2D, JointHelpers.AnchorBias.Main);
            }

            using (new HandleColor(GetAdjustedColor(editorSettings.anchorsToMainBodyColor)))
            {
                Handles.DrawLine(center,
                                 center + Helpers2D.GetDirection(angleToMain + settings.mainAngleOffset) * handleSize);
            }
        }
        else if (bias == JointHelpers.AnchorBias.Connected)
        {
            if (hingeJoint2D.connectedBody)
            {
                float angleToConnected;

                if (Vector2.Distance(connectedBodyPosition, center) > AnchorEpsilon)
                {
                    angleToConnected = Helpers2D.GetAngle(connectedBodyPosition - center);
                }
                else
                {
                    angleToConnected = JointHelpers.GetTargetRotation(hingeJoint2D, JointHelpers.AnchorBias.Connected);
                }

                using (new HandleColor(GetAdjustedColor(editorSettings.anchorsToConnectedBodyColor)))
                {
                    Handles.DrawLine(center,
                                     center + Helpers2D.GetDirection(angleToConnected + settings.connectedAngleOffset) * handleSize);
                }
            }
            else
            {
                using (new HandleColor(GetAdjustedColor(editorSettings.anchorsToConnectedBodyColor)))
                {
                    Handles.DrawLine(center, center + Helpers2D.GetDirection(settings.connectedAngleOffset) * handleSize);
                }
            }
        }

        if (settings.showDiscs)
        {
            var sliderControlID = anchorInfo.GetControlID("slider");

            if (editorSettings.ringDisplayMode == JointEditorSettings.RingDisplayMode.Always ||
                (editorSettings.ringDisplayMode == JointEditorSettings.RingDisplayMode.Hover &&
                 //if nothing else is hot and we are being hovered, or the anchor's widgets are hot
                 ((GUIUtility.hotControl == 0 && HandleUtility.nearestControl == sliderControlID) ||
                  GUIUtility.hotControl == sliderControlID))
                )
            {
                using (new HandleColor(GetAdjustedColor(editorSettings.mainRingColor)))
                {
                    Handles.DrawWireDisc(center, Vector3.forward, Vector2.Distance(center, mainBodyPosition));
                }

                if (hingeJoint2D.connectedBody)
                {
                    using (new HandleColor((editorSettings.connectedRingColor))) {
                        Handles.DrawWireDisc(center, Vector3.forward,
                                             Vector2.Distance(center,
                                                              connectedBodyPosition));
                    }
                }
            }
        }

        HandleUtility.Repaint();
    }
예제 #30
0
    protected override bool PostAnchorGUI(AnchoredJoint2D joint2D, AnchorInfo info, List <Vector2> otherAnchors,
                                          JointHelpers.AnchorBias bias)
    {
        var hingeJoint2D = joint2D as HingeJoint2D;

        if (hingeJoint2D == null)
        {
            return(false);
        }

        if (!hingeJoint2D.useLimits)
        {
            return(false);
        }

        var   showAngle    = false;
        float angle        = 0;
        float displayAngle = 0;

        float jointAngle;

        if (EditorApplication.isPlayingOrWillChangePlaymode || Application.isPlaying)
        {
            jointAngle = hingeJoint2D.jointAngle;
        }
        else
        {
            jointAngle = 0;
        }

        var startPosition = JointHelpers.GetAnchorPosition(hingeJoint2D, bias);

        var mainBodyPosition = GetTargetPosition(hingeJoint2D, JointHelpers.AnchorBias.Main);

        var mainBodyAngle = JointHelpers.AngleFromAnchor(startPosition, mainBodyPosition,
                                                         JointHelpers.GetTargetRotation(hingeJoint2D, JointHelpers.AnchorBias.Main));

        var connectedBodyPosition = GetTargetPosition(hingeJoint2D, JointHelpers.AnchorBias.Connected);

        float connectedBodyAngle;

        if (hingeJoint2D.connectedBody)
        {
            connectedBodyAngle = JointHelpers.AngleFromAnchor(startPosition, connectedBodyPosition,
                                                              JointHelpers.GetTargetRotation(hingeJoint2D, JointHelpers.AnchorBias.Connected));
        }
        else
        {
            connectedBodyAngle = 0;
        }

        var angleDiff = jointAngle - (connectedBodyAngle - mainBodyAngle);

        var liveMainAngle = connectedBodyAngle + angleDiff;

        var minMainAngle = liveMainAngle - hingeJoint2D.limits.min;
        var maxMainAngle = liveMainAngle - hingeJoint2D.limits.max;

        var labelText = "";

        float angleOffset = 0;

        var settings = SettingsHelper.GetOrCreate <HingeJoint2DSettings>(hingeJoint2D);

        if (EditorHelpers.IsWarm(info.GetControlID("lowerMainAngle")))
        {
            showAngle    = true;
            angle        = minMainAngle;
            displayAngle = hingeJoint2D.limits.min;
            labelText    = "Lower: ";
            angleOffset  = settings.mainAngleOffset;
        }
        else if (EditorHelpers.IsWarm(info.GetControlID("upperMainAngle")))
        {
            showAngle    = true;
            angle        = maxMainAngle;
            displayAngle = hingeJoint2D.limits.max;
            labelText    = "Upper: ";
            angleOffset  = settings.mainAngleOffset;
        }
        else if (EditorHelpers.IsWarm(info.GetControlID("lowerConnectedAngle")))
        {
            showAngle     = true;
            angle         = hingeJoint2D.limits.min;
            displayAngle  = angle;
            labelText     = "Lower: ";
            startPosition = JointHelpers.GetConnectedAnchorPosition(hingeJoint2D);
            angleOffset   = settings.connectedAngleOffset;
        }
        else if (EditorHelpers.IsWarm(info.GetControlID("upperConnectedAngle")))
        {
            showAngle     = true;
            angle         = hingeJoint2D.limits.max;
            labelText     = "Upper: ";
            displayAngle  = angle;
            startPosition = JointHelpers.GetConnectedAnchorPosition(hingeJoint2D);
            angleOffset   = settings.connectedAngleOffset;
        }

        LimitContext(hingeJoint2D, info.GetControlID("lowerMainAngle"), Limit.Min);
        LimitContext(hingeJoint2D, info.GetControlID("upperMainAngle"), Limit.Max);
        LimitContext(hingeJoint2D, info.GetControlID("lowerConnectedAngle"), Limit.Min);
        LimitContext(hingeJoint2D, info.GetControlID("upperConnectedAngle"), Limit.Max);

        if (showAngle)
        {
            var distanceFromCenter = GetAngleSliderRadius(startPosition);


            var anglePosition = startPosition + Helpers2D.GetDirection(angle + angleOffset) * distanceFromCenter;

            var labelContent = new GUIContent(labelText + "\n" + String.Format("{0:0.00}", displayAngle));

            var fontSize = HandleUtility.GetHandleSize(anglePosition) * (1f / 64f);

            var labelOffset = fontSize * EditorHelpers.FontWithBackgroundStyle.CalcSize(labelContent).y;

            EditorHelpers.OverlayLabel((Vector3)anglePosition + (Camera.current.transform.up * labelOffset),
                                       labelContent,
                                       EditorHelpers.FontWithBackgroundStyle);
        }
        return(false);
    }
 protected virtual bool PostAnchorGUI(AnchoredJoint2D joint2D, AnchorInfo info, List<Vector2> otherAnchors,
     JointHelpers.AnchorBias bias)
 {
     return false;
 }
 protected virtual IEnumerable<Vector2> GetSnapPositions(AnchoredJoint2D joint2D,
     AnchorInfo anchorInfo,
     JointHelpers.AnchorBias bias,
     Vector2 anchorPosition)
 {
     return null;
 }
    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 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 bool DrawAngleLimits(HingeJoint2D hingeJoint2D, AnchorInfo anchorInfo, JointHelpers.AnchorBias bias)
    {
        var changed = false;
        var settings = SettingsHelper.GetOrCreate<HingeJoint2DSettings>(hingeJoint2D);
        if (!settings.showAngleLimits) {
            return false;
        }

        if (hingeJoint2D.useLimits) {
            var limits = hingeJoint2D.limits;
            var minLimit = limits.min;
            var maxLimit = limits.max;

            var anchorPriority = settings.anchorPriority;

            var showMain = anchorPriority == HingeJoint2DSettings.AnchorPriority.Main ||
                           anchorPriority == HingeJoint2DSettings.AnchorPriority.Both;

            var showConnected = (anchorPriority == HingeJoint2DSettings.AnchorPriority.Connected ||
                                 anchorPriority == HingeJoint2DSettings.AnchorPriority.Both);

            var anchorPosition = JointHelpers.GetAnchorPosition(hingeJoint2D, bias);

            var distanceFromCenter = GetAngleSliderRadius(anchorPosition);
            var angleHandleSize = editorSettings.angleHandleSize;

            float jointAngle;
            var isPlaying = EditorApplication.isPlayingOrWillChangePlaymode || Application.isPlaying;
            if (isPlaying) {
                jointAngle = hingeJoint2D.jointAngle;
            } else {
                jointAngle = 0;
            }

            var mainBodyPosition = GetTargetPosition(hingeJoint2D, JointHelpers.AnchorBias.Main);

            var mainBodyAngle = JointHelpers.AngleFromAnchor(anchorPosition, mainBodyPosition,
                JointHelpers.GetTargetRotation(hingeJoint2D, JointHelpers.AnchorBias.Main));

            var connectedBodyPosition = GetTargetPosition(hingeJoint2D, JointHelpers.AnchorBias.Connected);

            float connectedBodyAngle;
            if (hingeJoint2D.connectedBody) {
                connectedBodyAngle = JointHelpers.AngleFromAnchor(anchorPosition, connectedBodyPosition,
                    JointHelpers.GetTargetRotation(hingeJoint2D, JointHelpers.AnchorBias.Connected));
            } else {
                connectedBodyAngle = 0;
            }

            var angleDiff = jointAngle - (connectedBodyAngle - mainBodyAngle);

            var liveMainAngle = connectedBodyAngle + angleDiff;

            var minMainAngle = liveMainAngle - minLimit;
            var maxMainAngle = liveMainAngle - maxLimit;

            var limitDifference = maxLimit - minLimit;

            Color limitColor, limitAreaColor;
            if (!isPlaying
                &&
                ((minLimit < jointAngle && maxLimit < jointAngle) || (minLimit > jointAngle && maxLimit > jointAngle))) {
                limitColor = editorSettings.incorrectLimitsColor;
                limitAreaColor = editorSettings.incorrectLimitsArea;
            } else {
                limitColor = editorSettings.correctLimitsColor;
                limitAreaColor = editorSettings.limitsAreaColor;
            }

            var angleWidgetColor = editorSettings.angleWidgetColor;
            var activeAngleColor = editorSettings.activeAngleColor;
            var hoverAngleColor = editorSettings.hoverAngleColor;

            if (isCreatedByTarget) {
                angleWidgetColor.a *= editorSettings.connectedJointTransparency;
                activeAngleColor.a *= editorSettings.connectedJointTransparency;
                hoverAngleColor.a *= editorSettings.connectedJointTransparency;

                limitColor.a *= editorSettings.connectedJointTransparency;
                limitAreaColor.a *= editorSettings.connectedJointTransparency;
            }

            if (showMain && bias != JointHelpers.AnchorBias.Connected) { //main or 'both'
                changed = HandleMainLimits(hingeJoint2D, anchorInfo, limitAreaColor, limitDifference, anchorPosition, distanceFromCenter, maxMainAngle, settings, limitColor, minMainAngle, angleWidgetColor, activeAngleColor, hoverAngleColor, angleHandleSize, limits, liveMainAngle);
            }
            if (showConnected && bias != JointHelpers.AnchorBias.Main) { //connected or both?
                changed = HandleConnectedLimits(hingeJoint2D, anchorInfo, mainBodyAngle, angleDiff, minLimit, maxLimit, limitAreaColor, limitDifference, anchorPosition, distanceFromCenter, settings, limitColor, angleWidgetColor, activeAngleColor, hoverAngleColor, angleHandleSize, limits, changed);
            }
        }

        return changed;
    }
    private Vector2 HandleSnapping(int controlID, IEnumerable<Vector2> snapPositions, JointHelpers.AnchorBias bias,
        AnchoredJoint2D joint,
        AnchorInfo anchorInfo, Vector2 result, float handleSize)
    {
        Vector2[] snapPositionsArray;

        var customSnapPositions = GetSnapPositions(joint, anchorInfo, bias, result);

        if (customSnapPositions != null) {
            if (snapPositions == null) {
                snapPositions = customSnapPositions;
            } else {
                snapPositions = snapPositions.Concat(customSnapPositions);
            }
        }

        if (snapPositions != null) {
            snapPositionsArray = snapPositions as Vector2[] ?? snapPositions.ToArray();
        } else {
            snapPositionsArray = null;
        }

        if (Event.current.type == EventType.repaint &&
            (editorSettings.highlightSnapPositions &&
             GUIUtility.hotControl == controlID && EditorGUI.actionKey &&
             snapPositionsArray != null)) {
            var snapHighlightColor = GetAdjustedColor(editorSettings.snapHighlightColor);

            using (new HandleColor(snapHighlightColor)) {
                foreach (var snapPosition in snapPositionsArray) {
                    Handles.CircleCap(0, snapPosition, Quaternion.identity,
                        HandleUtility.GetHandleSize(snapPosition) * EditorHelpers.HandleSizeToPixels *
                        editorSettings.snapDistance * 0.5f);
                }
            }
        }

        if (EditorGUI.EndChangeCheck() && EditorGUI.actionKey && snapPositionsArray != null) {
            foreach (var snapPosition in snapPositionsArray) {
                var distance = Vector2.Distance(result, snapPosition);
                if (distance < handleSize * EditorHelpers.HandleSizeToPixels * editorSettings.snapDistance) {
                    result = snapPosition;
                    break;
                }
            }
        }
        return result;
    }
 private static void UpdateAnchorInfo(IArrangedElement element)
 {
     AnchorInfo anchorInfo = GetAnchorInfo(element);
     if (anchorInfo == null)
     {
         anchorInfo = new AnchorInfo();
         SetAnchorInfo(element, anchorInfo);
     }
     if (CommonProperties.GetNeedsAnchorLayout(element) && (element.Container != null))
     {
         GetCachedBounds(element);
         anchorInfo.Left = element.Bounds.Left;
         anchorInfo.Top = element.Bounds.Top;
         anchorInfo.Right = element.Bounds.Right;
         anchorInfo.Bottom = element.Bounds.Bottom;
         Rectangle displayRectangle = element.Container.DisplayRectangle;
         int width = displayRectangle.Width;
         int height = displayRectangle.Height;
         anchorInfo.Left -= displayRectangle.X;
         anchorInfo.Top -= displayRectangle.Y;
         anchorInfo.Right -= displayRectangle.X;
         anchorInfo.Bottom -= displayRectangle.Y;
         AnchorStyles anchor = GetAnchor(element);
         if (IsAnchored(anchor, AnchorStyles.Right))
         {
             anchorInfo.Right -= width;
             if (!IsAnchored(anchor, AnchorStyles.Left))
             {
                 anchorInfo.Left -= width;
             }
         }
         else if (!IsAnchored(anchor, AnchorStyles.Left))
         {
             anchorInfo.Right -= width / 2;
             anchorInfo.Left -= width / 2;
         }
         if (IsAnchored(anchor, AnchorStyles.Bottom))
         {
             anchorInfo.Bottom -= height;
             if (!IsAnchored(anchor, AnchorStyles.Top))
             {
                 anchorInfo.Top -= height;
             }
         }
         else if (!IsAnchored(anchor, AnchorStyles.Top))
         {
             anchorInfo.Bottom -= height / 2;
             anchorInfo.Top -= height / 2;
         }
     }
 }
 protected virtual bool SingleAnchorGUI(AnchoredJoint2D joint2D, AnchorInfo anchorInfo, JointHelpers.AnchorBias bias)
 {
     return false;
 }
예제 #39
0
    private static bool HandleMainLimits(HingeJoint2D hingeJoint2D, AnchorInfo anchorInfo, Color limitAreaColor,
                                         float limitDifference, Vector2 anchorPosition, float distanceFromCenter,
                                         float maxMainAngle, HingeJoint2DSettings settings, Color limitColor,
                                         float minMainAngle, Color angleWidgetColor, Color activeAngleColor,
                                         Color hoverAngleColor, float angleHandleSize, JointAngleLimits2D limits,
                                         float liveMainAngle)
    {
        var changed = false;

        using (new HandleColor(limitAreaColor)) {
            if (limitDifference > 360)
            {
                Handles.DrawSolidDisc(anchorPosition, Vector3.forward, distanceFromCenter);
            }
            else
            {
                Handles.DrawSolidArc(anchorPosition, Vector3.forward,
                                     Helpers2D.GetDirection(maxMainAngle + settings.mainAngleOffset),
                                     limitDifference, distanceFromCenter);
            }
        }
        using (new HandleColor(limitColor)) {
            Vector3 minMainEnd = anchorPosition +
                                 Helpers2D.GetDirection(minMainAngle + settings.mainAngleOffset) *
                                 distanceFromCenter;
            Handles.DrawLine(anchorPosition, minMainEnd);

            Vector3 maxMainEnd = anchorPosition +
                                 Helpers2D.GetDirection(maxMainAngle + settings.mainAngleOffset) *
                                 distanceFromCenter;
            Handles.DrawLine(anchorPosition, maxMainEnd);

            if (limitDifference > 360)
            {
                Handles.DrawWireDisc(anchorPosition, Vector3.forward, distanceFromCenter);
            }
            else
            {
                Handles.DrawWireArc(anchorPosition, Vector3.forward,
                                    Helpers2D.GetDirection(maxMainAngle + settings.mainAngleOffset),
                                    limitDifference, distanceFromCenter);
            }


            EditorGUI.BeginChangeCheck();
            using (
                HandleDrawerBase drawer = new HandleCircleDrawer(angleWidgetColor, activeAngleColor,
                                                                 hoverAngleColor)) {
                minMainAngle = EditorHelpers.AngleSlider(anchorInfo.GetControlID("lowerMainAngle"), drawer,
                                                         anchorPosition,
                                                         minMainAngle + settings.mainAngleOffset,
                                                         distanceFromCenter, angleHandleSize * HandleUtility.GetHandleSize(minMainEnd) / 64) -
                               settings.mainAngleOffset;
            }

            if (EditorGUI.EndChangeCheck())
            {
                EditorHelpers.RecordUndo("Change Angle Limits", hingeJoint2D);
                limits.min          = Handles.SnapValue(liveMainAngle - minMainAngle, editorSettings.snapAngle);
                hingeJoint2D.limits = limits;
                changed             = true;
            }

            EditorGUI.BeginChangeCheck();
            using (
                HandleDrawerBase drawer = new HandleCircleDrawer(angleWidgetColor,
                                                                 activeAngleColor, hoverAngleColor)) {
                maxMainAngle = EditorHelpers.AngleSlider(anchorInfo.GetControlID("upperMainAngle"), drawer,
                                                         anchorPosition,
                                                         maxMainAngle + settings.mainAngleOffset,
                                                         distanceFromCenter, angleHandleSize * HandleUtility.GetHandleSize(maxMainEnd) / 64) -
                               settings.mainAngleOffset;
            }

            if (EditorGUI.EndChangeCheck())
            {
                EditorHelpers.RecordUndo("Change Angle Limits", hingeJoint2D);
                limits.max          = Handles.SnapValue(liveMainAngle - maxMainAngle, editorSettings.snapAngle);
                hingeJoint2D.limits = limits;
                changed             = true;
            }
        }
        return(changed);
    }
    private static bool HandleMainLimits(HingeJoint2D hingeJoint2D, AnchorInfo anchorInfo, Color limitAreaColor,
        float limitDifference, Vector2 anchorPosition, float distanceFromCenter,
        float maxMainAngle, HingeJoint2DSettings settings, Color limitColor,
        float minMainAngle, Color angleWidgetColor, Color activeAngleColor,
        Color hoverAngleColor, float angleHandleSize, JointAngleLimits2D limits,
        float liveMainAngle)
    {
        var changed = false;
        using (new HandleColor(limitAreaColor)) {
            if (limitDifference > 360) {
                Handles.DrawSolidDisc(anchorPosition, Vector3.forward, distanceFromCenter);
            } else {
                Handles.DrawSolidArc(anchorPosition, Vector3.forward,
                    Helpers2D.GetDirection(maxMainAngle + settings.mainAngleOffset),
                    limitDifference, distanceFromCenter);
            }
        }
        using (new HandleColor(limitColor)) {
            Vector3 minMainEnd = anchorPosition +
                                 Helpers2D.GetDirection(minMainAngle + settings.mainAngleOffset) *
                                 distanceFromCenter;
            Handles.DrawLine(anchorPosition, minMainEnd);

            Vector3 maxMainEnd = anchorPosition +
                                 Helpers2D.GetDirection(maxMainAngle + settings.mainAngleOffset) *
                                 distanceFromCenter;
            Handles.DrawLine(anchorPosition, maxMainEnd);

            if (limitDifference > 360) {
                Handles.DrawWireDisc(anchorPosition, Vector3.forward, distanceFromCenter);
            } else {
                Handles.DrawWireArc(anchorPosition, Vector3.forward,
                    Helpers2D.GetDirection(maxMainAngle + settings.mainAngleOffset),
                    limitDifference, distanceFromCenter);
            }

            EditorGUI.BeginChangeCheck();
            using (
                HandleDrawerBase drawer = new HandleCircleDrawer(angleWidgetColor, activeAngleColor,
                    hoverAngleColor)) {
                minMainAngle = EditorHelpers.AngleSlider(anchorInfo.GetControlID("lowerMainAngle"), drawer,
                    anchorPosition,
                    minMainAngle + settings.mainAngleOffset,
                    distanceFromCenter, angleHandleSize * HandleUtility.GetHandleSize(minMainEnd) / 64) -
                               settings.mainAngleOffset;
            }

            if (EditorGUI.EndChangeCheck()) {
                EditorHelpers.RecordUndo("Change Angle Limits", hingeJoint2D);
                limits.min = Handles.SnapValue(liveMainAngle - minMainAngle, editorSettings.snapAngle);
                hingeJoint2D.limits = limits;
                changed = true;
            }

            EditorGUI.BeginChangeCheck();
            using (
                HandleDrawerBase drawer = new HandleCircleDrawer(angleWidgetColor,
                    activeAngleColor, hoverAngleColor)) {
                maxMainAngle = EditorHelpers.AngleSlider(anchorInfo.GetControlID("upperMainAngle"), drawer,
                    anchorPosition,
                    maxMainAngle + settings.mainAngleOffset,
                    distanceFromCenter, angleHandleSize * HandleUtility.GetHandleSize(maxMainEnd) / 64) -
                               settings.mainAngleOffset;
            }

            if (EditorGUI.EndChangeCheck()) {
                EditorHelpers.RecordUndo("Change Angle Limits", hingeJoint2D);
                limits.max = Handles.SnapValue(liveMainAngle - maxMainAngle, editorSettings.snapAngle);
                hingeJoint2D.limits = limits;
                changed = true;
            }
        }
        return changed;
    }
        /// <devdoc>
        ///     Updates the Anchor information based on the controls current bounds.
        ///     This should only be called when the parent control changes or the
        ///     anchor mode changes.
        /// </devdoc>
        private static void UpdateAnchorInfo(IArrangedElement element) {
            Debug.Assert(!HasCachedBounds(element.Container),
                "Do not call this method with an active cached bounds list.");

            AnchorInfo anchorInfo = GetAnchorInfo(element);
            if(anchorInfo == null) {
                anchorInfo = new AnchorInfo();
                SetAnchorInfo(element, anchorInfo);
            }
            
            Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "Update anchor info");
            Debug.Indent();
            Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, element.Container == null ? "No parent" : "Parent");


            if (CommonProperties.GetNeedsAnchorLayout(element) && element.Container != null) {

                Rectangle bounds = GetCachedBounds(element);
                
                anchorInfo.Left = element.Bounds.Left;
                anchorInfo.Top = element.Bounds.Top;
                anchorInfo.Right = element.Bounds.Right;
                anchorInfo.Bottom = element.Bounds.Bottom;

                Rectangle parentDisplayRect = element.Container.DisplayRectangle;
                Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "Parent displayRectangle" + parentDisplayRect);
                int parentWidth = parentDisplayRect.Width;
                int parentHeight = parentDisplayRect.Height;

                // VS#46140
                // The anchor is relative to the parent DisplayRectangle, so offset the anchor
                // by the DisplayRect origin
                anchorInfo.Left -= parentDisplayRect.X;
                anchorInfo.Top -= parentDisplayRect.Y;
                anchorInfo.Right -= parentDisplayRect.X;
                anchorInfo.Bottom -= parentDisplayRect.Y;

                AnchorStyles anchor = GetAnchor(element);
                if (IsAnchored(anchor, AnchorStyles.Right)) {
                    anchorInfo.Right -= parentWidth;
                    
                    if (!IsAnchored(anchor, AnchorStyles.Left)) {
                        anchorInfo.Left -= parentWidth;
                    }
                }
                else if (!IsAnchored(anchor, AnchorStyles.Left)) {
                    anchorInfo.Right -= (parentWidth/2);
                    anchorInfo.Left -= (parentWidth/2);
                }

                if (IsAnchored(anchor, AnchorStyles.Bottom)) {
                    anchorInfo.Bottom -= parentHeight;

                    if (!IsAnchored(anchor, AnchorStyles.Top)) {
                        anchorInfo.Top -= parentHeight;
                    }
                }
                else if (!IsAnchored(anchor, AnchorStyles.Top)) {
                    anchorInfo.Bottom -= (parentHeight/2);
                    anchorInfo.Top -= (parentHeight/2);
                }
                Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "anchor info (l,t,r,b): (" + anchorInfo.Left + ", " + anchorInfo.Top  + ", " + anchorInfo.Right  + ", " + anchorInfo.Bottom + ")");
            }
            Debug.Unindent();
        }
 private static void SetAnchorInfo(IArrangedElement element, AnchorInfo value) {
     element.Properties.SetObject(_layoutInfoProperty, value);
 }
예제 #43
0
        private static Rectangle GetAnchorDestination(IArrangedElement element, Rectangle displayRect, bool measureOnly)
        {
            // Container can not be null since we AschorControls takes a non-null container.
            //
            // NB: DO NOT convert the following into Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "...")
            // because it WILL execute GetCachedBounds(element).ToString() calls even if CompModSwitches.RichLayout.TraceInfo=false
            // This in turn will lead to a cascade of native calls and callbacks
            if (CompModSwitches.RichLayout.TraceInfo)
            {
                Debug.WriteLine($"\t\t'{element}' is anchored at {GetCachedBounds(element).ToString()}");
            }

            AnchorInfo layout = GetAnchorInfo(element);

            int left   = layout.Left + displayRect.X;
            int top    = layout.Top + displayRect.Y;
            int right  = layout.Right + displayRect.X;
            int bottom = layout.Bottom + displayRect.Y;

            Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "\t\t...anchor dim (l,t,r,b) {"
                              + (left)
                              + ", " + (top)
                              + ", " + (right)
                              + ", " + (bottom)
                              + "}");

            AnchorStyles anchor = GetAnchor(element);

            if (IsAnchored(anchor, AnchorStyles.Right))
            {
                Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "\t\t...adjusting right");
                right += displayRect.Width;

                if (!IsAnchored(anchor, AnchorStyles.Left))
                {
                    Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "\t\t...adjusting left");
                    left += displayRect.Width;
                }
            }
            else if (!IsAnchored(anchor, AnchorStyles.Left))
            {
                Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "\t\t...adjusting left & right");
                right += (displayRect.Width / 2);
                left  += (displayRect.Width / 2);
            }

            if (IsAnchored(anchor, AnchorStyles.Bottom))
            {
                Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "\t\t...adjusting bottom");
                bottom += displayRect.Height;

                if (!IsAnchored(anchor, AnchorStyles.Top))
                {
                    Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "\t\t...adjusting top");
                    top += displayRect.Height;
                }
            }
            else if (!IsAnchored(anchor, AnchorStyles.Top))
            {
                Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "\t\t...adjusting top & bottom");
                bottom += (displayRect.Height / 2);
                top    += (displayRect.Height / 2);
            }

            if (!measureOnly)
            {
                // the size is actually zero, set the width and heights appropriately.
                if (right < left)
                {
                    right = left;
                }

                if (bottom < top)
                {
                    bottom = top;
                }
            }
            else
            {
                Rectangle cachedBounds = GetCachedBounds(element);
                // in this scenario we've likely been passed a 0 sized display rectangle to determine our height.
                // we will need to translate the right and bottom edges as necessary to the positive plane.

                // right < left means the control is anchored both left and right.
                // cachedBounds != element.Bounds means  the element's size has changed
                // any, all, or none of these can be true.
                if (right < left || cachedBounds.Width != element.Bounds.Width || cachedBounds.X != element.Bounds.X)
                {
                    if (cachedBounds != element.Bounds)
                    {
                        left = Math.Max(Math.Abs(left), Math.Abs(cachedBounds.Left));
                    }
                    right = left + Math.Max(element.Bounds.Width, cachedBounds.Width) + Math.Abs(right);
                }
                else
                {
                    left  = left > 0 ? left : element.Bounds.Left;
                    right = right > 0 ? right : element.Bounds.Right + Math.Abs(right);
                }

                // bottom < top means the control is anchored both top and bottom.
                // cachedBounds != element.Bounds means  the element's size has changed
                // any, all, or none of these can be true.
                if (bottom < top || cachedBounds.Height != element.Bounds.Height || cachedBounds.Y != element.Bounds.Y)
                {
                    if (cachedBounds != element.Bounds)
                    {
                        top = Math.Max(Math.Abs(top), Math.Abs(cachedBounds.Top));
                    }
                    bottom = top + Math.Max(element.Bounds.Height, cachedBounds.Height) + Math.Abs(bottom);
                }
                else
                {
                    top    = top > 0 ? top : element.Bounds.Top;
                    bottom = bottom > 0 ? bottom : element.Bounds.Bottom + Math.Abs(bottom);
                }
            }

            Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "\t\t...new anchor dim (l,t,r,b) {"
                              + (left)
                              + ", " + (top)
                              + ", " + (right)
                              + ", " + (bottom)
                              + "}");

            return(new Rectangle(left, top, right - left, bottom - top));
        }
    private void DrawLinesAndDiscs(HingeJoint2D hingeJoint2D, AnchorInfo anchorInfo, JointHelpers.AnchorBias bias)
    {
        var center = JointHelpers.GetAnchorPosition(hingeJoint2D, bias);

        var scale = editorSettings.anchorScale;
        var handleSize = HandleUtility.GetHandleSize(center) * scale;

        var mainBodyPosition = GetTargetPosition(hingeJoint2D, JointHelpers.AnchorBias.Main);
        var connectedBodyPosition = GetTargetPosition(hingeJoint2D, JointHelpers.AnchorBias.Connected);

        var settings = SettingsHelper.GetOrCreate<HingeJoint2DSettings>(hingeJoint2D);

        if (bias == JointHelpers.AnchorBias.Main) {
            float angleToMain;

            if (Vector2.Distance(mainBodyPosition, center) > AnchorEpsilon) {
                angleToMain = Helpers2D.GetAngle(mainBodyPosition - center);
            } else {
                angleToMain = JointHelpers.GetTargetRotation(hingeJoint2D, JointHelpers.AnchorBias.Main);
            }

            using (new HandleColor(GetAdjustedColor(editorSettings.anchorsToMainBodyColor)))
            {
                Handles.DrawLine(center,
                    center + Helpers2D.GetDirection(angleToMain + settings.mainAngleOffset) * handleSize);
            }
        } else if (bias == JointHelpers.AnchorBias.Connected) {
            if (hingeJoint2D.connectedBody) {
                float angleToConnected;

                if (Vector2.Distance(connectedBodyPosition, center) > AnchorEpsilon) {
                    angleToConnected = Helpers2D.GetAngle(connectedBodyPosition - center);
                } else {
                    angleToConnected = JointHelpers.GetTargetRotation(hingeJoint2D, JointHelpers.AnchorBias.Connected);
                }

                using (new HandleColor(GetAdjustedColor(editorSettings.anchorsToConnectedBodyColor)))
                {
                    Handles.DrawLine(center,
                        center + Helpers2D.GetDirection(angleToConnected + settings.connectedAngleOffset) * handleSize);
                }
            } else {
                using (new HandleColor(GetAdjustedColor(editorSettings.anchorsToConnectedBodyColor)))
                {
                    Handles.DrawLine(center, center + Helpers2D.GetDirection(settings.connectedAngleOffset) * handleSize);
                }
            }
        }

        if (settings.showDiscs) {
            var sliderControlID = anchorInfo.GetControlID("slider");

            if (editorSettings.ringDisplayMode == JointEditorSettings.RingDisplayMode.Always ||
                (editorSettings.ringDisplayMode == JointEditorSettings.RingDisplayMode.Hover &&
                 //if nothing else is hot and we are being hovered, or the anchor's widgets are hot
                 ((GUIUtility.hotControl == 0 && HandleUtility.nearestControl == sliderControlID) ||
                  GUIUtility.hotControl == sliderControlID))
                ) {
                    using (new HandleColor(GetAdjustedColor(editorSettings.mainRingColor)))
                    {
                    Handles.DrawWireDisc(center, Vector3.forward, Vector2.Distance(center, mainBodyPosition));
                }

                if (hingeJoint2D.connectedBody) {
                    using (new HandleColor((editorSettings.connectedRingColor))) {
                        Handles.DrawWireDisc(center, Vector3.forward,
                            Vector2.Distance(center,
                                connectedBodyPosition));
                    }
                }
            }
        }

        HandleUtility.Repaint();
    }
예제 #45
0
 internal virtual void EnsureAnchorReady(FlexibleViewRecycler recycler, AnchorInfo anchorInfo, int itemDirection)
 {
 }
예제 #46
0
 private static void SetAnchorInfo(IArrangedElement element, AnchorInfo value)
 {
     element.Properties.SetObject(s_layoutInfoProperty, value);
 }
    protected bool AnchorDraggingWidgetGUI(AnchoredJoint2D joint2D, AnchorInfo anchorInfo,
        IEnumerable<Vector2> otherAnchors, JointHelpers.AnchorBias bias)
    {
        var lockID = anchorInfo.GetControlID("lock");

        var changed = PreSliderGUI(joint2D, anchorInfo, bias);

        if (!changed && WantsLocking() && (Event.current.shift || GUIUtility.hotControl == lockID) &&
            (GUIUtility.hotControl == lockID || !anchorInfo.IsActive())) {
            var farAway =
                Vector2.Distance(
                    JointHelpers.GetMainAnchorPosition(joint2D),
                    GetWantedAnchorPosition(joint2D, JointHelpers.AnchorBias.Main)
                    ) > AnchorEpsilon
                || Vector2.Distance(
                    JointHelpers.GetConnectedAnchorPosition(joint2D),
                    GetWantedAnchorPosition(joint2D, JointHelpers.AnchorBias.Connected)
                    ) > AnchorEpsilon;

            if (SettingsHelper.GetOrCreate(joint2D)
                              .lockAnchors && (bias == JointHelpers.AnchorBias.Either || !farAway)) {
                //locked! show unlock
                if (ToggleUnlockButton(lockID, joint2D, bias)) {
                    changed = true;
                }
            } else {
                if (ToggleLockButton(lockID, joint2D, bias)) {
                    changed = true;
                }
            }
        } else if (SliderGUI(joint2D, anchorInfo, otherAnchors, bias)) {
            changed = true;
        }

        if (bias == JointHelpers.AnchorBias.Either) {
            DrawLineToBody(joint2D, JointHelpers.AnchorBias.Main);
            DrawLineToBody(joint2D, JointHelpers.AnchorBias.Connected);
        } else {
            DrawLineToBody(joint2D, bias);
        }

        changed = SingleAnchorGUI(joint2D, anchorInfo, bias) || changed;

        return changed;
    }
    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;
    }