提交修改
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace FairyGUI
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class ColliderHitTest : IHitTest
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Collider collider;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="contentRect"></param>
|
||||
/// <param name="localPoint"></param>
|
||||
/// <returns></returns>
|
||||
virtual public bool HitTest(Rect contentRect, Vector2 localPoint)
|
||||
{
|
||||
RaycastHit hit;
|
||||
if (!HitTestContext.GetRaycastHitFromCache(HitTestContext.camera, out hit))
|
||||
return false;
|
||||
|
||||
if (hit.collider != collider)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ffed53edbd969f3439a942ca847cd43d
|
||||
timeCreated: 1461773299
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,88 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace FairyGUI
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class HitTestContext
|
||||
{
|
||||
//set before hit test
|
||||
public static Vector3 screenPoint;
|
||||
public static Vector3 worldPoint;
|
||||
public static Vector3 direction;
|
||||
public static bool forTouch;
|
||||
public static Camera camera;
|
||||
|
||||
public static int layerMask = -1;
|
||||
public static float maxDistance = Mathf.Infinity;
|
||||
|
||||
public static Camera cachedMainCamera;
|
||||
|
||||
static Dictionary<Camera, RaycastHit?> raycastHits = new Dictionary<Camera, RaycastHit?>();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="camera"></param>
|
||||
/// <param name="hit"></param>
|
||||
/// <returns></returns>
|
||||
public static bool GetRaycastHitFromCache(Camera camera, out RaycastHit hit)
|
||||
{
|
||||
RaycastHit? hitRef;
|
||||
if (!raycastHits.TryGetValue(camera, out hitRef))
|
||||
{
|
||||
Ray ray = camera.ScreenPointToRay(screenPoint);
|
||||
if (Physics.Raycast(ray, out hit, maxDistance, layerMask))
|
||||
{
|
||||
raycastHits[camera] = hit;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
raycastHits[camera] = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (hitRef == null)
|
||||
{
|
||||
hit = new RaycastHit();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
hit = (RaycastHit)hitRef;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="camera"></param>
|
||||
/// <param name="hit"></param>
|
||||
public static void CacheRaycastHit(Camera camera, ref RaycastHit hit)
|
||||
{
|
||||
raycastHits[camera] = hit;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static void ClearRaycastHitCache()
|
||||
{
|
||||
raycastHits.Clear();
|
||||
}
|
||||
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
static void InitializeOnLoad()
|
||||
{
|
||||
cachedMainCamera = null;
|
||||
raycastHits.Clear();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19869d6307205b84a81aef6031ba1f33
|
||||
timeCreated: 1461750571
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,27 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace FairyGUI
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public enum HitTestMode
|
||||
{
|
||||
Default,
|
||||
Raycast
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public interface IHitTest
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="contentRect"></param>
|
||||
/// <param name="localPoint"></param>
|
||||
/// <returns></returns>
|
||||
bool HitTest(Rect contentRect, Vector2 localPoint);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8bbadf82645501c41957c257ab020708
|
||||
timeCreated: 1461853133
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,43 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace FairyGUI
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class MeshColliderHitTest : ColliderHitTest
|
||||
{
|
||||
public Vector2 lastHit;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="collider"></param>
|
||||
public MeshColliderHitTest(MeshCollider collider)
|
||||
{
|
||||
this.collider = collider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="contentRect"></param>
|
||||
/// <param name="localPoint"></param>
|
||||
/// <returns></returns>
|
||||
override public bool HitTest(Rect contentRect, Vector2 localPoint)
|
||||
{
|
||||
RaycastHit hit;
|
||||
if (!HitTestContext.GetRaycastHitFromCache(HitTestContext.camera, out hit))
|
||||
return false;
|
||||
|
||||
if (hit.collider != collider)
|
||||
return false;
|
||||
|
||||
lastHit = new Vector2(hit.textureCoord.x * contentRect.width, (1 - hit.textureCoord.y) * contentRect.height);
|
||||
HitTestContext.direction = Vector3.back;
|
||||
HitTestContext.worldPoint = StageCamera.main.ScreenToWorldPoint(new Vector2(lastHit.x, Screen.height - lastHit.y));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d0a2fa0c7008814795dc7f5f3bd4b19
|
||||
timeCreated: 1461750571
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,82 +0,0 @@
|
||||
using FairyGUI.Utils;
|
||||
using UnityEngine;
|
||||
|
||||
namespace FairyGUI
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class PixelHitTestData
|
||||
{
|
||||
public int pixelWidth;
|
||||
public float scale;
|
||||
public byte[] pixels;
|
||||
public int pixelsLength;
|
||||
public int pixelsOffset;
|
||||
|
||||
public void Load(ByteBuffer ba)
|
||||
{
|
||||
ba.ReadInt();
|
||||
pixelWidth = ba.ReadInt();
|
||||
scale = 1.0f / ba.ReadByte();
|
||||
pixels = ba.buffer;
|
||||
pixelsLength = ba.ReadInt();
|
||||
pixelsOffset = ba.position;
|
||||
ba.Skip(pixelsLength);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class PixelHitTest : IHitTest
|
||||
{
|
||||
public int offsetX;
|
||||
public int offsetY;
|
||||
public float sourceWidth;
|
||||
public float sourceHeight;
|
||||
|
||||
PixelHitTestData _data;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="offsetX"></param>
|
||||
/// <param name="offsetY"></param>
|
||||
public PixelHitTest(PixelHitTestData data, int offsetX, int offsetY, float sourceWidth, float sourceHeight)
|
||||
{
|
||||
_data = data;
|
||||
this.offsetX = offsetX;
|
||||
this.offsetY = offsetY;
|
||||
this.sourceWidth = sourceWidth;
|
||||
this.sourceHeight = sourceHeight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="contentRect"></param>
|
||||
/// <param name="localPoint"></param>
|
||||
/// <returns></returns>
|
||||
public bool HitTest(Rect contentRect, Vector2 localPoint)
|
||||
{
|
||||
if (!contentRect.Contains(localPoint))
|
||||
return false;
|
||||
|
||||
int x = Mathf.FloorToInt((localPoint.x * sourceWidth / contentRect.width - offsetX) * _data.scale);
|
||||
int y = Mathf.FloorToInt((localPoint.y * sourceHeight / contentRect.height - offsetY) * _data.scale);
|
||||
if (x < 0 || y < 0 || x >= _data.pixelWidth)
|
||||
return false;
|
||||
|
||||
int pos = y * _data.pixelWidth + x;
|
||||
int pos2 = pos / 8;
|
||||
int pos3 = pos % 8;
|
||||
|
||||
if (pos2 >= 0 && pos2 < _data.pixelsLength)
|
||||
return ((_data.pixels[_data.pixelsOffset + pos2] >> pos3) & 0x1) > 0;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 98cb65df7f5853c4b8e3719a28d4d81f
|
||||
timeCreated: 1535374215
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,26 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace FairyGUI
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class RectHitTest : IHitTest
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Rect rect;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="contentRect"></param>
|
||||
/// <param name="localPoint"></param>
|
||||
/// <returns></returns>
|
||||
public bool HitTest(Rect contentRect, Vector2 localPoint)
|
||||
{
|
||||
return rect.Contains(localPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92768f03d9b8dea47b1649613c4d0de7
|
||||
timeCreated: 1474896442
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,44 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace FairyGUI
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class ShapeHitTest : IHitTest
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public DisplayObject shape;
|
||||
|
||||
public ShapeHitTest(DisplayObject obj)
|
||||
{
|
||||
shape = obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="contentRect"></param>
|
||||
/// <param name="localPoint"></param>
|
||||
/// <returns></returns>
|
||||
public bool HitTest(Rect contentRect, Vector2 localPoint)
|
||||
{
|
||||
if (shape.graphics == null)
|
||||
return false;
|
||||
|
||||
if (shape.parent != null)
|
||||
{
|
||||
localPoint = shape.parent.TransformPoint(localPoint, shape);
|
||||
contentRect.size = shape.size;
|
||||
}
|
||||
|
||||
IHitTest ht = shape.graphics.meshFactory as IHitTest;
|
||||
if (ht == null)
|
||||
return false;
|
||||
|
||||
return ht.HitTest(contentRect, localPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0cd85528f2766431cafc5282f956c060
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user