• 大小: 311KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-10
  • 语言: 其他
  • 标签: unity3d  

资源简介

unity3d的2d光影插件 unity3d的2d光影插件 unity3d的2d光影插件

资源截图

代码片段和文件信息

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace LOS {

/// 
/// LOS camera. 
/// Needs to be placed in a camera for the system to work.
/// 

[RequireComponent (typeof(Camera))]
public class LOSCamera : LOSobjectbase {

[HideInInspector]
public Vector2 halfViewboxSize;

private List _viewbox;
private Camera _camera;


public List viewbox {
get {
if (_viewbox == null) {
_viewbox = new List();
for (int i=0; i<4; i++) {
_viewbox.Add(new ViewBoxLine());
}
UpdateViewingBox();
}
return _viewbox;
}
}

public List viewboxCorners {
get {
List result = new List();
foreach (var line in viewbox) {
result.Add(line.end);
}
return result;
}
}

public void UpdateViewingBox () {
Vector2 screenSize = SHelper.GetScreenSizeInWorld(unityCamera);
halfViewboxSize = screenSize / 2 * LOSManager.instance.viewboxExtension;

Vector2 upperRight = new Vector2(halfViewboxSize.x halfViewboxSize.y) + SMath.Vec3ToVec2(_trans.position);
Vector2 upperLeft = new Vector2(-halfViewboxSize.x halfViewboxSize.y) + SMath.Vec3ToVec2(_trans.position);
Vector2 lowerLeft = new Vector2(-halfViewboxSize.x -halfViewboxSize.y) + SMath.Vec3ToVec2(_trans.position);
Vector2 lowerRight = new Vector2(halfViewboxSize.x -halfViewboxSize.y) + SMath.Vec3ToVec2(_trans.position);

viewbox[0].SetStartEnd(lowerRight upperRight); // right
viewbox[1].SetStartEnd(upperRight upperLeft); // up
viewbox[2].SetStartEnd(upperLeft lowerLeft); // left
viewbox[3].SetStartEnd(lowerLeft lowerRight); // down
}

public Camera unityCamera {
get {
if (_camera == null) {
_camera = GetComponent();
}
return _camera;
}
}


public Vector3 GetCollisionPointWithViewBox (Vector3 origin Vector3 direction) {
Vector3 point = Vector3.zero;
foreach (var line in viewbox) {
Vector2 q = line.start;
Vector2 s = line.end - line.start;

Vector2 p = SMath.Vec3ToVec2(origin);
Vector2 r = SMath.Vec3ToVec2(direction);

// The intersection is where q + u*s == p + t*r and 0 <= u <= 1 && 0 <= t
// t = (q − p) × s / (r × s)
// u = (q − p) × r / (r × s)

float crossRS = SMath.CrossProduct2D(r s);
float crossQP_S = SMath.CrossProduct2D(q - p s);
float crossQP_R = SMath.CrossProduct2D(q - p r);

if (crossRS == 0) {
// TODO: other situations
}
else {
float t = crossQP_S / crossRS;
float u = crossQP_R / crossRS;

if (0 <= u && u <= 1 && 0 <= t) {
point = q + u * s;
break;
}
}
}
return point;
}

// Works in counter-clock wise pointA is the one with smaller angle against vector (1 0)
public List GetViewboxCornersBetweenPoints (Vector3 pointA Vector3 pointB Vector3 origin bool give4CornersWhenAEqualB) {
poin

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\
     文件         107  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Core.meta
     目录           0  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Core\
     文件         107  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Core\Event.meta
     目录           0  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Core\Event\
     文件        2571  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Core\Event\LOSEventManager.cs
     文件         178  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Core\Event\LOSEventManager.cs.meta
     文件        3586  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Core\Event\LOSEventSource.cs
     文件         178  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Core\Event\LOSEventSource.cs.meta
     文件        2015  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Core\Event\LOSEventTrigger.cs
     文件         178  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Core\Event\LOSEventTrigger.cs.meta
     文件        4879  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Core\LOSCamera.cs
     文件         178  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Core\LOSCamera.cs.meta
     文件       20743  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Core\LOSFullScreenLight.cs
     文件         178  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Core\LOSFullScreenLight.cs.meta
     文件       11749  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Core\LOSLightbase.cs
     文件         178  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Core\LOSLightbase.cs.meta
     文件        5532  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Core\LOSManager.cs
     文件         178  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Core\LOSManager.cs.meta
     文件         882  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Core\LOSobjectbase.cs
     文件         178  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Core\LOSobjectbase.cs.meta
     文件        1369  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Core\LOSObstacle.cs
     文件         178  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Core\LOSObstacle.cs.meta
     文件        7345  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Core\LOSRadialLight.cs
     文件         178  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Core\LOSRadialLight.cs.meta
     文件         107  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Editor.meta
     目录           0  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Editor\
     文件         942  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Editor\LOSFullScreenLightEditor.cs
     文件         178  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Editor\LOSFullScreenLightEditor.cs.meta
     文件        2011  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Editor\LOSLightbaseEditor.cs
     文件         178  2015-06-18 12:09  2D-Light-of-Sight-Unity-master\Editor\LOSLightbaseEditor.cs.meta
............此处省略103个文件信息

评论

共有 条评论