111
This commit is contained in:
8
Assets/ThirdParty/BruteForce.meta
vendored
Normal file
8
Assets/ThirdParty/BruteForce.meta
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d68d325e695d28b408cd3b1ad4e742cc
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/ThirdParty/BruteForce/Editor.meta
vendored
Normal file
8
Assets/ThirdParty/BruteForce/Editor.meta
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84e8f8a763edd2740aed29f824219c0c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
41
Assets/ThirdParty/BruteForce/Editor/BF_TerrainEdit.cs
vendored
Normal file
41
Assets/ThirdParty/BruteForce/Editor/BF_TerrainEdit.cs
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.UI;
|
||||
|
||||
public class BF_TerrainEdit : Editor
|
||||
{
|
||||
[CustomEditor(typeof(BF_SnowTerrain))]
|
||||
class DecalMeshHelperEditor : Editor
|
||||
{
|
||||
private GUIStyle style;
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
BF_SnowTerrain myTarget = (BF_SnowTerrain)target;
|
||||
myTarget.terrainToCopy = EditorGUILayout.ObjectField("Terrain To Copy (Data Override)", myTarget.terrainToCopy, typeof(Terrain), true) as Terrain;
|
||||
myTarget.avoidCulling = EditorGUILayout.Toggle("Avoid Terrain Culling", myTarget.avoidCulling);
|
||||
if (style == null)
|
||||
{
|
||||
style = new GUIStyle(GUI.skin.button);
|
||||
}
|
||||
if (myTarget.terrainToCopy != null)
|
||||
{
|
||||
if (GUILayout.Button("Sync Terrain Data (Data Override)", style))
|
||||
{
|
||||
myTarget.CopyTerrainData();
|
||||
myTarget.MoveTerrainSync();
|
||||
style.normal.background = Texture2D.linearGrayTexture;
|
||||
}
|
||||
if (GUILayout.Button("Revert Terrain Data"))
|
||||
{
|
||||
myTarget.RevertTerrainData();
|
||||
style.normal.background = Texture2D.whiteTexture;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/BruteForce/Editor/BF_TerrainEdit.cs.meta
vendored
Normal file
11
Assets/ThirdParty/BruteForce/Editor/BF_TerrainEdit.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1c44ad8e2bf34e408cd927d6e35ae44
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/ThirdParty/BruteForce/Extra.meta
vendored
Normal file
8
Assets/ThirdParty/BruteForce/Extra.meta
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b54493ba97fdb624885ba1b045995d0d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/ThirdParty/BruteForce/Extra/BloomKino.meta
vendored
Normal file
8
Assets/ThirdParty/BruteForce/Extra/BloomKino.meta
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b5941bcf8739ec46af0ac5bfae62692
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
251
Assets/ThirdParty/BruteForce/Extra/BloomKino/BloomKino.cginc
vendored
Normal file
251
Assets/ThirdParty/BruteForce/Extra/BloomKino/BloomKino.cginc
vendored
Normal file
@@ -0,0 +1,251 @@
|
||||
//
|
||||
// Kino/Bloom v2 - Bloom filter for Unity
|
||||
//
|
||||
// Copyright (C) 2015, 2016 Keijiro Takahashi
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
// Mobile: use RGBM instead of float/half RGB
|
||||
#define USE_RGBM defined(SHADER_API_MOBILE)
|
||||
|
||||
sampler2D _MainTex;
|
||||
sampler2D _BaseTex;
|
||||
float2 _MainTex_TexelSize;
|
||||
float2 _BaseTex_TexelSize;
|
||||
half4 _MainTex_ST;
|
||||
half4 _BaseTex_ST;
|
||||
|
||||
float _PrefilterOffs;
|
||||
half _Threshold;
|
||||
half3 _Curve;
|
||||
float _SampleScale;
|
||||
half _Intensity;
|
||||
|
||||
// Brightness function
|
||||
half Brightness(half3 c)
|
||||
{
|
||||
return max(max(c.r, c.g), c.b);
|
||||
}
|
||||
|
||||
// 3-tap median filter
|
||||
half3 Median(half3 a, half3 b, half3 c)
|
||||
{
|
||||
return a + b + c - min(min(a, b), c) - max(max(a, b), c);
|
||||
}
|
||||
|
||||
// Clamp HDR value within a safe range
|
||||
half3 SafeHDR(half3 c) { return min(c, 65000); }
|
||||
half4 SafeHDR(half4 c) { return min(c, 65000); }
|
||||
|
||||
// RGBM encoding/decoding
|
||||
half4 EncodeHDR(float3 rgb)
|
||||
{
|
||||
#if USE_RGBM
|
||||
rgb *= 1.0 / 8;
|
||||
float m = max(max(rgb.r, rgb.g), max(rgb.b, 1e-6));
|
||||
m = ceil(m * 255) / 255;
|
||||
return half4(rgb / m, m);
|
||||
#else
|
||||
return half4(rgb, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
float3 DecodeHDR(half4 rgba)
|
||||
{
|
||||
#if USE_RGBM
|
||||
return rgba.rgb * rgba.a * 8;
|
||||
#else
|
||||
return rgba.rgb;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Downsample with a 4x4 box filter
|
||||
half3 DownsampleFilter(float2 uv)
|
||||
{
|
||||
float4 d = _MainTex_TexelSize.xyxy * float4(-1, -1, +1, +1);
|
||||
|
||||
half3 s;
|
||||
s = DecodeHDR(tex2D(_MainTex, uv + d.xy));
|
||||
s += DecodeHDR(tex2D(_MainTex, uv + d.zy));
|
||||
s += DecodeHDR(tex2D(_MainTex, uv + d.xw));
|
||||
s += DecodeHDR(tex2D(_MainTex, uv + d.zw));
|
||||
|
||||
return s * (1.0 / 4);
|
||||
}
|
||||
|
||||
// Downsample with a 4x4 box filter + anti-flicker filter
|
||||
half3 DownsampleAntiFlickerFilter(float2 uv)
|
||||
{
|
||||
float4 d = _MainTex_TexelSize.xyxy * float4(-1, -1, +1, +1);
|
||||
|
||||
half3 s1 = DecodeHDR(tex2D(_MainTex, uv + d.xy));
|
||||
half3 s2 = DecodeHDR(tex2D(_MainTex, uv + d.zy));
|
||||
half3 s3 = DecodeHDR(tex2D(_MainTex, uv + d.xw));
|
||||
half3 s4 = DecodeHDR(tex2D(_MainTex, uv + d.zw));
|
||||
|
||||
// Karis's luma weighted average (using brightness instead of luma)
|
||||
half s1w = 1 / (Brightness(s1) + 1);
|
||||
half s2w = 1 / (Brightness(s2) + 1);
|
||||
half s3w = 1 / (Brightness(s3) + 1);
|
||||
half s4w = 1 / (Brightness(s4) + 1);
|
||||
half one_div_wsum = 1 / (s1w + s2w + s3w + s4w);
|
||||
|
||||
return (s1 * s1w + s2 * s2w + s3 * s3w + s4 * s4w) * one_div_wsum;
|
||||
}
|
||||
|
||||
half3 UpsampleFilter(float2 uv)
|
||||
{
|
||||
#if HIGH_QUALITY
|
||||
// 9-tap bilinear upsampler (tent filter)
|
||||
float4 d = _MainTex_TexelSize.xyxy * float4(1, 1, -1, 0) * _SampleScale;
|
||||
|
||||
half3 s;
|
||||
s = DecodeHDR(tex2D(_MainTex, uv - d.xy));
|
||||
s += DecodeHDR(tex2D(_MainTex, uv - d.wy)) * 2;
|
||||
s += DecodeHDR(tex2D(_MainTex, uv - d.zy));
|
||||
|
||||
s += DecodeHDR(tex2D(_MainTex, uv + d.zw)) * 2;
|
||||
s += DecodeHDR(tex2D(_MainTex, uv )) * 4;
|
||||
s += DecodeHDR(tex2D(_MainTex, uv + d.xw)) * 2;
|
||||
|
||||
s += DecodeHDR(tex2D(_MainTex, uv + d.zy));
|
||||
s += DecodeHDR(tex2D(_MainTex, uv + d.wy)) * 2;
|
||||
s += DecodeHDR(tex2D(_MainTex, uv + d.xy));
|
||||
|
||||
return s * (1.0 / 16);
|
||||
#else
|
||||
// 4-tap bilinear upsampler
|
||||
float4 d = _MainTex_TexelSize.xyxy * float4(-1, -1, +1, +1) * (_SampleScale * 0.5);
|
||||
|
||||
half3 s;
|
||||
s = DecodeHDR(tex2D(_MainTex, uv + d.xy));
|
||||
s += DecodeHDR(tex2D(_MainTex, uv + d.zy));
|
||||
s += DecodeHDR(tex2D(_MainTex, uv + d.xw));
|
||||
s += DecodeHDR(tex2D(_MainTex, uv + d.zw));
|
||||
|
||||
return s * (1.0 / 4);
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
// Vertex shader
|
||||
//
|
||||
|
||||
v2f_img vert(appdata_img v)
|
||||
{
|
||||
v2f_img o;
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = UnityStereoScreenSpaceUVAdjust(v.texcoord, _MainTex_ST);
|
||||
return o;
|
||||
}
|
||||
|
||||
struct v2f_multitex
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float2 uvMain : TEXCOORD0;
|
||||
float2 uvBase : TEXCOORD1;
|
||||
};
|
||||
|
||||
v2f_multitex vert_multitex(appdata_img v)
|
||||
{
|
||||
v2f_multitex o;
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
o.uvMain = UnityStereoScreenSpaceUVAdjust(v.texcoord, _MainTex_ST);
|
||||
o.uvBase = UnityStereoScreenSpaceUVAdjust(v.texcoord, _BaseTex_ST);
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
if (_BaseTex_TexelSize.y < 0.0)
|
||||
o.uvBase.y = 1.0 - v.texcoord.y;
|
||||
#endif
|
||||
return o;
|
||||
}
|
||||
|
||||
//
|
||||
// fragment shader
|
||||
//
|
||||
|
||||
half4 frag_prefilter(v2f_img i) : SV_Target
|
||||
{
|
||||
float2 uv = i.uv + _MainTex_TexelSize.xy * _PrefilterOffs;
|
||||
|
||||
#if ANTI_FLICKER
|
||||
float3 d = _MainTex_TexelSize.xyx * float3(1, 1, 0);
|
||||
half4 s0 = SafeHDR(tex2D(_MainTex, uv));
|
||||
half3 s1 = SafeHDR(tex2D(_MainTex, uv - d.xz).rgb);
|
||||
half3 s2 = SafeHDR(tex2D(_MainTex, uv + d.xz).rgb);
|
||||
half3 s3 = SafeHDR(tex2D(_MainTex, uv - d.zy).rgb);
|
||||
half3 s4 = SafeHDR(tex2D(_MainTex, uv + d.zy).rgb);
|
||||
half3 m = Median(Median(s0.rgb, s1, s2), s3, s4);
|
||||
#else
|
||||
half4 s0 = SafeHDR(tex2D(_MainTex, uv));
|
||||
half3 m = s0.rgb;
|
||||
#endif
|
||||
|
||||
#if UNITY_COLORSPACE_GAMMA
|
||||
m = GammaToLinearSpace(m);
|
||||
#endif
|
||||
// Pixel brightness
|
||||
half br = Brightness(m);
|
||||
|
||||
// Under-threshold part: quadratic curve
|
||||
half rq = clamp(br - _Curve.x, 0, _Curve.y);
|
||||
rq = _Curve.z * rq * rq;
|
||||
|
||||
// Combine and apply the brightness response curve.
|
||||
m *= max(rq, br - _Threshold) / max(br, 1e-5);
|
||||
|
||||
return EncodeHDR(m);
|
||||
}
|
||||
|
||||
half4 frag_downsample1(v2f_img i) : SV_Target
|
||||
{
|
||||
#if ANTI_FLICKER
|
||||
return EncodeHDR(DownsampleAntiFlickerFilter(i.uv));
|
||||
#else
|
||||
return EncodeHDR(DownsampleFilter(i.uv));
|
||||
#endif
|
||||
}
|
||||
|
||||
half4 frag_downsample2(v2f_img i) : SV_Target
|
||||
{
|
||||
return EncodeHDR(DownsampleFilter(i.uv));
|
||||
}
|
||||
|
||||
half4 frag_upsample(v2f_multitex i) : SV_Target
|
||||
{
|
||||
half3 base = DecodeHDR(tex2D(_BaseTex, i.uvBase));
|
||||
half3 blur = UpsampleFilter(i.uvMain);
|
||||
return EncodeHDR(base + blur);
|
||||
}
|
||||
|
||||
half4 frag_upsample_final(v2f_multitex i) : SV_Target
|
||||
{
|
||||
half4 base = tex2D(_BaseTex, i.uvBase);
|
||||
half3 blur = UpsampleFilter(i.uvMain);
|
||||
#if UNITY_COLORSPACE_GAMMA
|
||||
base.rgb = GammaToLinearSpace(base.rgb);
|
||||
#endif
|
||||
half3 cout = base.rgb + blur * _Intensity;
|
||||
#if UNITY_COLORSPACE_GAMMA
|
||||
cout = LinearToGammaSpace(cout);
|
||||
#endif
|
||||
return half4(cout, base.a);
|
||||
}
|
||||
9
Assets/ThirdParty/BruteForce/Extra/BloomKino/BloomKino.cginc.meta
vendored
Normal file
9
Assets/ThirdParty/BruteForce/Extra/BloomKino/BloomKino.cginc.meta
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b8325918052c4c5492831d116e3ed27
|
||||
timeCreated: 1463470294
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
268
Assets/ThirdParty/BruteForce/Extra/BloomKino/BloomKino.cs
vendored
Normal file
268
Assets/ThirdParty/BruteForce/Extra/BloomKino/BloomKino.cs
vendored
Normal file
@@ -0,0 +1,268 @@
|
||||
//
|
||||
// Kino/Bloom v2 - Bloom filter for Unity
|
||||
//
|
||||
// Copyright (C) 2015, 2016 Keijiro Takahashi
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
using UnityEngine;
|
||||
|
||||
namespace Kino
|
||||
{
|
||||
[ExecuteInEditMode]
|
||||
[RequireComponent(typeof(Camera))]
|
||||
[AddComponentMenu("Kino Image Effects/BloomKino")]
|
||||
public class BloomKino : MonoBehaviour
|
||||
{
|
||||
#if !UNITY_ANDROID && !UNITY_IOS && !UNITY_WEBGL
|
||||
#region Public Properties
|
||||
|
||||
/// Prefilter threshold (gamma-encoded)
|
||||
/// Filters out pixels under this level of brightness.
|
||||
public float thresholdGamma {
|
||||
get { return Mathf.Max(_threshold, 0); }
|
||||
set { _threshold = value; }
|
||||
}
|
||||
|
||||
/// Prefilter threshold (linearly-encoded)
|
||||
/// Filters out pixels under this level of brightness.
|
||||
public float thresholdLinear {
|
||||
get { return GammaToLinear(thresholdGamma); }
|
||||
set { _threshold = LinearToGamma(value); }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("Filters out pixels under this level of brightness.")]
|
||||
float _threshold = 0.8f;
|
||||
|
||||
/// Soft-knee coefficient
|
||||
/// Makes transition between under/over-threshold gradual.
|
||||
public float softKnee {
|
||||
get { return _softKnee; }
|
||||
set { _softKnee = value; }
|
||||
}
|
||||
|
||||
[SerializeField, Range(0, 1)]
|
||||
[Tooltip("Makes transition between under/over-threshold gradual.")]
|
||||
float _softKnee = 0.5f;
|
||||
|
||||
/// Bloom radius
|
||||
/// Changes extent of veiling effects in a screen
|
||||
/// resolution-independent fashion.
|
||||
public float radius {
|
||||
get { return _radius; }
|
||||
set { _radius = value; }
|
||||
}
|
||||
|
||||
[SerializeField, Range(1, 7)]
|
||||
[Tooltip("Changes extent of veiling effects\n" +
|
||||
"in a screen resolution-independent fashion.")]
|
||||
float _radius = 2.5f;
|
||||
|
||||
/// Bloom intensity
|
||||
/// Blend factor of the result image.
|
||||
public float intensity {
|
||||
get { return Mathf.Max(_intensity, 0); }
|
||||
set { _intensity = value; }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("Blend factor of the result image.")]
|
||||
float _intensity = 0.8f;
|
||||
|
||||
/// High quality mode
|
||||
/// Controls filter quality and buffer resolution.
|
||||
public bool highQuality {
|
||||
get { return _highQuality; }
|
||||
set { _highQuality = value; }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("Controls filter quality and buffer resolution.")]
|
||||
bool _highQuality = true;
|
||||
|
||||
/// Anti-flicker filter
|
||||
/// Reduces flashing noise with an additional filter.
|
||||
[SerializeField]
|
||||
[Tooltip("Reduces flashing noise with an additional filter.")]
|
||||
bool _antiFlicker = true;
|
||||
|
||||
public bool antiFlicker {
|
||||
get { return _antiFlicker; }
|
||||
set { _antiFlicker = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Members
|
||||
|
||||
[SerializeField, HideInInspector]
|
||||
Shader _shader;
|
||||
|
||||
Material _material;
|
||||
|
||||
const int kMaxIterations = 16;
|
||||
RenderTexture[] _blurBuffer1 = new RenderTexture[kMaxIterations];
|
||||
RenderTexture[] _blurBuffer2 = new RenderTexture[kMaxIterations];
|
||||
|
||||
float LinearToGamma(float x)
|
||||
{
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
return Mathf.LinearToGammaSpace(x);
|
||||
#else
|
||||
if (x <= 0.0031308f)
|
||||
return 12.92f * x;
|
||||
else
|
||||
return 1.055f * Mathf.Pow(x, 1 / 2.4f) - 0.055f;
|
||||
#endif
|
||||
}
|
||||
|
||||
float GammaToLinear(float x)
|
||||
{
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
return Mathf.GammaToLinearSpace(x);
|
||||
#else
|
||||
if (x <= 0.04045f)
|
||||
return x / 12.92f;
|
||||
else
|
||||
return Mathf.Pow((x + 0.055f) / 1.055f, 2.4f);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region MonoBehaviour Functions
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
var shader = _shader ? _shader : Shader.Find("Hidden/Kino/BloomKino");
|
||||
_material = new Material(shader);
|
||||
_material.hideFlags = HideFlags.DontSave;
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
DestroyImmediate(_material);
|
||||
}
|
||||
|
||||
void OnRenderImage(RenderTexture source, RenderTexture destination)
|
||||
{
|
||||
var useRGBM = Application.isMobilePlatform;
|
||||
|
||||
// source texture size
|
||||
var tw = source.width;
|
||||
var th = source.height;
|
||||
|
||||
// halve the texture size for the low quality mode
|
||||
if (!_highQuality)
|
||||
{
|
||||
tw /= 2;
|
||||
th /= 2;
|
||||
}
|
||||
|
||||
// blur buffer format
|
||||
var rtFormat = useRGBM ?
|
||||
RenderTextureFormat.Default : RenderTextureFormat.DefaultHDR;
|
||||
|
||||
// determine the iteration count
|
||||
var logh = Mathf.Log(th, 2) + _radius - 8;
|
||||
var logh_i = (int)logh;
|
||||
var iterations = Mathf.Clamp(logh_i, 1, kMaxIterations);
|
||||
|
||||
// update the shader properties
|
||||
var lthresh = thresholdLinear;
|
||||
_material.SetFloat("_Threshold", lthresh);
|
||||
|
||||
var knee = lthresh * _softKnee + 1e-5f;
|
||||
var curve = new Vector3(lthresh - knee, knee * 2, 0.25f / knee);
|
||||
_material.SetVector("_Curve", curve);
|
||||
|
||||
var pfo = !_highQuality && _antiFlicker;
|
||||
_material.SetFloat("_PrefilterOffs", pfo ? -0.5f : 0.0f);
|
||||
|
||||
_material.SetFloat("_SampleScale", 0.5f + logh - logh_i);
|
||||
_material.SetFloat("_Intensity", intensity);
|
||||
|
||||
// prefilter pass
|
||||
var prefiltered = RenderTexture.GetTemporary(tw, th, 0, rtFormat);
|
||||
var pass = _antiFlicker ? 1 : 0;
|
||||
Graphics.Blit(source, prefiltered, _material, pass);
|
||||
|
||||
// construct a mip pyramid
|
||||
var last = prefiltered;
|
||||
for (var level = 0; level < iterations; level++)
|
||||
{
|
||||
_blurBuffer1[level] = RenderTexture.GetTemporary(
|
||||
last.width / 2, last.height / 2, 0, rtFormat
|
||||
);
|
||||
|
||||
pass = (level == 0) ? (_antiFlicker ? 3 : 2) : 4;
|
||||
Graphics.Blit(last, _blurBuffer1[level], _material, pass);
|
||||
|
||||
last = _blurBuffer1[level];
|
||||
}
|
||||
|
||||
// upsample and combine loop
|
||||
for (var level = iterations - 2; level >= 0; level--)
|
||||
{
|
||||
var basetex = _blurBuffer1[level];
|
||||
_material.SetTexture("_BaseTex", basetex);
|
||||
|
||||
_blurBuffer2[level] = RenderTexture.GetTemporary(
|
||||
basetex.width, basetex.height, 0, rtFormat
|
||||
);
|
||||
|
||||
pass = _highQuality ? 6 : 5;
|
||||
Graphics.Blit(last, _blurBuffer2[level], _material, pass);
|
||||
last = _blurBuffer2[level];
|
||||
}
|
||||
|
||||
// finish process
|
||||
if (_material.GetTexture("_BaseTex") != null)
|
||||
{
|
||||
if (source.dimension != _material.GetTexture("_BaseTex").dimension)
|
||||
{
|
||||
this.enabled = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
_material.SetTexture("_BaseTex", source);
|
||||
pass = _highQuality ? 8 : 7;
|
||||
Graphics.Blit(last, destination, _material, pass);
|
||||
|
||||
// release the temporary buffers
|
||||
for (var i = 0; i < kMaxIterations; i++)
|
||||
{
|
||||
if (_blurBuffer1[i] != null)
|
||||
RenderTexture.ReleaseTemporary(_blurBuffer1[i]);
|
||||
|
||||
if (_blurBuffer2[i] != null)
|
||||
RenderTexture.ReleaseTemporary(_blurBuffer2[i]);
|
||||
|
||||
_blurBuffer1[i] = null;
|
||||
_blurBuffer2[i] = null;
|
||||
}
|
||||
|
||||
RenderTexture.ReleaseTemporary(prefiltered);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endif
|
||||
}
|
||||
}
|
||||
13
Assets/ThirdParty/BruteForce/Extra/BloomKino/BloomKino.cs.meta
vendored
Normal file
13
Assets/ThirdParty/BruteForce/Extra/BloomKino/BloomKino.cs.meta
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6363bba448bf64e60a763433f9ddf81b
|
||||
timeCreated: 1445671165
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- _shader: {fileID: 4800000, guid: 5a711a01011934ebcb58ef5ad52159d6, type: 3}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
141
Assets/ThirdParty/BruteForce/Extra/BloomKino/BloomKino.shader
vendored
Normal file
141
Assets/ThirdParty/BruteForce/Extra/BloomKino/BloomKino.shader
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
//
|
||||
// Kino/Bloom v2 - Bloom filter for Unity
|
||||
//
|
||||
// Copyright (C) 2015, 2016 Keijiro Takahashi
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
Shader "Hidden/Kino/BloomKino"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex("", 2D) = "" {}
|
||||
_BaseTex("", 2D) = "" {}
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
// 0: Prefilter
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
CGPROGRAM
|
||||
#pragma multi_compile _ UNITY_COLORSPACE_GAMMA
|
||||
#include "BloomKino.cginc"
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag_prefilter
|
||||
#pragma target 3.0
|
||||
ENDCG
|
||||
}
|
||||
// 1: Prefilter with anti-flicker
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
CGPROGRAM
|
||||
#define ANTI_FLICKER 1
|
||||
#pragma multi_compile _ UNITY_COLORSPACE_GAMMA
|
||||
#include "BloomKino.cginc"
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag_prefilter
|
||||
#pragma target 3.0
|
||||
ENDCG
|
||||
}
|
||||
// 2: First level downsampler
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
CGPROGRAM
|
||||
#include "BloomKino.cginc"
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag_downsample1
|
||||
#pragma target 3.0
|
||||
ENDCG
|
||||
}
|
||||
// 3: First level downsampler with anti-flicker
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
CGPROGRAM
|
||||
#define ANTI_FLICKER 1
|
||||
#include "BloomKino.cginc"
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag_downsample1
|
||||
#pragma target 3.0
|
||||
ENDCG
|
||||
}
|
||||
// 4: Second level downsampler
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
CGPROGRAM
|
||||
#include "BloomKino.cginc"
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag_downsample2
|
||||
#pragma target 3.0
|
||||
ENDCG
|
||||
}
|
||||
// 5: Upsampler
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
CGPROGRAM
|
||||
#include "BloomKino.cginc"
|
||||
#pragma vertex vert_multitex
|
||||
#pragma fragment frag_upsample
|
||||
#pragma target 3.0
|
||||
ENDCG
|
||||
}
|
||||
// 6: High quality upsampler
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
CGPROGRAM
|
||||
#define HIGH_QUALITY 1
|
||||
#include "BloomKino.cginc"
|
||||
#pragma vertex vert_multitex
|
||||
#pragma fragment frag_upsample
|
||||
#pragma target 3.0
|
||||
ENDCG
|
||||
}
|
||||
// 7: Combiner
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
CGPROGRAM
|
||||
#pragma multi_compile _ UNITY_COLORSPACE_GAMMA
|
||||
#include "BloomKino.cginc"
|
||||
#pragma vertex vert_multitex
|
||||
#pragma fragment frag_upsample_final
|
||||
#pragma target 3.0
|
||||
ENDCG
|
||||
}
|
||||
// 8: High quality combiner
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
CGPROGRAM
|
||||
#define HIGH_QUALITY 1
|
||||
#pragma multi_compile _ UNITY_COLORSPACE_GAMMA
|
||||
#include "BloomKino.cginc"
|
||||
#pragma vertex vert_multitex
|
||||
#pragma fragment frag_upsample_final
|
||||
#pragma target 3.0
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
9
Assets/ThirdParty/BruteForce/Extra/BloomKino/BloomKino.shader.meta
vendored
Normal file
9
Assets/ThirdParty/BruteForce/Extra/BloomKino/BloomKino.shader.meta
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a711a01011934ebcb58ef5ad52159d6
|
||||
timeCreated: 1435809878
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/ThirdParty/BruteForce/Extra/BloomKino/Other.meta
vendored
Normal file
8
Assets/ThirdParty/BruteForce/Extra/BloomKino/Other.meta
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b41e1cdacebace34588d09f21a79b50c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/ThirdParty/BruteForce/Extra/BloomKino/Other/Editor.meta
vendored
Normal file
8
Assets/ThirdParty/BruteForce/Extra/BloomKino/Other/Editor.meta
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62047f7ec6cc07245b2f03b93c15cfad
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
79
Assets/ThirdParty/BruteForce/Extra/BloomKino/Other/Editor/BloomKinoEditor.cs
vendored
Normal file
79
Assets/ThirdParty/BruteForce/Extra/BloomKino/Other/Editor/BloomKinoEditor.cs
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// Kino/Bloom v2 - Bloom filter for Unity
|
||||
//
|
||||
// Copyright (C) 2015, 2016 Keijiro Takahashi
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Kino
|
||||
{
|
||||
|
||||
#if !UNITY_ANDROID && !UNITY_IOS && !UNITY_WEBGL
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(BloomKino))]
|
||||
public class BloomKinoEditor : Editor
|
||||
{
|
||||
BloomKinoGraphDrawer _graph;
|
||||
|
||||
SerializedProperty _threshold;
|
||||
SerializedProperty _softKnee;
|
||||
SerializedProperty _radius;
|
||||
SerializedProperty _intensity;
|
||||
SerializedProperty _highQuality;
|
||||
SerializedProperty _antiFlicker;
|
||||
|
||||
static GUIContent _textThreshold = new GUIContent("Threshold (gamma)");
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
_graph = new BloomKinoGraphDrawer();
|
||||
_threshold = serializedObject.FindProperty("_threshold");
|
||||
_softKnee = serializedObject.FindProperty("_softKnee");
|
||||
_radius = serializedObject.FindProperty("_radius");
|
||||
_intensity = serializedObject.FindProperty("_intensity");
|
||||
_highQuality = serializedObject.FindProperty("_highQuality");
|
||||
_antiFlicker = serializedObject.FindProperty("_antiFlicker");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
|
||||
if (!serializedObject.isEditingMultipleObjects) {
|
||||
EditorGUILayout.Space();
|
||||
_graph.Prepare((BloomKino)target);
|
||||
_graph.DrawGraph();
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
EditorGUILayout.PropertyField(_threshold, _textThreshold);
|
||||
EditorGUILayout.PropertyField(_softKnee);
|
||||
EditorGUILayout.PropertyField(_intensity);
|
||||
EditorGUILayout.PropertyField(_radius);
|
||||
EditorGUILayout.PropertyField(_highQuality);
|
||||
EditorGUILayout.PropertyField(_antiFlicker);
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
12
Assets/ThirdParty/BruteForce/Extra/BloomKino/Other/Editor/BloomKinoEditor.cs.meta
vendored
Normal file
12
Assets/ThirdParty/BruteForce/Extra/BloomKino/Other/Editor/BloomKinoEditor.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 036bc30d96c3349ce86bfc8d95667da7
|
||||
timeCreated: 1435816745
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
187
Assets/ThirdParty/BruteForce/Extra/BloomKino/Other/Editor/BloomKinoGraphDrawer.cs
vendored
Normal file
187
Assets/ThirdParty/BruteForce/Extra/BloomKino/Other/Editor/BloomKinoGraphDrawer.cs
vendored
Normal file
@@ -0,0 +1,187 @@
|
||||
//
|
||||
// Kino/Bloom v2 - Bloom filter for Unity
|
||||
//
|
||||
// Copyright (C) 2015, 2016 Keijiro Takahashi
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Kino
|
||||
{
|
||||
// Class used for drawing the brightness response curve
|
||||
|
||||
#if !UNITY_ANDROID && !UNITY_IOS && !UNITY_WEBGL
|
||||
public class BloomKinoGraphDrawer
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
// Update internal state with a given bloom instance.
|
||||
public void Prepare(BloomKino bloom)
|
||||
{
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
if (bloom.GetComponent<Camera>().allowHDR)
|
||||
#else
|
||||
if (bloom.GetComponent<Camera>().hdr)
|
||||
#endif
|
||||
{
|
||||
_rangeX = 6;
|
||||
_rangeY = 1.5f;
|
||||
}
|
||||
else
|
||||
{
|
||||
_rangeX = 1;
|
||||
_rangeY = 1;
|
||||
}
|
||||
|
||||
_threshold = bloom.thresholdLinear;
|
||||
_knee = bloom.softKnee * _threshold + 1e-5f;
|
||||
|
||||
// Intensity is capped to prevent sampling errors.
|
||||
_intensity = Mathf.Min(bloom.intensity, 10);
|
||||
}
|
||||
|
||||
// Draw the graph at the current position.
|
||||
public void DrawGraph()
|
||||
{
|
||||
_rectGraph = GUILayoutUtility.GetRect(128, 80);
|
||||
|
||||
// Background
|
||||
DrawRect(0, 0, _rangeX, _rangeY, 0.1f, 0.4f);
|
||||
|
||||
// Soft-knee range
|
||||
DrawRect(_threshold - _knee, 0, _threshold + _knee, _rangeY, 0.25f, -1);
|
||||
|
||||
// Horizontal lines
|
||||
for (var i = 1; i < _rangeY; i++)
|
||||
DrawLine(0, i, _rangeX, i, 0.4f);
|
||||
|
||||
// Vertical lines
|
||||
for (var i = 1; i < _rangeX; i++)
|
||||
DrawLine(i, 0, i, _rangeY, 0.4f);
|
||||
|
||||
// Label
|
||||
Handles.Label(
|
||||
PointInRect(0, _rangeY) + Vector3.right,
|
||||
"Brightness Response (linear)", EditorStyles.miniLabel
|
||||
);
|
||||
|
||||
// Threshold line
|
||||
DrawLine(_threshold, 0, _threshold, _rangeY, 0.6f);
|
||||
|
||||
// Response curve
|
||||
var vcount = 0;
|
||||
while (vcount < _curveResolution)
|
||||
{
|
||||
var x = _rangeX * vcount / (_curveResolution - 1);
|
||||
var y = ResponseFunction(x);
|
||||
if (y < _rangeY)
|
||||
{
|
||||
_curveVertices[vcount++] = PointInRect(x, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (vcount > 1)
|
||||
{
|
||||
// Extend the last segment to the top edge of the rect.
|
||||
var v1 = _curveVertices[vcount - 2];
|
||||
var v2 = _curveVertices[vcount - 1];
|
||||
var clip = (_rectGraph.y - v1.y) / (v2.y - v1.y);
|
||||
_curveVertices[vcount - 1] = v1 + (v2 - v1) * clip;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (vcount > 1)
|
||||
{
|
||||
Handles.color = Color.white * 0.9f;
|
||||
Handles.DrawAAPolyLine(2.0f, vcount, _curveVertices);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Response Function
|
||||
|
||||
float _threshold;
|
||||
float _knee;
|
||||
float _intensity;
|
||||
|
||||
float ResponseFunction(float x)
|
||||
{
|
||||
var rq = Mathf.Clamp(x - _threshold + _knee, 0, _knee * 2);
|
||||
rq = rq * rq * 0.25f / _knee;
|
||||
return Mathf.Max(rq, x - _threshold) * _intensity;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Graph Functions
|
||||
|
||||
// Number of vertices in curve
|
||||
const int _curveResolution = 96;
|
||||
|
||||
// Vertex buffers
|
||||
Vector3[] _rectVertices = new Vector3[4];
|
||||
Vector3[] _lineVertices = new Vector3[2];
|
||||
Vector3[] _curveVertices = new Vector3[_curveResolution];
|
||||
|
||||
Rect _rectGraph;
|
||||
float _rangeX;
|
||||
float _rangeY;
|
||||
|
||||
// Transform a point into the graph rect.
|
||||
Vector3 PointInRect(float x, float y)
|
||||
{
|
||||
x = Mathf.Lerp(_rectGraph.x, _rectGraph.xMax, x / _rangeX);
|
||||
y = Mathf.Lerp(_rectGraph.yMax, _rectGraph.y, y / _rangeY);
|
||||
return new Vector3(x, y, 0);
|
||||
}
|
||||
|
||||
// Draw a line in the graph rect.
|
||||
void DrawLine(float x1, float y1, float x2, float y2, float grayscale)
|
||||
{
|
||||
_lineVertices[0] = PointInRect(x1, y1);
|
||||
_lineVertices[1] = PointInRect(x2, y2);
|
||||
Handles.color = Color.white * grayscale;
|
||||
Handles.DrawAAPolyLine(2.0f, _lineVertices);
|
||||
}
|
||||
|
||||
// Draw a rect in the graph rect.
|
||||
void DrawRect(float x1, float y1, float x2, float y2, float fill, float line)
|
||||
{
|
||||
_rectVertices[0] = PointInRect(x1, y1);
|
||||
_rectVertices[1] = PointInRect(x2, y1);
|
||||
_rectVertices[2] = PointInRect(x2, y2);
|
||||
_rectVertices[3] = PointInRect(x1, y2);
|
||||
|
||||
Handles.DrawSolidRectangleWithOutline(
|
||||
_rectVertices,
|
||||
fill < 0 ? Color.clear : Color.white * fill,
|
||||
line < 0 ? Color.clear : Color.white * line
|
||||
);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
12
Assets/ThirdParty/BruteForce/Extra/BloomKino/Other/Editor/BloomKinoGraphDrawer.cs.meta
vendored
Normal file
12
Assets/ThirdParty/BruteForce/Extra/BloomKino/Other/Editor/BloomKinoGraphDrawer.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4afcb2949e7fb42679b587b8848b7e02
|
||||
timeCreated: 1457674915
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/ThirdParty/BruteForce/Scripts.meta
vendored
Normal file
8
Assets/ThirdParty/BruteForce/Scripts.meta
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3e95e6fd06fca649bcab063648904f3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
338
Assets/ThirdParty/BruteForce/Scripts/BF_AddSnow.cs
vendored
Normal file
338
Assets/ThirdParty/BruteForce/Scripts/BF_AddSnow.cs
vendored
Normal file
@@ -0,0 +1,338 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public class BF_AddSnow : MonoBehaviour
|
||||
{
|
||||
public Material snowMaterial;
|
||||
public float angle = 80f;
|
||||
public bool isAuto = false;
|
||||
public float intersectionOffset = 0.25f;
|
||||
public bool useIntersection = false;
|
||||
public bool useUpdatedRotation = false;
|
||||
|
||||
private Mesh originalMesh;
|
||||
private MeshFilter meshFilter;
|
||||
private Mesh newMesh;
|
||||
private GameObject newGO;
|
||||
private float yIntersection = 0f;
|
||||
private Quaternion ySlope = Quaternion.identity;
|
||||
private float zNormal = 0;
|
||||
private Vector3 normalHit = Vector3.zero;
|
||||
private float oldyIntersection = -1f;
|
||||
|
||||
private int[] oldTri;
|
||||
private Vector3[] oldVert;
|
||||
private Vector3[] oldNorm;
|
||||
private Vector3[] oldNormWorld;
|
||||
private Vector2[] oldUV;
|
||||
private Color[] oldCol;
|
||||
|
||||
private List<int> triangles = new List<int>();
|
||||
private List<Vector3> vertexs = new List<Vector3>();
|
||||
private List<Vector2> uvs = new List<Vector2>();
|
||||
private List<Color> cols = new List<Color>();
|
||||
|
||||
void Start()
|
||||
{
|
||||
CheckValues();
|
||||
BuildInitialGeometry();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (useIntersection)
|
||||
{
|
||||
CheckIntersection();
|
||||
}
|
||||
|
||||
if (useUpdatedRotation)
|
||||
{
|
||||
UpdateVertexColor();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void CheckValues()
|
||||
{
|
||||
meshFilter = gameObject.GetComponent<MeshFilter>();
|
||||
originalMesh = meshFilter.mesh;
|
||||
oldTri = originalMesh.triangles;
|
||||
oldVert = originalMesh.vertices;
|
||||
oldNorm = originalMesh.normals;
|
||||
oldNormWorld = oldNorm;
|
||||
|
||||
if (isAuto)
|
||||
{
|
||||
int k = 0;
|
||||
foreach (Vector3 norm in oldNorm)
|
||||
{
|
||||
oldNormWorld[k] = this.transform.localToWorldMatrix.MultiplyVector(norm).normalized;
|
||||
k++;
|
||||
}
|
||||
oldCol = new Color[oldVert.Length];
|
||||
}
|
||||
else
|
||||
{
|
||||
oldCol = originalMesh.colors;
|
||||
}
|
||||
oldUV = originalMesh.uv;
|
||||
}
|
||||
|
||||
private void CheckIntersection()
|
||||
{
|
||||
int layerMask = 1 << 0 | 1 << 4;
|
||||
RaycastHit hit;
|
||||
RaycastHit hitIfHit;
|
||||
|
||||
if (Physics.Raycast(transform.position + Vector3.up*5f, Vector3.down, out hit, 200, layerMask))
|
||||
{
|
||||
if (hit.transform != this.transform)
|
||||
{
|
||||
yIntersection = hit.point.y + intersectionOffset;
|
||||
//Vector3 tangent = Vector3.ProjectOnPlane(Vector3.down, hit.normal).normalized;
|
||||
|
||||
ySlope = Quaternion.LookRotation(hit.normal, Vector3.forward);
|
||||
|
||||
zNormal = ((hit.normal.normalized.z) + 1f) / 2f;
|
||||
normalHit = hit.normal.normalized;
|
||||
|
||||
if (yIntersection != oldyIntersection)
|
||||
{
|
||||
UpdateSlopeColor();
|
||||
}
|
||||
oldyIntersection = yIntersection;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Physics.Raycast(hit.point + Vector3.up * -0.05f, Vector3.down, out hitIfHit, 200, layerMask))
|
||||
{
|
||||
if (hitIfHit.transform != this.transform)
|
||||
{
|
||||
yIntersection = hitIfHit.point.y + intersectionOffset;
|
||||
//Vector3 tangent = Vector3.ProjectOnPlane(Vector3.down, hitIfHit.normal).normalized;
|
||||
|
||||
ySlope = Quaternion.LookRotation(hitIfHit.normal, Vector3.forward);
|
||||
zNormal = ((hitIfHit.normal.normalized.z) + 1f) / 2f;
|
||||
normalHit = hitIfHit.normal.normalized;
|
||||
|
||||
if (yIntersection != oldyIntersection)
|
||||
{
|
||||
UpdateSlopeColor();
|
||||
}
|
||||
oldyIntersection = yIntersection;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearGeometry()
|
||||
{
|
||||
triangles.Clear();
|
||||
triangles.TrimExcess();
|
||||
vertexs.Clear();
|
||||
vertexs.TrimExcess();
|
||||
uvs.Clear();
|
||||
uvs.TrimExcess();
|
||||
cols.Clear();
|
||||
cols.TrimExcess();
|
||||
}
|
||||
|
||||
private void BuildInitialGeometry()
|
||||
{
|
||||
if (meshFilter == null)
|
||||
{
|
||||
meshFilter = gameObject.GetComponent<MeshFilter>();
|
||||
}
|
||||
newMesh = new Mesh();
|
||||
newGO = new GameObject();
|
||||
MeshFilter mF = newGO.AddComponent<MeshFilter>();
|
||||
MeshRenderer mR = newGO.AddComponent<MeshRenderer>();
|
||||
mF.mesh = newMesh;
|
||||
mR.material = snowMaterial;
|
||||
|
||||
snowMaterial.SetFloat("_ISADD", 1);
|
||||
snowMaterial.EnableKeyword("IS_ADD");
|
||||
if (useIntersection)
|
||||
{
|
||||
if (snowMaterial.GetFloat("_USEINTER") == 0)
|
||||
{
|
||||
snowMaterial.SetFloat("_USEINTER", 1);
|
||||
snowMaterial.EnableKeyword("USE_INTER");
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (snowMaterial.GetFloat("_USEINTER") == 1)
|
||||
{
|
||||
snowMaterial.SetFloat("_USEINTER", 0);
|
||||
snowMaterial.DisableKeyword("USE_INTER");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
newGO.transform.parent = this.transform;
|
||||
newGO.transform.localPosition = Vector3.zero;
|
||||
newGO.transform.localScale = Vector3.one;
|
||||
newGO.transform.localRotation = Quaternion.identity;
|
||||
|
||||
int indexNewV = 0;
|
||||
foreach (Vector3 v in oldVert)
|
||||
{
|
||||
vertexs.Add(v + new Vector3(0,0,0));
|
||||
uvs.Add(oldUV[indexNewV]);
|
||||
|
||||
indexNewV++;
|
||||
}
|
||||
indexNewV = 0;
|
||||
foreach (int innt in oldTri)
|
||||
{
|
||||
triangles.Add(oldTri[indexNewV]);
|
||||
|
||||
indexNewV++;
|
||||
}
|
||||
|
||||
if (isAuto)
|
||||
{
|
||||
int j = 0;
|
||||
foreach (Vector3 norm in oldNormWorld)
|
||||
{
|
||||
if(j>= oldCol.Length)
|
||||
{
|
||||
break;
|
||||
}
|
||||
oldCol[j] = Color.red;
|
||||
float theAngle = Vector3.Angle(Vector3.up, norm);
|
||||
if (theAngle < (angle+10f))
|
||||
{
|
||||
Color lerpedColor = Color.Lerp(Color.white, Color.red, Mathf.Max(0f,theAngle- angle/2f) / (angle / 2f));
|
||||
oldCol[j] = lerpedColor;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
cols = oldCol.ToList();
|
||||
newMesh.vertices = vertexs.ToArray();
|
||||
newMesh.triangles = triangles.ToArray();
|
||||
newMesh.uv = uvs.ToArray();
|
||||
newMesh.colors = cols.ToArray();
|
||||
|
||||
newMesh.normals = originalMesh.normals;
|
||||
|
||||
RecalculateNormalsSeamless(newMesh);
|
||||
newMesh.RecalculateBounds();
|
||||
newMesh.Optimize();
|
||||
}
|
||||
|
||||
private void UpdateVertexColor()
|
||||
{
|
||||
Color[] updatedColors = newMesh.colors;
|
||||
Vector3[] newNormWorld = newMesh.normals;
|
||||
|
||||
if (isAuto)
|
||||
{
|
||||
int k = 0;
|
||||
foreach (Vector3 norm in newMesh.normals)
|
||||
{
|
||||
newNormWorld[k] = this.transform.localToWorldMatrix.MultiplyVector(norm).normalized;
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (isAuto)
|
||||
{
|
||||
int j = 0;
|
||||
foreach (Vector3 norm in newNormWorld)
|
||||
{
|
||||
if (j >= updatedColors.Length)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
float theAngle = Vector3.Angle(Vector3.up, norm);
|
||||
if (theAngle < (angle + 10f))
|
||||
{
|
||||
Color lerpedColor = Color.Lerp(new Color(1,1,1, updatedColors[j].a), new Color(1, 0, 0, updatedColors[j].a), Mathf.Max(0f, theAngle - angle / 2f) / (angle / 2f));
|
||||
updatedColors[j].r = lerpedColor.r;
|
||||
updatedColors[j].g = lerpedColor.g;
|
||||
updatedColors[j].b = lerpedColor.b;
|
||||
updatedColors[j].a = lerpedColor.a;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
}
|
||||
newMesh.colors = updatedColors;
|
||||
}
|
||||
|
||||
private void UpdateSlopeColor()
|
||||
{
|
||||
// This is not perfect for now but gets the job done... //
|
||||
int j = 0;
|
||||
|
||||
Color[] updatedColors = newMesh.colors;
|
||||
Vector2[] updatedUV4 = new Vector2[updatedColors.Count()];
|
||||
Vector2[] updatedUV5 = new Vector2[updatedColors.Count()];
|
||||
Vector2[] updatedUV6 = new Vector2[updatedColors.Count()];
|
||||
Vector2[] updatedUV7 = new Vector2[updatedColors.Count()];
|
||||
foreach (Color norm in newMesh.colors)
|
||||
{
|
||||
updatedColors[j].a = yIntersection;
|
||||
updatedUV4[j] = new Vector2(normalHit.x, normalHit.y);
|
||||
updatedUV5[j] = new Vector2(zNormal, normalHit.z);
|
||||
updatedUV6[j] = new Vector2(ySlope.x, ySlope.y);
|
||||
updatedUV7[j] = new Vector2(ySlope.z, ySlope.w);
|
||||
j++;
|
||||
}
|
||||
|
||||
newMesh.colors = updatedColors;
|
||||
newMesh.uv4 = updatedUV4;
|
||||
newMesh.uv5 = updatedUV5;
|
||||
newMesh.uv6 = updatedUV6;
|
||||
newMesh.uv7 = updatedUV7;
|
||||
}
|
||||
|
||||
private void RecalculateNormalsSeamless(Mesh mesh)
|
||||
{
|
||||
var trianglesOriginal = mesh.triangles;
|
||||
var triangles = trianglesOriginal.ToArray();
|
||||
|
||||
var vertices = mesh.vertices;
|
||||
|
||||
var mergeIndices = new Dictionary<int, int>();
|
||||
|
||||
for (int i = 0; i < vertices.Length; i++)
|
||||
{
|
||||
var vertexHash = vertices[i].GetHashCode();
|
||||
|
||||
if (mergeIndices.TryGetValue(vertexHash, out var index))
|
||||
{
|
||||
for (int j = 0; j < triangles.Length; j++)
|
||||
if (triangles[j] == i)
|
||||
triangles[j] = index;
|
||||
}
|
||||
else
|
||||
mergeIndices.Add(vertexHash, i);
|
||||
}
|
||||
|
||||
mesh.triangles = triangles;
|
||||
|
||||
var normals = new Vector3[vertices.Length];
|
||||
|
||||
mesh.RecalculateNormals();
|
||||
var newNormals = mesh.normals;
|
||||
|
||||
for (int i = 0; i < vertices.Length; i++)
|
||||
if (mergeIndices.TryGetValue(vertices[i].GetHashCode(), out var index))
|
||||
normals[i] = newNormals[index];
|
||||
|
||||
mesh.triangles = trianglesOriginal;
|
||||
mesh.normals = normals;
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/BruteForce/Scripts/BF_AddSnow.cs.meta
vendored
Normal file
11
Assets/ThirdParty/BruteForce/Scripts/BF_AddSnow.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 384d5b78126338848a3f397c6c80dc55
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
46
Assets/ThirdParty/BruteForce/Scripts/BF_FPS.cs
vendored
Normal file
46
Assets/ThirdParty/BruteForce/Scripts/BF_FPS.cs
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class BF_FPS : MonoBehaviour
|
||||
{
|
||||
float deltaTime = 0.0f;
|
||||
|
||||
private GUIStyle style = null;
|
||||
|
||||
private bool ShowFps = false;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
ShowFps = true;
|
||||
style = new GUIStyle();
|
||||
style.alignment = TextAnchor.UpperLeft;
|
||||
style.normal.textColor = new Color(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if(Input.GetKeyDown(KeyCode.Alpha2))
|
||||
{
|
||||
ShowFps = !ShowFps;
|
||||
}
|
||||
|
||||
if(ShowFps)
|
||||
deltaTime += (Time.unscaledDeltaTime - deltaTime) * 0.1f;
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
if (ShowFps)
|
||||
{
|
||||
int w = Screen.width, h = Screen.height;
|
||||
|
||||
style.fontSize = h * 4 / 100;
|
||||
|
||||
Rect rect = new Rect(0, 0, w, h * 2 / 100);
|
||||
|
||||
float msec = deltaTime * 1000.0f;
|
||||
float fps = 1.0f / deltaTime;
|
||||
GUI.Label(rect, string.Format("{0:0.0} ms ({1:0.} fps)", msec, fps), style);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/BruteForce/Scripts/BF_FPS.cs.meta
vendored
Normal file
11
Assets/ThirdParty/BruteForce/Scripts/BF_FPS.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a87ad753b0ceaed4285ff052cf561fbc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
133
Assets/ThirdParty/BruteForce/Scripts/BF_FxMouse.cs
vendored
Normal file
133
Assets/ThirdParty/BruteForce/Scripts/BF_FxMouse.cs
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
using UnityEngine.InputSystem;
|
||||
#endif
|
||||
|
||||
public class BF_FxMouse : MonoBehaviour
|
||||
{
|
||||
private Camera mainCam;
|
||||
public ParticleSystem ps;
|
||||
public ParticleSystem psRightClick;
|
||||
public ParticleSystem psMiddleClick;
|
||||
private float raycastSize = 200f;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
mainCam = this.GetComponent<Camera>();
|
||||
}
|
||||
void OnEnable()
|
||||
{
|
||||
mainCam = this.GetComponent<Camera>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
#if ENABLE_LEGACY_INPUT_MANAGER
|
||||
if (Input.GetMouseButton(0))
|
||||
{
|
||||
RaycastHit hit;
|
||||
Ray ray = mainCam.ScreenPointToRay(Input.mousePosition);
|
||||
Debug.DrawRay(this.transform.position, ray.direction);
|
||||
if (Physics.Raycast(ray, out hit, raycastSize))
|
||||
{
|
||||
if (!ps.isEmitting)
|
||||
{
|
||||
ps.Play();
|
||||
}
|
||||
ps.transform.position = hit.point;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ps.Stop();
|
||||
}
|
||||
|
||||
if (Input.GetMouseButton(1))
|
||||
{
|
||||
RaycastHit hit;
|
||||
Ray ray = mainCam.ScreenPointToRay(Input.mousePosition);
|
||||
Debug.DrawRay(this.transform.position, ray.direction);
|
||||
if (Physics.Raycast(ray, out hit, raycastSize))
|
||||
{
|
||||
if (!psRightClick.isEmitting)
|
||||
{
|
||||
psRightClick.Play();
|
||||
}
|
||||
psRightClick.transform.position = hit.point;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
psRightClick.Stop();
|
||||
}
|
||||
|
||||
if (Input.GetMouseButton(2))
|
||||
{
|
||||
RaycastHit hit;
|
||||
Ray ray = mainCam.ScreenPointToRay(Input.mousePosition);
|
||||
Debug.DrawRay(this.transform.position, ray.direction);
|
||||
if (Physics.Raycast(ray, out hit, raycastSize))
|
||||
{
|
||||
if (!psMiddleClick.isEmitting)
|
||||
{
|
||||
psMiddleClick.Play();
|
||||
}
|
||||
psMiddleClick.transform.position = hit.point;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
psMiddleClick.Stop();
|
||||
}
|
||||
#else
|
||||
if (Mouse.current.leftButton.isPressed)
|
||||
{
|
||||
RaycastHit hit;
|
||||
Ray ray = mainCam.ScreenPointToRay(Mouse.current.position.ReadValue());
|
||||
Debug.DrawRay(this.transform.position, ray.direction);
|
||||
if (Physics.Raycast(ray, out hit, raycastSize))
|
||||
{
|
||||
if (!ps.isEmitting)
|
||||
{
|
||||
ps.Play();
|
||||
}
|
||||
ps.transform.position = hit.point;
|
||||
}
|
||||
else
|
||||
{
|
||||
// ps.Stop();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ps.Stop();
|
||||
}
|
||||
|
||||
if (Mouse.current.rightButton.isPressed)
|
||||
{
|
||||
RaycastHit hit;
|
||||
Ray ray = mainCam.ScreenPointToRay(Mouse.current.position.ReadValue());
|
||||
Debug.DrawRay(this.transform.position, ray.direction);
|
||||
if (Physics.Raycast(ray, out hit, raycastSize))
|
||||
{
|
||||
if (!psRightClick.isEmitting)
|
||||
{
|
||||
psRightClick.Play();
|
||||
}
|
||||
psRightClick.transform.position = hit.point;
|
||||
}
|
||||
else
|
||||
{
|
||||
// ps.Stop();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
psRightClick.Stop();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/BruteForce/Scripts/BF_FxMouse.cs.meta
vendored
Normal file
11
Assets/ThirdParty/BruteForce/Scripts/BF_FxMouse.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 417e02b765d08944c98436fe98c91bda
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
31
Assets/ThirdParty/BruteForce/Scripts/BF_InputSystemSwitcher.cs
vendored
Normal file
31
Assets/ThirdParty/BruteForce/Scripts/BF_InputSystemSwitcher.cs
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.UI;
|
||||
#endif
|
||||
|
||||
public class BF_InputSystemSwitcher : MonoBehaviour
|
||||
{
|
||||
public GameObject eventS;
|
||||
// Start is called before the first frame update
|
||||
void Awake()
|
||||
{
|
||||
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
if (eventS.GetComponent<InputSystemUIInputModule>() == null)
|
||||
{
|
||||
if(eventS.GetComponent<StandaloneInputModule>() != null)
|
||||
{
|
||||
Destroy(eventS.GetComponent<StandaloneInputModule>());
|
||||
}
|
||||
InputSystemUIInputModule inputSystem = eventS.AddComponent<InputSystemUIInputModule>();
|
||||
inputSystem.enabled = false;
|
||||
inputSystem.enabled = true;
|
||||
inputSystem.UpdateModule();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/BruteForce/Scripts/BF_InputSystemSwitcher.cs.meta
vendored
Normal file
11
Assets/ThirdParty/BruteForce/Scripts/BF_InputSystemSwitcher.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 04d2879101b9eea479cb0d2f2754514d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
74
Assets/ThirdParty/BruteForce/Scripts/BF_InteractiveEffects.cs
vendored
Normal file
74
Assets/ThirdParty/BruteForce/Scripts/BF_InteractiveEffects.cs
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class BF_InteractiveEffects : MonoBehaviour
|
||||
{
|
||||
public Transform transformToFollow;
|
||||
public RenderTexture rt;
|
||||
public string GlobalTexName = "_GlobalEffectRT";
|
||||
public string GlobalOrthoName = "_OrthographicCamSize";
|
||||
public bool isPaced = false;
|
||||
|
||||
private float orthoMem = 0;
|
||||
private Coroutine waitPace;
|
||||
private bool paceRunning = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
orthoMem = GetComponent<Camera>().orthographicSize;
|
||||
Shader.SetGlobalFloat(GlobalOrthoName, orthoMem);
|
||||
Shader.SetGlobalTexture(GlobalTexName, rt);
|
||||
Shader.SetGlobalFloat("_HasRT", 1);
|
||||
}
|
||||
private void OnEnable()
|
||||
{
|
||||
orthoMem = GetComponent<Camera>().orthographicSize;
|
||||
Shader.SetGlobalFloat(GlobalOrthoName, orthoMem);
|
||||
Shader.SetGlobalTexture(GlobalTexName, rt);
|
||||
Shader.SetGlobalFloat("_HasRT", 1);
|
||||
}
|
||||
private void MoveCamera()
|
||||
{
|
||||
if (transformToFollow != null)
|
||||
{
|
||||
transform.position = new Vector3(transformToFollow.position.x, transformToFollow.position.y + 20, transformToFollow.position.z);
|
||||
}
|
||||
Shader.SetGlobalVector("_Position", transform.position);
|
||||
transform.rotation = Quaternion.Euler(new Vector3(90, 0, 0));
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if(isPaced)
|
||||
{
|
||||
if(!paceRunning)
|
||||
{
|
||||
waitPace = StartCoroutine(WaitPace());
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (paceRunning)
|
||||
{
|
||||
paceRunning = false;
|
||||
StopCoroutine(WaitPace());
|
||||
}
|
||||
|
||||
MoveCamera();
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator WaitPace()
|
||||
{
|
||||
for(; ;)
|
||||
{
|
||||
paceRunning = true;
|
||||
|
||||
MoveCamera();
|
||||
|
||||
yield return new WaitForSeconds(1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/BruteForce/Scripts/BF_InteractiveEffects.cs.meta
vendored
Normal file
11
Assets/ThirdParty/BruteForce/Scripts/BF_InteractiveEffects.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3213c75ba5401eb42aee936e4b61a69f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
79
Assets/ThirdParty/BruteForce/Scripts/BF_InteractiveEffectsAdditional.cs
vendored
Normal file
79
Assets/ThirdParty/BruteForce/Scripts/BF_InteractiveEffectsAdditional.cs
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class BF_InteractiveEffectsAdditional : MonoBehaviour
|
||||
{
|
||||
public Transform mainCamera;
|
||||
public RenderTexture rt;
|
||||
public string GlobalTexName = "_GlobalEffectRTAdditional";
|
||||
public string GlobalOrthoName = "_OrthographicCamSizeAdditional";
|
||||
public bool isPaced = false;
|
||||
|
||||
private float orthoMem = 0;
|
||||
private Vector3 camDir;
|
||||
private Coroutine waitPace;
|
||||
private bool paceRunning = false;
|
||||
private void Awake()
|
||||
{
|
||||
orthoMem = GetComponent<Camera>().orthographicSize;
|
||||
Shader.SetGlobalFloat(GlobalOrthoName, orthoMem);
|
||||
Shader.SetGlobalTexture(GlobalTexName, rt);
|
||||
}
|
||||
private void OnEnable()
|
||||
{
|
||||
orthoMem = GetComponent<Camera>().orthographicSize;
|
||||
Shader.SetGlobalFloat(GlobalOrthoName, orthoMem);
|
||||
Shader.SetGlobalTexture(GlobalTexName, rt);
|
||||
}
|
||||
|
||||
private void MoveCamera()
|
||||
{
|
||||
if (mainCamera != null)
|
||||
{
|
||||
camDir = Vector3.ProjectOnPlane(mainCamera.forward, Vector3.up).normalized;
|
||||
camDir.y = 0f;
|
||||
|
||||
if (mainCamera != null)
|
||||
{
|
||||
float YView = Vector3.Angle(Vector3.down, mainCamera.forward);
|
||||
transform.position = new Vector3(mainCamera.position.x, mainCamera.position.y + 20, mainCamera.position.z) + camDir.normalized * Mathf.Max(0f, orthoMem - 20f) * Mathf.Clamp01(((YView - 35) * 3) / 35);
|
||||
}
|
||||
}
|
||||
Shader.SetGlobalVector("_PositionAdd", transform.position);
|
||||
transform.rotation = Quaternion.Euler(new Vector3(90, 0, 0));
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (isPaced)
|
||||
{
|
||||
if (!paceRunning)
|
||||
{
|
||||
waitPace = StartCoroutine(WaitPace());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (paceRunning)
|
||||
{
|
||||
paceRunning = false;
|
||||
StopCoroutine(WaitPace());
|
||||
}
|
||||
|
||||
MoveCamera();
|
||||
}
|
||||
}
|
||||
private IEnumerator WaitPace()
|
||||
{
|
||||
for (; ; )
|
||||
{
|
||||
paceRunning = true;
|
||||
|
||||
MoveCamera();
|
||||
|
||||
yield return new WaitForSeconds(1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/BruteForce/Scripts/BF_InteractiveEffectsAdditional.cs.meta
vendored
Normal file
11
Assets/ThirdParty/BruteForce/Scripts/BF_InteractiveEffectsAdditional.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7329b255050ede64f96bc899973e510f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
30
Assets/ThirdParty/BruteForce/Scripts/BF_LightSwitch.cs
vendored
Normal file
30
Assets/ThirdParty/BruteForce/Scripts/BF_LightSwitch.cs
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BF_LightSwitch : MonoBehaviour
|
||||
{
|
||||
public GameObject lightScene;
|
||||
public Material skyboxScene;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if(lightScene != null)
|
||||
{
|
||||
lightScene.SetActive(true);
|
||||
}
|
||||
if(skyboxScene != null)
|
||||
{
|
||||
RenderSettings.skybox = skyboxScene;
|
||||
}
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
if (lightScene != null)
|
||||
{
|
||||
lightScene.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/ThirdParty/BruteForce/Scripts/BF_LightSwitch.cs.meta
vendored
Normal file
11
Assets/ThirdParty/BruteForce/Scripts/BF_LightSwitch.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 500e34ee2d18f3c43be45c3ec1c393ea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
84
Assets/ThirdParty/BruteForce/Scripts/BF_PlayerMovement.cs
vendored
Normal file
84
Assets/ThirdParty/BruteForce/Scripts/BF_PlayerMovement.cs
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
using UnityEngine.InputSystem;
|
||||
#endif
|
||||
|
||||
public class BF_PlayerMovement : MonoBehaviour
|
||||
{
|
||||
public Camera cam;
|
||||
private Rigidbody rb;
|
||||
private Quaternion camRot;
|
||||
private Vector3 moveDirection;
|
||||
private Vector3 inputDirection;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
rb = this.GetComponent<Rigidbody>();
|
||||
if(cam == null)
|
||||
{
|
||||
cam = Camera.main;
|
||||
}
|
||||
} // Start is called before the first frame update
|
||||
void OnEnable()
|
||||
{
|
||||
rb = this.GetComponent<Rigidbody>();
|
||||
if(cam == null)
|
||||
{
|
||||
cam = Camera.main;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate()
|
||||
{
|
||||
inputDirection = Vector3.zero;
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
if (Keyboard.current.qKey.isPressed || Keyboard.current.aKey.isPressed)
|
||||
{
|
||||
inputDirection += new Vector3(0, 0, 1);
|
||||
}
|
||||
if (Keyboard.current.dKey.isPressed)
|
||||
{
|
||||
inputDirection += new Vector3(0, 0, -1);
|
||||
}
|
||||
if (Keyboard.current.wKey.isPressed || Keyboard.current.zKey.isPressed)
|
||||
{
|
||||
inputDirection += new Vector3(1, 0, 0);
|
||||
}
|
||||
if (Keyboard.current.sKey.isPressed)
|
||||
{
|
||||
inputDirection += new Vector3(-1, 0, 0);
|
||||
}
|
||||
#else
|
||||
if (Input.GetKey(KeyCode.Q)|| Input.GetKey(KeyCode.A))
|
||||
{
|
||||
inputDirection += new Vector3(0, 0, 1);
|
||||
}
|
||||
if (Input.GetKey(KeyCode.D))
|
||||
{
|
||||
inputDirection += new Vector3(0, 0, -1);
|
||||
}
|
||||
if (Input.GetKey(KeyCode.Z) || Input.GetKey(KeyCode.W))
|
||||
{
|
||||
inputDirection += new Vector3(1, 0, 0);
|
||||
}
|
||||
if (Input.GetKey(KeyCode.S))
|
||||
{
|
||||
inputDirection += new Vector3(-1, 0, 0);
|
||||
}
|
||||
#endif
|
||||
MoveBall();
|
||||
}
|
||||
|
||||
private void MoveBall()
|
||||
{
|
||||
camRot = Quaternion.LookRotation(cam.transform.forward, Vector3.up);
|
||||
moveDirection = camRot * new Vector3(Mathf.Clamp(inputDirection.x * 2, -1, 1), 0, Mathf.Clamp(inputDirection.z * 2, -1, 1));
|
||||
rb.AddTorque(moveDirection*22.5f);
|
||||
rb.AddForce(moveDirection*15f,ForceMode.Force);
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/BruteForce/Scripts/BF_PlayerMovement.cs.meta
vendored
Normal file
11
Assets/ThirdParty/BruteForce/Scripts/BF_PlayerMovement.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d0c540651fd7ade458bcf18adb77a455
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
Assets/ThirdParty/BruteForce/Scripts/BF_PlayerReset.cs
vendored
Normal file
19
Assets/ThirdParty/BruteForce/Scripts/BF_PlayerReset.cs
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BF_PlayerReset : MonoBehaviour
|
||||
{
|
||||
public GameObject player;
|
||||
public Transform playerPos;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
player.transform.position = playerPos.position;
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
player.transform.position = playerPos.position;
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/ThirdParty/BruteForce/Scripts/BF_PlayerReset.cs.meta
vendored
Normal file
11
Assets/ThirdParty/BruteForce/Scripts/BF_PlayerReset.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02f858f19ebff6c469275aa024a241f6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
156
Assets/ThirdParty/BruteForce/Scripts/BF_PlayerSnow.cs
vendored
Normal file
156
Assets/ThirdParty/BruteForce/Scripts/BF_PlayerSnow.cs
vendored
Normal file
@@ -0,0 +1,156 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BF_PlayerSnow : MonoBehaviour
|
||||
{
|
||||
public Collider playerCollider;
|
||||
public ParticleSystem particleSys;
|
||||
|
||||
public PhysicsMaterial playerMatDefault;
|
||||
public PhysicsMaterial playerMatSnow;
|
||||
public PhysicsMaterial playerMatIce;
|
||||
|
||||
private Rigidbody rB;
|
||||
private float speedMult = 1;
|
||||
private float lerpIce = 0;
|
||||
private MeshCollider oldMC = null;
|
||||
private Mesh mesh = null;
|
||||
private ParticleSystem.MainModule pSMain;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
oldMC = null;
|
||||
mesh = null;
|
||||
rB = this.GetComponent<Rigidbody>();
|
||||
pSMain = particleSys.main;
|
||||
}
|
||||
|
||||
private void CheckIceCols(float snowCol)
|
||||
{
|
||||
lerpIce = snowCol / 255f;
|
||||
|
||||
if (snowCol == -1)
|
||||
{
|
||||
if (playerCollider.material != playerMatDefault)
|
||||
{
|
||||
playerCollider.material = playerMatDefault;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (lerpIce <= 0.925f && playerCollider.material != playerMatIce)
|
||||
{
|
||||
playerCollider.material = playerMatIce;
|
||||
rB.angularDamping = 0.25f;
|
||||
}
|
||||
else if(lerpIce >= 0.925f && playerCollider.material != playerMatSnow)
|
||||
{
|
||||
playerCollider.material = playerMatSnow;
|
||||
rB.angularDamping = 5f;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCollisionStay(Collision collision)
|
||||
{
|
||||
if (lerpIce >= 0.925f && collision.collider.gameObject.layer == 4)
|
||||
{
|
||||
AddSnow(1.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveSnow(0.05f);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
if(collision.impulse.magnitude>10)
|
||||
{
|
||||
// RemoveSnow(20);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddSnow(float multiplier)
|
||||
{
|
||||
if (playerCollider.transform.localScale.x < 7f)
|
||||
{
|
||||
speedMult = Mathf.Clamp(rB.linearVelocity.magnitude * 0.02f,0,1);
|
||||
playerCollider.transform.localScale += Vector3.zero + Vector3.one * 0.0035f * 2 * multiplier* speedMult;
|
||||
playerCollider.transform.localScale += Vector3.zero + Vector3.one * 0.005f * 2 * multiplier * speedMult;
|
||||
}
|
||||
}
|
||||
private void RemoveSnow(float multiplier)
|
||||
{
|
||||
if (playerCollider.transform.localScale.x >= 1.1f)
|
||||
{
|
||||
if (!playerCollider.transform.gameObject.activeInHierarchy)
|
||||
{
|
||||
// SnowPlayer.gameObject.SetActive(true);
|
||||
}
|
||||
playerCollider.transform.localScale -= Vector3.zero + Vector3.one * 0.0035f * 4 * multiplier;
|
||||
playerCollider.transform.localScale -= Vector3.zero + Vector3.one * 0.005f * 4 * multiplier;
|
||||
}
|
||||
if (playerCollider.transform.localScale.x < 1.1f)
|
||||
{
|
||||
if (playerCollider.transform.gameObject.activeInHierarchy)
|
||||
{
|
||||
// SnowPlayer.gameObject.SetActive(false);
|
||||
}
|
||||
playerCollider.transform.localScale = Vector3.one * 1.1f;
|
||||
playerCollider.transform.localScale = Vector3.one * 1.1f;
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
ChangePlayerMass();
|
||||
CheckSnowUnderneath();
|
||||
}
|
||||
|
||||
private void CheckSnowUnderneath()
|
||||
{
|
||||
RaycastHit hit;
|
||||
|
||||
int layerMask = 1 << 4;
|
||||
if (Physics.Raycast(transform.position+(Vector3.down*(playerCollider.transform.localScale.x/2)+Vector3.up*0.5f), Vector3.down, out hit, 5, layerMask,QueryTriggerInteraction.Ignore))
|
||||
{
|
||||
MeshCollider meshCollider = hit.collider as MeshCollider;
|
||||
if (oldMC != meshCollider || mesh == null)
|
||||
{
|
||||
mesh = meshCollider.GetComponent<MeshFilter>().sharedMesh;
|
||||
}
|
||||
oldMC = meshCollider;
|
||||
if (meshCollider == null || meshCollider.sharedMesh == null)
|
||||
{
|
||||
CheckIceCols(255f);
|
||||
return;
|
||||
}
|
||||
|
||||
//Mesh mesh = meshCollider.sharedMesh;
|
||||
|
||||
int[] triangles = mesh.triangles;
|
||||
Color32[] colorArray;
|
||||
colorArray = mesh.colors32;
|
||||
|
||||
var vertIndex1 = triangles[hit.triangleIndex * 3 + 0];
|
||||
CheckIceCols(((float)colorArray[vertIndex1].g) / 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (playerCollider.material != playerMatDefault)
|
||||
{
|
||||
playerCollider.material = playerMatDefault;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ChangePlayerMass()
|
||||
{
|
||||
rB.mass = Mathf.Lerp(1.95f, 2.5f, (playerCollider.transform.localScale.x-1.2f) / 7);
|
||||
pSMain.startSize = playerCollider.transform.localScale.x+0.5f;
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/BruteForce/Scripts/BF_PlayerSnow.cs.meta
vendored
Normal file
11
Assets/ThirdParty/BruteForce/Scripts/BF_PlayerSnow.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fb1cf2caeea15a641a9b68e147daa302
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
12
Assets/ThirdParty/BruteForce/Scripts/BF_Rotator.cs
vendored
Normal file
12
Assets/ThirdParty/BruteForce/Scripts/BF_Rotator.cs
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BF_Rotator : MonoBehaviour
|
||||
{
|
||||
public float RotSpeed = 1;
|
||||
void Update()
|
||||
{
|
||||
this.transform.Rotate(new Vector3(0, RotSpeed*Time.deltaTime, 0), Space.World);
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/BruteForce/Scripts/BF_Rotator.cs.meta
vendored
Normal file
11
Assets/ThirdParty/BruteForce/Scripts/BF_Rotator.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53088f735d92cd94fa9c9c91525485b2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
122
Assets/ThirdParty/BruteForce/Scripts/BF_SnowAssetManager.cs
vendored
Normal file
122
Assets/ThirdParty/BruteForce/Scripts/BF_SnowAssetManager.cs
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
using UnityEngine.InputSystem;
|
||||
#endif
|
||||
|
||||
public class BF_SnowAssetManager : MonoBehaviour
|
||||
{
|
||||
public GameObject UIText;
|
||||
public int showcaseIndex = 0;
|
||||
[HideInInspector] public int subShowcaseIndex = 0;
|
||||
public List<GameObject> showcasesGO;
|
||||
public List<GameObject> cameras;
|
||||
public List<GameObject> lights;
|
||||
public List<Material> skyboxes;
|
||||
[Space]
|
||||
public GameObject specialCamera;
|
||||
public GameObject specialButton;
|
||||
public GameObject specialInfo;
|
||||
private int maxIndex = 4;
|
||||
[HideInInspector] public int maxSubIndex = 3;
|
||||
|
||||
[HideInInspector] public UnityEvent m_ShowcaseChange = new UnityEvent();
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
maxIndex = showcasesGO.Count - 1;
|
||||
SwitchShowcase(0);
|
||||
SwitchSubShowcase(0);
|
||||
RenderSettings.fog = true;
|
||||
RenderSettings.fogDensity = 0.00f;
|
||||
UIText.SetActive(false);
|
||||
specialCamera.SetActive(false);
|
||||
specialButton.SetActive(true);
|
||||
specialInfo.SetActive(true);
|
||||
}
|
||||
|
||||
public void SwitchShowcase(int addIndex)
|
||||
{
|
||||
for (int i = 0; i <= maxIndex; i++)
|
||||
{
|
||||
showcasesGO[i].SetActive(false);
|
||||
cameras[i].SetActive(false);
|
||||
lights[i].SetActive(false);
|
||||
}
|
||||
showcaseIndex += addIndex;
|
||||
if (showcaseIndex <= -1)
|
||||
{
|
||||
showcaseIndex = maxIndex;
|
||||
}
|
||||
else if (showcaseIndex == maxIndex + 1)
|
||||
{
|
||||
showcaseIndex = 0;
|
||||
}
|
||||
showcasesGO[showcaseIndex].SetActive(true);
|
||||
cameras[showcaseIndex].SetActive(true);
|
||||
lights[showcaseIndex].SetActive(true);
|
||||
RenderSettings.skybox = skyboxes[showcaseIndex];
|
||||
subShowcaseIndex = 0;
|
||||
m_ShowcaseChange.Invoke();
|
||||
|
||||
if(showcaseIndex != 0)
|
||||
{
|
||||
RenderSettings.fogDensity = 0.001f;
|
||||
specialCamera.SetActive(false);
|
||||
specialButton.SetActive(false);
|
||||
specialInfo.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
specialCamera.SetActive(false);
|
||||
RenderSettings.fogDensity = 0.00f;
|
||||
specialButton.SetActive(true);
|
||||
specialInfo.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void SwitchSubShowcase(int addIndex)
|
||||
{
|
||||
subShowcaseIndex += addIndex;
|
||||
if (subShowcaseIndex <= -1)
|
||||
{
|
||||
subShowcaseIndex = maxSubIndex;
|
||||
}
|
||||
else if (subShowcaseIndex == maxSubIndex + 1)
|
||||
{
|
||||
subShowcaseIndex = 0;
|
||||
}
|
||||
m_ShowcaseChange.Invoke();
|
||||
}
|
||||
|
||||
public void ActivateSpecialCamera()
|
||||
{
|
||||
specialCamera.SetActive(!specialCamera.activeInHierarchy);
|
||||
cameras[0].SetActive(!cameras[0].activeInHierarchy);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
#if ENABLE_LEGACY_INPUT_MANAGER
|
||||
if (Input.GetKeyDown(KeyCode.Alpha1))
|
||||
{
|
||||
SwitchSubShowcase(-1);
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.Alpha2))
|
||||
{
|
||||
SwitchSubShowcase(1);
|
||||
}
|
||||
#else
|
||||
if (Keyboard.current.digit1Key.wasPressedThisFrame)
|
||||
{
|
||||
SwitchSubShowcase(-1);
|
||||
}
|
||||
if (Keyboard.current.digit2Key.wasPressedThisFrame)
|
||||
{
|
||||
SwitchSubShowcase(1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/BruteForce/Scripts/BF_SnowAssetManager.cs.meta
vendored
Normal file
11
Assets/ThirdParty/BruteForce/Scripts/BF_SnowAssetManager.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 86e6ab644acef394f9a3498ddeb8e3dd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
55
Assets/ThirdParty/BruteForce/Scripts/BF_SnowSubShowcase.cs
vendored
Normal file
55
Assets/ThirdParty/BruteForce/Scripts/BF_SnowSubShowcase.cs
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class BF_SnowSubShowcase : MonoBehaviour
|
||||
{
|
||||
public BF_SnowAssetManager aM;
|
||||
public Text uiText;
|
||||
public List<GameObject> subShowcases;
|
||||
public List<string> nameSubs;
|
||||
private int oldIndex = -1;
|
||||
|
||||
private UnityAction showcaseChange;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void OnEnable()
|
||||
{
|
||||
aM.maxSubIndex = subShowcases.Count-1;
|
||||
aM.m_ShowcaseChange.AddListener(ChangeIndex);
|
||||
}
|
||||
private void OnDisable()
|
||||
{
|
||||
aM.m_ShowcaseChange.RemoveListener(ChangeIndex);
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
/*
|
||||
if(aM.subShowcaseIndex != oldIndex)
|
||||
{
|
||||
oldIndex = aM.subShowcaseIndex;
|
||||
foreach(GameObject GO in subShowcases)
|
||||
{
|
||||
GO.SetActive(false);
|
||||
}
|
||||
subShowcases[oldIndex].SetActive(true);
|
||||
uiText.text = nameSubs[oldIndex];
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
private void ChangeIndex()
|
||||
{
|
||||
oldIndex = aM.subShowcaseIndex;
|
||||
|
||||
foreach (GameObject GO in subShowcases)
|
||||
{
|
||||
GO.SetActive(false);
|
||||
}
|
||||
subShowcases[oldIndex].SetActive(true);
|
||||
uiText.text = nameSubs[oldIndex];
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/ThirdParty/BruteForce/Scripts/BF_SnowSubShowcase.cs.meta
vendored
Normal file
11
Assets/ThirdParty/BruteForce/Scripts/BF_SnowSubShowcase.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 08e6d17c1c9ea7d4189ee556f2049d88
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
204
Assets/ThirdParty/BruteForce/Scripts/BF_SnowTerrain.cs
vendored
Normal file
204
Assets/ThirdParty/BruteForce/Scripts/BF_SnowTerrain.cs
vendored
Normal file
@@ -0,0 +1,204 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class BF_SnowTerrain : MonoBehaviour
|
||||
{
|
||||
public Terrain terrainToCopy;
|
||||
public bool avoidCulling = false;
|
||||
|
||||
private Terrain terrainAsset;
|
||||
private TerrainData terrainData;
|
||||
private TerrainData terrainDataOld = null;
|
||||
private Vector3 sizeOld = Vector3.one * 100f;
|
||||
private float[,] terrainHeightOld = null;
|
||||
private int heightRezOld = 0;
|
||||
private Vector3 posOld = Vector3.zero;
|
||||
private Material terrainMaterial;
|
||||
private GameObject selectGO;
|
||||
private bool isSynced = false;
|
||||
|
||||
void Start()
|
||||
{
|
||||
UpdateTerrainData();
|
||||
}
|
||||
void OnEnable()
|
||||
{
|
||||
UpdateTerrainData();
|
||||
}
|
||||
|
||||
private void StoreTerrainData()
|
||||
{
|
||||
if (terrainDataOld == null)
|
||||
{
|
||||
terrainDataOld = terrainAsset.terrainData;
|
||||
terrainHeightOld = terrainAsset.terrainData.GetHeights(0, 0, terrainAsset.terrainData.heightmapResolution, terrainAsset.terrainData.heightmapResolution);
|
||||
sizeOld = terrainAsset.terrainData.size;
|
||||
heightRezOld = terrainAsset.terrainData.heightmapResolution;
|
||||
posOld = terrainAsset.transform.position;
|
||||
}
|
||||
}
|
||||
private void ClearTerrainData()
|
||||
{
|
||||
terrainDataOld = null;
|
||||
terrainHeightOld = null;
|
||||
isSynced = false;
|
||||
sizeOld = Vector3.one*100f;
|
||||
}
|
||||
|
||||
private void UpdateTerrainData()
|
||||
{
|
||||
terrainAsset = this.GetComponent<Terrain>();
|
||||
if (avoidCulling)
|
||||
{
|
||||
terrainAsset.patchBoundsMultiplier = Vector3.one * 2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
terrainAsset.patchBoundsMultiplier = Vector3.one;
|
||||
}
|
||||
terrainData = terrainAsset.terrainData;
|
||||
|
||||
terrainMaterial = terrainAsset.materialTemplate;
|
||||
terrainMaterial.SetTexture("_Control0", terrainData.GetAlphamapTexture(0));
|
||||
terrainMaterial.SetTexture("_Control1", terrainData.GetAlphamapTexture(1));
|
||||
terrainMaterial.SetVector("_TerrainScale", terrainData.size);
|
||||
|
||||
|
||||
terrainMaterial.SetFloat("_IST", 1);
|
||||
terrainMaterial.EnableKeyword("IS_T");
|
||||
|
||||
if (terrainData.terrainLayers.Length <= 4)
|
||||
{
|
||||
terrainMaterial.DisableKeyword("USE_COMPLEX_T");
|
||||
}
|
||||
|
||||
if (terrainData.terrainLayers.Length > 4)
|
||||
{
|
||||
terrainMaterial.EnableKeyword("USE_COMPLEX_T");
|
||||
terrainMaterial.SetTexture("_Normal4", terrainData.terrainLayers[4].normalMapTexture);
|
||||
terrainMaterial.SetFloat("_NormalScale4", terrainData.terrainLayers[4].normalScale);
|
||||
terrainMaterial.SetTexture("_Splat4", terrainData.terrainLayers[4].diffuseTexture);
|
||||
terrainMaterial.SetVector("_Splat4_STn", new Vector4(terrainData.terrainLayers[4].tileSize.x, terrainData.terrainLayers[4].tileSize.y, terrainData.terrainLayers[4].tileOffset.x, terrainData.terrainLayers[4].tileOffset.y));
|
||||
terrainMaterial.SetColor("_Specular4", terrainData.terrainLayers[4].specular);
|
||||
terrainMaterial.SetFloat("_Metallic4", terrainData.terrainLayers[4].metallic);
|
||||
terrainMaterial.SetTexture("_Mask4", terrainData.terrainLayers[4].maskMapTexture);
|
||||
}
|
||||
if (terrainData.terrainLayers.Length > 5)
|
||||
{
|
||||
terrainMaterial.SetTexture("_Normal5", terrainData.terrainLayers[5].normalMapTexture);
|
||||
terrainMaterial.SetFloat("_NormalScale5", terrainData.terrainLayers[5].normalScale);
|
||||
terrainMaterial.SetTexture("_Splat5", terrainData.terrainLayers[5].diffuseTexture);
|
||||
terrainMaterial.SetVector("_Splat5_STn", new Vector4(terrainData.terrainLayers[5].tileSize.x, terrainData.terrainLayers[5].tileSize.y, terrainData.terrainLayers[5].tileOffset.x, terrainData.terrainLayers[5].tileOffset.y));
|
||||
terrainMaterial.SetColor("_Specular5", terrainData.terrainLayers[5].specular);
|
||||
terrainMaterial.SetFloat("_Metallic5", terrainData.terrainLayers[5].metallic);
|
||||
terrainMaterial.SetTexture("_Mask5", terrainData.terrainLayers[5].maskMapTexture);
|
||||
}
|
||||
if (terrainData.terrainLayers.Length > 6)
|
||||
{
|
||||
terrainMaterial.SetTexture("_Normal6", terrainData.terrainLayers[6].normalMapTexture);
|
||||
terrainMaterial.SetFloat("_NormalScale6", terrainData.terrainLayers[6].normalScale);
|
||||
terrainMaterial.SetTexture("_Splat6", terrainData.terrainLayers[6].diffuseTexture);
|
||||
terrainMaterial.SetVector("_Splat6_STn", new Vector4(terrainData.terrainLayers[6].tileSize.x, terrainData.terrainLayers[6].tileSize.y, terrainData.terrainLayers[6].tileOffset.x, terrainData.terrainLayers[6].tileOffset.y));
|
||||
terrainMaterial.SetColor("_Specular6", terrainData.terrainLayers[6].specular);
|
||||
terrainMaterial.SetFloat("_Metallic6", terrainData.terrainLayers[6].metallic);
|
||||
terrainMaterial.SetTexture("_Mask6", terrainData.terrainLayers[6].maskMapTexture);
|
||||
}
|
||||
if (terrainData.terrainLayers.Length > 7)
|
||||
{
|
||||
terrainMaterial.SetTexture("_Normal7", terrainData.terrainLayers[7].normalMapTexture);
|
||||
terrainMaterial.SetFloat("_NormalScale7", terrainData.terrainLayers[7].normalScale);
|
||||
terrainMaterial.SetTexture("_Splat7", terrainData.terrainLayers[7].diffuseTexture);
|
||||
terrainMaterial.SetVector("_Splat7_STn", new Vector4(terrainData.terrainLayers[7].tileSize.x, terrainData.terrainLayers[7].tileSize.y, terrainData.terrainLayers[7].tileOffset.x, terrainData.terrainLayers[7].tileOffset.y));
|
||||
terrainMaterial.SetColor("_Specular7", terrainData.terrainLayers[7].specular);
|
||||
terrainMaterial.SetFloat("_Metallic7", terrainData.terrainLayers[7].metallic);
|
||||
terrainMaterial.SetTexture("_Mask7", terrainData.terrainLayers[7].maskMapTexture);
|
||||
}
|
||||
}
|
||||
|
||||
public void CopyTerrainData()
|
||||
{
|
||||
if(terrainToCopy != null && terrainToCopy != terrainAsset)
|
||||
{
|
||||
StoreTerrainData();
|
||||
|
||||
terrainAsset.terrainData.heightmapResolution = terrainToCopy.terrainData.heightmapResolution;
|
||||
terrainAsset.terrainData.SetHeights(0, 0, terrainToCopy.terrainData.GetHeights(0, 0, terrainToCopy.terrainData.heightmapResolution, terrainToCopy.terrainData.heightmapResolution));
|
||||
terrainAsset.terrainData.size = terrainToCopy.terrainData.size;
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveTerrainSync()
|
||||
{
|
||||
if (terrainToCopy != null && terrainToCopy != terrainAsset)
|
||||
{
|
||||
isSynced = true;
|
||||
terrainAsset.transform.position = terrainToCopy.transform.position + Vector3.up * 0.01f;
|
||||
//terrainMaterial.SetFloat("_GrassCut", 1);
|
||||
terrainAsset.terrainData.heightmapResolution = terrainToCopy.terrainData.heightmapResolution;
|
||||
terrainAsset.terrainData.baseMapResolution = terrainToCopy.terrainData.baseMapResolution;
|
||||
terrainAsset.terrainData.alphamapResolution = terrainToCopy.terrainData.alphamapResolution;
|
||||
|
||||
terrainMaterial.SetFloat("_ISADD", 1);
|
||||
terrainMaterial.EnableKeyword("IS_ADD");
|
||||
}
|
||||
else
|
||||
{
|
||||
//terrainMaterial.SetFloat("_GrassCut", 0);
|
||||
terrainMaterial.SetFloat("_ISADD", 0);
|
||||
terrainMaterial.DisableKeyword("IS_ADD");
|
||||
}
|
||||
}
|
||||
public void RevertTerrainData()
|
||||
{
|
||||
if (terrainDataOld != null)
|
||||
{
|
||||
terrainToCopy = null;
|
||||
terrainAsset.terrainData = terrainDataOld;
|
||||
terrainAsset.terrainData.heightmapResolution = heightRezOld;
|
||||
terrainAsset.terrainData.size = sizeOld;
|
||||
terrainAsset.terrainData.SetHeights(0, 0, terrainHeightOld);
|
||||
//terrainMaterial.SetFloat("_GrassCut", 0);
|
||||
terrainMaterial.SetFloat("_ISADD", 0);
|
||||
terrainMaterial.DisableKeyword("IS_ADD");
|
||||
terrainAsset.transform.position = posOld;
|
||||
ClearTerrainData();
|
||||
}
|
||||
}
|
||||
|
||||
void OnRenderObject()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if ((Application.isEditor && !Application.isPlaying)&& terrainToCopy!=null && isSynced)
|
||||
{
|
||||
if (Selection.activeGameObject == this.gameObject && selectGO != this.gameObject)
|
||||
{
|
||||
selectGO = Selection.activeGameObject;
|
||||
terrainAsset.transform.position = terrainToCopy.transform.position + Vector3.up * 0.01f;
|
||||
}
|
||||
else if (Selection.activeGameObject == terrainToCopy.gameObject && selectGO != terrainToCopy.gameObject)
|
||||
{
|
||||
selectGO = Selection.activeGameObject;
|
||||
terrainAsset.transform.position = terrainToCopy.transform.position + Vector3.down * 0.01f;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (Application.isEditor && !Application.isPlaying)
|
||||
{
|
||||
UpdateTerrainData();
|
||||
if (isSynced && terrainToCopy != null && terrainToCopy.terrainData.GetHeights(0, 0, terrainToCopy.terrainData.heightmapResolution, terrainToCopy.terrainData.heightmapResolution) != terrainAsset.terrainData.GetHeights(0, 0, terrainAsset.terrainData.heightmapResolution, terrainAsset.terrainData.heightmapResolution))
|
||||
{
|
||||
CopyTerrainData();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/ThirdParty/BruteForce/Scripts/BF_SnowTerrain.cs.meta
vendored
Normal file
11
Assets/ThirdParty/BruteForce/Scripts/BF_SnowTerrain.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 41c94d07ab70d5b4e881198d094c5d0b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
15
Assets/ThirdParty/BruteForce/Scripts/BF_SquareBanding.cs
vendored
Normal file
15
Assets/ThirdParty/BruteForce/Scripts/BF_SquareBanding.cs
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
[RequireComponent(typeof(Camera))]
|
||||
public class BF_SquareBanding : MonoBehaviour
|
||||
{
|
||||
public Material cinematicBandsFX = null;
|
||||
|
||||
private void OnRenderImage(RenderTexture source, RenderTexture destination)
|
||||
{
|
||||
Graphics.Blit(source, destination, cinematicBandsFX);
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/BruteForce/Scripts/BF_SquareBanding.cs.meta
vendored
Normal file
11
Assets/ThirdParty/BruteForce/Scripts/BF_SquareBanding.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8293a710c5345854cb7d5039e78a596d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/ThirdParty/BruteForce/Textures.meta
vendored
Normal file
8
Assets/ThirdParty/BruteForce/Textures.meta
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 161f7f8e529745a40bf349e3dce4e70b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/ThirdParty/BruteForce/Textures/Ice.meta
vendored
Normal file
8
Assets/ThirdParty/BruteForce/Textures/Ice.meta
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 23c88a5b269769f4483247ae85ca4d6d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/ThirdParty/BruteForce/Textures/Ice/IceNormal03.png
vendored
Normal file
BIN
Assets/ThirdParty/BruteForce/Textures/Ice/IceNormal03.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 MiB |
92
Assets/ThirdParty/BruteForce/Textures/Ice/IceNormal03.png.meta
vendored
Normal file
92
Assets/ThirdParty/BruteForce/Textures/Ice/IceNormal03.png.meta
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f42cea328e314cb44a1359ea9e70a7d6
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 11
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 1
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: -1
|
||||
aniso: -1
|
||||
mipBias: -100
|
||||
wrapU: -1
|
||||
wrapV: -1
|
||||
wrapW: -1
|
||||
nPOTScale: 1
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 0
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 0
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
applyGammaDecoding: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/ThirdParty/Ciconia Studio.meta
vendored
Normal file
8
Assets/ThirdParty/Ciconia Studio.meta
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 63b712fc009ac8349af1c0be95a601d3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/ThirdParty/Ciconia Studio/_Shared Files.meta
vendored
Normal file
8
Assets/ThirdParty/Ciconia Studio/_Shared Files.meta
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 47e9e677aeb1b4647baa3028c581792c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/ThirdParty/Ciconia Studio/_Shared Files/Scripts.meta
vendored
Normal file
8
Assets/ThirdParty/Ciconia Studio/_Shared Files/Scripts.meta
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f71b3f45bdcc2141b89817c086dadfe
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/ThirdParty/Ciconia Studio/_Shared Files/Scripts/Demo.meta
vendored
Normal file
8
Assets/ThirdParty/Ciconia Studio/_Shared Files/Scripts/Demo.meta
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c27e855c1de25d04dab99f3449eac973
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
145
Assets/ThirdParty/Ciconia Studio/_Shared Files/Scripts/Demo/FreeCam.cs
vendored
Normal file
145
Assets/ThirdParty/Ciconia Studio/_Shared Files/Scripts/Demo/FreeCam.cs
vendored
Normal file
@@ -0,0 +1,145 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// A simple free camera to be added to a Unity game object.
|
||||
///
|
||||
/// Keys:
|
||||
/// wasd / arrows - movement
|
||||
/// q/e - up/down (local space)
|
||||
/// r/f - up/down (world space)
|
||||
/// pageup/pagedown - up/down (world space)
|
||||
/// hold shift - enable fast movement mode
|
||||
/// right mouse - enable free look
|
||||
/// mouse - free look / rotation
|
||||
///
|
||||
/// </summary>
|
||||
public class FreeCam : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Normal speed of camera movement.
|
||||
/// </summary>
|
||||
public float movementSpeed = 10f;
|
||||
|
||||
/// <summary>
|
||||
/// Speed of camera movement when shift is held down,
|
||||
/// </summary>
|
||||
public float fastMovementSpeed = 100f;
|
||||
|
||||
/// <summary>
|
||||
/// Sensitivity for free look.
|
||||
/// </summary>
|
||||
public float freeLookSensitivity = 3f;
|
||||
|
||||
/// <summary>
|
||||
/// Amount to zoom the camera when using the mouse wheel.
|
||||
/// </summary>
|
||||
public float zoomSensitivity = 10f;
|
||||
|
||||
/// <summary>
|
||||
/// Amount to zoom the camera when using the mouse wheel (fast mode).
|
||||
/// </summary>
|
||||
public float fastZoomSensitivity = 50f;
|
||||
|
||||
/// <summary>
|
||||
/// Set to true when free looking (on right mouse button).
|
||||
/// </summary>
|
||||
private bool looking = false;
|
||||
|
||||
void Update()
|
||||
{
|
||||
var fastMode = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
|
||||
var movementSpeed = fastMode ? this.fastMovementSpeed : this.movementSpeed;
|
||||
|
||||
if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
|
||||
{
|
||||
transform.position = transform.position + (-transform.right * movementSpeed * Time.deltaTime);
|
||||
}
|
||||
|
||||
if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
|
||||
{
|
||||
transform.position = transform.position + (transform.right * movementSpeed * Time.deltaTime);
|
||||
}
|
||||
|
||||
if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
|
||||
{
|
||||
transform.position = transform.position + (transform.forward * movementSpeed * Time.deltaTime);
|
||||
}
|
||||
|
||||
if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
|
||||
{
|
||||
transform.position = transform.position + (-transform.forward * movementSpeed * Time.deltaTime);
|
||||
}
|
||||
|
||||
if (Input.GetKey(KeyCode.Q))
|
||||
{
|
||||
transform.position = transform.position + (transform.up * movementSpeed * Time.deltaTime);
|
||||
}
|
||||
|
||||
if (Input.GetKey(KeyCode.E))
|
||||
{
|
||||
transform.position = transform.position + (-transform.up * movementSpeed * Time.deltaTime);
|
||||
}
|
||||
|
||||
if (Input.GetKey(KeyCode.R) || Input.GetKey(KeyCode.PageUp))
|
||||
{
|
||||
transform.position = transform.position + (Vector3.up * movementSpeed * Time.deltaTime);
|
||||
}
|
||||
|
||||
if (Input.GetKey(KeyCode.F) || Input.GetKey(KeyCode.PageDown))
|
||||
{
|
||||
transform.position = transform.position + (-Vector3.up * movementSpeed * Time.deltaTime);
|
||||
}
|
||||
|
||||
if (looking)
|
||||
{
|
||||
float newRotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * freeLookSensitivity;
|
||||
float newRotationY = transform.localEulerAngles.x - Input.GetAxis("Mouse Y") * freeLookSensitivity;
|
||||
transform.localEulerAngles = new Vector3(newRotationY, newRotationX, 0f);
|
||||
}
|
||||
|
||||
float axis = Input.GetAxis("Mouse ScrollWheel");
|
||||
if (axis != 0)
|
||||
{
|
||||
var zoomSensitivity = fastMode ? this.fastZoomSensitivity : this.zoomSensitivity;
|
||||
transform.position = transform.position + transform.forward * axis * zoomSensitivity;
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Mouse1))
|
||||
{
|
||||
StartLooking();
|
||||
}
|
||||
else if (Input.GetKeyUp(KeyCode.Mouse1))
|
||||
{
|
||||
StopLooking();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
StopLooking();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enable free looking.
|
||||
/// </summary>
|
||||
public void StartLooking()
|
||||
{
|
||||
looking = true;
|
||||
Cursor.visible = false;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disable free looking.
|
||||
/// </summary>
|
||||
public void StopLooking()
|
||||
{
|
||||
looking = false;
|
||||
Cursor.visible = true;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/Ciconia Studio/_Shared Files/Scripts/Demo/FreeCam.cs.meta
vendored
Normal file
11
Assets/ThirdParty/Ciconia Studio/_Shared Files/Scripts/Demo/FreeCam.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a327e9ee6fee36c48b7b3c085b10ac47
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
74
Assets/ThirdParty/Ciconia Studio/_Shared Files/Scripts/Demo/FreeCamera.cs
vendored
Normal file
74
Assets/ThirdParty/Ciconia Studio/_Shared Files/Scripts/Demo/FreeCamera.cs
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class FreeCamera : MonoBehaviour {
|
||||
public bool enableInputCapture = true;
|
||||
public bool holdRightMouseCapture = false;
|
||||
|
||||
public float lookSpeed = 5f;
|
||||
public float moveSpeed = 5f;
|
||||
public float sprintSpeed = 50f;
|
||||
|
||||
bool m_inputCaptured;
|
||||
float m_yaw;
|
||||
float m_pitch;
|
||||
|
||||
void Awake() {
|
||||
enabled = enableInputCapture;
|
||||
}
|
||||
|
||||
void OnValidate() {
|
||||
if(Application.isPlaying)
|
||||
enabled = enableInputCapture;
|
||||
}
|
||||
|
||||
void CaptureInput() {
|
||||
|
||||
m_inputCaptured = true;
|
||||
|
||||
m_yaw = transform.eulerAngles.y;
|
||||
m_pitch = transform.eulerAngles.x;
|
||||
}
|
||||
|
||||
void ReleaseInput() {
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
m_inputCaptured = false;
|
||||
}
|
||||
|
||||
void OnApplicationFocus(bool focus) {
|
||||
if(m_inputCaptured && !focus)
|
||||
ReleaseInput();
|
||||
}
|
||||
|
||||
void Update() {
|
||||
if(!m_inputCaptured) {
|
||||
if(!holdRightMouseCapture && Input.GetMouseButtonDown(0))
|
||||
CaptureInput();
|
||||
else if(holdRightMouseCapture && Input.GetMouseButtonDown(1))
|
||||
CaptureInput();
|
||||
}
|
||||
|
||||
if(!m_inputCaptured)
|
||||
return;
|
||||
|
||||
if(m_inputCaptured) {
|
||||
if(!holdRightMouseCapture && Input.GetKeyDown(KeyCode.Escape))
|
||||
ReleaseInput();
|
||||
else if(holdRightMouseCapture && Input.GetMouseButtonUp(1))
|
||||
ReleaseInput();
|
||||
}
|
||||
|
||||
var rotStrafe = Input.GetAxis("Mouse X");
|
||||
var rotFwd = Input.GetAxis("Mouse Y");
|
||||
|
||||
m_yaw = (m_yaw + lookSpeed * rotStrafe) % 360f;
|
||||
m_pitch = (m_pitch - lookSpeed * rotFwd) % 360f;
|
||||
transform.rotation = Quaternion.AngleAxis(m_yaw, Vector3.up) * Quaternion.AngleAxis(m_pitch, Vector3.right);
|
||||
|
||||
var speed = Time.deltaTime * (Input.GetKey(KeyCode.LeftShift) ? sprintSpeed : moveSpeed);
|
||||
var forward = speed * Input.GetAxis("Vertical");
|
||||
var right = speed * Input.GetAxis("Horizontal");
|
||||
var up = speed * ((Input.GetKey(KeyCode.E) ? 1f : 0f) - (Input.GetKey(KeyCode.Q) ? 1f : 0f));
|
||||
transform.position += transform.forward * forward + transform.right * right + Vector3.up * up;
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/Ciconia Studio/_Shared Files/Scripts/Demo/FreeCamera.cs.meta
vendored
Normal file
11
Assets/ThirdParty/Ciconia Studio/_Shared Files/Scripts/Demo/FreeCamera.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8380dd9a5ff44ff459b72e0cca9670de
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
164
Assets/ThirdParty/Ciconia Studio/_Shared Files/Scripts/Demo/SuperCamera.cs
vendored
Normal file
164
Assets/ThirdParty/Ciconia Studio/_Shared Files/Scripts/Demo/SuperCamera.cs
vendored
Normal file
@@ -0,0 +1,164 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class SuperCamera : MonoBehaviour {
|
||||
|
||||
public GameObject pivot;
|
||||
|
||||
public KeyCode resetShortcut = KeyCode.Space;
|
||||
|
||||
[Range(0f, 100f)]
|
||||
public float rotationSensibility = 10f;
|
||||
public bool invertRotationX = false;
|
||||
public bool invertRotationY = false;
|
||||
|
||||
[Range(0f, 100f)]
|
||||
public float translationSensibility = 10f;
|
||||
public bool invertTranslationX = false;
|
||||
public bool invertTranslationY = false;
|
||||
|
||||
public float zoomMax = 2f;
|
||||
public float zoomMin = 20f;
|
||||
|
||||
[Range(0f, 100f)]
|
||||
public float wheelSensibility = 10;
|
||||
|
||||
|
||||
private float delayDoubleClic = 0.2f;
|
||||
|
||||
|
||||
private Vector3 oldCamPos;
|
||||
private Quaternion oldCamRot;
|
||||
private Vector3 oldMousePos;
|
||||
private float timeDoubleClic;
|
||||
private bool firstClic = false;
|
||||
private Vector3 pivotPos;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
pivotPos = pivot.transform.position;
|
||||
oldCamPos = Camera.main.transform.position;
|
||||
oldCamRot = Camera.main.transform.rotation;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
Debug.DrawRay(pivotPos, Vector3.up, Color.red);
|
||||
Debug.DrawRay(pivotPos, Camera.main.transform.right, Color.green);
|
||||
|
||||
if (Input.GetKeyDown(resetShortcut))
|
||||
{
|
||||
Camera.main.transform.position = oldCamPos;
|
||||
Camera.main.transform.rotation = oldCamRot;
|
||||
}
|
||||
|
||||
float wheel = Input.GetAxis("Mouse ScrollWheel");
|
||||
if (wheel != 0f)
|
||||
{
|
||||
Vector3 movVec = (pivotPos - Camera.main.transform.position);
|
||||
movVec.Normalize();
|
||||
movVec *= wheel/ 20 * wheelSensibility;
|
||||
Vector3 newPos = Camera.main.transform.position + movVec;
|
||||
if ((newPos - pivotPos).magnitude >= zoomMax && (newPos - pivotPos).magnitude <= zoomMin)
|
||||
{
|
||||
Camera.main.transform.position = newPos;
|
||||
}
|
||||
}
|
||||
|
||||
bool doubleClic = false;
|
||||
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
if (firstClic)
|
||||
{
|
||||
doubleClic = true;
|
||||
firstClic = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
firstClic = true;
|
||||
timeDoubleClic = Time.time;
|
||||
}
|
||||
}
|
||||
|
||||
if (firstClic && Time.time - timeDoubleClic > delayDoubleClic)
|
||||
{
|
||||
firstClic = false;
|
||||
}
|
||||
|
||||
|
||||
if (doubleClic)
|
||||
{
|
||||
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(ray, out hit))
|
||||
{
|
||||
pivotPos = hit.point;
|
||||
Debug.Log(hit.point);
|
||||
}
|
||||
else
|
||||
{
|
||||
pivotPos = pivot.transform.position;
|
||||
Debug.Log("reset Pivot");
|
||||
}
|
||||
}
|
||||
|
||||
if (!Input.GetMouseButton(0) && !Input.GetMouseButton(2))
|
||||
{
|
||||
//Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = true;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Cursor.visible = false;
|
||||
}
|
||||
|
||||
Vector3 mousePos = Input.mousePosition;
|
||||
|
||||
if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(2))
|
||||
{
|
||||
oldMousePos = mousePos;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (Input.GetMouseButton(2))
|
||||
{
|
||||
int factor = -1;
|
||||
if (invertTranslationX)
|
||||
{
|
||||
factor = 1;
|
||||
}
|
||||
gameObject.transform.Translate(new Vector3(factor * translationSensibility * (mousePos.x - oldMousePos.x) / 100f,0, 0));
|
||||
factor = -1;
|
||||
if (invertTranslationY)
|
||||
{
|
||||
factor = 1;
|
||||
}
|
||||
gameObject.transform.Translate(new Vector3(0, factor * translationSensibility * (mousePos.y - oldMousePos.y) / 100f, 0));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
int factor = 1;
|
||||
if (invertRotationX)
|
||||
{
|
||||
factor = -1;
|
||||
}
|
||||
gameObject.transform.RotateAround(pivotPos, Vector3.up, factor * rotationSensibility * (mousePos.x - oldMousePos.x)/100f);
|
||||
factor = 1;
|
||||
if (invertRotationY)
|
||||
{
|
||||
factor = -1;
|
||||
}
|
||||
gameObject.transform.RotateAround(pivotPos, Camera.main.transform.right, factor * - rotationSensibility * (mousePos.y - oldMousePos.y)/100f);
|
||||
|
||||
}
|
||||
|
||||
|
||||
oldMousePos = mousePos;
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/Ciconia Studio/_Shared Files/Scripts/Demo/SuperCamera.cs.meta
vendored
Normal file
11
Assets/ThirdParty/Ciconia Studio/_Shared Files/Scripts/Demo/SuperCamera.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dec7eeaee8ae52f409f0518a94bad221
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
43
Assets/ThirdParty/Ciconia Studio/_Shared Files/Scripts/Demo/UIButton_ShowNext.cs
vendored
Normal file
43
Assets/ThirdParty/Ciconia Studio/_Shared Files/Scripts/Demo/UIButton_ShowNext.cs
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class UIButton_ShowNext : MonoBehaviour
|
||||
{
|
||||
// GameObjects list
|
||||
public GameObject[] GameObjectsList;
|
||||
private int shownGameObjectIndex = -1;
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
for (int i = 0; i < GameObjectsList.Length; ++i)
|
||||
GameObjectsList[i].SetActive(false);
|
||||
SelectNextGameObject();
|
||||
}
|
||||
|
||||
|
||||
// Next or previous GameObjects onClick
|
||||
public void SelectNextGameObject()
|
||||
{
|
||||
int index = shownGameObjectIndex >= GameObjectsList.Length - 1 ? -1 : shownGameObjectIndex;
|
||||
SelectGameObject(index + 1);
|
||||
}
|
||||
public void SelectPreviousGameObject()
|
||||
{
|
||||
int index = shownGameObjectIndex <= 0 ? GameObjectsList.Length : shownGameObjectIndex;
|
||||
SelectGameObject(index - 1);
|
||||
}
|
||||
public void SelectGameObject(int index)
|
||||
{
|
||||
if (shownGameObjectIndex >= 0)
|
||||
GameObjectsList[shownGameObjectIndex].SetActive(false);
|
||||
shownGameObjectIndex = index;
|
||||
GameObjectsList[shownGameObjectIndex].SetActive(true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
11
Assets/ThirdParty/Ciconia Studio/_Shared Files/Scripts/Demo/UIButton_ShowNext.cs.meta
vendored
Normal file
11
Assets/ThirdParty/Ciconia Studio/_Shared Files/Scripts/Demo/UIButton_ShowNext.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 09c459dc70065c541a7e3b5d7ccbd6f1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/ThirdParty/Mirror.meta
vendored
Normal file
8
Assets/ThirdParty/Mirror.meta
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c19439d44c2665c4e8a2a3b7110afa38
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/ThirdParty/Mirror/Authenticators.meta
vendored
Normal file
8
Assets/ThirdParty/Mirror/Authenticators.meta
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b2f9d254154cd942ba40b06b869b8f3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
192
Assets/ThirdParty/Mirror/Authenticators/BasicAuthenticator.cs
vendored
Normal file
192
Assets/ThirdParty/Mirror/Authenticators/BasicAuthenticator.cs
vendored
Normal file
@@ -0,0 +1,192 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror.Authenticators
|
||||
{
|
||||
[AddComponentMenu("Network/ Authenticators/Basic Authenticator")]
|
||||
[HelpURL("https://mirror-networking.gitbook.io/docs/components/network-authenticators/basic-authenticator")]
|
||||
public class BasicAuthenticator : NetworkAuthenticator
|
||||
{
|
||||
[Header("Server Credentials")]
|
||||
public string serverUsername;
|
||||
public string serverPassword;
|
||||
|
||||
[Header("Client Credentials")]
|
||||
public string username;
|
||||
public string password;
|
||||
|
||||
readonly HashSet<NetworkConnectionToClient> connectionsPendingDisconnect = new HashSet<NetworkConnectionToClient>();
|
||||
|
||||
#region Messages
|
||||
|
||||
public struct AuthRequestMessage : NetworkMessage
|
||||
{
|
||||
// use whatever credentials make sense for your game
|
||||
// for example, you might want to pass the accessToken if using oauth
|
||||
public string authUsername;
|
||||
public string authPassword;
|
||||
}
|
||||
|
||||
public struct AuthResponseMessage : NetworkMessage
|
||||
{
|
||||
public byte code;
|
||||
public string message;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Server
|
||||
|
||||
/// <summary>
|
||||
/// Called on server from StartServer to initialize the Authenticator
|
||||
/// <para>Server message handlers should be registered in this method.</para>
|
||||
/// </summary>
|
||||
public override void OnStartServer()
|
||||
{
|
||||
// register a handler for the authentication request we expect from client
|
||||
NetworkServer.RegisterHandler<AuthRequestMessage>(OnAuthRequestMessage, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called on server from StopServer to reset the Authenticator
|
||||
/// <para>Server message handlers should be unregistered in this method.</para>
|
||||
/// </summary>
|
||||
public override void OnStopServer()
|
||||
{
|
||||
// unregister the handler for the authentication request
|
||||
NetworkServer.UnregisterHandler<AuthRequestMessage>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called on server from OnServerConnectInternal when a client needs to authenticate
|
||||
/// </summary>
|
||||
/// <param name="conn">Connection to client.</param>
|
||||
public override void OnServerAuthenticate(NetworkConnectionToClient conn)
|
||||
{
|
||||
// do nothing...wait for AuthRequestMessage from client
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called on server when the client's AuthRequestMessage arrives
|
||||
/// </summary>
|
||||
/// <param name="conn">Connection to client.</param>
|
||||
/// <param name="msg">The message payload</param>
|
||||
public void OnAuthRequestMessage(NetworkConnectionToClient conn, AuthRequestMessage msg)
|
||||
{
|
||||
//Debug.Log($"Authentication Request: {msg.authUsername} {msg.authPassword}");
|
||||
|
||||
if (connectionsPendingDisconnect.Contains(conn)) return;
|
||||
|
||||
// check the credentials by calling your web server, database table, playfab api, or any method appropriate.
|
||||
if (msg.authUsername == serverUsername && msg.authPassword == serverPassword)
|
||||
{
|
||||
// create and send msg to client so it knows to proceed
|
||||
AuthResponseMessage authResponseMessage = new AuthResponseMessage
|
||||
{
|
||||
code = 100,
|
||||
message = "Success"
|
||||
};
|
||||
|
||||
conn.Send(authResponseMessage);
|
||||
|
||||
// Accept the successful authentication
|
||||
ServerAccept(conn);
|
||||
}
|
||||
else
|
||||
{
|
||||
connectionsPendingDisconnect.Add(conn);
|
||||
|
||||
// create and send msg to client so it knows to disconnect
|
||||
AuthResponseMessage authResponseMessage = new AuthResponseMessage
|
||||
{
|
||||
code = 200,
|
||||
message = "Invalid Credentials"
|
||||
};
|
||||
|
||||
conn.Send(authResponseMessage);
|
||||
|
||||
// must set NetworkConnection isAuthenticated = false
|
||||
conn.isAuthenticated = false;
|
||||
|
||||
// disconnect the client after 1 second so that response message gets delivered
|
||||
StartCoroutine(DelayedDisconnect(conn, 1f));
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator DelayedDisconnect(NetworkConnectionToClient conn, float waitTime)
|
||||
{
|
||||
yield return new WaitForSeconds(waitTime);
|
||||
|
||||
// Reject the unsuccessful authentication
|
||||
ServerReject(conn);
|
||||
|
||||
yield return null;
|
||||
|
||||
// remove conn from pending connections
|
||||
connectionsPendingDisconnect.Remove(conn);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Client
|
||||
|
||||
/// <summary>
|
||||
/// Called on client from StartClient to initialize the Authenticator
|
||||
/// <para>Client message handlers should be registered in this method.</para>
|
||||
/// </summary>
|
||||
public override void OnStartClient()
|
||||
{
|
||||
// register a handler for the authentication response we expect from server
|
||||
NetworkClient.RegisterHandler<AuthResponseMessage>(OnAuthResponseMessage, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called on client from StopClient to reset the Authenticator
|
||||
/// <para>Client message handlers should be unregistered in this method.</para>
|
||||
/// </summary>
|
||||
public override void OnStopClient()
|
||||
{
|
||||
// unregister the handler for the authentication response
|
||||
NetworkClient.UnregisterHandler<AuthResponseMessage>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called on client from OnClientConnectInternal when a client needs to authenticate
|
||||
/// </summary>
|
||||
public override void OnClientAuthenticate()
|
||||
{
|
||||
AuthRequestMessage authRequestMessage = new AuthRequestMessage
|
||||
{
|
||||
authUsername = username,
|
||||
authPassword = password
|
||||
};
|
||||
|
||||
NetworkClient.Send(authRequestMessage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called on client when the server's AuthResponseMessage arrives
|
||||
/// </summary>
|
||||
/// <param name="msg">The message payload</param>
|
||||
public void OnAuthResponseMessage(AuthResponseMessage msg)
|
||||
{
|
||||
if (msg.code == 100)
|
||||
{
|
||||
//Debug.Log($"Authentication Response: {msg.message}");
|
||||
|
||||
// Authentication has been accepted
|
||||
ClientAccept();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"Authentication Response: {msg.message}");
|
||||
|
||||
// Authentication has been rejected
|
||||
ClientReject();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/Mirror/Authenticators/BasicAuthenticator.cs.meta
vendored
Normal file
11
Assets/ThirdParty/Mirror/Authenticators/BasicAuthenticator.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 28496b776660156428f00cf78289c1ec
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 7453abfe9e8b2c04a8a47eb536fe21eb, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
129
Assets/ThirdParty/Mirror/Authenticators/DeviceAuthenticator.cs
vendored
Normal file
129
Assets/ThirdParty/Mirror/Authenticators/DeviceAuthenticator.cs
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror.Authenticators
|
||||
{
|
||||
/// <summary>
|
||||
/// An authenticator that identifies the user by their device.
|
||||
/// <para>A GUID is used as a fallback when the platform doesn't support SystemInfo.deviceUniqueIdentifier.</para>
|
||||
/// <para>Note: deviceUniqueIdentifier can be spoofed, so security is not guaranteed.</para>
|
||||
/// <para>See https://docs.unity3d.com/ScriptReference/SystemInfo-deviceUniqueIdentifier.html for details.</para>
|
||||
/// </summary>
|
||||
[AddComponentMenu("Network/ Authenticators/Device Authenticator")]
|
||||
[HelpURL("https://mirror-networking.gitbook.io/docs/components/network-authenticators/device-authenticator")]
|
||||
public class DeviceAuthenticator : NetworkAuthenticator
|
||||
{
|
||||
#region Messages
|
||||
|
||||
public struct AuthRequestMessage : NetworkMessage
|
||||
{
|
||||
public string clientDeviceID;
|
||||
}
|
||||
|
||||
public struct AuthResponseMessage : NetworkMessage { }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Server
|
||||
|
||||
/// <summary>
|
||||
/// Called on server from StartServer to initialize the Authenticator
|
||||
/// <para>Server message handlers should be registered in this method.</para>
|
||||
/// </summary>
|
||||
public override void OnStartServer()
|
||||
{
|
||||
// register a handler for the authentication request we expect from client
|
||||
NetworkServer.RegisterHandler<AuthRequestMessage>(OnAuthRequestMessage, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called on server from StopServer to reset the Authenticator
|
||||
/// <para>Server message handlers should be registered in this method.</para>
|
||||
/// </summary>
|
||||
public override void OnStopServer()
|
||||
{
|
||||
// unregister the handler for the authentication request
|
||||
NetworkServer.UnregisterHandler<AuthRequestMessage>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called on server from OnServerConnectInternal when a client needs to authenticate
|
||||
/// </summary>
|
||||
/// <param name="conn">Connection to client.</param>
|
||||
public override void OnServerAuthenticate(NetworkConnectionToClient conn)
|
||||
{
|
||||
// do nothing, wait for client to send his id
|
||||
}
|
||||
|
||||
void OnAuthRequestMessage(NetworkConnectionToClient conn, AuthRequestMessage msg)
|
||||
{
|
||||
Debug.Log($"connection {conn.connectionId} authenticated with id {msg.clientDeviceID}");
|
||||
|
||||
// Store the device id for later reference, e.g. when spawning the player
|
||||
conn.authenticationData = msg.clientDeviceID;
|
||||
|
||||
// Send a response to client telling it to proceed as authenticated
|
||||
conn.Send(new AuthResponseMessage());
|
||||
|
||||
// Accept the successful authentication
|
||||
ServerAccept(conn);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Client
|
||||
|
||||
/// <summary>
|
||||
/// Called on client from StartClient to initialize the Authenticator
|
||||
/// <para>Client message handlers should be registered in this method.</para>
|
||||
/// </summary>
|
||||
public override void OnStartClient()
|
||||
{
|
||||
// register a handler for the authentication response we expect from server
|
||||
NetworkClient.RegisterHandler<AuthResponseMessage>(OnAuthResponseMessage, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called on client from StopClient to reset the Authenticator
|
||||
/// <para>Client message handlers should be unregistered in this method.</para>
|
||||
/// </summary>
|
||||
public override void OnStopClient()
|
||||
{
|
||||
// unregister the handler for the authentication response
|
||||
NetworkClient.UnregisterHandler<AuthResponseMessage>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called on client from OnClientConnectInternal when a client needs to authenticate
|
||||
/// </summary>
|
||||
public override void OnClientAuthenticate()
|
||||
{
|
||||
string deviceUniqueIdentifier = SystemInfo.deviceUniqueIdentifier;
|
||||
|
||||
// Not all platforms support this, so we use a GUID instead
|
||||
if (deviceUniqueIdentifier == SystemInfo.unsupportedIdentifier)
|
||||
{
|
||||
// Get the value from PlayerPrefs if it exists, new GUID if it doesn't
|
||||
deviceUniqueIdentifier = PlayerPrefs.GetString("deviceUniqueIdentifier", Guid.NewGuid().ToString());
|
||||
|
||||
// Store the deviceUniqueIdentifier to PlayerPrefs (in case we just made a new GUID)
|
||||
PlayerPrefs.SetString("deviceUniqueIdentifier", deviceUniqueIdentifier);
|
||||
}
|
||||
|
||||
// send the deviceUniqueIdentifier to the server
|
||||
NetworkClient.Send(new AuthRequestMessage { clientDeviceID = deviceUniqueIdentifier } );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called on client when the server's AuthResponseMessage arrives
|
||||
/// </summary>
|
||||
/// <param name="msg">The message payload</param>
|
||||
public void OnAuthResponseMessage(AuthResponseMessage msg)
|
||||
{
|
||||
Debug.Log("Authentication Success");
|
||||
ClientAccept();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/Mirror/Authenticators/DeviceAuthenticator.cs.meta
vendored
Normal file
11
Assets/ThirdParty/Mirror/Authenticators/DeviceAuthenticator.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 60960a6ba81a842deb2fdcdc93788242
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 7453abfe9e8b2c04a8a47eb536fe21eb, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
16
Assets/ThirdParty/Mirror/Authenticators/Mirror.Authenticators.asmdef
vendored
Normal file
16
Assets/ThirdParty/Mirror/Authenticators/Mirror.Authenticators.asmdef
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "Mirror.Authenticators",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:30817c1a0e6d646d99c048fc403f5979"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
7
Assets/ThirdParty/Mirror/Authenticators/Mirror.Authenticators.asmdef.meta
vendored
Normal file
7
Assets/ThirdParty/Mirror/Authenticators/Mirror.Authenticators.asmdef.meta
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e720aa64e3f58fb4880566a322584340
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
70
Assets/ThirdParty/Mirror/Authenticators/TimeoutAuthenticator.cs
vendored
Normal file
70
Assets/ThirdParty/Mirror/Authenticators/TimeoutAuthenticator.cs
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror.Authenticators
|
||||
{
|
||||
/// <summary>
|
||||
/// An authenticator that disconnects connections if they don't
|
||||
/// authenticate within a specified time limit.
|
||||
/// </summary>
|
||||
[AddComponentMenu("Network/ Authenticators/Timeout Authenticator")]
|
||||
public class TimeoutAuthenticator : NetworkAuthenticator
|
||||
{
|
||||
public NetworkAuthenticator authenticator;
|
||||
|
||||
[Range(0, 600), Tooltip("Timeout to auto-disconnect in seconds. Set to 0 for no timeout.")]
|
||||
public float timeout = 60;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
authenticator.OnServerAuthenticated.AddListener(connection => OnServerAuthenticated.Invoke(connection));
|
||||
authenticator.OnClientAuthenticated.AddListener(OnClientAuthenticated.Invoke);
|
||||
}
|
||||
|
||||
public override void OnStartServer()
|
||||
{
|
||||
authenticator.OnStartServer();
|
||||
}
|
||||
|
||||
public override void OnStopServer()
|
||||
{
|
||||
authenticator.OnStopServer();
|
||||
}
|
||||
|
||||
public override void OnStartClient()
|
||||
{
|
||||
authenticator.OnStartClient();
|
||||
}
|
||||
|
||||
public override void OnStopClient()
|
||||
{
|
||||
authenticator.OnStopClient();
|
||||
}
|
||||
|
||||
public override void OnServerAuthenticate(NetworkConnectionToClient conn)
|
||||
{
|
||||
authenticator.OnServerAuthenticate(conn);
|
||||
if (timeout > 0)
|
||||
StartCoroutine(BeginAuthentication(conn));
|
||||
}
|
||||
|
||||
public override void OnClientAuthenticate()
|
||||
{
|
||||
authenticator.OnClientAuthenticate();
|
||||
if (timeout > 0)
|
||||
StartCoroutine(BeginAuthentication(NetworkClient.connection));
|
||||
}
|
||||
|
||||
IEnumerator BeginAuthentication(NetworkConnection conn)
|
||||
{
|
||||
//Debug.Log($"Authentication countdown started {conn} {timeout}");
|
||||
yield return new WaitForSecondsRealtime(timeout);
|
||||
|
||||
if (!conn.isAuthenticated)
|
||||
{
|
||||
Debug.LogError($"Authentication Timeout - Disconnecting {conn}");
|
||||
conn.Disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/Mirror/Authenticators/TimeoutAuthenticator.cs.meta
vendored
Normal file
11
Assets/ThirdParty/Mirror/Authenticators/TimeoutAuthenticator.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 24d8269a07b8e4edfa374753a91c946e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 7453abfe9e8b2c04a8a47eb536fe21eb, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/ThirdParty/Mirror/CompilerSymbols.meta
vendored
Normal file
8
Assets/ThirdParty/Mirror/CompilerSymbols.meta
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f8b918bcd89f5c488b06f5574f34760
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14
Assets/ThirdParty/Mirror/CompilerSymbols/Mirror.CompilerSymbols.asmdef
vendored
Normal file
14
Assets/ThirdParty/Mirror/CompilerSymbols/Mirror.CompilerSymbols.asmdef
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "Mirror.CompilerSymbols",
|
||||
"references": [],
|
||||
"optionalUnityReferences": [],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": []
|
||||
}
|
||||
7
Assets/ThirdParty/Mirror/CompilerSymbols/Mirror.CompilerSymbols.asmdef.meta
vendored
Normal file
7
Assets/ThirdParty/Mirror/CompilerSymbols/Mirror.CompilerSymbols.asmdef.meta
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 325984b52e4128546bc7558552f8b1d2
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
45
Assets/ThirdParty/Mirror/CompilerSymbols/PreprocessorDefine.cs
vendored
Normal file
45
Assets/ThirdParty/Mirror/CompilerSymbols/PreprocessorDefine.cs
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Mirror
|
||||
{
|
||||
static class PreprocessorDefine
|
||||
{
|
||||
/// <summary>
|
||||
/// Add define symbols as soon as Unity gets done compiling.
|
||||
/// </summary>
|
||||
[InitializeOnLoadMethod]
|
||||
public static void AddDefineSymbols()
|
||||
{
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
string currentDefines = PlayerSettings.GetScriptingDefineSymbols(UnityEditor.Build.NamedBuildTarget.FromBuildTargetGroup(EditorUserBuildSettings.selectedBuildTargetGroup));
|
||||
#else
|
||||
// Deprecated in Unity 2023.1
|
||||
string currentDefines = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
|
||||
#endif
|
||||
// Remove oldest when adding next month's symbol.
|
||||
// Keep a rolling 12 months of symbols.
|
||||
HashSet<string> defines = new HashSet<string>(currentDefines.Split(';'))
|
||||
{
|
||||
"MIRROR",
|
||||
"MIRROR_89_OR_NEWER",
|
||||
"MIRROR_90_OR_NEWER",
|
||||
"MIRROR_93_OR_NEWER",
|
||||
"MIRROR_96_OR_NEWER"
|
||||
};
|
||||
|
||||
// only touch PlayerSettings if we actually modified it,
|
||||
// otherwise it shows up as changed in git each time.
|
||||
string newDefines = string.Join(";", defines);
|
||||
if (newDefines != currentDefines)
|
||||
{
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
PlayerSettings.SetScriptingDefineSymbols(UnityEditor.Build.NamedBuildTarget.FromBuildTargetGroup(EditorUserBuildSettings.selectedBuildTargetGroup), newDefines);
|
||||
#else
|
||||
// Deprecated in Unity 2023.1
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, newDefines);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/Mirror/CompilerSymbols/PreprocessorDefine.cs.meta
vendored
Normal file
11
Assets/ThirdParty/Mirror/CompilerSymbols/PreprocessorDefine.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1d66fe74ec6f42dd974cba37d25d453
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 7453abfe9e8b2c04a8a47eb536fe21eb, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/ThirdParty/Mirror/Components.meta
vendored
Normal file
8
Assets/ThirdParty/Mirror/Components.meta
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9bee879fbc8ef4b1a9a9f7088bfbf726
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
12
Assets/ThirdParty/Mirror/Components/AssemblyInfo.cs
vendored
Normal file
12
Assets/ThirdParty/Mirror/Components/AssemblyInfo.cs
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Mirror.Tests.Common")]
|
||||
[assembly: InternalsVisibleTo("Mirror.Tests")]
|
||||
// need to use Unity.*.CodeGen assembly name to import Unity.CompilationPipeline
|
||||
// for ILPostProcessor tests.
|
||||
[assembly: InternalsVisibleTo("Unity.Mirror.Tests.CodeGen")]
|
||||
[assembly: InternalsVisibleTo("Mirror.Tests.Generated")]
|
||||
[assembly: InternalsVisibleTo("Mirror.Tests.Runtime")]
|
||||
[assembly: InternalsVisibleTo("Mirror.Tests.Performance.Editor")]
|
||||
[assembly: InternalsVisibleTo("Mirror.Tests.Performance.Runtime")]
|
||||
[assembly: InternalsVisibleTo("Mirror.Editor")]
|
||||
11
Assets/ThirdParty/Mirror/Components/AssemblyInfo.cs.meta
vendored
Normal file
11
Assets/ThirdParty/Mirror/Components/AssemblyInfo.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a65b9283f7a724e70b8e17cb277f4c1e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 7453abfe9e8b2c04a8a47eb536fe21eb, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/ThirdParty/Mirror/Components/Discovery.meta
vendored
Normal file
8
Assets/ThirdParty/Mirror/Components/Discovery.meta
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5dcf9618f5e14a4eb60bff5480284a6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
93
Assets/ThirdParty/Mirror/Components/Discovery/NetworkDiscovery.cs
vendored
Normal file
93
Assets/ThirdParty/Mirror/Components/Discovery/NetworkDiscovery.cs
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Mirror.Discovery
|
||||
{
|
||||
[Serializable]
|
||||
public class ServerFoundUnityEvent<TResponseType> : UnityEvent<TResponseType> {};
|
||||
|
||||
[DisallowMultipleComponent]
|
||||
[AddComponentMenu("Network/Network Discovery")]
|
||||
public class NetworkDiscovery : NetworkDiscoveryBase<ServerRequest, ServerResponse>
|
||||
{
|
||||
#region Server
|
||||
|
||||
/// <summary>
|
||||
/// Process the request from a client
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Override if you wish to provide more information to the clients
|
||||
/// such as the name of the host player
|
||||
/// </remarks>
|
||||
/// <param name="request">Request coming from client</param>
|
||||
/// <param name="endpoint">Address of the client that sent the request</param>
|
||||
/// <returns>The message to be sent back to the client or null</returns>
|
||||
protected override ServerResponse ProcessRequest(ServerRequest request, IPEndPoint endpoint)
|
||||
{
|
||||
// In this case we don't do anything with the request
|
||||
// but other discovery implementations might want to use the data
|
||||
// in there, This way the client can ask for
|
||||
// specific game mode or something
|
||||
|
||||
try
|
||||
{
|
||||
// this is an example reply message, return your own
|
||||
// to include whatever is relevant for your game
|
||||
return new ServerResponse
|
||||
{
|
||||
serverId = ServerId,
|
||||
uri = transport.ServerUri()
|
||||
};
|
||||
}
|
||||
catch (NotImplementedException)
|
||||
{
|
||||
Debug.LogError($"Transport {transport} does not support network discovery");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Client
|
||||
|
||||
/// <summary>
|
||||
/// Create a message that will be broadcasted on the network to discover servers
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Override if you wish to include additional data in the discovery message
|
||||
/// such as desired game mode, language, difficulty, etc... </remarks>
|
||||
/// <returns>An instance of ServerRequest with data to be broadcasted</returns>
|
||||
protected override ServerRequest GetRequest() => new ServerRequest();
|
||||
|
||||
/// <summary>
|
||||
/// Process the answer from a server
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A client receives a reply from a server, this method processes the
|
||||
/// reply and raises an event
|
||||
/// </remarks>
|
||||
/// <param name="response">Response that came from the server</param>
|
||||
/// <param name="endpoint">Address of the server that replied</param>
|
||||
protected override void ProcessResponse(ServerResponse response, IPEndPoint endpoint)
|
||||
{
|
||||
// we received a message from the remote endpoint
|
||||
response.EndPoint = endpoint;
|
||||
|
||||
// although we got a supposedly valid url, we may not be able to resolve
|
||||
// the provided host
|
||||
// However we know the real ip address of the server because we just
|
||||
// received a packet from it, so use that as host.
|
||||
UriBuilder realUri = new UriBuilder(response.uri)
|
||||
{
|
||||
Host = response.EndPoint.Address.ToString()
|
||||
};
|
||||
response.uri = realUri.Uri;
|
||||
|
||||
OnServerFound.Invoke(response);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/Mirror/Components/Discovery/NetworkDiscovery.cs.meta
vendored
Normal file
11
Assets/ThirdParty/Mirror/Components/Discovery/NetworkDiscovery.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c761308e733c51245b2e8bb4201f46dc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 7453abfe9e8b2c04a8a47eb536fe21eb, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
473
Assets/ThirdParty/Mirror/Components/Discovery/NetworkDiscoveryBase.cs
vendored
Normal file
473
Assets/ThirdParty/Mirror/Components/Discovery/NetworkDiscoveryBase.cs
vendored
Normal file
@@ -0,0 +1,473 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
// Based on https://github.com/EnlightenedOne/MirrorNetworkDiscovery
|
||||
// forked from https://github.com/in0finite/MirrorNetworkDiscovery
|
||||
// Both are MIT Licensed
|
||||
|
||||
namespace Mirror.Discovery
|
||||
{
|
||||
/// <summary>
|
||||
/// Base implementation for Network Discovery. Extend this component
|
||||
/// to provide custom discovery with game specific data
|
||||
/// <see cref="NetworkDiscovery">NetworkDiscovery</see> for a sample implementation
|
||||
/// </summary>
|
||||
[DisallowMultipleComponent]
|
||||
[HelpURL("https://mirror-networking.gitbook.io/docs/components/network-discovery")]
|
||||
public abstract class NetworkDiscoveryBase<Request, Response> : MonoBehaviour
|
||||
where Request : NetworkMessage
|
||||
where Response : NetworkMessage
|
||||
{
|
||||
public static bool SupportedOnThisPlatform { get { return Application.platform != RuntimePlatform.WebGLPlayer; } }
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("If true, broadcasts a discovery request every ActiveDiscoveryInterval seconds")]
|
||||
public bool enableActiveDiscovery = true;
|
||||
|
||||
// broadcast address needs to be configurable on iOS:
|
||||
// https://github.com/vis2k/Mirror/pull/3255
|
||||
[Tooltip("iOS may require LAN IP address here (e.g. 192.168.x.x), otherwise leave blank.")]
|
||||
public string BroadcastAddress = "";
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("The UDP port the server will listen for multi-cast messages")]
|
||||
protected int serverBroadcastListenPort = 47777;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("Time in seconds between multi-cast messages")]
|
||||
[Range(1, 60)]
|
||||
float ActiveDiscoveryInterval = 3;
|
||||
|
||||
[Tooltip("Transport to be advertised during discovery")]
|
||||
public Transport transport;
|
||||
|
||||
[Tooltip("Invoked when a server is found")]
|
||||
public ServerFoundUnityEvent<Response> OnServerFound;
|
||||
|
||||
// Each game should have a random unique handshake,
|
||||
// this way you can tell if this is the same game or not
|
||||
[HideInInspector]
|
||||
public long secretHandshake;
|
||||
|
||||
public long ServerId { get; private set; }
|
||||
|
||||
protected UdpClient serverUdpClient;
|
||||
protected UdpClient clientUdpClient;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public virtual void OnValidate()
|
||||
{
|
||||
if (transport == null)
|
||||
transport = GetComponent<Transport>();
|
||||
|
||||
if (secretHandshake == 0)
|
||||
{
|
||||
secretHandshake = RandomLong();
|
||||
UnityEditor.Undo.RecordObject(this, "Set secret handshake");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// virtual so that inheriting classes' Start() can call base.Start() too
|
||||
/// </summary>
|
||||
public virtual void Start()
|
||||
{
|
||||
ServerId = RandomLong();
|
||||
|
||||
// active transport gets initialized in Awake
|
||||
// so make sure we set it here in Start() after Awake
|
||||
// Or just let the user assign it in the inspector
|
||||
if (transport == null)
|
||||
transport = Transport.active;
|
||||
|
||||
// Server mode? then start advertising
|
||||
if (Utils.IsHeadless())
|
||||
{
|
||||
AdvertiseServer();
|
||||
}
|
||||
}
|
||||
|
||||
public static long RandomLong()
|
||||
{
|
||||
int value1 = UnityEngine.Random.Range(int.MinValue, int.MaxValue);
|
||||
int value2 = UnityEngine.Random.Range(int.MinValue, int.MaxValue);
|
||||
return value1 + ((long)value2 << 32);
|
||||
}
|
||||
|
||||
// Ensure the ports are cleared no matter when Game/Unity UI exits
|
||||
void OnApplicationQuit()
|
||||
{
|
||||
//Debug.Log("NetworkDiscoveryBase OnApplicationQuit");
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
//Debug.Log("NetworkDiscoveryBase OnDisable");
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
//Debug.Log("NetworkDiscoveryBase OnDestroy");
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
void Shutdown()
|
||||
{
|
||||
EndpMulticastLock();
|
||||
if (serverUdpClient != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
serverUdpClient.Close();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// it is just close, swallow the error
|
||||
}
|
||||
|
||||
serverUdpClient = null;
|
||||
}
|
||||
|
||||
if (clientUdpClient != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
clientUdpClient.Close();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// it is just close, swallow the error
|
||||
}
|
||||
|
||||
clientUdpClient = null;
|
||||
}
|
||||
|
||||
CancelInvoke();
|
||||
}
|
||||
|
||||
#region Server
|
||||
|
||||
/// <summary>
|
||||
/// Advertise this server in the local network
|
||||
/// </summary>
|
||||
public void AdvertiseServer()
|
||||
{
|
||||
if (!SupportedOnThisPlatform)
|
||||
throw new PlatformNotSupportedException("Network discovery not supported in this platform");
|
||||
|
||||
StopDiscovery();
|
||||
|
||||
// Setup port -- may throw exception
|
||||
serverUdpClient = new UdpClient(serverBroadcastListenPort)
|
||||
{
|
||||
EnableBroadcast = true,
|
||||
MulticastLoopback = false
|
||||
};
|
||||
|
||||
//Debug.Log($"Discovery: Advertising Server {Dns.GetHostName()}");
|
||||
|
||||
// listen for client pings
|
||||
_ = ServerListenAsync();
|
||||
}
|
||||
|
||||
public async Task ServerListenAsync()
|
||||
{
|
||||
BeginMulticastLock();
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
await ReceiveRequestAsync(serverUdpClient);
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
// socket has been closed
|
||||
break;
|
||||
}
|
||||
catch (Exception) {}
|
||||
}
|
||||
}
|
||||
|
||||
async Task ReceiveRequestAsync(UdpClient udpClient)
|
||||
{
|
||||
// only proceed if there is available data in network buffer, or otherwise Receive() will block
|
||||
// average time for UdpClient.Available : 10 us
|
||||
|
||||
UdpReceiveResult udpReceiveResult = await udpClient.ReceiveAsync();
|
||||
|
||||
using (NetworkReaderPooled networkReader = NetworkReaderPool.Get(udpReceiveResult.Buffer))
|
||||
{
|
||||
long handshake = networkReader.ReadLong();
|
||||
if (handshake != secretHandshake)
|
||||
{
|
||||
// message is not for us
|
||||
throw new ProtocolViolationException("Invalid handshake");
|
||||
}
|
||||
|
||||
Request request = networkReader.Read<Request>();
|
||||
|
||||
ProcessClientRequest(request, udpReceiveResult.RemoteEndPoint);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reply to the client to inform it of this server
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Override if you wish to ignore server requests based on
|
||||
/// custom criteria such as language, full server game mode or difficulty
|
||||
/// </remarks>
|
||||
/// <param name="request">Request coming from client</param>
|
||||
/// <param name="endpoint">Address of the client that sent the request</param>
|
||||
protected virtual void ProcessClientRequest(Request request, IPEndPoint endpoint)
|
||||
{
|
||||
Response info = ProcessRequest(request, endpoint);
|
||||
|
||||
if (info == null)
|
||||
return;
|
||||
|
||||
using (NetworkWriterPooled writer = NetworkWriterPool.Get())
|
||||
{
|
||||
try
|
||||
{
|
||||
writer.WriteLong(secretHandshake);
|
||||
|
||||
writer.Write(info);
|
||||
|
||||
ArraySegment<byte> data = writer.ToArraySegment();
|
||||
// signature matches
|
||||
// send response
|
||||
serverUdpClient.Send(data.Array, data.Count, endpoint);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogException(ex, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Process the request from a client
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Override if you wish to provide more information to the clients
|
||||
/// such as the name of the host player
|
||||
/// </remarks>
|
||||
/// <param name="request">Request coming from client</param>
|
||||
/// <param name="endpoint">Address of the client that sent the request</param>
|
||||
/// <returns>The message to be sent back to the client or null</returns>
|
||||
protected abstract Response ProcessRequest(Request request, IPEndPoint endpoint);
|
||||
|
||||
// Android Multicast fix: https://github.com/vis2k/Mirror/pull/2887
|
||||
#if UNITY_ANDROID
|
||||
AndroidJavaObject multicastLock;
|
||||
bool hasMulticastLock;
|
||||
#endif
|
||||
|
||||
void BeginMulticastLock()
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
if (hasMulticastLock) return;
|
||||
|
||||
if (Application.platform == RuntimePlatform.Android)
|
||||
{
|
||||
using (AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity"))
|
||||
{
|
||||
using (var wifiManager = activity.Call<AndroidJavaObject>("getSystemService", "wifi"))
|
||||
{
|
||||
multicastLock = wifiManager.Call<AndroidJavaObject>("createMulticastLock", "lock");
|
||||
multicastLock.Call("acquire");
|
||||
hasMulticastLock = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void EndpMulticastLock()
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
if (!hasMulticastLock) return;
|
||||
|
||||
multicastLock?.Call("release");
|
||||
hasMulticastLock = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Client
|
||||
|
||||
/// <summary>
|
||||
/// Start Active Discovery
|
||||
/// </summary>
|
||||
public void StartDiscovery()
|
||||
{
|
||||
if (!SupportedOnThisPlatform)
|
||||
throw new PlatformNotSupportedException("Network discovery not supported in this platform");
|
||||
|
||||
StopDiscovery();
|
||||
|
||||
try
|
||||
{
|
||||
// Setup port
|
||||
clientUdpClient = new UdpClient(0)
|
||||
{
|
||||
EnableBroadcast = true,
|
||||
MulticastLoopback = false
|
||||
};
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Free the port if we took it
|
||||
//Debug.LogError("NetworkDiscoveryBase StartDiscovery Exception");
|
||||
Shutdown();
|
||||
throw;
|
||||
}
|
||||
|
||||
_ = ClientListenAsync();
|
||||
|
||||
if (enableActiveDiscovery) InvokeRepeating(nameof(BroadcastDiscoveryRequest), 0, ActiveDiscoveryInterval);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stop Active Discovery
|
||||
/// </summary>
|
||||
public void StopDiscovery()
|
||||
{
|
||||
//Debug.Log("NetworkDiscoveryBase StopDiscovery");
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Awaits for server response
|
||||
/// </summary>
|
||||
/// <returns>ClientListenAsync Task</returns>
|
||||
public async Task ClientListenAsync()
|
||||
{
|
||||
// while clientUpdClient to fix:
|
||||
// https://github.com/vis2k/Mirror/pull/2908
|
||||
//
|
||||
// If, you cancel discovery the clientUdpClient is set to null.
|
||||
// However, nothing cancels ClientListenAsync. If we change the if(true)
|
||||
// to check if the client is null. You can properly cancel the discovery,
|
||||
// and kill the listen thread.
|
||||
//
|
||||
// Prior to this fix, if you cancel the discovery search. It crashes the
|
||||
// thread, and is super noisy in the output. As well as causes issues on
|
||||
// the quest.
|
||||
while (clientUdpClient != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
await ReceiveGameBroadcastAsync(clientUdpClient);
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
// socket was closed, no problem
|
||||
return;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends discovery request from client
|
||||
/// </summary>
|
||||
public void BroadcastDiscoveryRequest()
|
||||
{
|
||||
if (clientUdpClient == null)
|
||||
return;
|
||||
|
||||
if (NetworkClient.isConnected)
|
||||
{
|
||||
StopDiscovery();
|
||||
return;
|
||||
}
|
||||
|
||||
IPEndPoint endPoint = new IPEndPoint(IPAddress.Broadcast, serverBroadcastListenPort);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(BroadcastAddress))
|
||||
{
|
||||
try
|
||||
{
|
||||
endPoint = new IPEndPoint(IPAddress.Parse(BroadcastAddress), serverBroadcastListenPort);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
using (NetworkWriterPooled writer = NetworkWriterPool.Get())
|
||||
{
|
||||
writer.WriteLong(secretHandshake);
|
||||
|
||||
try
|
||||
{
|
||||
Request request = GetRequest();
|
||||
|
||||
writer.Write(request);
|
||||
|
||||
ArraySegment<byte> data = writer.ToArraySegment();
|
||||
|
||||
//Debug.Log($"Discovery: Sending BroadcastDiscoveryRequest {request}");
|
||||
clientUdpClient.SendAsync(data.Array, data.Count, endPoint);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// It is ok if we can't broadcast to one of the addresses
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a message that will be broadcasted on the network to discover servers
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Override if you wish to include additional data in the discovery message
|
||||
/// such as desired game mode, language, difficulty, etc... </remarks>
|
||||
/// <returns>An instance of ServerRequest with data to be broadcasted</returns>
|
||||
protected virtual Request GetRequest() => default;
|
||||
|
||||
async Task ReceiveGameBroadcastAsync(UdpClient udpClient)
|
||||
{
|
||||
// only proceed if there is available data in network buffer, or otherwise Receive() will block
|
||||
// average time for UdpClient.Available : 10 us
|
||||
|
||||
UdpReceiveResult udpReceiveResult = await udpClient.ReceiveAsync();
|
||||
|
||||
using (NetworkReaderPooled networkReader = NetworkReaderPool.Get(udpReceiveResult.Buffer))
|
||||
{
|
||||
if (networkReader.ReadLong() != secretHandshake)
|
||||
return;
|
||||
|
||||
Response response = networkReader.Read<Response>();
|
||||
|
||||
ProcessResponse(response, udpReceiveResult.RemoteEndPoint);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Process the answer from a server
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A client receives a reply from a server, this method processes the
|
||||
/// reply and raises an event
|
||||
/// </remarks>
|
||||
/// <param name="response">Response that came from the server</param>
|
||||
/// <param name="endpoint">Address of the server that replied</param>
|
||||
protected abstract void ProcessResponse(Response response, IPEndPoint endpoint);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/Mirror/Components/Discovery/NetworkDiscoveryBase.cs.meta
vendored
Normal file
11
Assets/ThirdParty/Mirror/Components/Discovery/NetworkDiscoveryBase.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b9971d60ce61f4e39b07cd9e7e0c68fa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 7453abfe9e8b2c04a8a47eb536fe21eb, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
146
Assets/ThirdParty/Mirror/Components/Discovery/NetworkDiscoveryHUD.cs
vendored
Normal file
146
Assets/ThirdParty/Mirror/Components/Discovery/NetworkDiscoveryHUD.cs
vendored
Normal file
@@ -0,0 +1,146 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror.Discovery
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
[AddComponentMenu("Network/Network Discovery HUD")]
|
||||
[HelpURL("https://mirror-networking.gitbook.io/docs/components/network-discovery")]
|
||||
[RequireComponent(typeof(NetworkDiscovery))]
|
||||
public class NetworkDiscoveryHUD : MonoBehaviour
|
||||
{
|
||||
readonly Dictionary<long, ServerResponse> discoveredServers = new Dictionary<long, ServerResponse>();
|
||||
Vector2 scrollViewPos = Vector2.zero;
|
||||
|
||||
public NetworkDiscovery networkDiscovery;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
void OnValidate()
|
||||
{
|
||||
if (Application.isPlaying) return;
|
||||
Reset();
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
networkDiscovery = GetComponent<NetworkDiscovery>();
|
||||
|
||||
// Add default event handler if not already present
|
||||
if (!Enumerable.Range(0, networkDiscovery.OnServerFound.GetPersistentEventCount())
|
||||
.Any(i => networkDiscovery.OnServerFound.GetPersistentMethodName(i) == nameof(OnDiscoveredServer)))
|
||||
{
|
||||
UnityEditor.Events.UnityEventTools.AddPersistentListener(networkDiscovery.OnServerFound, OnDiscoveredServer);
|
||||
UnityEditor.Undo.RecordObjects(new UnityEngine.Object[] { this, networkDiscovery }, "Set NetworkDiscovery");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !UNITY_SERVER || UNITY_EDITOR
|
||||
void OnGUI()
|
||||
{
|
||||
if (NetworkManager.singleton == null)
|
||||
return;
|
||||
|
||||
if (!NetworkClient.isConnected && !NetworkServer.active && !NetworkClient.active)
|
||||
DrawGUI();
|
||||
|
||||
if (NetworkServer.active || NetworkClient.active)
|
||||
StopButtons();
|
||||
}
|
||||
|
||||
void DrawGUI()
|
||||
{
|
||||
GUILayout.BeginArea(new Rect(10, 10, 300, 500));
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
if (GUILayout.Button("Find Servers"))
|
||||
{
|
||||
discoveredServers.Clear();
|
||||
networkDiscovery.StartDiscovery();
|
||||
}
|
||||
|
||||
// LAN Host
|
||||
if (GUILayout.Button("Start Host"))
|
||||
{
|
||||
discoveredServers.Clear();
|
||||
NetworkManager.singleton.StartHost();
|
||||
networkDiscovery.AdvertiseServer();
|
||||
}
|
||||
|
||||
// Dedicated server
|
||||
if (GUILayout.Button("Start Server"))
|
||||
{
|
||||
discoveredServers.Clear();
|
||||
NetworkManager.singleton.StartServer();
|
||||
networkDiscovery.AdvertiseServer();
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
// show list of found server
|
||||
|
||||
GUILayout.Label($"Discovered Servers [{discoveredServers.Count}]:");
|
||||
|
||||
// servers
|
||||
scrollViewPos = GUILayout.BeginScrollView(scrollViewPos);
|
||||
|
||||
foreach (ServerResponse info in discoveredServers.Values)
|
||||
if (GUILayout.Button(info.EndPoint.Address.ToString()))
|
||||
Connect(info);
|
||||
|
||||
GUILayout.EndScrollView();
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
|
||||
void StopButtons()
|
||||
{
|
||||
GUILayout.BeginArea(new Rect(10, 40, 100, 25));
|
||||
|
||||
// stop host if host mode
|
||||
if (NetworkServer.active && NetworkClient.isConnected)
|
||||
{
|
||||
if (GUILayout.Button("Stop Host"))
|
||||
{
|
||||
NetworkManager.singleton.StopHost();
|
||||
networkDiscovery.StopDiscovery();
|
||||
}
|
||||
}
|
||||
// stop client if client-only
|
||||
else if (NetworkClient.isConnected)
|
||||
{
|
||||
if (GUILayout.Button("Stop Client"))
|
||||
{
|
||||
NetworkManager.singleton.StopClient();
|
||||
networkDiscovery.StopDiscovery();
|
||||
}
|
||||
}
|
||||
// stop server if server-only
|
||||
else if (NetworkServer.active)
|
||||
{
|
||||
if (GUILayout.Button("Stop Server"))
|
||||
{
|
||||
NetworkManager.singleton.StopServer();
|
||||
networkDiscovery.StopDiscovery();
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
#endif
|
||||
|
||||
void Connect(ServerResponse info)
|
||||
{
|
||||
networkDiscovery.StopDiscovery();
|
||||
NetworkManager.singleton.StartClient(info.uri);
|
||||
}
|
||||
|
||||
public void OnDiscoveredServer(ServerResponse info)
|
||||
{
|
||||
Debug.Log($"Discovered Server: {info.serverId} | {info.EndPoint} | {info.uri}");
|
||||
|
||||
// Note that you can check the versioning to decide if you can connect to the server or not using this method
|
||||
discoveredServers[info.serverId] = info;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/Mirror/Components/Discovery/NetworkDiscoveryHUD.cs.meta
vendored
Normal file
11
Assets/ThirdParty/Mirror/Components/Discovery/NetworkDiscoveryHUD.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 88c37d3deca7a834d80cfd8d3cfcc510
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 7453abfe9e8b2c04a8a47eb536fe21eb, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
4
Assets/ThirdParty/Mirror/Components/Discovery/ServerRequest.cs
vendored
Normal file
4
Assets/ThirdParty/Mirror/Components/Discovery/ServerRequest.cs
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
namespace Mirror.Discovery
|
||||
{
|
||||
public struct ServerRequest : NetworkMessage {}
|
||||
}
|
||||
11
Assets/ThirdParty/Mirror/Components/Discovery/ServerRequest.cs.meta
vendored
Normal file
11
Assets/ThirdParty/Mirror/Components/Discovery/ServerRequest.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea7254bf7b9454da4adad881d94cd141
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 7453abfe9e8b2c04a8a47eb536fe21eb, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
18
Assets/ThirdParty/Mirror/Components/Discovery/ServerResponse.cs
vendored
Normal file
18
Assets/ThirdParty/Mirror/Components/Discovery/ServerResponse.cs
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
|
||||
namespace Mirror.Discovery
|
||||
{
|
||||
public struct ServerResponse : NetworkMessage
|
||||
{
|
||||
// The server that sent this
|
||||
// this is a property so that it is not serialized, but the
|
||||
// client fills this up after we receive it
|
||||
public IPEndPoint EndPoint { get; set; }
|
||||
|
||||
public Uri uri;
|
||||
|
||||
// Prevent duplicate server appearance when a connection can be made via LAN on multiple NICs
|
||||
public long serverId;
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/Mirror/Components/Discovery/ServerResponse.cs.meta
vendored
Normal file
11
Assets/ThirdParty/Mirror/Components/Discovery/ServerResponse.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 36f97227fdf2d7a4e902db5bfc43039c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 7453abfe9e8b2c04a8a47eb536fe21eb, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
135
Assets/ThirdParty/Mirror/Components/GUIConsole.cs
vendored
Normal file
135
Assets/ThirdParty/Mirror/Components/GUIConsole.cs
vendored
Normal file
@@ -0,0 +1,135 @@
|
||||
// People should be able to see and report errors to the developer very easily.
|
||||
//
|
||||
// Unity's Developer Console only works in development builds and it only shows
|
||||
// errors. This class provides a console that works in all builds and also shows
|
||||
// log and warnings in development builds.
|
||||
//
|
||||
// Note: we don't include the stack trace, because that can also be grabbed from
|
||||
// the log files if needed.
|
||||
//
|
||||
// Note: there is no 'hide' button because we DO want people to see those errors
|
||||
// and report them back to us.
|
||||
//
|
||||
// Note: normal Debug.Log messages can be shown by building in Debug/Development
|
||||
// mode.
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Mirror
|
||||
{
|
||||
struct LogEntry
|
||||
{
|
||||
public string message;
|
||||
public LogType type;
|
||||
|
||||
public LogEntry(string message, LogType type)
|
||||
{
|
||||
this.message = message;
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
||||
public class GUIConsole : MonoBehaviour
|
||||
{
|
||||
public int height = 80;
|
||||
public int offsetY = 40;
|
||||
|
||||
// only keep the recent 'n' entries. otherwise memory would grow forever
|
||||
// and drawing would get slower and slower.
|
||||
public int maxLogCount = 50;
|
||||
|
||||
// Unity Editor has the Console window, we don't need to show it there.
|
||||
// unless for testing, so keep it as option.
|
||||
public bool showInEditor = false;
|
||||
|
||||
// log as queue so we can remove the first entry easily
|
||||
readonly Queue<LogEntry> log = new Queue<LogEntry>();
|
||||
|
||||
// hotkey to show/hide at runtime for easier debugging
|
||||
// (sometimes we need to temporarily hide/show it)
|
||||
// Default is BackQuote, because F keys are already assigned in browsers
|
||||
[Tooltip("Hotkey to show/hide the console at runtime\nBack Quote is usually on the left above Tab\nChange with caution - F keys are generally already taken in Browsers")]
|
||||
public KeyCode hotKey = KeyCode.BackQuote;
|
||||
|
||||
// GUI
|
||||
bool visible;
|
||||
Vector2 scroll = Vector2.zero;
|
||||
|
||||
// only show at runtime, or if showInEditor is enabled
|
||||
bool show => !Application.isEditor || showInEditor;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
// only show at runtime, or if showInEditor is enabled
|
||||
if (show)
|
||||
Application.logMessageReceived += OnLog;
|
||||
}
|
||||
|
||||
// OnLog logs everything, even Debug.Log messages in release builds
|
||||
// => this makes a lot of things easier. e.g. addon initialization logs.
|
||||
// => it's really better to have than not to have those
|
||||
void OnLog(string message, string stackTrace, LogType type)
|
||||
{
|
||||
// is this important?
|
||||
// => always show exceptions & errors
|
||||
// => usually a good idea to show warnings too, otherwise it's too
|
||||
// easy to miss OnDeserialize warnings etc. in builds
|
||||
bool isImportant = type == LogType.Error || type == LogType.Exception || type == LogType.Warning;
|
||||
|
||||
// use stack trace only if important
|
||||
// (otherwise users would have to find and search the log file.
|
||||
// seeing it in the console directly is way easier to deal with.)
|
||||
// => only add \n if stack trace is available (only in debug builds)
|
||||
if (isImportant && !string.IsNullOrWhiteSpace(stackTrace))
|
||||
message += $"\n{stackTrace}";
|
||||
|
||||
// add to queue
|
||||
log.Enqueue(new LogEntry(message, type));
|
||||
|
||||
// respect max entries
|
||||
if (log.Count > maxLogCount)
|
||||
log.Dequeue();
|
||||
|
||||
// become visible if it was important
|
||||
// (no need to become visible for regular log. let the user decide.)
|
||||
if (isImportant)
|
||||
visible = true;
|
||||
|
||||
// auto scroll
|
||||
scroll.y = float.MaxValue;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (show && Input.GetKeyDown(hotKey))
|
||||
visible = !visible;
|
||||
}
|
||||
|
||||
#if !UNITY_SERVER || UNITY_EDITOR
|
||||
void OnGUI()
|
||||
{
|
||||
if (!visible) return;
|
||||
|
||||
// If this offset is changed, also change width in NetworkManagerHUD::OnGUI
|
||||
int offsetX = 300 + 20;
|
||||
|
||||
GUILayout.BeginArea(new Rect(offsetX, offsetY, Screen.width - offsetX - 10, height));
|
||||
|
||||
scroll = GUILayout.BeginScrollView(scroll, "Box", GUILayout.Width(Screen.width - offsetX - 10), GUILayout.Height(height));
|
||||
foreach (LogEntry entry in log)
|
||||
{
|
||||
if (entry.type == LogType.Error || entry.type == LogType.Exception)
|
||||
GUI.color = Color.red;
|
||||
else if (entry.type == LogType.Warning)
|
||||
GUI.color = Color.yellow;
|
||||
|
||||
GUILayout.Label(entry.message);
|
||||
GUI.color = Color.white;
|
||||
}
|
||||
GUILayout.EndScrollView();
|
||||
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/Mirror/Components/GUIConsole.cs.meta
vendored
Normal file
11
Assets/ThirdParty/Mirror/Components/GUIConsole.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9021b6cc314944290986ab6feb48db79
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 7453abfe9e8b2c04a8a47eb536fe21eb, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/ThirdParty/Mirror/Components/InterestManagement.meta
vendored
Normal file
8
Assets/ThirdParty/Mirror/Components/InterestManagement.meta
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c66f27e006ab94253b39a55a3b213651
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
3
Assets/ThirdParty/Mirror/Components/InterestManagement/Distance.meta
vendored
Normal file
3
Assets/ThirdParty/Mirror/Components/InterestManagement/Distance.meta
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa4cbc6b9c584db4971985cb9f369077
|
||||
timeCreated: 1613110605
|
||||
89
Assets/ThirdParty/Mirror/Components/InterestManagement/Distance/DistanceInterestManagement.cs
vendored
Normal file
89
Assets/ThirdParty/Mirror/Components/InterestManagement/Distance/DistanceInterestManagement.cs
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
// straight forward Vector3.Distance based interest management.
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror
|
||||
{
|
||||
[AddComponentMenu("Network/ Interest Management/ Distance/Distance Interest Management")]
|
||||
public class DistanceInterestManagement : InterestManagement
|
||||
{
|
||||
[Tooltip("The maximum range that objects will be visible at. Add DistanceInterestManagementCustomRange onto NetworkIdentities for custom ranges.")]
|
||||
public int visRange = 500;
|
||||
|
||||
[Tooltip("Rebuild all every 'rebuildInterval' seconds.")]
|
||||
public float rebuildInterval = 1;
|
||||
double lastRebuildTime;
|
||||
|
||||
// cache custom ranges to avoid runtime TryGetComponent lookups
|
||||
readonly Dictionary<NetworkIdentity, DistanceInterestManagementCustomRange> CustomRanges = new Dictionary<NetworkIdentity, DistanceInterestManagementCustomRange>();
|
||||
|
||||
// helper function to get vis range for a given object, or default.
|
||||
[ServerCallback]
|
||||
int GetVisRange(NetworkIdentity identity)
|
||||
{
|
||||
return CustomRanges.TryGetValue(identity, out DistanceInterestManagementCustomRange custom) ? custom.visRange : visRange;
|
||||
}
|
||||
|
||||
[ServerCallback]
|
||||
public override void ResetState()
|
||||
{
|
||||
lastRebuildTime = 0D;
|
||||
CustomRanges.Clear();
|
||||
}
|
||||
|
||||
public override void OnSpawned(NetworkIdentity identity)
|
||||
{
|
||||
if (identity.TryGetComponent(out DistanceInterestManagementCustomRange custom))
|
||||
CustomRanges[identity] = custom;
|
||||
}
|
||||
|
||||
public override void OnDestroyed(NetworkIdentity identity)
|
||||
{
|
||||
CustomRanges.Remove(identity);
|
||||
}
|
||||
|
||||
public override bool OnCheckObserver(NetworkIdentity identity, NetworkConnectionToClient newObserver)
|
||||
{
|
||||
int range = GetVisRange(identity);
|
||||
return Vector3.Distance(identity.transform.position, newObserver.identity.transform.position) < range;
|
||||
}
|
||||
|
||||
public override void OnRebuildObservers(NetworkIdentity identity, HashSet<NetworkConnectionToClient> newObservers)
|
||||
{
|
||||
// cache range and .transform because both call GetComponent.
|
||||
int range = GetVisRange(identity);
|
||||
Vector3 position = identity.transform.position;
|
||||
|
||||
// brute force distance check
|
||||
// -> only player connections can be observers, so it's enough if we
|
||||
// go through all connections instead of all spawned identities.
|
||||
// -> compared to UNET's sphere cast checking, this one is orders of
|
||||
// magnitude faster. if we have 10k monsters and run a sphere
|
||||
// cast 10k times, we will see a noticeable lag even with physics
|
||||
// layers. but checking to every connection is fast.
|
||||
foreach (NetworkConnectionToClient conn in NetworkServer.connections.Values)
|
||||
{
|
||||
// authenticated and joined world with a player?
|
||||
if (conn != null && conn.isAuthenticated && conn.identity != null)
|
||||
{
|
||||
// check distance
|
||||
if (Vector3.Distance(conn.identity.transform.position, position) < range)
|
||||
{
|
||||
newObservers.Add(conn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ServerCallback]
|
||||
void LateUpdate()
|
||||
{
|
||||
// rebuild all spawned NetworkIdentity's observers every interval
|
||||
if (NetworkTime.localTime >= lastRebuildTime + rebuildInterval)
|
||||
{
|
||||
RebuildAll();
|
||||
lastRebuildTime = NetworkTime.localTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f60becab051427fbdd3c8ac9ab4712b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 7453abfe9e8b2c04a8a47eb536fe21eb, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user