Beispiel #1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        public void UpdateWithCursor(CursorType pType, Vector3?pCursorWorldPos)
        {
            vCursorWorldPosMap[pType] = pCursorWorldPos;

            bool prevent = (
                pCursorWorldPos == null ||
                !Item.IsEnabled ||
                !Item.IsVisible ||
                vPreventSelectionViaDisplayMap.Any(x => x.Value) ||
                !Item.AreParentsEnabled ||
                !Item.AreParentsVisible
                );

            if (prevent)
            {
                vHighlightDistanceMap[pType] = float.MaxValue;
                vHighlightProgressMap[pType] = 0;
                return;
            }

            Vector3 cursorWorldPos = (Vector3)pCursorWorldPos;

            HoverPointUpdater(vPoints, cursorWorldPos);

            Vector3[] pointWorldPosList = vPoints.GetWorldPoints();

            if (pointWorldPosList.Length == 0)
            {
                throw new Exception("No hover points provided.");
            }

            float sqrMagMin = float.MaxValue;

            //Vector3 nearest = Vector3.zero;

            foreach (Vector3 pointWorldPos in pointWorldPosList)
            {
                float sqrMag = (pointWorldPos - cursorWorldPos).sqrMagnitude;

                if (sqrMag < sqrMagMin)
                {
                    sqrMagMin = sqrMag;
                    //nearest = pointWorldPos;
                }
            }

            /*foreach ( Vector3 pointWorldPos in pointWorldPosList ) {
             *      Debug.DrawLine(pointWorldPos, cursorWorldPos,
             *              (pointWorldPos == nearest ? Color.red : Color.gray));
             * }*/

            float dist = (float)Math.Sqrt(sqrMagMin);
            float prog = Mathf.InverseLerp(vSettings.HighlightDistanceMax,
                                           vSettings.HighlightDistanceMin, dist * vSettings.ScaleMultiplier);

            vHighlightDistanceMap[pType] = dist;
            vHighlightProgressMap[pType] = prog;
        }
        /*--------------------------------------------------------------------------------------------*/
        public void UpdateWithCursor(CursorType pType, Vector3?pCursorWorldPos)
        {
            vCursorWorldPosMap[pType] = pCursorWorldPos;

            if (IsHighlightPrevented)
            {
                return;
            }

            if (pCursorWorldPos == null)
            {
                vHighlightDistanceMap[pType] = float.MaxValue;
                vHighlightProgressMap[pType] = 0;
                return;
            }

            Vector3 cursorWorldPos = (Vector3)pCursorWorldPos;

            HoverPointUpdater(vPoints, cursorWorldPos);

            ReadOnlyCollection <Vector3> pointWorldPosList = vPoints.GetWorldPoints();

            if (pointWorldPosList.Count == 0)
            {
                throw new Exception("No hover points provided.");
            }

            float sqrMagMin = float.MaxValue;

            //Vector3 nearest = Vector3.zero;

            for (int i = 0; i < pointWorldPosList.Count; i++)
            {
                float sqrMag = (pointWorldPosList[i] - cursorWorldPos).sqrMagnitude;

                if (sqrMag < sqrMagMin)
                {
                    sqrMagMin = sqrMag;
                    //nearest = pointWorldPosList[i];
                }
            }

            /*foreach ( Vector3 pointWorldPos in pointWorldPosList ) {
             *      Debug.DrawLine(pointWorldPos, cursorWorldPos,
             *              (pointWorldPos == nearest ? Color.red : Color.gray));
             * }*/

            float dist = (float)Math.Sqrt(sqrMagMin);
            float prog = Mathf.InverseLerp(vSettings.HighlightDistanceMax,
                                           vSettings.HighlightDistanceMin, dist * vSettings.ScaleMultiplier);

            vHighlightDistanceMap[pType] = dist;
            vHighlightProgressMap[pType] = prog;
        }