Updating MRTK to 2017.2.1.4
This commit is contained in:
Родитель
e94cd44aa0
Коммит
0670150fb4
|
@ -7,13 +7,15 @@ Material:
|
|||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_Name: FloorMaterial
|
||||
m_Shader: {fileID: 4800000, guid: f1f3948b20c230044bda31b620ddd37f, type: 3}
|
||||
m_ShaderKeywords: ETC1_EXTERNAL_ALPHA _EMISSION _USEAMBIENT_ON _USEDIFFUSE_ON _USEMAINCOLOR_ON
|
||||
m_Shader: {fileID: 4800000, guid: d45c0efca53019e43891b0f610f8146e, type: 3}
|
||||
m_ShaderKeywords: ETC1_EXTERNAL_ALPHA _BORDER_LIGHT_USES_HOVER_COLOR _DISABLE_ALBEDO_MAP
|
||||
_SPECULAR_HIGHLIGHTS _USEAMBIENT_ON _USEDIFFUSE_ON _USEMAINCOLOR_ON
|
||||
m_LightmapFlags: 1
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
m_CustomRenderQueue: 2000
|
||||
stringTagMap:
|
||||
RenderType: Opaque
|
||||
disabledShaderPasses: []
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
|
@ -22,6 +24,10 @@ Material:
|
|||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _CubeMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
|
@ -42,6 +48,10 @@ Material:
|
|||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _GlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
|
@ -50,6 +60,10 @@ Material:
|
|||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _NormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
|
@ -58,27 +72,71 @@ Material:
|
|||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _SpecularMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Floats:
|
||||
- _AlbedoAlphaMode: 0
|
||||
- _AlphaTest: 0
|
||||
- _BlendOp: 0
|
||||
- _BorderLight: 0
|
||||
- _BorderLightOpaque: 0
|
||||
- _BorderLightUsesHoverColor: 1
|
||||
- _BorderMinValue: 0.1
|
||||
- _BorderWidth: 0.1
|
||||
- _BumpScale: 1
|
||||
- _CalibrationSpaceReflections: 0
|
||||
- _ClippingPlane: 0
|
||||
- _ClippingPlaneBorder: 0
|
||||
- _ClippingPlaneBorderWidth: 0.025
|
||||
- _ColorWriteMask: 15
|
||||
- _Cull: 2
|
||||
- _CullMode: 2
|
||||
- _CustomMode: 0
|
||||
- _Cutoff: 0.5
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DirectionalLight: 0
|
||||
- _DstBlend: 0
|
||||
- _EdgeSmoothingValue: 0.002
|
||||
- _EnableEmission: 0
|
||||
- _EnableHoverColorOpaqueOverride: 0
|
||||
- _EnableHoverColorOverride: 0
|
||||
- _EnableNormalMap: 0
|
||||
- _EnvironmentColorIntensity: 0.5
|
||||
- _EnvironmentColorThreshold: 1.5
|
||||
- _EnvironmentColoring: 0
|
||||
- _FadeBeginDistance: 0.85
|
||||
- _FadeCompleteDistance: 0.5
|
||||
- _ForcePerPixel: 0
|
||||
- _Gloss: 1
|
||||
- _GlossMapScale: 1
|
||||
- _Glossiness: 0.5
|
||||
- _GlossyReflections: 1
|
||||
- _HoverLight: 0
|
||||
- _HoverLightOpaque: 0
|
||||
- _InnerGlow: 0
|
||||
- _LineScale: 0.015
|
||||
- _LinesPerMeter: 3
|
||||
- _MainTex_OFFSET: 0
|
||||
- _MainTex_SCALE: 0
|
||||
- _Metallic: 0
|
||||
- _Mode: 0
|
||||
- _NearPlaneFade: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.02
|
||||
- _ReflectionScale: 2
|
||||
- _Reflections: 0
|
||||
- _Refraction: 0
|
||||
- _RefractiveIndex: 0
|
||||
- _RenderQueueOverride: -1
|
||||
- _RimLight: 0
|
||||
- _RimPower: 0.7
|
||||
- _RoundCornerMargin: 0
|
||||
- _RoundCornerRadius: 0.25
|
||||
- _RoundCorners: 0
|
||||
- _Shade4: 0
|
||||
- _Smoothness: 0.5
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _Specular: 10
|
||||
- _SpecularHighlights: 1
|
||||
|
@ -89,17 +147,32 @@ Material:
|
|||
- _UseBumpMap: 0
|
||||
- _UseDiffuse: 1
|
||||
- _UseEmissionColor: 0
|
||||
- _UseEmissionMap: 0
|
||||
- _UseEmissionTex: 0
|
||||
- _UseGlossMap: 0
|
||||
- _UseMainColor: 1
|
||||
- _UseMainTex: 0
|
||||
- _UseOcclusionMap: 0
|
||||
- _UseReflections: 0
|
||||
- _UseRimLighting: 0
|
||||
- _UseSpecular: 0
|
||||
- _UseSpecularMap: 0
|
||||
- _UseVertexColor: 0
|
||||
- _ZTest: 4
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _ClipPlane: {r: 0, g: 1, b: 0, a: 0}
|
||||
- _ClippingPlaneBorderColor: {r: 1, g: 0.2, b: 0, a: 1}
|
||||
- _Color: {r: 0.4776116, g: 0.5930785, b: 0.6691177, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _EmissiveColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _EnvironmentColorX: {r: 1, g: 0, b: 0, a: 1}
|
||||
- _EnvironmentColorY: {r: 0, g: 1, b: 0, a: 1}
|
||||
- _EnvironmentColorZ: {r: 0, g: 0, b: 1, a: 1}
|
||||
- _HoverColorOpaqueOverride: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _HoverColorOverride: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _InnerGlowColor: {r: 1, g: 1, b: 1, a: 0.75}
|
||||
- _RimColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _SpecColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
|
||||
- _SpecularColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
|
||||
- _TextureScaleOffset: {r: 1, g: 1, b: 0, a: 0}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR;
|
||||
using UnityEngine.XR.WSA;
|
||||
#endif
|
||||
|
@ -17,11 +16,11 @@ namespace HoloToolkit.Unity.Boundary
|
|||
/// </summary>
|
||||
public class BoundaryManager : Singleton<BoundaryManager>
|
||||
{
|
||||
[Tooltip("Quad prefab to display as the floor.")]
|
||||
public GameObject FloorQuad;
|
||||
private GameObject floorQuadInstance;
|
||||
|
||||
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
|
||||
[Tooltip("Quad prefab to display as the floor.")]
|
||||
public GameObject FloorQuad = null;
|
||||
private GameObject floorQuadInstance = null;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("Approximate max Y height of your space.")]
|
||||
private float boundaryHeight = 10f;
|
||||
|
@ -33,12 +32,11 @@ namespace HoloToolkit.Unity.Boundary
|
|||
// This puts the origin (0, 0, 0) on the floor if a floor has been established during setup via MixedRealityPortal.
|
||||
private TrackingSpaceType opaqueTrackingSpaceType = TrackingSpaceType.RoomScale;
|
||||
|
||||
[SerializeField]
|
||||
// Removed for now, until the HoloLens tracking space type story is more clear.
|
||||
//[SerializeField]
|
||||
// Defaulting coordinate system to Stationary for transparent headsets, like HoloLens.
|
||||
// This puts the origin (0, 0, 0) at the first place where the user started the application.
|
||||
private TrackingSpaceType transparentTrackingSpaceType = TrackingSpaceType.Stationary;
|
||||
#endif
|
||||
|
||||
//private TrackingSpaceType transparentTrackingSpaceType = TrackingSpaceType.Stationary;
|
||||
// Testing in the editor found that this moved the floor out of the way enough, and it is only
|
||||
// used in the case where a headset isn't attached. Otherwise, the floor is positioned like normal.
|
||||
private readonly Vector3 floorPositionInEditor = new Vector3(0f, -3f, 0f);
|
||||
|
@ -72,6 +70,7 @@ namespace HoloToolkit.Unity.Boundary
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
|
@ -84,7 +83,11 @@ namespace HoloToolkit.Unity.Boundary
|
|||
}
|
||||
else
|
||||
{
|
||||
XRDevice.SetTrackingSpaceType(transparentTrackingSpaceType);
|
||||
// Removed for now, until the HoloLens tracking space type story is more clear.
|
||||
//XRDevice.SetTrackingSpaceType(transparentTrackingSpaceType);
|
||||
|
||||
Destroy(this);
|
||||
return;
|
||||
}
|
||||
|
||||
// Render the floor based on if you are in editor or immersive device.
|
||||
|
@ -95,7 +98,6 @@ namespace HoloToolkit.Unity.Boundary
|
|||
|
||||
// Create a volume out of the specified user boundary.
|
||||
CalculateBoundaryVolume();
|
||||
#endif
|
||||
}
|
||||
|
||||
private void SetFloorRendering()
|
||||
|
@ -104,11 +106,12 @@ namespace HoloToolkit.Unity.Boundary
|
|||
{
|
||||
floorQuadInstance.SetActive(renderFloor);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private void SetBoundaryRendering()
|
||||
{
|
||||
#if UNITY_2017_2_OR_NEWER
|
||||
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
|
||||
// TODO: BUG: Unity: configured bool always returns false in 2017.2.0p2-MRTP5.
|
||||
if (UnityEngine.Experimental.XR.Boundary.configured)
|
||||
{
|
||||
|
@ -186,6 +189,10 @@ namespace HoloToolkit.Unity.Boundary
|
|||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("TryGetGeometry always returns false.");
|
||||
}
|
||||
|
||||
// Ensuring that we set height of the bounds volume to be say 10 feet tall.
|
||||
boundaryBounds.Encapsulate(new Vector3(0, boundaryHeight, 0));
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_2017_2_OR_NEWER
|
||||
using System.Collections;
|
||||
using UnityEngine.XR;
|
||||
#else
|
||||
using UnityEngine.VR;
|
||||
|
@ -32,12 +32,11 @@ namespace HoloToolkit.Unity.Boundary
|
|||
UsePresetXAndZWithHeadHeight
|
||||
}
|
||||
|
||||
private int frameWaitHack = 0;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("Optional container object reference. If null, this script will move the object it's attached to.")]
|
||||
private Transform containerObject;
|
||||
private Transform containerObject = null;
|
||||
|
||||
#if UNITY_2017_2_OR_NEWER
|
||||
[SerializeField]
|
||||
[Tooltip("Select this if the container should be placed in front of the head on app launch in a room scale app.")]
|
||||
private AlignmentType alignmentType = AlignmentType.AlignWithHeadHeight;
|
||||
|
@ -52,6 +51,9 @@ namespace HoloToolkit.Unity.Boundary
|
|||
|
||||
private Vector3 contentPosition = Vector3.zero;
|
||||
|
||||
private int frameWaitHack = 0;
|
||||
#endif
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (containerObject == null)
|
||||
|
@ -63,19 +65,16 @@ namespace HoloToolkit.Unity.Boundary
|
|||
// If no XR device is present, the editor will default to (0, 0, 0) and no adjustment is needed.
|
||||
// This script runs on both opaque and transparent display devices, since the floor offset is based on
|
||||
// TrackingSpaceType and not display type.
|
||||
if (!XRDevice.isPresent)
|
||||
#else
|
||||
if (true)
|
||||
#endif
|
||||
{
|
||||
Destroy(this);
|
||||
}
|
||||
else
|
||||
if (XRDevice.isPresent)
|
||||
{
|
||||
StartCoroutine(SetContentHeight());
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
Destroy(this);
|
||||
}
|
||||
|
||||
#if UNITY_2017_2_OR_NEWER
|
||||
private IEnumerator SetContentHeight()
|
||||
{
|
||||
if (frameWaitHack < 1)
|
||||
|
@ -106,5 +105,6 @@ namespace HoloToolkit.Unity.Boundary
|
|||
containerObject.position = contentPosition;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
|
@ -16,9 +17,12 @@ namespace HoloToolkit.Unity
|
|||
private const string EditorPrefs_IncrementBuildVersion = "_BuildDeployWindow_IncrementBuildVersion";
|
||||
private const string EditorPrefs_MSBuildVer = "_BuildDeployWindow_MSBuildVer";
|
||||
private const string EditorPrefs_TargetIPs = "_BuildDeployWindow_DestIPs";
|
||||
private const string EditorPrefs_ConnectInfos = "_BuildDeployWindow_ConnectInfos";
|
||||
private const string EditorPrefs_DeviceUser = "_BuildDeployWindow_DeviceUser";
|
||||
private const string EditorPrefs_DevicePwd = "_BuildDeployWindow_DevicePwd";
|
||||
private const string EditorPrefs_FullReinstall = "_BuildDeployWindow_FullReinstall";
|
||||
private const string EditorPrefs_UseSSL = "_BuildDeployWindow_UseSSL";
|
||||
private const string EditorPrefs_ProcessAll = "_BuildDeployWindow_ProcessAll";
|
||||
|
||||
public static string BuildDirectory
|
||||
{
|
||||
|
@ -28,7 +32,16 @@ namespace HoloToolkit.Unity
|
|||
|
||||
public static string AbsoluteBuildDirectory
|
||||
{
|
||||
get { return Path.GetFullPath(Path.Combine(Path.Combine(Application.dataPath, ".."), BuildDirectory)); }
|
||||
get
|
||||
{
|
||||
string rootBuildDirectory = BuildDirectory;
|
||||
int dirCharIndex = rootBuildDirectory.IndexOf("/", StringComparison.Ordinal);
|
||||
if (dirCharIndex != -1)
|
||||
{
|
||||
rootBuildDirectory = rootBuildDirectory.Substring(0, dirCharIndex);
|
||||
}
|
||||
return Path.GetFullPath(Path.Combine(Path.Combine(Application.dataPath, ".."), rootBuildDirectory));
|
||||
}
|
||||
}
|
||||
|
||||
public static string MsBuildVersion
|
||||
|
@ -61,28 +74,56 @@ namespace HoloToolkit.Unity
|
|||
set { EditorPrefsUtility.SetEditorPref(EditorPrefs_IncrementBuildVersion, value); }
|
||||
}
|
||||
|
||||
public static bool FullReinstall
|
||||
{
|
||||
get { return EditorPrefsUtility.GetEditorPref(EditorPrefs_FullReinstall, true); }
|
||||
set { EditorPrefsUtility.SetEditorPref(EditorPrefs_FullReinstall, value); }
|
||||
}
|
||||
|
||||
public static string DevicePortalConnections
|
||||
{
|
||||
get
|
||||
{
|
||||
return EditorPrefsUtility.GetEditorPref(
|
||||
EditorPrefs_ConnectInfos,
|
||||
JsonUtility.ToJson(
|
||||
new DevicePortalConnections(
|
||||
new ConnectInfo("127.0.0.1", string.Empty, string.Empty, "Local Machine"))));
|
||||
}
|
||||
set { EditorPrefsUtility.SetEditorPref(EditorPrefs_ConnectInfos, value); }
|
||||
}
|
||||
|
||||
[Obsolete("Use DevicePortalConnections")]
|
||||
public static string DeviceUser
|
||||
{
|
||||
get { return EditorPrefsUtility.GetEditorPref(EditorPrefs_DeviceUser, string.Empty); }
|
||||
set { EditorPrefsUtility.SetEditorPref(EditorPrefs_DeviceUser, value); }
|
||||
}
|
||||
|
||||
[Obsolete("Use DevicePortalConnections")]
|
||||
public static string DevicePassword
|
||||
{
|
||||
get { return EditorPrefsUtility.GetEditorPref(EditorPrefs_DevicePwd, string.Empty); }
|
||||
set { EditorPrefsUtility.SetEditorPref(EditorPrefs_DevicePwd, value); }
|
||||
}
|
||||
|
||||
[Obsolete("Use DevicePortalConnections")]
|
||||
public static string TargetIPs
|
||||
{
|
||||
get { return EditorPrefsUtility.GetEditorPref(EditorPrefs_TargetIPs, "127.0.0.1"); }
|
||||
set { EditorPrefsUtility.SetEditorPref(EditorPrefs_TargetIPs, value); }
|
||||
}
|
||||
|
||||
public static string DeviceUser
|
||||
public static bool UseSSL
|
||||
{
|
||||
get { return EditorPrefsUtility.GetEditorPref(EditorPrefs_DeviceUser, ""); }
|
||||
set { EditorPrefsUtility.SetEditorPref(EditorPrefs_DeviceUser, value); }
|
||||
get { return EditorPrefsUtility.GetEditorPref(EditorPrefs_UseSSL, true); }
|
||||
set { EditorPrefsUtility.SetEditorPref(EditorPrefs_UseSSL, value); }
|
||||
}
|
||||
|
||||
public static string DevicePassword
|
||||
public static bool TargetAllConnections
|
||||
{
|
||||
get { return EditorPrefsUtility.GetEditorPref(EditorPrefs_DevicePwd, ""); }
|
||||
set { EditorPrefsUtility.SetEditorPref(EditorPrefs_DevicePwd, value); }
|
||||
}
|
||||
|
||||
public static bool FullReinstall
|
||||
{
|
||||
get { return EditorPrefsUtility.GetEditorPref(EditorPrefs_FullReinstall, true); }
|
||||
set { EditorPrefsUtility.SetEditorPref(EditorPrefs_FullReinstall, value); }
|
||||
get { return EditorPrefsUtility.GetEditorPref(EditorPrefs_ProcessAll, false); }
|
||||
set { EditorPrefsUtility.SetEditorPref(EditorPrefs_ProcessAll, value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace HoloToolkit.Unity
|
|||
/// </summary>
|
||||
public class BuildDeployTools
|
||||
{
|
||||
public static readonly string DefaultMSBuildVersion = "15.0";
|
||||
public const string DefaultMSBuildVersion = "15.0";
|
||||
|
||||
public static bool CanBuild()
|
||||
{
|
||||
|
@ -56,6 +56,14 @@ namespace HoloToolkit.Unity
|
|||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Do a build configured for Mixed Reality Applications, returns the error from BuildPipeline.BuildPlayer
|
||||
/// </summary>
|
||||
public static bool BuildSLN()
|
||||
{
|
||||
return BuildSLN(BuildDeployPrefs.BuildDirectory, false);
|
||||
}
|
||||
|
||||
public static bool BuildSLN(string buildDirectory, bool showDialog = true)
|
||||
{
|
||||
// Use BuildSLNUtilities to create the SLN
|
||||
|
@ -175,6 +183,9 @@ namespace HoloToolkit.Unity
|
|||
|
||||
public static bool RestoreNugetPackages(string nugetPath, string storePath)
|
||||
{
|
||||
Debug.Assert(File.Exists(nugetPath));
|
||||
Debug.Assert(Directory.Exists(storePath));
|
||||
|
||||
var nugetPInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = nugetPath,
|
||||
|
@ -230,14 +241,17 @@ namespace HoloToolkit.Unity
|
|||
}
|
||||
|
||||
string nugetPath = Path.Combine(unity, @"Data\PlaybackEngines\MetroSupport\Tools\NuGet.exe");
|
||||
string assemblyCSharp = storePath + "/GeneratedProjects/UWP/Assembly-CSharp";
|
||||
string assemblyCSharpFirstPass = storePath + "/GeneratedProjects/UWP/Assembly-CSharp-firstpass";
|
||||
bool restoreFirstPass = Directory.Exists(assemblyCSharpFirstPass);
|
||||
|
||||
// Before building, need to run a nuget restore to generate a json.lock file. Failing to do
|
||||
// this breaks the build in VS RTM
|
||||
if (PlayerSettings.GetScriptingBackend(BuildTargetGroup.WSA) == ScriptingImplementation.WinRTDotNET &&
|
||||
(!RestoreNugetPackages(nugetPath, storePath) ||
|
||||
!RestoreNugetPackages(nugetPath, storePath + "\\" + productName) ||
|
||||
EditorUserBuildSettings.wsaGenerateReferenceProjects && !RestoreNugetPackages(nugetPath, storePath + "/GeneratedProjects/UWP/Assembly-CSharp") ||
|
||||
EditorUserBuildSettings.wsaGenerateReferenceProjects && !RestoreNugetPackages(nugetPath, storePath + "/GeneratedProjects/UWP/Assembly-CSharp-firstpass")))
|
||||
EditorUserBuildSettings.wsaGenerateReferenceProjects && !RestoreNugetPackages(nugetPath, assemblyCSharp) ||
|
||||
EditorUserBuildSettings.wsaGenerateReferenceProjects && restoreFirstPass && !RestoreNugetPackages(nugetPath, assemblyCSharpFirstPass)))
|
||||
{
|
||||
Debug.LogError("Failed to restore nuget packages");
|
||||
EditorUtility.ClearProgressBar();
|
||||
|
@ -285,9 +299,9 @@ namespace HoloToolkit.Unity
|
|||
|
||||
if (process.ExitCode == 0 &&
|
||||
showDialog &&
|
||||
!EditorUtility.DisplayDialog("Build AppX", "AppX Build Successful!", "OK", "Open Project Folder"))
|
||||
!EditorUtility.DisplayDialog("Build AppX", "AppX Build Successful!", "OK", "Open AppX Folder"))
|
||||
{
|
||||
Process.Start("explorer.exe", "/select," + storePath);
|
||||
Process.Start("explorer.exe", "/f /open," + Path.GetFullPath(BuildDeployPrefs.BuildDirectory + "/" + PlayerSettings.productName + "/AppPackages"));
|
||||
}
|
||||
|
||||
if (process.ExitCode != 0)
|
||||
|
@ -343,12 +357,14 @@ namespace HoloToolkit.Unity
|
|||
return;
|
||||
}
|
||||
|
||||
// Assume package version always has a '.'.
|
||||
// Assume package version always has a '.' between each number.
|
||||
// According to https://msdn.microsoft.com/en-us/library/windows/apps/br211441.aspx
|
||||
// Package versions are always of the form Major.Minor.Build.Revision
|
||||
var version = new Version(versionAttr.Value);
|
||||
var newVersion = new Version(version.Major, version.Minor, version.Build, version.Revision + 1);
|
||||
// Package versions are always of the form Major.Minor.Build.Revision.
|
||||
// Note: Revision number reserved for Windows Store, and a value other than 0 will fail WACK.
|
||||
var version = PlayerSettings.WSA.packageVersion;
|
||||
var newVersion = new Version(version.Major, version.Minor, version.Build + 1, version.Revision);
|
||||
|
||||
PlayerSettings.WSA.packageVersion = newVersion;
|
||||
versionAttr.Value = newVersion.ToString();
|
||||
rootNode.Save(manifest);
|
||||
}
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,7 +1,5 @@
|
|||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -54,7 +52,7 @@ namespace HoloToolkit.Unity
|
|||
public void AppendSymbols(IEnumerable<string> symbols)
|
||||
{
|
||||
string[] toAdd = symbols.Except(BuildSymbols.Split(';'))
|
||||
.Where(sym => !string.IsNullOrEmpty(sym)).ToArray();
|
||||
.Where(sym => !string.IsNullOrEmpty(sym)).ToArray();
|
||||
|
||||
if (!toAdd.Any())
|
||||
{
|
||||
|
@ -82,9 +80,9 @@ namespace HoloToolkit.Unity
|
|||
BuildSLNUtilities.BuildSymbolMaster);
|
||||
}
|
||||
|
||||
public static IEnumerable<string> RemoveConfigurationSymbols(string symbolstring)
|
||||
public static IEnumerable<string> RemoveConfigurationSymbols(string symbols)
|
||||
{
|
||||
return symbolstring.Split(';').Except(new[]
|
||||
return symbols.Split(';').Except(new[]
|
||||
{
|
||||
BuildSLNUtilities.BuildSymbolDebug,
|
||||
BuildSLNUtilities.BuildSymbolRelease,
|
||||
|
|
|
@ -129,8 +129,6 @@ namespace HoloToolkit.Unity
|
|||
string buildError = "Error";
|
||||
try
|
||||
{
|
||||
VerifyWsaUwpSdkIsInstalled(EditorUserBuildSettings.wsaUWPSDK);
|
||||
|
||||
// For the WSA player, Unity builds into a target directory.
|
||||
// For other players, the OutputPath parameter indicates the
|
||||
// path to the target executable to build.
|
||||
|
@ -144,7 +142,7 @@ namespace HoloToolkit.Unity
|
|||
buildInfo.Scenes.ToArray(),
|
||||
buildInfo.OutputDirectory,
|
||||
buildInfo.BuildTarget,
|
||||
buildInfo.BuildOptions);
|
||||
buildInfo.BuildOptions).ToString();
|
||||
|
||||
if (buildError.StartsWith("Error"))
|
||||
{
|
||||
|
@ -174,54 +172,6 @@ namespace HoloToolkit.Unity
|
|||
}
|
||||
}
|
||||
|
||||
private static void VerifyWsaUwpSdkIsInstalled(string wsaUwpSdk)
|
||||
{
|
||||
if (string.IsNullOrEmpty(wsaUwpSdk))
|
||||
{
|
||||
// Unity uses a null or empty string to mean "use the latest sdk that's installed", so we don't need to
|
||||
// verify any particular version.
|
||||
return;
|
||||
}
|
||||
|
||||
IEnumerable<Version> uwpSdksAvailable;
|
||||
try
|
||||
{
|
||||
// In order to get the same list of SDKs that the Unity build settings "UWP SDK" box has, we call into an
|
||||
// internal Unity function. If Unity changes how its internals work, we'll need to update this code.
|
||||
Type uwpReferencesType = typeof(Editor).Assembly.GetType("UnityEditor.Scripting.Compilers.UWPReferences", throwOnError: false);
|
||||
|
||||
MethodInfo uwpReferencesMethod = uwpReferencesType == null
|
||||
? null
|
||||
: uwpReferencesType.GetMethod("GetInstalledSDKVersions");
|
||||
|
||||
uwpSdksAvailable = uwpReferencesMethod == null
|
||||
? null
|
||||
: uwpReferencesMethod.Invoke(null, null) as IEnumerable<Version>;
|
||||
}
|
||||
catch
|
||||
{
|
||||
uwpSdksAvailable = null;
|
||||
}
|
||||
|
||||
if (uwpSdksAvailable == null)
|
||||
{
|
||||
Debug.LogWarningFormat("Couldn't verify that UWP SDK \"{0}\" is installed. You better make sure it's installed"
|
||||
+ " and available in your Unity Build settings menu, or you may get unexpected build breaks or runtime"
|
||||
+ " behavior.",
|
||||
wsaUwpSdk
|
||||
);
|
||||
}
|
||||
else if (!uwpSdksAvailable.Select(version => version.ToString()).Contains(wsaUwpSdk))
|
||||
{
|
||||
throw new Exception(string.Format("UWP SDK \"{0}\" is not installed. Please install it and try building again. If"
|
||||
+ " you really want to build without that SDK, build directly from Unity's Build settings menu instead.",
|
||||
wsaUwpSdk
|
||||
));
|
||||
}
|
||||
|
||||
// The SDK is verified installed. All is right with the world!
|
||||
}
|
||||
|
||||
public static void ParseBuildCommandLine(ref BuildInfo buildInfo)
|
||||
{
|
||||
string[] arguments = Environment.GetCommandLineArgs();
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using UnityEditor;
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 183ec72b0e46f5d4a974ffbe5d11fe95
|
||||
folderAsset: yes
|
||||
timeCreated: 1511727687
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace HoloToolkit.Unity
|
||||
{
|
||||
[Serializable]
|
||||
public class AdapterInfo
|
||||
{
|
||||
public string Description;
|
||||
public string HardwareAddress;
|
||||
public int Index;
|
||||
public string Name;
|
||||
public string Type;
|
||||
public DHCPInfo DHCP;
|
||||
public IpAddressInfo[] Gateways;
|
||||
public IpAddressInfo[] IpAddresses;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 18685959604544043af2a2b05fc42dfe
|
||||
timeCreated: 1501873745
|
||||
guid: e9e582b5e23c1ce4db5af4795de2ea11
|
||||
timeCreated: 1511921435
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
|
@ -0,0 +1,18 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace HoloToolkit.Unity
|
||||
{
|
||||
[Serializable]
|
||||
public class AppDetails
|
||||
{
|
||||
public string Name;
|
||||
public string PackageFamilyName;
|
||||
public string PackageFullName;
|
||||
public int PackageOrigin;
|
||||
public string PackageRelativeId;
|
||||
public string Publisher;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 78d89e4089fc412fbd92cf88db9abb54
|
||||
timeCreated: 1505630361
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace HoloToolkit.Unity
|
||||
{
|
||||
[Serializable]
|
||||
public class AppList
|
||||
{
|
||||
public AppDetails[] InstalledPackages;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1b08d6ba78f3428e9ea3dbfd1dec00f3
|
||||
timeCreated: 1505630361
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace HoloToolkit.Unity
|
||||
{
|
||||
[Serializable]
|
||||
public struct ConnectInfo
|
||||
{
|
||||
public ConnectInfo(string ip, string user, string password, string machineName = "")
|
||||
{
|
||||
IP = ip;
|
||||
User = user;
|
||||
Password = password;
|
||||
MachineName = string.IsNullOrEmpty(machineName) ? ip : machineName;
|
||||
}
|
||||
|
||||
public string IP;
|
||||
public string User;
|
||||
public string Password;
|
||||
public string MachineName;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e2f1a5e5a63040eb99e1c07b389abef6
|
||||
timeCreated: 1505630244
|
|
@ -1,7 +1,5 @@
|
|||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
//
|
||||
|
||||
namespace HoloToolkit.Unity
|
||||
{
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace HoloToolkit.Unity
|
||||
{
|
||||
[Serializable]
|
||||
public class DHCPInfo
|
||||
{
|
||||
public int LeaseExpires;
|
||||
public int LeaseObtained;
|
||||
public IpAddressInfo Address;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b9f4adcf165401e44b8dd0fdc1f01406
|
||||
timeCreated: 1511921662
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace HoloToolkit.Unity
|
||||
{
|
||||
[Serializable]
|
||||
public class DevicePortalConnections
|
||||
{
|
||||
public List<ConnectInfo> Connections = new List<ConnectInfo>(0);
|
||||
|
||||
public DevicePortalConnections(ConnectInfo connectInfo)
|
||||
{
|
||||
Connections.Add(connectInfo);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d9fa39adff61e294d9fac017583d4dfa
|
||||
timeCreated: 1511774995
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace HoloToolkit.Unity
|
||||
{
|
||||
[Serializable]
|
||||
public class InstallStatus
|
||||
{
|
||||
public int Code;
|
||||
public string CodeText;
|
||||
public string Reason;
|
||||
public bool Success;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3bac05516c6546fc9692f8e3575e5bc4
|
||||
timeCreated: 1505630361
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace HoloToolkit.Unity
|
||||
{
|
||||
[Serializable]
|
||||
public class IpAddressInfo
|
||||
{
|
||||
public string IpAddress;
|
||||
public string Mask;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 89cbcc9bf958da744ac19dfb03b05f36
|
||||
timeCreated: 1511923796
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace HoloToolkit.Unity
|
||||
{
|
||||
[Serializable]
|
||||
public class MachineName
|
||||
{
|
||||
public string ComputerName;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6b38e86f792363c45afa2e3aba61e715
|
||||
timeCreated: 1511828513
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace HoloToolkit.Unity
|
||||
{
|
||||
[Serializable]
|
||||
public class NetworkInfo
|
||||
{
|
||||
public AdapterInfo[] Adapters;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 34cde40c31747a94e901220591f0a238
|
||||
timeCreated: 1511921270
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace HoloToolkit.Unity
|
||||
{
|
||||
[Serializable]
|
||||
public class ProcessDesc
|
||||
{
|
||||
public float CPUUsage;
|
||||
public string ImageName;
|
||||
public float PageFileUsage;
|
||||
public int PrivateWorkingSet;
|
||||
public int ProcessId;
|
||||
public int SessionId;
|
||||
public string UserName;
|
||||
public int VirtualSize;
|
||||
public int WorkingSetSize;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 444b49b99f6c486a9f94123fefa890c8
|
||||
timeCreated: 1505630361
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace HoloToolkit.Unity
|
||||
{
|
||||
[Serializable]
|
||||
public class ProcessList
|
||||
{
|
||||
public ProcessDesc[] Processes;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bb334efdb39a4bf4902fa71524072b4a
|
||||
timeCreated: 1505630361
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace HoloToolkit.Unity
|
||||
{
|
||||
[Serializable]
|
||||
public class Response
|
||||
{
|
||||
public string Reason;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3ba58874bb124faa8037fb6733e6475f
|
||||
timeCreated: 1505630361
|
|
@ -1,7 +1,7 @@
|
|||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
namespace HoloToolkit.Unity
|
||||
{
|
||||
|
@ -13,6 +13,7 @@ namespace HoloToolkit.Unity
|
|||
/// <summary>
|
||||
/// Do a build configured for the HoloLens, returns the error from BuildPipeline.BuildPlayer
|
||||
/// </summary>
|
||||
[Obsolete("Use BuildDeployTools.BuildSLN")]
|
||||
public static bool BuildSLN()
|
||||
{
|
||||
return BuildDeployTools.BuildSLN(BuildDeployPrefs.BuildDirectory, false);
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 080001477ab9a6248b3cd5c3c4bfbff4
|
||||
folderAsset: yes
|
||||
timeCreated: 1512167852
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -18,19 +18,14 @@ namespace HoloToolkit.Unity
|
|||
Revision = revision;
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
public int VendorId { get; private set; }
|
||||
|
||||
[SerializeField]
|
||||
public string Udid { get; private set; }
|
||||
|
||||
[SerializeField]
|
||||
public int ProductId { get; private set; }
|
||||
|
||||
[SerializeField]
|
||||
public string Name { get; private set; }
|
||||
|
||||
[SerializeField]
|
||||
public int Revision { get; private set; }
|
||||
}
|
||||
}
|
|
@ -1,7 +1,5 @@
|
|||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
//
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
@ -35,8 +33,6 @@ namespace HoloToolkit.Unity
|
|||
/// <remarks>This is manually parsing the Unity generated MSBuild projects, which means it will be fragile to changes.</remarks>
|
||||
private static void UpdateProjectFile(string filename)
|
||||
{
|
||||
//UnityEngine.Debug.LogFormat("Update Project File: {0}", filename);
|
||||
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
UnityEngine.Debug.LogWarningFormat("Unable to find file \"{0}\", double check that the build succeeded and that the C# Projects are set to be generated.", filename);
|
||||
|
@ -61,7 +57,10 @@ namespace HoloToolkit.Unity
|
|||
foreach (XmlNode node in projectDocument.DocumentElement.ChildNodes)
|
||||
{
|
||||
// Everything we are looking for is inside a PropertyGroup...
|
||||
if (node.Name != "PropertyGroup" || node.Attributes == null) { continue; }
|
||||
if (node.Name != "PropertyGroup" || node.Attributes == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (node.Attributes.Count == 0 && node["Configuration"] != null && node["Platform"] != null)
|
||||
{
|
||||
|
@ -84,7 +83,7 @@ namespace HoloToolkit.Unity
|
|||
WriteXmlDocumentToFile(projectDocument, filename);
|
||||
}
|
||||
|
||||
private static void UpdateDefineConstants(XmlElement defineConstants, string configuration, string platform)
|
||||
private static void UpdateDefineConstants(XmlNode defineConstants, string configuration, string platform)
|
||||
{
|
||||
if (defineConstants == null)
|
||||
{
|
||||
|
@ -103,7 +102,7 @@ namespace HoloToolkit.Unity
|
|||
//UnityEngine.Debug.LogFormat("Updating defines for Configuration|Platform: {0}|{1} => {2}", configuration, platform, defineConstants.InnerText);
|
||||
}
|
||||
|
||||
private static void WriteXmlDocumentToFile(XmlDocument document, string fullPath)
|
||||
private static void WriteXmlDocumentToFile(XmlNode document, string fullPath)
|
||||
{
|
||||
FileStream fileStream = null;
|
||||
try
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
//
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// Copyright (c) Rafael Rivera
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Copyright (c) Rafael Rivera.
|
||||
// Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
@ -14,6 +12,9 @@ using System.Threading;
|
|||
|
||||
namespace HoloToolkit.Unity
|
||||
{
|
||||
/// <summary>
|
||||
/// Emulator Utility Class
|
||||
/// </summary>
|
||||
public static class XdeGuestLocator
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 4)]
|
||||
|
@ -46,75 +47,79 @@ namespace HoloToolkit.Unity
|
|||
public static void FindGuestAddressAsync()
|
||||
{
|
||||
if (IsSearching)
|
||||
return;
|
||||
|
||||
ThreadPool.QueueUserWorkItem((_) =>
|
||||
{
|
||||
IsSearching = true;
|
||||
HasData = false;
|
||||
GuestIpAddress = IPAddress.None;
|
||||
return;
|
||||
}
|
||||
|
||||
UnicastIPAddressInformation internalSwitchAddressInfo = null;
|
||||
try
|
||||
{
|
||||
internalSwitchAddressInfo = GetInternalSwitchAddressInfo();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
UnityEngine.Debug.LogError("Failed to locate internal switch adapter");
|
||||
}
|
||||
ThreadPool.QueueUserWorkItem(FindGuestAddress);
|
||||
}
|
||||
|
||||
if (internalSwitchAddressInfo != null)
|
||||
private static void FindGuestAddress(object state)
|
||||
{
|
||||
IsSearching = true;
|
||||
HasData = false;
|
||||
GuestIpAddress = IPAddress.None;
|
||||
|
||||
UnicastIPAddressInformation internalSwitchAddressInfo = null;
|
||||
try
|
||||
{
|
||||
internalSwitchAddressInfo = GetInternalSwitchAddressInfo();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
UnityEngine.Debug.LogError("Failed to locate internal switch adapter");
|
||||
}
|
||||
|
||||
if (internalSwitchAddressInfo != null)
|
||||
{
|
||||
using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp))
|
||||
{
|
||||
using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp))
|
||||
try
|
||||
{
|
||||
try
|
||||
// Bind to next available UDP port for a listen operation
|
||||
socket.Blocking = true;
|
||||
socket.ReceiveTimeout = (int)TimeSpan.FromSeconds(5).TotalMilliseconds;
|
||||
|
||||
socket.Bind(new IPEndPoint(internalSwitchAddressInfo.Address, 0));
|
||||
var localPort = (socket.LocalEndPoint as IPEndPoint).Port;
|
||||
|
||||
// Send out a probe to 'devices' connected to the internal switch
|
||||
// listening on port 3553 (Microsoft Device Emulator specific)
|
||||
var broadcastAddress = GetBroadcastAddressForAddress(internalSwitchAddressInfo.Address, internalSwitchAddressInfo.IPv4Mask);
|
||||
var broadcastTarget = new IPEndPoint(broadcastAddress, 3553);
|
||||
|
||||
//
|
||||
// WORKAROUND: We don't have easy access to WMI to go querying
|
||||
// for virtual machine information so we just cover finding
|
||||
// the first 255 potential candidates xx 00 - xx FF.
|
||||
//
|
||||
// It sounds like a lot but we're talking super tiny
|
||||
// payloads on an internal interface. It's very fast.
|
||||
//
|
||||
for (int i = 0; i <= 0xFF; i++)
|
||||
{
|
||||
// Bind to next available UDP port for a listen operation
|
||||
socket.Blocking = true;
|
||||
socket.ReceiveTimeout = (int)TimeSpan.FromSeconds(5).TotalMilliseconds;
|
||||
|
||||
socket.Bind(new IPEndPoint(internalSwitchAddressInfo.Address, 0));
|
||||
var localPort = (socket.LocalEndPoint as IPEndPoint).Port;
|
||||
|
||||
// Send out a probe to 'devices' connected to the internal switch
|
||||
// listening on port 3553 (Microsoft Device Emulator specific)
|
||||
var broadcastAddress = GetBroadcastAddressForAddress(internalSwitchAddressInfo.Address, internalSwitchAddressInfo.IPv4Mask);
|
||||
var broadcastTarget = new IPEndPoint(broadcastAddress, 3553);
|
||||
|
||||
//
|
||||
// WORKAROUND: We don't have easy access to WMI to go querying
|
||||
// for virtual machine information so we just cover finding
|
||||
// the first 255 potential candidates xx 00 - xx FF.
|
||||
//
|
||||
// It sounds like a lot but we're talking super tiny
|
||||
// payloads on an internal interface. It's very fast.
|
||||
//
|
||||
for (int i = 0; i <= 0xFF; i++)
|
||||
{
|
||||
var probe = GenerateProbe(localPort, i);
|
||||
socket.SendTo(probe, broadcastTarget);
|
||||
}
|
||||
|
||||
// Return the endpoint information for the first 'device' that replies
|
||||
// (we don't necessarily care about the returned identifier info)
|
||||
var responseBytes = new byte[Marshal.SizeOf(typeof(XdePeerGuestIdentifier))];
|
||||
|
||||
EndPoint guestEndpoint = new IPEndPoint(broadcastAddress, 0);
|
||||
|
||||
socket.ReceiveFrom(responseBytes, ref guestEndpoint);
|
||||
GuestIpAddress = (guestEndpoint as IPEndPoint).Address;
|
||||
HasData = true;
|
||||
}
|
||||
catch (SocketException)
|
||||
{
|
||||
// Do nothing, our probe went unanswered or failed
|
||||
var probe = GenerateProbe(localPort, i);
|
||||
socket.SendTo(probe, broadcastTarget);
|
||||
}
|
||||
|
||||
// Return the endpoint information for the first 'device' that replies
|
||||
// (we don't necessarily care about the returned identifier info)
|
||||
var responseBytes = new byte[Marshal.SizeOf(typeof(XdePeerGuestIdentifier))];
|
||||
|
||||
EndPoint guestEndpoint = new IPEndPoint(broadcastAddress, 0);
|
||||
|
||||
socket.ReceiveFrom(responseBytes, ref guestEndpoint);
|
||||
GuestIpAddress = (guestEndpoint as IPEndPoint).Address;
|
||||
HasData = true;
|
||||
}
|
||||
catch (SocketException)
|
||||
{
|
||||
// Do nothing, our probe went unanswered or failed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IsSearching = false;
|
||||
});
|
||||
IsSearching = false;
|
||||
}
|
||||
|
||||
private static UnicastIPAddressInformation GetInternalSwitchAddressInfo()
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: beb9861457cb1af4ab53484d562592a7
|
||||
folderAsset: yes
|
||||
timeCreated: 1512156161
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,228 @@
|
|||
## [Common]()
|
||||
Classes that are needed by most feature areas are in this folder.
|
||||
|
||||
### [Scripts](Scripts)
|
||||
---
|
||||
Utilitiy Scripts.
|
||||
|
||||
#### [Editor](Scripts/Editor)
|
||||
---
|
||||
Editor Specific Scripts.
|
||||
|
||||
##### AutoConfigureMenu.cs
|
||||
Configuration options derived from Microsoft Documentation [Configuring a Unity Project for HoloLens](https://developer.microsoft.com/en-us/windows/mixed-reality/unity_development_overview#Configuring_a_Unity_project_for_HoloLens).
|
||||
|
||||
##### AutoConfigureWindow.cs
|
||||
Base class for auto configuration build windows.
|
||||
|
||||
##### CapabilitySettingsWindow.cs
|
||||
Renders the UI and handles update logic for MixedRealityToolkit/Configure/Apply HoloLens Capability Settings.
|
||||
|
||||
##### EditorGUIExtensions.cs
|
||||
Extensions for the UnityEnditor.EditorGUI class.
|
||||
|
||||
##### EditorGUILayoutExtensions.cs
|
||||
Extensions for the UnityEditor.EditorGUILayout class.
|
||||
|
||||
##### EnforceEditorSettings.cs
|
||||
Sets Force Text Serialization and visible meta files in all projects that use the MixedRealityToolkit.
|
||||
|
||||
##### ExternalProcess.cs
|
||||
Helper class for launching external processes inside of the unity editor.
|
||||
|
||||
##### LayerMaskExtensions.cs
|
||||
Extensions for the UnityEngine.LayerMask class.
|
||||
|
||||
##### ProjectSettingsWindow.cs
|
||||
Renders the UI and handles update logic for MixedRealityToolkit/Configure/Apply HoloLens Project Settings.
|
||||
|
||||
##### SceneSettingsWindow.cs
|
||||
Renders the UI and handles update logic for MixedRealityToolkit/Configure/Apply HoloLens Scene Settings.
|
||||
|
||||
##### StandardShaderGUI.cs
|
||||
A custom shader inspector for the "MixedRealityToolkit/Standard" shader.
|
||||
|
||||
#### [Extensions](Scripts/Extensions)
|
||||
|
||||
##### ActionExtensions.cs
|
||||
Extensions for the action class. These methods encapsulate the null check before raising an event for an Action.
|
||||
|
||||
##### ComponentExtensions.cs
|
||||
Extensions methods for the Unity Component class. This also includes some component-related extensions for the GameObjet class.
|
||||
|
||||
##### Extensions.cs
|
||||
A class with general purpose extensions methods.
|
||||
|
||||
##### TransformExtensions.cs
|
||||
An extension method that will get you the full path to an object.
|
||||
|
||||
##### VectorExtensions.cs
|
||||
A collection of useful extension methods for Unity's Vector structs.
|
||||
|
||||
#### [InterpolatedValues](Scripts/InterpolatedValues)
|
||||
---
|
||||
Interpolated Value Scripts.
|
||||
|
||||
##### InterpolatedColor.cs
|
||||
Provides interpolation over Color.
|
||||
|
||||
##### InterpolatedFloat.cs
|
||||
Provides interpolation over float.
|
||||
|
||||
##### InterpolatedQuaternion.cs
|
||||
Provides interpolation over Quaternion.
|
||||
|
||||
##### InterpolatedValue.cs
|
||||
Base class that provides the common logic for interpolating between values. This class does not inherit from MonoBehaviour in order to enable various scenarios under which it used. To perform the interpolation step, call FrameUpdate.
|
||||
|
||||
##### InterpolatedVector2.cs
|
||||
Provides interpolation over Vector2.
|
||||
|
||||
##### InterpolatedVector3.cs
|
||||
Provides interpolation over Vector3.
|
||||
|
||||
##### QuaternionInterpolated.cs
|
||||
Class to encapsulate an interpolating Quaternion property.
|
||||
TODO: Remove if redundant to InterpolatedQuaternion.cs
|
||||
|
||||
##### Vector3Interpolated.cs
|
||||
Class to encapsulate an interpolating Vector3 property.
|
||||
TODO: Remove if redundant to InterpolatedVector3.cs
|
||||
|
||||
---
|
||||
|
||||
#### ApplicationViewManager.cs
|
||||
Switches app to a XAML page view, and waits for a return value from it.
|
||||
|
||||
#### Billboard.cs
|
||||
Rotates a hologram so it is always facing towards the camera.
|
||||
|
||||
#### BitManipulator.cs
|
||||
Helper class for bit manipulation.
|
||||
|
||||
#### CircularBuffer.cs
|
||||
Helper class for transmitting data over network.
|
||||
|
||||
#### DirectionIndicator.cs
|
||||
Show a GameObject around the cursor that points in the direction of the GameObject which this script is attached to.
|
||||
|
||||
You must provide GameObjects for the **_Cursor_** and **_DirectionIndicatorObject_** public fields.
|
||||
|
||||
**_Cursor_** The object in your scene that is being used as the cursor. The direction indicator will be rendered around this cursor.
|
||||
|
||||
**_DirectionIndicatorObject_** The object that will point in the direction toward the object which this script is attached to. This object can be a 2D or 3D object.
|
||||
|
||||
**DirectionIndicatorColor** The color you want the DirectionIndicatorObject to be. The material on the DirectionIndicatorObject will need to support the color or TintColor property for this field to work. Otherwise the DirectionIndicatorObject will continue to render as its exported color.
|
||||
|
||||
**TitleSafeFactor** The percentage the GameObject can be within the view frustum for the DirectionIndicatorObject to start appearing. A value of 0 will display the DirectionIndicatorObject when the GameObject leaves the view. 0.1 will display when the GameObject is 10% away from the edge of the view. -0.1 will display when the GameObject is 10% out of view.
|
||||
|
||||
#### DisplayDependentObjectActivator.cs
|
||||
Causes a GameObject to activate or disable depending on the settings and type of display the application is launched on.
|
||||
|
||||
#### FixedAngularSize.cs
|
||||
Causes a hologram to maintain a fixed angular size, which is to say it occupies the same pixels in the view regardless of its distance from the camera.
|
||||
|
||||
#### FpsDisplay.cs
|
||||
Simple Behaviour which calculates the average frames per second over a number of frames and shows the FPS in a referenced Text control.
|
||||
|
||||
#### HeadsUpDirectionIndicator.cs
|
||||
Spawns a user specified "pointer" object and startup and alligns it to aim at a target object which keeping the pointer in view at all times.
|
||||
|
||||
#### InterpolationUtilities.cs
|
||||
Static class containing interpolation-related utility functions.
|
||||
|
||||
#### Interpolator.cs
|
||||
A MonoBehaviour that interpolates a transform's position, rotation or scale.
|
||||
|
||||
#### MathUtils.cs
|
||||
Math Utilities class.
|
||||
|
||||
#### NearPlaneFade.cs
|
||||
Updates the shader parameters for use in near plane fading.
|
||||
|
||||
#### PriorityQueue.cs
|
||||
Min-heap priority queue. In other words, lower priorities will be removed from the queue first.
|
||||
See [Binary Heap](http://en.wikipedia.org/wiki/Binary_heap) for more info.
|
||||
|
||||
#### SessionExtensions.cs
|
||||
Extensions methods for the Session class.
|
||||
|
||||
#### SimpleTagalong.cs
|
||||
A Tagalong that stays at a fixed distance from the camera and always seeks to have a part of itself in the view frustum of the camera.
|
||||
|
||||
#### Singleton.cs
|
||||
A base class to make a MonoBehaviour follow the singleton design pattern.
|
||||
|
||||
#### SphereBasedTagalong.cs
|
||||
A simple Tagalong that stays inside a sphere at a fixed distance from the camera. Very cheap implementation with smoothing capability.
|
||||
|
||||
#### StabilizationPlaneModifier.cs
|
||||
StabilizationPlaneModifier handles the setting of the stabilization plane in several ways.
|
||||
|
||||
#### Tagalong.cs
|
||||
A Tagalong that extends SimpleTagalong that allows for specifying the minimum and target percentage of the object to keep in the view frustum of the camera and that keeps the Tagalong object in front of other holograms including the Spatial Mapping Mesh.
|
||||
|
||||
#### TextToSpeechManager.cs
|
||||
Provides dynamic Text to Speech. Speech is generated using the UWP SpeechSynthesizer and then played through a Unity AudioSource. Both plain text and SSML are supported.
|
||||
|
||||
#### Timer.cs
|
||||
Structure that defines a timer. A timer can be scheduled through the TimerScheduler.
|
||||
|
||||
#### TimerScheduler.cs
|
||||
A scheduler that manages various timers.
|
||||
|
||||
#### Utils.cs
|
||||
Miscellaneous utility methods.
|
||||
|
||||
#### VectorRollingStatistics.cs
|
||||
Vector Statistics used in gaze stabilization.
|
||||
|
||||
#### WorldAnchorManager.cs
|
||||
Wrapper around world anchor store to streamline some of the persistence api busy work.
|
||||
|
||||
#### HoverLight.cs
|
||||
Utility component to animate and visualize a hover light that can be used with the "MixedRealityToolkit/Standard" shader "_HoverLight" feature.
|
||||
|
||||
#### ClipPlane.cs
|
||||
Utility component to animate and visualize a clipping plane that can be used with the "MixedRealityToolkit/Standard" shader "_ClippingPlane" feature.
|
||||
|
||||
### [Shaders](Shaders)
|
||||
---
|
||||
|
||||
#### Standard.shader
|
||||
A collection of shading techniques to mimic visuals similar to Unity's Standard Shader, implement Fluent Design System principles, and remain performant on mixed reality devices.
|
||||
|
||||
#### WindowOcclusion.shader
|
||||
A simple occlusion shader that can be used to hide other objects. This prevents other objects from being rendered by drawing invisible 'opaque' pixels to the depth buffer. This shader differs from Occlusion.shader in that it doesn't have any depth offset, so it should sort as expected with other objects adjacent to the window.
|
||||
|
||||
### [Tests](../../MixedRealityToolkit-Examples/Utilities/Scenes)
|
||||
---
|
||||
Tests related to the utilities features. To use the scene:
|
||||
|
||||
1. Navigate to the Tests folder.
|
||||
2. Double click on the test scene you wish to explore.
|
||||
3. Either click "Play" in the unity editor or File -> Build Settings.
|
||||
4. Add Open Scenes, Platform -> Windows Store, SDK -> Universal 10, Build Type -> D3D, Check 'Unity C# Projects'.
|
||||
5. Click 'Build' and create an App folder. When compile is done, open the solution and deploy to device.
|
||||
|
||||
#### HeadsUpDirectionIndicator.unity
|
||||
This scene shows 7 marker objects with 7 HeadsUpDirectionIndicators pointing to each. Each indicator has a label that matches its corresponding marker. 6 of the marker/indicator pairs are used to test the edge cases of axis aligned markers. The 7th is an arbitrary point off of the cartesean axes. From the starting position, the user should be able to follow the direction of each indicator and arrive at the marker with the corresponding axis label. At the start, the labels should be in the following screen locations.
|
||||
|
||||
- \-X at the left
|
||||
- +X at the right
|
||||
- \-Y at the bottom
|
||||
- +Y at the top
|
||||
- \-Z also at the bottom
|
||||
- +Z in front
|
||||
|
||||
#### TextToSpeechManager.unity
|
||||
|
||||
This scene demonstrates how to use TextToSpeechManager.cs. The script is placed on 3 cubes in the scene. Whenever a cube is activated with an air tap, a text to speech voice will emanate from the cube. The user can also ask "What time is it?" to hear the current time from a voice that stays with the user as they move.
|
||||
|
||||
#### WindowOcclusion.unity
|
||||
|
||||
This scene demonstrates how to use WindowOcclusion.shader. It positions a virtual 'window' directly in front of you when the scene starts. A cube in the back is only visible when viewed through the window because quads around the window use the WindowOcclusion shader.
|
||||
|
||||
---
|
||||
##### [Go back up to the table of contents.](../../../README.md)
|
||||
---
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 63a33d07ea6c0f947969c1af5143b5fc
|
||||
timeCreated: 1512157109
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,9 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6bca8de3014df864fb5160e4323f4277
|
||||
guid: 9dec9262d6eab35428419548331319af
|
||||
folderAsset: yes
|
||||
timeCreated: 1496257003
|
||||
timeCreated: 1512156210
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,158 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace HoloToolkit.Unity
|
||||
{
|
||||
/// <summary>
|
||||
/// Utility component to animate and visualize a clipping plane that can be used with
|
||||
/// the "MixedRealityToolkit/Standard" shader "_ClippingPlane" feature.
|
||||
/// </summary>
|
||||
[ExecuteInEditMode]
|
||||
public class ClipPlane : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Renderer[] renderers = null;
|
||||
|
||||
private int clipPlaneID;
|
||||
private Material[] materials;
|
||||
private MaterialPropertyBlock materialPropertyBlock;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
Initialize();
|
||||
UpdatePlanePosition();
|
||||
ToggleClippingPlane(true);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
UpdatePlanePosition();
|
||||
ToggleClippingPlane(false);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void Update()
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Initialize();
|
||||
UpdatePlanePosition();
|
||||
}
|
||||
#endif
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
UpdatePlanePosition();
|
||||
}
|
||||
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
if (!enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Gizmos.matrix = transform.localToWorldMatrix;
|
||||
Gizmos.DrawLine(Vector3.zero, Vector3.up * 0.5f);
|
||||
Gizmos.DrawWireCube(Vector3.zero, new Vector3(1.0f, 0.0f, 1.0f));
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (materials != null)
|
||||
{
|
||||
foreach (Material material in materials)
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
Destroy(material);
|
||||
}
|
||||
}
|
||||
|
||||
materials = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
clipPlaneID = Shader.PropertyToID("_ClipPlane");
|
||||
|
||||
materials = new Material[renderers.Length];
|
||||
|
||||
for (int i = 0; i < renderers.Length; ++i)
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
materials[i] = renderers[i].material;
|
||||
}
|
||||
else
|
||||
{
|
||||
materials[i] = renderers[i].sharedMaterial;
|
||||
}
|
||||
}
|
||||
|
||||
materialPropertyBlock = new MaterialPropertyBlock();
|
||||
}
|
||||
|
||||
private void UpdatePlanePosition()
|
||||
{
|
||||
if (renderers == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 up = transform.up;
|
||||
Vector4 plane = new Vector4(up.x, up.y, up.z, Vector3.Dot(up, transform.position));
|
||||
|
||||
foreach (Renderer renderer in renderers)
|
||||
{
|
||||
if (renderer == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
renderer.GetPropertyBlock(materialPropertyBlock);
|
||||
materialPropertyBlock.SetVector(clipPlaneID, plane);
|
||||
renderer.SetPropertyBlock(materialPropertyBlock);
|
||||
}
|
||||
}
|
||||
|
||||
private void ToggleClippingPlane(bool isClippingPlaneOn)
|
||||
{
|
||||
if (materials == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (Material material in materials)
|
||||
{
|
||||
if (material == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
const string clippingPlaneKeyword = "_CLIPPING_PLANE";
|
||||
|
||||
if (isClippingPlaneOn)
|
||||
{
|
||||
if (!material.IsKeywordEnabled(clippingPlaneKeyword))
|
||||
{
|
||||
material.EnableKeyword(clippingPlaneKeyword);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (material.IsKeywordEnabled(clippingPlaneKeyword))
|
||||
{
|
||||
material.DisableKeyword(clippingPlaneKeyword);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3314ab59de926264094cc25d32068b6b
|
||||
timeCreated: 1519154739
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,9 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2fd9d4de22062964cbd1349a15a5afb1
|
||||
guid: 59820c6fbf494f74fa6ce7bcdf8be4e3
|
||||
folderAsset: yes
|
||||
timeCreated: 1489609655
|
||||
timeCreated: 1512588290
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -18,6 +18,16 @@ namespace HoloToolkit.Unity
|
|||
EditorPrefs.SetBool(Application.productName + key, value);
|
||||
}
|
||||
|
||||
public static void SetEditorPref(string key, float value)
|
||||
{
|
||||
EditorPrefs.SetFloat(Application.productName + key, value);
|
||||
}
|
||||
|
||||
public static void SetEditorPref(string key, int value)
|
||||
{
|
||||
EditorPrefs.SetInt(Application.productName + key, value);
|
||||
}
|
||||
|
||||
public static string GetEditorPref(string key, string defaultValue)
|
||||
{
|
||||
if (EditorPrefs.HasKey(Application.productName + key))
|
||||
|
@ -39,5 +49,27 @@ namespace HoloToolkit.Unity
|
|||
EditorPrefs.SetBool(Application.productName + key, defaultValue);
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public static float GetEditorPref(string key, float defaultValue)
|
||||
{
|
||||
if (EditorPrefs.HasKey(Application.productName + key))
|
||||
{
|
||||
return EditorPrefs.GetFloat(Application.productName + key);
|
||||
}
|
||||
|
||||
EditorPrefs.SetFloat(Application.productName + key, defaultValue);
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public static int GetEditorPref(string key, int defaultValue)
|
||||
{
|
||||
if (EditorPrefs.HasKey(Application.productName + key))
|
||||
{
|
||||
return EditorPrefs.GetInt(Application.productName + key);
|
||||
}
|
||||
|
||||
EditorPrefs.SetInt(Application.productName + key, defaultValue);
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ec2418e0c15c71e4f8df965a4d02dd03
|
||||
folderAsset: yes
|
||||
timeCreated: 1521490728
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,855 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HoloToolkit.Unity
|
||||
{
|
||||
/// <summary>
|
||||
/// A custom shader inspector for the "MixedRealityToolkit/Standard" shader.
|
||||
/// </summary>
|
||||
public class StandardShaderGUI : ShaderGUI
|
||||
{
|
||||
public enum RenderingMode
|
||||
{
|
||||
Opaque,
|
||||
TransparentCutout,
|
||||
Transparent,
|
||||
PremultipliedTransparent,
|
||||
Additive,
|
||||
Custom
|
||||
}
|
||||
|
||||
public enum CustomRenderingMode
|
||||
{
|
||||
Opaque,
|
||||
TransparentCutout,
|
||||
Transparent
|
||||
}
|
||||
|
||||
public enum AlbedoAlphaMode
|
||||
{
|
||||
Transparency,
|
||||
Metallic,
|
||||
Smoothness
|
||||
}
|
||||
|
||||
public enum DepthWrite
|
||||
{
|
||||
Off,
|
||||
On
|
||||
}
|
||||
|
||||
public static class Styles
|
||||
{
|
||||
public static string primaryMapsTitle = "Main Maps";
|
||||
public static string renderingOptionsTitle = "Rendering Options";
|
||||
public static string advancedOptionsTitle = "Advanced Options";
|
||||
public static string fluentOptionsTitle = "Fluent Options";
|
||||
public static string renderTypeName = "RenderType";
|
||||
public static string renderingModeName = "_Mode";
|
||||
public static string customRenderingModeName = "_CustomMode";
|
||||
public static string sourceBlendName = "_SrcBlend";
|
||||
public static string destinationBlendName = "_DstBlend";
|
||||
public static string blendOperationName = "_BlendOp";
|
||||
public static string depthTestName = "_ZTest";
|
||||
public static string depthWriteName = "_ZWrite";
|
||||
public static string colorWriteMaskName = "_ColorWriteMask";
|
||||
public static string alphaTestOnName = "_ALPHATEST_ON";
|
||||
public static string alphaBlendOnName = "_ALPHABLEND_ON";
|
||||
public static string disableAlbedoMapName = "_DISABLE_ALBEDO_MAP";
|
||||
public static string albedoMapAlphaMetallicName = "_METALLIC_TEXTURE_ALBEDO_CHANNEL_A";
|
||||
public static string albedoMapAlphaSmoothnessName = "_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A";
|
||||
public static readonly string[] renderingModeNames = Enum.GetNames(typeof(RenderingMode));
|
||||
public static readonly string[] customRenderingModeNames = Enum.GetNames(typeof(CustomRenderingMode));
|
||||
public static readonly string[] albedoAlphaModeNames = Enum.GetNames(typeof(AlbedoAlphaMode));
|
||||
public static readonly string[] depthWriteNames = Enum.GetNames(typeof(DepthWrite));
|
||||
public static GUIContent sourceBlend = new GUIContent("Source Blend", "Blend Mode of Newly Calculated Color");
|
||||
public static GUIContent destinationBlend = new GUIContent("Destination Blend", "Blend Mode of Exisiting Color");
|
||||
public static GUIContent blendOperation = new GUIContent("Blend Operation", "Operation for Blending New Color With Exisiting Color");
|
||||
public static GUIContent depthTest = new GUIContent("Depth Test", "How Should Depth Testing Be Performed.");
|
||||
public static GUIContent depthWrite = new GUIContent("Depth Write", "Controls Whether Pixels From This Object Are Written to the Depth Buffer");
|
||||
public static GUIContent colorWriteMask = new GUIContent("Color Write Mask", "Color Channel Writing Mask");
|
||||
public static GUIContent cullMode = new GUIContent("Cull Mode", "Triangle Culling Mode");
|
||||
public static GUIContent renderQueueOverride = new GUIContent("Render Queue Override", "Manually Override the Render Queue");
|
||||
public static GUIContent albedo = new GUIContent("Albedo", "Albedo (RGB) and Transparency (A)");
|
||||
public static GUIContent alphaCutoff = new GUIContent("Alpha Cutoff", "Threshold for Alpha Cutoff");
|
||||
public static GUIContent metallic = new GUIContent("Metallic", "Metallic Value");
|
||||
public static GUIContent smoothness = new GUIContent("Smoothness", "Smoothness Value");
|
||||
public static GUIContent enableNormalMap = new GUIContent("Normal Map", "Enable Normal Map");
|
||||
public static GUIContent normalMap = new GUIContent("Normal Map");
|
||||
public static GUIContent enableEmission = new GUIContent("Emission", "Enable Emission");
|
||||
public static GUIContent emissiveColor = new GUIContent("Color");
|
||||
public static GUIContent directionalLight = new GUIContent("Directional Light", "Affected by Unity Directional Light");
|
||||
public static GUIContent specularHighlights = new GUIContent("Specular Highlights", "Calculate Specular Highlights");
|
||||
public static GUIContent reflections = new GUIContent("Reflections", "Calculate Glossy Reflections");
|
||||
public static GUIContent refraction = new GUIContent("Refraction", "Calculate Refraction");
|
||||
public static GUIContent refractiveIndex = new GUIContent("Refractive Index", "Ratio of Indices of Refraction at the Surface Interface");
|
||||
public static GUIContent rimLight = new GUIContent("Rim Light", "Enable Rim/Edge Lighting");
|
||||
public static GUIContent rimColor = new GUIContent("Color", "Rim Highlight Color");
|
||||
public static GUIContent rimPower = new GUIContent("Power", "Rim Highlight Saturation");
|
||||
public static GUIContent clippingPlane = new GUIContent("Clipping Plane", "Enable Clipping Against a Plane");
|
||||
public static GUIContent clipPlane = new GUIContent("Plane", "Plane To Clip Against");
|
||||
public static GUIContent clippingPlaneBorder = new GUIContent("Border", "Enable a Border Along the Clipping Plane");
|
||||
public static GUIContent clippingPlaneBorderWidth = new GUIContent("Width", "Width of the Clipping Plane Border");
|
||||
public static GUIContent clippingPlaneBorderColor = new GUIContent("Color", "Interpolated Color of the Clipping Plane Border");
|
||||
public static GUIContent nearPlaneFade = new GUIContent("Near Plane Fade", "Objects Disappear (Turn to Black) as the Camera Nears Them");
|
||||
public static GUIContent fadeBeginDistance = new GUIContent("Fade Begin", "Distance From Camera to Begin Fade In");
|
||||
public static GUIContent fadeCompleteDistance = new GUIContent("Fade Complete", "Distance From Camera When Fade is Fully In");
|
||||
public static GUIContent hoverLight = new GUIContent("Hover Light", "Enable utilization of a Hover Light");
|
||||
public static GUIContent enableHoverColorOverride = new GUIContent("Override Color", "Override Global Hover Color");
|
||||
public static GUIContent hoverLightOpaque = new GUIContent("Hover Light Opaque", "Enable Hover Light on Transparent pixels");
|
||||
public static GUIContent enableHoverColorOpaqueOverride = new GUIContent("Override Color", "Override Opaque Hover Color");
|
||||
public static GUIContent hoverColorOpaqueOverride = new GUIContent("Color", "Override Hover Color for Trasnparent Pixels");
|
||||
public static GUIContent hoverColorOverride = new GUIContent("Color", "Override Hover Color");
|
||||
public static GUIContent roundCorners = new GUIContent("Round Corners", "(Assumes UVs Specify Borders)");
|
||||
public static GUIContent roundCornerRadius = new GUIContent("Unit Radius", "Rounded Rectangle Corner Unit Sphere Radius");
|
||||
public static GUIContent roundCornerMargin = new GUIContent("Margin %", "Distance From Geometry Edge");
|
||||
public static GUIContent borderLight = new GUIContent("Border Light", "Enable Border Lighting (Assumes UVs Specify Borders)");
|
||||
public static GUIContent borderLightUsesHoverColor = new GUIContent("Use Hover Color", "Border Color Comes From Hover Light");
|
||||
public static GUIContent borderLightOpaque = new GUIContent("Opaque Borders", "Borders Override Alpha Value to Appear Opaque");
|
||||
public static GUIContent borderWidth = new GUIContent("Width %", "Uniform Width Along Border as a % of the Smallest XYZ Dimension");
|
||||
public static GUIContent borderMinValue = new GUIContent("Min Value", "Minimum Border Saturation");
|
||||
public static GUIContent edgeSmoothingValue = new GUIContent("Edge Smoothing Value", "Smooths Edges When Round Corners and Transparency Is Enabled");
|
||||
public static GUIContent innerGlow = new GUIContent("Inner Glow", "Enable Inner Glow (Assumes UVs Specify Borders)");
|
||||
public static GUIContent innerGlowColor = new GUIContent("Color", "Inner Glow Color (RGB) and Intensity (A)");
|
||||
public static GUIContent environmentColoring = new GUIContent("Environment Coloring", "Change Color Based on View");
|
||||
public static GUIContent environmentColorThreshold = new GUIContent("Threshold", "Threshold When Environment Coloring Should Appear Based on Surface Normal");
|
||||
public static GUIContent environmentColorIntensity = new GUIContent("Intensity", "Intensity (or Brightness) of the Environment Coloring");
|
||||
public static GUIContent environmentColorX = new GUIContent("X-Axis Color", "Color Along the Worldspace X-Axis");
|
||||
public static GUIContent environmentColorY = new GUIContent("Y-Axis Color", "Color Along the Worldspace Y-Axis");
|
||||
public static GUIContent environmentColorZ = new GUIContent("Z-Axis Color", "Color Along the Worldspace Z-Axis");
|
||||
}
|
||||
|
||||
protected bool initilized;
|
||||
|
||||
protected MaterialProperty renderingMode;
|
||||
protected MaterialProperty customRenderingMode;
|
||||
protected MaterialProperty sourceBlend;
|
||||
protected MaterialProperty destinationBlend;
|
||||
protected MaterialProperty blendOperation;
|
||||
protected MaterialProperty depthTest;
|
||||
protected MaterialProperty depthWrite;
|
||||
protected MaterialProperty colorWriteMask;
|
||||
protected MaterialProperty cullMode;
|
||||
protected MaterialProperty renderQueueOverride;
|
||||
protected MaterialProperty albedoMap;
|
||||
protected MaterialProperty albedoColor;
|
||||
protected MaterialProperty albedoAlphaMode;
|
||||
protected MaterialProperty alphaCutoff;
|
||||
protected MaterialProperty enableNormalMap;
|
||||
protected MaterialProperty normalMap;
|
||||
protected MaterialProperty enableEmission;
|
||||
protected MaterialProperty emissiveColor;
|
||||
protected MaterialProperty metallic;
|
||||
protected MaterialProperty smoothness;
|
||||
protected MaterialProperty directionalLight;
|
||||
protected MaterialProperty specularHighlights;
|
||||
protected MaterialProperty reflections;
|
||||
protected MaterialProperty refraction;
|
||||
protected MaterialProperty refractiveIndex;
|
||||
protected MaterialProperty rimLight;
|
||||
protected MaterialProperty rimColor;
|
||||
protected MaterialProperty rimPower;
|
||||
protected MaterialProperty clippingPlane;
|
||||
protected MaterialProperty clipPlane;
|
||||
protected MaterialProperty clippingPlaneBorder;
|
||||
protected MaterialProperty clippingPlaneBorderWidth;
|
||||
protected MaterialProperty clippingPlaneBorderColor;
|
||||
protected MaterialProperty nearPlaneFade;
|
||||
protected MaterialProperty fadeBeginDistance;
|
||||
protected MaterialProperty fadeCompleteDistance;
|
||||
protected MaterialProperty hoverLight;
|
||||
protected MaterialProperty enableHoverColorOverride;
|
||||
protected MaterialProperty hoverLightOpaque;
|
||||
protected MaterialProperty enableHoverColorOpaqueOverride;
|
||||
protected MaterialProperty hoverColorOverrideOpaque;
|
||||
protected MaterialProperty hoverColorOverride;
|
||||
protected MaterialProperty roundCorners;
|
||||
protected MaterialProperty roundCornerRadius;
|
||||
protected MaterialProperty roundCornerMargin;
|
||||
protected MaterialProperty borderLight;
|
||||
protected MaterialProperty borderLightUsesHoverColor;
|
||||
protected MaterialProperty borderLightOpaque;
|
||||
protected MaterialProperty borderWidth;
|
||||
protected MaterialProperty borderMinValue;
|
||||
protected MaterialProperty edgeSmoothingValue;
|
||||
protected MaterialProperty innerGlow;
|
||||
protected MaterialProperty innerGlowColor;
|
||||
protected MaterialProperty environmentColoring;
|
||||
protected MaterialProperty environmentColorThreshold;
|
||||
protected MaterialProperty environmentColorIntensity;
|
||||
protected MaterialProperty environmentColorX;
|
||||
protected MaterialProperty environmentColorY;
|
||||
protected MaterialProperty environmentColorZ;
|
||||
|
||||
protected void FindProperties(MaterialProperty[] props)
|
||||
{
|
||||
renderingMode = FindProperty(Styles.renderingModeName, props);
|
||||
customRenderingMode = FindProperty(Styles.customRenderingModeName, props);
|
||||
sourceBlend = FindProperty(Styles.sourceBlendName, props);
|
||||
destinationBlend = FindProperty(Styles.destinationBlendName, props);
|
||||
blendOperation = FindProperty(Styles.blendOperationName, props);
|
||||
depthTest = FindProperty(Styles.depthTestName, props);
|
||||
depthWrite = FindProperty(Styles.depthWriteName, props);
|
||||
colorWriteMask = FindProperty(Styles.colorWriteMaskName, props);
|
||||
cullMode = FindProperty("_CullMode", props);
|
||||
renderQueueOverride = FindProperty("_RenderQueueOverride", props);
|
||||
albedoMap = FindProperty("_MainTex", props);
|
||||
albedoColor = FindProperty("_Color", props);
|
||||
albedoAlphaMode = FindProperty("_AlbedoAlphaMode", props);
|
||||
alphaCutoff = FindProperty("_Cutoff", props);
|
||||
metallic = FindProperty("_Metallic", props);
|
||||
smoothness = FindProperty("_Smoothness", props);
|
||||
enableNormalMap = FindProperty("_EnableNormalMap", props);
|
||||
normalMap = FindProperty("_NormalMap", props);
|
||||
enableEmission = FindProperty("_EnableEmission", props);
|
||||
emissiveColor = FindProperty("_EmissiveColor", props);
|
||||
directionalLight = FindProperty("_DirectionalLight", props);
|
||||
specularHighlights = FindProperty("_SpecularHighlights", props);
|
||||
reflections = FindProperty("_Reflections", props);
|
||||
refraction = FindProperty("_Refraction", props);
|
||||
refractiveIndex = FindProperty("_RefractiveIndex", props);
|
||||
rimLight = FindProperty("_RimLight", props);
|
||||
rimColor = FindProperty("_RimColor", props);
|
||||
rimPower = FindProperty("_RimPower", props);
|
||||
clippingPlane = FindProperty("_ClippingPlane", props);
|
||||
clipPlane = FindProperty("_ClipPlane", props);
|
||||
clippingPlaneBorder = FindProperty("_ClippingPlaneBorder", props);
|
||||
clippingPlaneBorderWidth = FindProperty("_ClippingPlaneBorderWidth", props);
|
||||
clippingPlaneBorderColor = FindProperty("_ClippingPlaneBorderColor", props);
|
||||
nearPlaneFade = FindProperty("_NearPlaneFade", props);
|
||||
fadeBeginDistance = FindProperty("_FadeBeginDistance", props);
|
||||
fadeCompleteDistance = FindProperty("_FadeCompleteDistance", props);
|
||||
hoverLight = FindProperty("_HoverLight", props);
|
||||
enableHoverColorOverride = FindProperty("_EnableHoverColorOverride", props);
|
||||
hoverColorOverride = FindProperty("_HoverColorOverride", props);
|
||||
hoverLightOpaque = FindProperty("_HoverLightOpaque", props);
|
||||
enableHoverColorOpaqueOverride = FindProperty("_EnableHoverColorOpaqueOverride", props);
|
||||
hoverColorOverrideOpaque = FindProperty("_HoverColorOpaqueOverride", props);
|
||||
roundCorners = FindProperty("_RoundCorners", props);
|
||||
roundCornerRadius = FindProperty("_RoundCornerRadius", props);
|
||||
roundCornerMargin = FindProperty("_RoundCornerMargin", props);
|
||||
borderLight = FindProperty("_BorderLight", props);
|
||||
borderLightUsesHoverColor = FindProperty("_BorderLightUsesHoverColor", props);
|
||||
borderLightOpaque = FindProperty("_BorderLightOpaque", props);
|
||||
borderWidth = FindProperty("_BorderWidth", props);
|
||||
borderMinValue = FindProperty("_BorderMinValue", props);
|
||||
edgeSmoothingValue = FindProperty("_EdgeSmoothingValue", props);
|
||||
innerGlow = FindProperty("_InnerGlow", props);
|
||||
innerGlowColor = FindProperty("_InnerGlowColor", props);
|
||||
environmentColoring = FindProperty("_EnvironmentColoring", props);
|
||||
environmentColorThreshold = FindProperty("_EnvironmentColorThreshold", props);
|
||||
environmentColorIntensity = FindProperty("_EnvironmentColorIntensity", props);
|
||||
environmentColorX = FindProperty("_EnvironmentColorX", props);
|
||||
environmentColorY = FindProperty("_EnvironmentColorY", props);
|
||||
environmentColorZ = FindProperty("_EnvironmentColorZ", props);
|
||||
}
|
||||
|
||||
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
|
||||
{
|
||||
Material material = (Material)materialEditor.target;
|
||||
|
||||
FindProperties(props);
|
||||
Initilize(material);
|
||||
|
||||
RenderingModeOptions(materialEditor);
|
||||
MainMapOptions(materialEditor, material);
|
||||
RenderingOptions(materialEditor, material);
|
||||
FluentOptions(materialEditor, material);
|
||||
AdvancedOptions(materialEditor, material);
|
||||
}
|
||||
|
||||
public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader)
|
||||
{
|
||||
// Cache old shader properties with potentially different names than the new shader.
|
||||
float? smoothness = GetFloatProperty(material, "_Glossiness");
|
||||
float? diffuse = GetFloatProperty(material, "_UseDiffuse");
|
||||
float? specularHighlights = GetFloatProperty(material, "_SpecularHighlights");
|
||||
float? normalMap = null;
|
||||
Texture normalMapTexture = material.GetTexture("_BumpMap");
|
||||
float? emission = null;
|
||||
Color? emissionColor = GetColorProperty(material, "_EmissionColor");
|
||||
float? reflections = null;
|
||||
float? rimLighting = null;
|
||||
Vector4? textureScaleOffset = null;
|
||||
float? cullMode = GetFloatProperty(material, "_Cull");
|
||||
|
||||
if (oldShader)
|
||||
{
|
||||
if (oldShader.name.Contains("Standard"))
|
||||
{
|
||||
normalMap = material.IsKeywordEnabled("_NORMALMAP") ? 1.0f : 0.0f;
|
||||
emission = material.IsKeywordEnabled("_EMISSION") ? 1.0f : 0.0f;
|
||||
reflections = GetFloatProperty(material, "_GlossyReflections");
|
||||
}
|
||||
else if (oldShader.name.Contains("Fast Configurable"))
|
||||
{
|
||||
normalMap = material.IsKeywordEnabled("_USEBUMPMAP_ON") ? 1.0f : 0.0f;
|
||||
emission = GetFloatProperty(material, "_UseEmissionColor");
|
||||
reflections = GetFloatProperty(material, "_UseReflections");
|
||||
rimLighting = GetFloatProperty(material, "_UseRimLighting");
|
||||
textureScaleOffset = GetVectorProperty(material, "_TextureScaleOffset");
|
||||
}
|
||||
}
|
||||
|
||||
base.AssignNewShaderToMaterial(material, oldShader, newShader);
|
||||
|
||||
// Apply old shader properties to the new shader.
|
||||
SetFloatProperty(material, null, "_Smoothness", smoothness);
|
||||
SetFloatProperty(material, "_DIRECTIONAL_LIGHT", "_DirectionalLight", diffuse);
|
||||
SetFloatProperty(material, "_SPECULAR_HIGHLIGHTS", "_SpecularHighlights", specularHighlights);
|
||||
SetFloatProperty(material, "_NORMAL_MAP", "_EnableNormalMap", normalMap);
|
||||
|
||||
if (normalMapTexture)
|
||||
{
|
||||
material.SetTexture("_NormalMap", normalMapTexture);
|
||||
}
|
||||
|
||||
SetFloatProperty(material, "_EMISSION", "_EnableEmission", emission);
|
||||
SetColorProperty(material, "_EmissiveColor", emissionColor);
|
||||
SetFloatProperty(material, "_REFLECTIONS", "_Reflections", reflections);
|
||||
SetFloatProperty(material, "_RIM_LIGHT", "_RimLight", rimLighting);
|
||||
SetVectorProperty(material, "_MainTex_ST", textureScaleOffset);
|
||||
SetFloatProperty(material, null, "_CullMode", cullMode);
|
||||
|
||||
// Setup the rendering mode based on the old shader.
|
||||
if (oldShader == null || !oldShader.name.Contains("Legacy Shaders/"))
|
||||
{
|
||||
SetupMaterialWithRenderingMode(material, (RenderingMode)material.GetFloat(Styles.renderingModeName), CustomRenderingMode.Opaque, -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
RenderingMode mode = RenderingMode.Opaque;
|
||||
|
||||
if (oldShader.name.Contains("/Transparent/Cutout/"))
|
||||
{
|
||||
mode = RenderingMode.TransparentCutout;
|
||||
}
|
||||
else if (oldShader.name.Contains("/Transparent/"))
|
||||
{
|
||||
mode = RenderingMode.Transparent;
|
||||
}
|
||||
|
||||
material.SetFloat(Styles.renderingModeName, (float)mode);
|
||||
|
||||
MaterialChanged(material);
|
||||
}
|
||||
}
|
||||
|
||||
protected void Initilize(Material material)
|
||||
{
|
||||
if (!initilized)
|
||||
{
|
||||
MaterialChanged(material);
|
||||
initilized = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected void MaterialChanged(Material material)
|
||||
{
|
||||
SetupMaterialWithAlbedo(material, albedoMap, albedoAlphaMode);
|
||||
SetupMaterialWithRenderingMode(material, (RenderingMode)renderingMode.floatValue, (CustomRenderingMode)customRenderingMode.floatValue, (int)renderQueueOverride.floatValue);
|
||||
}
|
||||
|
||||
protected void RenderingModeOptions(MaterialEditor materialEditor)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
EditorGUI.showMixedValue = renderingMode.hasMixedValue;
|
||||
RenderingMode mode = (RenderingMode)renderingMode.floatValue;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
mode = (RenderingMode)EditorGUILayout.Popup(renderingMode.displayName, (int)mode, Styles.renderingModeNames);
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
materialEditor.RegisterPropertyChangeUndo(renderingMode.displayName);
|
||||
renderingMode.floatValue = (float)mode;
|
||||
}
|
||||
|
||||
EditorGUI.showMixedValue = false;
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
UnityEngine.Object[] targets = renderingMode.targets;
|
||||
|
||||
foreach (UnityEngine.Object target in targets)
|
||||
{
|
||||
MaterialChanged((Material)target);
|
||||
}
|
||||
}
|
||||
|
||||
if ((RenderingMode)renderingMode.floatValue == RenderingMode.Custom)
|
||||
{
|
||||
EditorGUI.indentLevel += 2;
|
||||
customRenderingMode.floatValue = EditorGUILayout.Popup(customRenderingMode.displayName, (int)customRenderingMode.floatValue, Styles.customRenderingModeNames);
|
||||
materialEditor.ShaderProperty(sourceBlend, Styles.sourceBlend);
|
||||
materialEditor.ShaderProperty(destinationBlend, Styles.destinationBlend);
|
||||
materialEditor.ShaderProperty(blendOperation, Styles.blendOperation);
|
||||
materialEditor.ShaderProperty(depthTest, Styles.depthTest);
|
||||
depthWrite.floatValue = EditorGUILayout.Popup(depthWrite.displayName, (int)depthWrite.floatValue, Styles.depthWriteNames);
|
||||
materialEditor.ShaderProperty(colorWriteMask, Styles.colorWriteMask);
|
||||
EditorGUI.indentLevel -= 2;
|
||||
}
|
||||
|
||||
materialEditor.ShaderProperty(cullMode, Styles.cullMode);
|
||||
}
|
||||
|
||||
protected void MainMapOptions(MaterialEditor materialEditor, Material material)
|
||||
{
|
||||
GUILayout.Label(Styles.primaryMapsTitle, EditorStyles.boldLabel, new GUILayoutOption[0]);
|
||||
|
||||
materialEditor.TexturePropertySingleLine(Styles.albedo, albedoMap, albedoColor);
|
||||
|
||||
EditorGUI.indentLevel += 2;
|
||||
|
||||
albedoAlphaMode.floatValue = EditorGUILayout.Popup(albedoAlphaMode.displayName, (int)albedoAlphaMode.floatValue, Styles.albedoAlphaModeNames);
|
||||
|
||||
if ((RenderingMode)renderingMode.floatValue == RenderingMode.TransparentCutout)
|
||||
{
|
||||
materialEditor.ShaderProperty(alphaCutoff, Styles.alphaCutoff.text);
|
||||
}
|
||||
|
||||
if ((AlbedoAlphaMode)albedoAlphaMode.floatValue != AlbedoAlphaMode.Metallic)
|
||||
{
|
||||
materialEditor.ShaderProperty(metallic, Styles.metallic);
|
||||
}
|
||||
|
||||
if ((AlbedoAlphaMode)albedoAlphaMode.floatValue != AlbedoAlphaMode.Smoothness)
|
||||
{
|
||||
materialEditor.ShaderProperty(smoothness, Styles.smoothness);
|
||||
}
|
||||
|
||||
SetupMaterialWithAlbedo(material, albedoMap, albedoAlphaMode);
|
||||
|
||||
EditorGUI.indentLevel -= 2;
|
||||
|
||||
if (PropertyEnabled(directionalLight) ||
|
||||
PropertyEnabled(reflections) ||
|
||||
PropertyEnabled(rimLight) ||
|
||||
PropertyEnabled(environmentColoring))
|
||||
{
|
||||
materialEditor.ShaderProperty(enableNormalMap, Styles.enableNormalMap);
|
||||
|
||||
if (PropertyEnabled(enableNormalMap))
|
||||
{
|
||||
materialEditor.TexturePropertySingleLine(Styles.normalMap, normalMap);
|
||||
}
|
||||
}
|
||||
|
||||
materialEditor.ShaderProperty(enableEmission, Styles.enableEmission);
|
||||
|
||||
if (PropertyEnabled(enableEmission))
|
||||
{
|
||||
materialEditor.ShaderProperty(emissiveColor, Styles.emissiveColor, 2);
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
materialEditor.TextureScaleOffsetProperty(albedoMap);
|
||||
}
|
||||
|
||||
protected void RenderingOptions(MaterialEditor materialEditor, Material material)
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
GUILayout.Label(Styles.renderingOptionsTitle, EditorStyles.boldLabel, new GUILayoutOption[0]);
|
||||
|
||||
materialEditor.ShaderProperty(directionalLight, Styles.directionalLight);
|
||||
|
||||
if (PropertyEnabled(directionalLight))
|
||||
{
|
||||
materialEditor.ShaderProperty(specularHighlights, Styles.specularHighlights, 2);
|
||||
}
|
||||
|
||||
materialEditor.ShaderProperty(reflections, Styles.reflections);
|
||||
|
||||
if (PropertyEnabled(reflections))
|
||||
{
|
||||
materialEditor.ShaderProperty(refraction, Styles.refraction, 2);
|
||||
|
||||
if (PropertyEnabled(refraction))
|
||||
{
|
||||
materialEditor.ShaderProperty(refractiveIndex, Styles.refractiveIndex, 4);
|
||||
}
|
||||
}
|
||||
|
||||
materialEditor.ShaderProperty(rimLight, Styles.rimLight);
|
||||
|
||||
if (PropertyEnabled(rimLight))
|
||||
{
|
||||
materialEditor.ShaderProperty(rimColor, Styles.rimColor, 2);
|
||||
materialEditor.ShaderProperty(rimPower, Styles.rimPower, 2);
|
||||
}
|
||||
|
||||
materialEditor.ShaderProperty(clippingPlane, Styles.clippingPlane);
|
||||
|
||||
if (PropertyEnabled(clippingPlane))
|
||||
{
|
||||
materialEditor.ShaderProperty(clipPlane, Styles.clipPlane, 2);
|
||||
materialEditor.ShaderProperty(clippingPlaneBorder, Styles.clippingPlaneBorder, 2);
|
||||
|
||||
if (PropertyEnabled(clippingPlaneBorder))
|
||||
{
|
||||
materialEditor.ShaderProperty(clippingPlaneBorderWidth, Styles.clippingPlaneBorderWidth, 4);
|
||||
materialEditor.ShaderProperty(clippingPlaneBorderColor, Styles.clippingPlaneBorderColor, 4);
|
||||
}
|
||||
}
|
||||
|
||||
materialEditor.ShaderProperty(nearPlaneFade, Styles.nearPlaneFade);
|
||||
|
||||
if (PropertyEnabled(nearPlaneFade))
|
||||
{
|
||||
materialEditor.ShaderProperty(fadeBeginDistance, Styles.fadeBeginDistance, 2);
|
||||
materialEditor.ShaderProperty(fadeCompleteDistance, Styles.fadeCompleteDistance, 2);
|
||||
}
|
||||
}
|
||||
|
||||
protected void FluentOptions(MaterialEditor materialEditor, Material material)
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
GUILayout.Label(Styles.fluentOptionsTitle, EditorStyles.boldLabel, new GUILayoutOption[0]);
|
||||
RenderingMode mode = (RenderingMode)renderingMode.floatValue;
|
||||
CustomRenderingMode customMode = (CustomRenderingMode)customRenderingMode.floatValue;
|
||||
|
||||
materialEditor.ShaderProperty(hoverLight, Styles.hoverLight);
|
||||
|
||||
if (PropertyEnabled(hoverLight))
|
||||
{
|
||||
materialEditor.ShaderProperty(enableHoverColorOverride, Styles.enableHoverColorOverride, 2);
|
||||
|
||||
if (PropertyEnabled(enableHoverColorOverride))
|
||||
{
|
||||
materialEditor.ShaderProperty(hoverColorOverride, Styles.hoverColorOverride, 4);
|
||||
}
|
||||
|
||||
if (mode == RenderingMode.Transparent || (mode == RenderingMode.Custom && customMode == CustomRenderingMode.Transparent))
|
||||
{
|
||||
materialEditor.ShaderProperty(hoverLightOpaque, Styles.hoverLightOpaque, 2);
|
||||
}
|
||||
|
||||
if (PropertyEnabled(hoverLightOpaque))
|
||||
{
|
||||
materialEditor.ShaderProperty(enableHoverColorOpaqueOverride, Styles.enableHoverColorOpaqueOverride, 4);
|
||||
|
||||
if (PropertyEnabled(enableHoverColorOpaqueOverride))
|
||||
{
|
||||
materialEditor.ShaderProperty(hoverColorOverrideOpaque, Styles.hoverColorOpaqueOverride, 6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
materialEditor.ShaderProperty(roundCorners, Styles.roundCorners);
|
||||
|
||||
if (PropertyEnabled(roundCorners))
|
||||
{
|
||||
materialEditor.ShaderProperty(roundCornerRadius, Styles.roundCornerRadius, 2);
|
||||
materialEditor.ShaderProperty(roundCornerMargin, Styles.roundCornerMargin, 2);
|
||||
}
|
||||
|
||||
materialEditor.ShaderProperty(borderLight, Styles.borderLight);
|
||||
|
||||
if (PropertyEnabled(borderLight))
|
||||
{
|
||||
if (PropertyEnabled(hoverLight))
|
||||
{
|
||||
materialEditor.ShaderProperty(borderLightUsesHoverColor, Styles.borderLightUsesHoverColor, 2);
|
||||
}
|
||||
|
||||
if (mode == RenderingMode.TransparentCutout || mode == RenderingMode.Transparent ||
|
||||
(mode == RenderingMode.Custom && customMode == CustomRenderingMode.TransparentCutout) ||
|
||||
(mode == RenderingMode.Custom && customMode == CustomRenderingMode.Transparent))
|
||||
{
|
||||
materialEditor.ShaderProperty(borderLightOpaque, Styles.borderLightOpaque, 2);
|
||||
}
|
||||
|
||||
materialEditor.ShaderProperty(borderWidth, Styles.borderWidth, 2);
|
||||
|
||||
if (!PropertyEnabled(borderLightOpaque))
|
||||
{
|
||||
materialEditor.ShaderProperty(borderMinValue, Styles.borderMinValue, 2);
|
||||
}
|
||||
}
|
||||
|
||||
if (PropertyEnabled(roundCorners) || PropertyEnabled(borderLight))
|
||||
{
|
||||
materialEditor.ShaderProperty(edgeSmoothingValue, Styles.edgeSmoothingValue);
|
||||
}
|
||||
|
||||
materialEditor.ShaderProperty(innerGlow, Styles.innerGlow);
|
||||
|
||||
if (PropertyEnabled(innerGlow))
|
||||
{
|
||||
materialEditor.ShaderProperty(innerGlowColor, Styles.innerGlowColor, 2);
|
||||
}
|
||||
|
||||
materialEditor.ShaderProperty(environmentColoring, Styles.environmentColoring);
|
||||
|
||||
if (PropertyEnabled(environmentColoring))
|
||||
{
|
||||
materialEditor.ShaderProperty(environmentColorThreshold, Styles.environmentColorThreshold, 2);
|
||||
materialEditor.ShaderProperty(environmentColorIntensity, Styles.environmentColorIntensity, 2);
|
||||
materialEditor.ShaderProperty(environmentColorX, Styles.environmentColorX, 2);
|
||||
materialEditor.ShaderProperty(environmentColorY, Styles.environmentColorY, 2);
|
||||
materialEditor.ShaderProperty(environmentColorZ, Styles.environmentColorZ, 2);
|
||||
}
|
||||
}
|
||||
|
||||
protected void AdvancedOptions(MaterialEditor materialEditor, Material material)
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
GUILayout.Label(Styles.advancedOptionsTitle, EditorStyles.boldLabel, new GUILayoutOption[0]);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
materialEditor.ShaderProperty(renderQueueOverride, Styles.renderQueueOverride);
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
MaterialChanged(material);
|
||||
}
|
||||
|
||||
// Show the RenderQueueField but do not allow users to directly manipulate it. That is done via the renderQueueOverride.
|
||||
GUI.enabled = false;
|
||||
materialEditor.RenderQueueField();
|
||||
|
||||
// When round corner or border light features are used, enable instancing to disable batching. Static and dynamic
|
||||
// batching will normalize the object scale, which breakes border realted features.
|
||||
GUI.enabled = !PropertyEnabled(roundCorners) && !PropertyEnabled(borderLight);
|
||||
|
||||
if (!GUI.enabled && !material.enableInstancing)
|
||||
{
|
||||
material.enableInstancing = true;
|
||||
}
|
||||
|
||||
materialEditor.EnableInstancingField();
|
||||
}
|
||||
|
||||
protected static void SetupMaterialWithAlbedo(Material material, MaterialProperty albedoMap, MaterialProperty albedoAlphaMode)
|
||||
{
|
||||
if (albedoMap.textureValue)
|
||||
{
|
||||
material.DisableKeyword(Styles.disableAlbedoMapName);
|
||||
}
|
||||
else
|
||||
{
|
||||
material.EnableKeyword(Styles.disableAlbedoMapName);
|
||||
}
|
||||
|
||||
switch ((AlbedoAlphaMode)albedoAlphaMode.floatValue)
|
||||
{
|
||||
case AlbedoAlphaMode.Transparency:
|
||||
{
|
||||
material.DisableKeyword(Styles.albedoMapAlphaMetallicName);
|
||||
material.DisableKeyword(Styles.albedoMapAlphaSmoothnessName);
|
||||
}
|
||||
break;
|
||||
|
||||
case AlbedoAlphaMode.Metallic:
|
||||
{
|
||||
material.EnableKeyword(Styles.albedoMapAlphaMetallicName);
|
||||
material.DisableKeyword(Styles.albedoMapAlphaSmoothnessName);
|
||||
}
|
||||
break;
|
||||
|
||||
case AlbedoAlphaMode.Smoothness:
|
||||
{
|
||||
material.DisableKeyword(Styles.albedoMapAlphaMetallicName);
|
||||
material.EnableKeyword(Styles.albedoMapAlphaSmoothnessName);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected static void SetupMaterialWithRenderingMode(Material material, RenderingMode mode, CustomRenderingMode customMode, int renderQueueOverride)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case RenderingMode.Opaque:
|
||||
{
|
||||
material.SetOverrideTag(Styles.renderTypeName, Styles.renderingModeNames[(int)RenderingMode.Opaque]);
|
||||
material.SetInt(Styles.customRenderingModeName, (int)CustomRenderingMode.Opaque);
|
||||
material.SetInt(Styles.sourceBlendName, (int)UnityEngine.Rendering.BlendMode.One);
|
||||
material.SetInt(Styles.destinationBlendName, (int)UnityEngine.Rendering.BlendMode.Zero);
|
||||
material.SetInt(Styles.blendOperationName, (int)UnityEngine.Rendering.BlendOp.Add);
|
||||
material.SetInt(Styles.depthTestName, (int)UnityEngine.Rendering.CompareFunction.LessEqual);
|
||||
material.SetInt(Styles.depthWriteName, (int)DepthWrite.On);
|
||||
material.SetInt(Styles.colorWriteMaskName, (int)UnityEngine.Rendering.ColorWriteMask.All);
|
||||
material.DisableKeyword(Styles.alphaTestOnName);
|
||||
material.DisableKeyword(Styles.alphaBlendOnName);
|
||||
material.renderQueue = (renderQueueOverride >= 0) ? renderQueueOverride : (int)UnityEngine.Rendering.RenderQueue.Geometry;
|
||||
}
|
||||
break;
|
||||
|
||||
case RenderingMode.TransparentCutout:
|
||||
{
|
||||
material.SetOverrideTag(Styles.renderTypeName, Styles.renderingModeNames[(int)RenderingMode.TransparentCutout]);
|
||||
material.SetInt(Styles.customRenderingModeName, (int)CustomRenderingMode.TransparentCutout);
|
||||
material.SetInt(Styles.sourceBlendName, (int)UnityEngine.Rendering.BlendMode.One);
|
||||
material.SetInt(Styles.destinationBlendName, (int)UnityEngine.Rendering.BlendMode.Zero);
|
||||
material.SetInt(Styles.blendOperationName, (int)UnityEngine.Rendering.BlendOp.Add);
|
||||
material.SetInt(Styles.depthTestName, (int)UnityEngine.Rendering.CompareFunction.LessEqual);
|
||||
material.SetInt(Styles.depthWriteName, (int)DepthWrite.On);
|
||||
material.SetInt(Styles.colorWriteMaskName, (int)UnityEngine.Rendering.ColorWriteMask.All);
|
||||
material.EnableKeyword(Styles.alphaTestOnName);
|
||||
material.DisableKeyword(Styles.alphaBlendOnName);
|
||||
material.renderQueue = (renderQueueOverride >= 0) ? renderQueueOverride : (int)UnityEngine.Rendering.RenderQueue.AlphaTest;
|
||||
}
|
||||
break;
|
||||
|
||||
case RenderingMode.Transparent:
|
||||
{
|
||||
material.SetOverrideTag(Styles.renderTypeName, Styles.renderingModeNames[(int)RenderingMode.Transparent]);
|
||||
material.SetInt(Styles.customRenderingModeName, (int)CustomRenderingMode.Transparent);
|
||||
material.SetInt(Styles.sourceBlendName, (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
|
||||
material.SetInt(Styles.destinationBlendName, (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
|
||||
material.SetInt(Styles.blendOperationName, (int)UnityEngine.Rendering.BlendOp.Add);
|
||||
material.SetInt(Styles.depthTestName, (int)UnityEngine.Rendering.CompareFunction.LessEqual);
|
||||
material.SetInt(Styles.depthWriteName, (int)DepthWrite.Off);
|
||||
material.SetInt(Styles.colorWriteMaskName, (int)UnityEngine.Rendering.ColorWriteMask.All);
|
||||
material.DisableKeyword(Styles.alphaTestOnName);
|
||||
material.EnableKeyword(Styles.alphaBlendOnName);
|
||||
material.renderQueue = (renderQueueOverride >= 0) ? renderQueueOverride : (int)UnityEngine.Rendering.RenderQueue.Transparent;
|
||||
}
|
||||
break;
|
||||
|
||||
case RenderingMode.PremultipliedTransparent:
|
||||
{
|
||||
material.SetOverrideTag(Styles.renderTypeName, Styles.renderingModeNames[(int)RenderingMode.Transparent]);
|
||||
material.SetInt(Styles.customRenderingModeName, (int)CustomRenderingMode.Transparent);
|
||||
material.SetInt(Styles.sourceBlendName, (int)UnityEngine.Rendering.BlendMode.One);
|
||||
material.SetInt(Styles.destinationBlendName, (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
|
||||
material.SetInt(Styles.blendOperationName, (int)UnityEngine.Rendering.BlendOp.Add);
|
||||
material.SetInt(Styles.depthTestName, (int)UnityEngine.Rendering.CompareFunction.LessEqual);
|
||||
material.SetInt(Styles.depthWriteName, (int)DepthWrite.Off);
|
||||
material.SetInt(Styles.colorWriteMaskName, (int)UnityEngine.Rendering.ColorWriteMask.All);
|
||||
material.DisableKeyword(Styles.alphaTestOnName);
|
||||
material.EnableKeyword(Styles.alphaBlendOnName);
|
||||
material.renderQueue = (renderQueueOverride >= 0) ? renderQueueOverride : (int)UnityEngine.Rendering.RenderQueue.Transparent;
|
||||
}
|
||||
break;
|
||||
|
||||
case RenderingMode.Additive:
|
||||
{
|
||||
material.SetOverrideTag(Styles.renderTypeName, Styles.renderingModeNames[(int)RenderingMode.Transparent]);
|
||||
material.SetInt(Styles.customRenderingModeName, (int)CustomRenderingMode.Transparent);
|
||||
material.SetInt(Styles.sourceBlendName, (int)UnityEngine.Rendering.BlendMode.One);
|
||||
material.SetInt(Styles.destinationBlendName, (int)UnityEngine.Rendering.BlendMode.One);
|
||||
material.SetInt(Styles.blendOperationName, (int)UnityEngine.Rendering.BlendOp.Add);
|
||||
material.SetInt(Styles.depthTestName, (int)UnityEngine.Rendering.CompareFunction.LessEqual);
|
||||
material.SetInt(Styles.depthWriteName, (int)DepthWrite.Off);
|
||||
material.SetInt(Styles.colorWriteMaskName, (int)UnityEngine.Rendering.ColorWriteMask.All);
|
||||
material.DisableKeyword(Styles.alphaTestOnName);
|
||||
material.EnableKeyword(Styles.alphaBlendOnName);
|
||||
material.renderQueue = (renderQueueOverride >= 0) ? renderQueueOverride : (int)UnityEngine.Rendering.RenderQueue.Transparent;
|
||||
}
|
||||
break;
|
||||
|
||||
case RenderingMode.Custom:
|
||||
{
|
||||
material.SetOverrideTag(Styles.renderTypeName, Styles.customRenderingModeNames[(int)customMode]);
|
||||
// _SrcBlend, _DstBlend, _BlendOp, _ZTest, _ZWrite, _ColorWriteMask are controlled by UI.
|
||||
|
||||
switch (customMode)
|
||||
{
|
||||
case CustomRenderingMode.Opaque:
|
||||
{
|
||||
|
||||
material.DisableKeyword(Styles.alphaTestOnName);
|
||||
material.DisableKeyword(Styles.alphaBlendOnName);
|
||||
}
|
||||
break;
|
||||
|
||||
case CustomRenderingMode.TransparentCutout:
|
||||
{
|
||||
material.EnableKeyword(Styles.alphaTestOnName);
|
||||
material.DisableKeyword(Styles.alphaBlendOnName);
|
||||
}
|
||||
break;
|
||||
|
||||
case CustomRenderingMode.Transparent:
|
||||
{
|
||||
material.DisableKeyword(Styles.alphaTestOnName);
|
||||
material.EnableKeyword(Styles.alphaBlendOnName);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
material.renderQueue = (renderQueueOverride >= 0) ? renderQueueOverride : material.renderQueue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected static bool PropertyEnabled(MaterialProperty property)
|
||||
{
|
||||
return (property.floatValue != 0.0f);
|
||||
}
|
||||
|
||||
protected static float? GetFloatProperty(Material material, string propertyName)
|
||||
{
|
||||
if (material.HasProperty(propertyName))
|
||||
{
|
||||
return material.GetFloat(propertyName);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static Vector4? GetVectorProperty(Material material, string propertyName)
|
||||
{
|
||||
if (material.HasProperty(propertyName))
|
||||
{
|
||||
return material.GetVector(propertyName);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static Color? GetColorProperty(Material material, string propertyName)
|
||||
{
|
||||
if (material.HasProperty(propertyName))
|
||||
{
|
||||
return material.GetColor(propertyName);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static void SetFloatProperty(Material material, string keywordName, string propertyName, float? propertyValue)
|
||||
{
|
||||
if (propertyValue.HasValue)
|
||||
{
|
||||
if (keywordName != null)
|
||||
{
|
||||
if (propertyValue.Value != 0.0f)
|
||||
{
|
||||
material.EnableKeyword(keywordName);
|
||||
}
|
||||
else
|
||||
{
|
||||
material.DisableKeyword(keywordName);
|
||||
}
|
||||
}
|
||||
|
||||
material.SetFloat(propertyName, propertyValue.Value);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void SetVectorProperty(Material material, string propertyName, Vector4? propertyValue)
|
||||
{
|
||||
if (propertyValue.HasValue)
|
||||
{
|
||||
material.SetVector(propertyName, propertyValue.Value);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void SetColorProperty(Material material, string propertyName, Color? propertyValue)
|
||||
{
|
||||
if (propertyValue.HasValue)
|
||||
{
|
||||
material.SetColor(propertyName, propertyValue.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ff565a64f21091b45a83862a3bcb7880
|
||||
timeCreated: 1509574613
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,463 @@
|
|||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
//
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
public static class BoundsExtensions
|
||||
{
|
||||
// Corners
|
||||
public const int LBF = 0;
|
||||
public const int LBB = 1;
|
||||
public const int LTF = 2;
|
||||
public const int LTB = 3;
|
||||
public const int RBF = 4;
|
||||
public const int RBB = 5;
|
||||
public const int RTF = 6;
|
||||
public const int RTB = 7;
|
||||
|
||||
// X axis
|
||||
public const int LTF_RTF = 8;
|
||||
public const int LBF_RBF = 9;
|
||||
public const int RTB_LTB = 10;
|
||||
public const int RBB_LBB = 11;
|
||||
|
||||
// Y axis
|
||||
public const int LTF_LBF = 12;
|
||||
public const int RTB_RBB = 13;
|
||||
public const int LTB_LBB = 14;
|
||||
public const int RTF_RBF = 15;
|
||||
|
||||
// Z axis
|
||||
public const int RBF_RBB = 16;
|
||||
public const int RTF_RTB = 17;
|
||||
public const int LBF_LBB = 18;
|
||||
public const int LTF_LTB = 19;
|
||||
|
||||
// 2D corners
|
||||
public const int LT = 0;
|
||||
public const int LB = 1;
|
||||
public const int RT = 2;
|
||||
public const int RB = 3;
|
||||
|
||||
// 2D midpoints
|
||||
public const int LT_RT = 4;
|
||||
public const int RT_RB = 5;
|
||||
public const int RB_LB = 6;
|
||||
public const int LB_LT = 7;
|
||||
|
||||
// Face points
|
||||
public const int TOP = 0;
|
||||
public const int BOT = 1;
|
||||
public const int LFT = 2;
|
||||
public const int RHT = 3;
|
||||
public const int FWD = 4;
|
||||
public const int BCK = 5;
|
||||
|
||||
public enum Axis
|
||||
{
|
||||
X,
|
||||
Y,
|
||||
Z
|
||||
}
|
||||
|
||||
#region Public Static Functions
|
||||
/// <summary>
|
||||
/// Returns an instance of the 'Bounds' class which is invalid. An invalid 'Bounds' instance
|
||||
/// is one which has its size vector set to 'float.MaxValue' for all 3 components. The center
|
||||
/// of an invalid bounds instance is the zero vector.
|
||||
/// </summary>
|
||||
public static Bounds GetInvalidBoundsInstance()
|
||||
{
|
||||
return new Bounds(Vector3.zero, GetInvalidBoundsSize());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the specified bounds instance is valid. A valid 'Bounds' instance is
|
||||
/// one whose size vector does not have all 3 components set to 'float.MaxValue'.
|
||||
/// </summary>
|
||||
public static bool IsValid(this Bounds bounds)
|
||||
{
|
||||
return bounds.size != GetInvalidBoundsSize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the corner points of the bounds in world space
|
||||
/// </summary>
|
||||
/// <param name="collider"></param>
|
||||
/// <param name="positions"></param>
|
||||
/// <remarks>
|
||||
/// Use BoxColliderExtensions.{Left|Right}{Bottom|Top}{Front|Back} consts to index into the output
|
||||
/// corners array.
|
||||
/// </remarks>
|
||||
public static void GetCornerPositions(this Bounds bounds, Transform transform, ref Vector3[] positions)
|
||||
{
|
||||
// Calculate the local points to transform.
|
||||
Vector3 center = bounds.center;
|
||||
Vector3 extents = bounds.extents;
|
||||
float leftEdge = center.x - extents.x;
|
||||
float rightEdge = center.x + extents.x;
|
||||
float bottomEdge = center.y - extents.y;
|
||||
float topEdge = center.y + extents.y;
|
||||
float frontEdge = center.z - extents.z;
|
||||
float backEdge = center.z + extents.z;
|
||||
|
||||
// Allocate the array if needed.
|
||||
const int numPoints = 8;
|
||||
if (positions == null || positions.Length != numPoints)
|
||||
{
|
||||
positions = new Vector3[numPoints];
|
||||
}
|
||||
|
||||
// Transform all the local points to world space.
|
||||
positions[BoundsExtensions.LBF] = transform.TransformPoint(leftEdge, bottomEdge, frontEdge);
|
||||
positions[BoundsExtensions.LBB] = transform.TransformPoint(leftEdge, bottomEdge, backEdge);
|
||||
positions[BoundsExtensions.LTF] = transform.TransformPoint(leftEdge, topEdge, frontEdge);
|
||||
positions[BoundsExtensions.LTB] = transform.TransformPoint(leftEdge, topEdge, backEdge);
|
||||
positions[BoundsExtensions.RBF] = transform.TransformPoint(rightEdge, bottomEdge, frontEdge);
|
||||
positions[BoundsExtensions.RBB] = transform.TransformPoint(rightEdge, bottomEdge, backEdge);
|
||||
positions[BoundsExtensions.RTF] = transform.TransformPoint(rightEdge, topEdge, frontEdge);
|
||||
positions[BoundsExtensions.RTB] = transform.TransformPoint(rightEdge, topEdge, backEdge);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the corner points from Renderer's Bounds
|
||||
/// </summary>
|
||||
/// <param name="bounds"></param>
|
||||
/// <param name="positions"></param>
|
||||
public static void GetCornerPositionsFromRendererBounds(this Bounds bounds, ref Vector3[] positions)
|
||||
{
|
||||
Vector3 center = bounds.center;
|
||||
Vector3 extents = bounds.extents;
|
||||
float leftEdge = center.x - extents.x;
|
||||
float rightEdge = center.x + extents.x;
|
||||
float bottomEdge = center.y - extents.y;
|
||||
float topEdge = center.y + extents.y;
|
||||
float frontEdge = center.z - extents.z;
|
||||
float backEdge = center.z + extents.z;
|
||||
|
||||
const int numPoints = 8;
|
||||
if (positions == null || positions.Length != numPoints)
|
||||
{
|
||||
positions = new Vector3[numPoints];
|
||||
}
|
||||
|
||||
positions[BoundsExtensions.LBF] = new Vector3(leftEdge, bottomEdge, frontEdge);
|
||||
positions[BoundsExtensions.LBB] = new Vector3(leftEdge, bottomEdge, backEdge);
|
||||
positions[BoundsExtensions.LTF] = new Vector3(leftEdge, topEdge, frontEdge);
|
||||
positions[BoundsExtensions.LTB] = new Vector3(leftEdge, topEdge, backEdge);
|
||||
positions[BoundsExtensions.RBF] = new Vector3(rightEdge, bottomEdge, frontEdge);
|
||||
positions[BoundsExtensions.RBB] = new Vector3(rightEdge, bottomEdge, backEdge);
|
||||
positions[BoundsExtensions.RTF] = new Vector3(rightEdge, topEdge, frontEdge);
|
||||
positions[BoundsExtensions.RTB] = new Vector3(rightEdge, topEdge, backEdge);
|
||||
}
|
||||
|
||||
public static void GetFacePositions(this Bounds bounds, Transform transform, ref Vector3[] positions)
|
||||
{
|
||||
Vector3 center = bounds.center;
|
||||
Vector3 extents = bounds.extents;
|
||||
|
||||
const int numPoints = 6;
|
||||
if (positions == null || positions.Length != numPoints)
|
||||
{
|
||||
positions = new Vector3[numPoints];
|
||||
}
|
||||
|
||||
positions[BoundsExtensions.TOP] = transform.TransformPoint(center + Vector3.up * extents.y);
|
||||
positions[BoundsExtensions.BOT] = transform.TransformPoint(center + Vector3.down * extents.y);
|
||||
positions[BoundsExtensions.LFT] = transform.TransformPoint(center + Vector3.left * extents.x);
|
||||
positions[BoundsExtensions.RHT] = transform.TransformPoint(center + Vector3.right * extents.x);
|
||||
positions[BoundsExtensions.FWD] = transform.TransformPoint(center + Vector3.forward * extents.z);
|
||||
positions[BoundsExtensions.BCK] = transform.TransformPoint(center + Vector3.back * extents.z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the corner points and mid points from Renderer's Bounds
|
||||
/// </summary>
|
||||
/// <param name="bounds"></param>
|
||||
/// <param name="positions"></param>
|
||||
public static void GetCornerAndMidPointPositions(this Bounds bounds, Transform transform, ref Vector3[] positions)
|
||||
{
|
||||
// Calculate the local points to transform.
|
||||
Vector3 center = bounds.center;
|
||||
Vector3 extents = bounds.extents;
|
||||
float leftEdge = center.x - extents.x;
|
||||
float rightEdge = center.x + extents.x;
|
||||
float bottomEdge = center.y - extents.y;
|
||||
float topEdge = center.y + extents.y;
|
||||
float frontEdge = center.z - extents.z;
|
||||
float backEdge = center.z + extents.z;
|
||||
|
||||
// Allocate the array if needed.
|
||||
const int numPoints = BoundsExtensions.LTF_LTB + 1;
|
||||
if (positions == null || positions.Length != numPoints)
|
||||
{
|
||||
positions = new Vector3[numPoints];
|
||||
}
|
||||
|
||||
// Transform all the local points to world space.
|
||||
positions[BoundsExtensions.LBF] = transform.TransformPoint(leftEdge, bottomEdge, frontEdge);
|
||||
positions[BoundsExtensions.LBB] = transform.TransformPoint(leftEdge, bottomEdge, backEdge);
|
||||
positions[BoundsExtensions.LTF] = transform.TransformPoint(leftEdge, topEdge, frontEdge);
|
||||
positions[BoundsExtensions.LTB] = transform.TransformPoint(leftEdge, topEdge, backEdge);
|
||||
positions[BoundsExtensions.RBF] = transform.TransformPoint(rightEdge, bottomEdge, frontEdge);
|
||||
positions[BoundsExtensions.RBB] = transform.TransformPoint(rightEdge, bottomEdge, backEdge);
|
||||
positions[BoundsExtensions.RTF] = transform.TransformPoint(rightEdge, topEdge, frontEdge);
|
||||
positions[BoundsExtensions.RTB] = transform.TransformPoint(rightEdge, topEdge, backEdge);
|
||||
|
||||
positions[BoundsExtensions.LTF_RTF] = Vector3.Lerp(positions[BoundsExtensions.LTF], positions[BoundsExtensions.RTF], 0.5f);
|
||||
positions[BoundsExtensions.LBF_RBF] = Vector3.Lerp(positions[BoundsExtensions.LBF], positions[BoundsExtensions.RBF], 0.5f);
|
||||
positions[BoundsExtensions.RTB_LTB] = Vector3.Lerp(positions[BoundsExtensions.RTB], positions[BoundsExtensions.LTB], 0.5f);
|
||||
positions[BoundsExtensions.RBB_LBB] = Vector3.Lerp(positions[BoundsExtensions.RBB], positions[BoundsExtensions.LBB], 0.5f);
|
||||
|
||||
positions[BoundsExtensions.LTF_LBF] = Vector3.Lerp(positions[BoundsExtensions.LTF], positions[BoundsExtensions.LBF], 0.5f);
|
||||
positions[BoundsExtensions.RTB_RBB] = Vector3.Lerp(positions[BoundsExtensions.RTB], positions[BoundsExtensions.RBB], 0.5f);
|
||||
positions[BoundsExtensions.LTB_LBB] = Vector3.Lerp(positions[BoundsExtensions.LTB], positions[BoundsExtensions.LBB], 0.5f);
|
||||
positions[BoundsExtensions.RTF_RBF] = Vector3.Lerp(positions[BoundsExtensions.RTF], positions[BoundsExtensions.RBF], 0.5f);
|
||||
|
||||
positions[BoundsExtensions.RBF_RBB] = Vector3.Lerp(positions[BoundsExtensions.RBF], positions[BoundsExtensions.RBB], 0.5f);
|
||||
positions[BoundsExtensions.RTF_RTB] = Vector3.Lerp(positions[BoundsExtensions.RTF], positions[BoundsExtensions.RTB], 0.5f);
|
||||
positions[BoundsExtensions.LBF_LBB] = Vector3.Lerp(positions[BoundsExtensions.LBF], positions[BoundsExtensions.LBB], 0.5f);
|
||||
positions[BoundsExtensions.LTF_LTB] = Vector3.Lerp(positions[BoundsExtensions.LTF], positions[BoundsExtensions.LTB], 0.5f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the corner points and mid points from Renderer's Bounds, ignoring the z axis
|
||||
/// </summary>
|
||||
/// <param name="bounds"></param>
|
||||
/// <param name="positions"></param>
|
||||
public static void GetCornerAndMidPointPositions2D(this Bounds bounds, Transform transform, ref Vector3[] positions, Axis flattenAxis)
|
||||
{
|
||||
// Calculate the local points to transform.
|
||||
Vector3 center = bounds.center;
|
||||
Vector3 extents = bounds.extents;
|
||||
|
||||
float leftEdge = 0;
|
||||
float rightEdge = 0;
|
||||
float bottomEdge = 0;
|
||||
float topEdge = 0;
|
||||
|
||||
// Allocate the array if needed.
|
||||
const int numPoints = BoundsExtensions.LB_LT + 1;
|
||||
if (positions == null || positions.Length != numPoints)
|
||||
{
|
||||
positions = new Vector3[numPoints];
|
||||
}
|
||||
|
||||
switch (flattenAxis)
|
||||
{
|
||||
case Axis.X:
|
||||
default:
|
||||
leftEdge = center.z - extents.z;
|
||||
rightEdge = center.z + extents.z;
|
||||
bottomEdge = center.y - extents.y;
|
||||
topEdge = center.y + extents.y;
|
||||
// Transform all the local points to world space.
|
||||
positions[BoundsExtensions.LT] = transform.TransformPoint(0, topEdge, leftEdge);
|
||||
positions[BoundsExtensions.LB] = transform.TransformPoint(0, bottomEdge, leftEdge);
|
||||
positions[BoundsExtensions.RT] = transform.TransformPoint(0, topEdge, rightEdge);
|
||||
positions[BoundsExtensions.RB] = transform.TransformPoint(0, bottomEdge, rightEdge);
|
||||
break;
|
||||
|
||||
case Axis.Y:
|
||||
leftEdge = center.z - extents.z;
|
||||
rightEdge = center.z + extents.z;
|
||||
bottomEdge = center.x - extents.x;
|
||||
topEdge = center.x + extents.x;
|
||||
// Transform all the local points to world space.
|
||||
positions[BoundsExtensions.LT] = transform.TransformPoint(topEdge, 0, leftEdge);
|
||||
positions[BoundsExtensions.LB] = transform.TransformPoint(bottomEdge, 0, leftEdge);
|
||||
positions[BoundsExtensions.RT] = transform.TransformPoint(topEdge, 0, rightEdge);
|
||||
positions[BoundsExtensions.RB] = transform.TransformPoint(bottomEdge, 0, rightEdge);
|
||||
break;
|
||||
|
||||
case Axis.Z:
|
||||
leftEdge = center.x - extents.x;
|
||||
rightEdge = center.x + extents.x;
|
||||
bottomEdge = center.y - extents.y;
|
||||
topEdge = center.y + extents.y;
|
||||
// Transform all the local points to world space.
|
||||
positions[BoundsExtensions.LT] = transform.TransformPoint(leftEdge, topEdge, 0);
|
||||
positions[BoundsExtensions.LB] = transform.TransformPoint(leftEdge, bottomEdge, 0);
|
||||
positions[BoundsExtensions.RT] = transform.TransformPoint(rightEdge, topEdge, 0);
|
||||
positions[BoundsExtensions.RB] = transform.TransformPoint(rightEdge, bottomEdge, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
positions[BoundsExtensions.LT_RT] = Vector3.Lerp(positions[BoundsExtensions.LT], positions[BoundsExtensions.RT], 0.5f);
|
||||
positions[BoundsExtensions.RT_RB] = Vector3.Lerp(positions[BoundsExtensions.RT], positions[BoundsExtensions.RB], 0.5f);
|
||||
positions[BoundsExtensions.RB_LB] = Vector3.Lerp(positions[BoundsExtensions.RB], positions[BoundsExtensions.LB], 0.5f);
|
||||
positions[BoundsExtensions.LB_LT] = Vector3.Lerp(positions[BoundsExtensions.LB], positions[BoundsExtensions.LT], 0.5f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transforms 'bounds' using the specified transform matrix.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Transforming a 'Bounds' instance means that the function will construct a new 'Bounds'
|
||||
/// instance which has its center translated using the translation information stored in
|
||||
/// the specified matrix and its size adjusted to account for rotation and scale. The size
|
||||
/// of the new 'Bounds' instance will be calculated in such a way that it will contain the
|
||||
/// old 'Bounds'.
|
||||
/// </remarks>
|
||||
/// <param name="bounds">
|
||||
/// The 'Bounds' instance which must be transformed.
|
||||
/// </param>
|
||||
/// <param name="transformMatrix">
|
||||
/// The specified 'Bounds' instance will be transformed using this transform matrix. The function
|
||||
/// assumes that the matrix doesn't contain any projection or skew transformation.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// The transformed 'Bounds' instance.
|
||||
/// </returns>
|
||||
public static Bounds Transform(this Bounds bounds, Matrix4x4 transformMatrix)
|
||||
{
|
||||
// We will need access to the right, up and look vector which are encoded inside the transform matrix
|
||||
Vector3 rightAxis = transformMatrix.GetColumn(0);
|
||||
Vector3 upAxis = transformMatrix.GetColumn(1);
|
||||
Vector3 lookAxis = transformMatrix.GetColumn(2);
|
||||
|
||||
// We will 'imagine' that we want to rotate the bounds' extents vector using the rotation information
|
||||
// stored inside the specified transform matrix. We will need these when calculating the new size if
|
||||
// the transformed bounds.
|
||||
Vector3 rotatedExtentsRight = rightAxis * bounds.extents.x;
|
||||
Vector3 rotatedExtentsUp = upAxis * bounds.extents.y;
|
||||
Vector3 rotatedExtentsLook = lookAxis * bounds.extents.z;
|
||||
|
||||
// Calculate the new bounds size along each axis. The size on each axis is calculated by summing up the
|
||||
// corresponding vector component values of the rotated extents vectors. We multiply by 2 because we want
|
||||
// to get a size and curently we are working with extents which represent half the size.
|
||||
float newSizeX = (Mathf.Abs(rotatedExtentsRight.x) + Mathf.Abs(rotatedExtentsUp.x) + Mathf.Abs(rotatedExtentsLook.x)) * 2.0f;
|
||||
float newSizeY = (Mathf.Abs(rotatedExtentsRight.y) + Mathf.Abs(rotatedExtentsUp.y) + Mathf.Abs(rotatedExtentsLook.y)) * 2.0f;
|
||||
float newSizeZ = (Mathf.Abs(rotatedExtentsRight.z) + Mathf.Abs(rotatedExtentsUp.z) + Mathf.Abs(rotatedExtentsLook.z)) * 2.0f;
|
||||
|
||||
// Construct the transformed 'Bounds' instance
|
||||
var transformedBounds = new Bounds();
|
||||
transformedBounds.center = transformMatrix.MultiplyPoint(bounds.center);
|
||||
transformedBounds.size = new Vector3(newSizeX, newSizeY, newSizeZ);
|
||||
|
||||
// Return the instance to the caller
|
||||
return transformedBounds;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the screen space corner points of the specified 'Bounds' instance.
|
||||
/// </summary>
|
||||
/// <param name="camera">
|
||||
/// The camera used for rendering to the screen. This is needed to perform the
|
||||
/// transformation to screen space.
|
||||
/// </param>
|
||||
public static Vector2[] GetScreenSpaceCornerPoints(this Bounds bounds, Camera camera)
|
||||
{
|
||||
Vector3 aabbCenter = bounds.center;
|
||||
Vector3 aabbExtents = bounds.extents;
|
||||
|
||||
// Return the screen space point array
|
||||
return new Vector2[]
|
||||
{
|
||||
camera.WorldToScreenPoint(new Vector3(aabbCenter.x - aabbExtents.x, aabbCenter.y - aabbExtents.y, aabbCenter.z - aabbExtents.z)),
|
||||
camera.WorldToScreenPoint(new Vector3(aabbCenter.x + aabbExtents.x, aabbCenter.y - aabbExtents.y, aabbCenter.z - aabbExtents.z)),
|
||||
camera.WorldToScreenPoint(new Vector3(aabbCenter.x + aabbExtents.x, aabbCenter.y + aabbExtents.y, aabbCenter.z - aabbExtents.z)),
|
||||
camera.WorldToScreenPoint(new Vector3(aabbCenter.x - aabbExtents.x, aabbCenter.y + aabbExtents.y, aabbCenter.z - aabbExtents.z)),
|
||||
|
||||
camera.WorldToScreenPoint(new Vector3(aabbCenter.x - aabbExtents.x, aabbCenter.y - aabbExtents.y, aabbCenter.z + aabbExtents.z)),
|
||||
camera.WorldToScreenPoint(new Vector3(aabbCenter.x + aabbExtents.x, aabbCenter.y - aabbExtents.y, aabbCenter.z + aabbExtents.z)),
|
||||
camera.WorldToScreenPoint(new Vector3(aabbCenter.x + aabbExtents.x, aabbCenter.y + aabbExtents.y, aabbCenter.z + aabbExtents.z)),
|
||||
camera.WorldToScreenPoint(new Vector3(aabbCenter.x - aabbExtents.x, aabbCenter.y + aabbExtents.y, aabbCenter.z + aabbExtents.z))
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the rectangle which encloses the specifies 'Bounds' instance in screen space.
|
||||
/// </summary>
|
||||
public static Rect GetScreenRectangle(this Bounds bounds, Camera camera)
|
||||
{
|
||||
// Retrieve the bounds' corner points in screen space
|
||||
Vector2[] screenSpaceCornerPoints = bounds.GetScreenSpaceCornerPoints(camera);
|
||||
|
||||
// Identify the minimum and maximum points in the array
|
||||
Vector3 minScreenPoint = screenSpaceCornerPoints[0], maxScreenPoint = screenSpaceCornerPoints[0];
|
||||
for (int screenPointIndex = 1; screenPointIndex < screenSpaceCornerPoints.Length; ++screenPointIndex)
|
||||
{
|
||||
minScreenPoint = Vector3.Min(minScreenPoint, screenSpaceCornerPoints[screenPointIndex]);
|
||||
maxScreenPoint = Vector3.Max(maxScreenPoint, screenSpaceCornerPoints[screenPointIndex]);
|
||||
}
|
||||
|
||||
// Return the screen space rectangle
|
||||
return new Rect(minScreenPoint.x, minScreenPoint.y, maxScreenPoint.x - minScreenPoint.x, maxScreenPoint.y - minScreenPoint.y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the volume of the bounds.
|
||||
/// </summary>
|
||||
/// <param name="bounds"></param>
|
||||
/// <returns></returns>
|
||||
public static float Volume(this Bounds bounds)
|
||||
{
|
||||
return bounds.size.x * bounds.size.y * bounds.size.z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns bounds that contain both this bounds and the bounds passed in.
|
||||
/// </summary>
|
||||
/// <param name="originalBounds"></param>
|
||||
/// <param name="otherBounds"></param>
|
||||
/// <returns></returns>
|
||||
public static Bounds ExpandToContain(this Bounds originalBounds, Bounds otherBounds)
|
||||
{
|
||||
Bounds tmpBounds = originalBounds;
|
||||
|
||||
tmpBounds.Encapsulate(otherBounds);
|
||||
|
||||
return tmpBounds;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks to see if bounds contains the other bounds completely.
|
||||
/// </summary>
|
||||
/// <param name="bounds"></param>
|
||||
/// <param name="otherBounds"></param>
|
||||
/// <returns></returns>
|
||||
public static bool ContainsBounds(this Bounds bounds, Bounds otherBounds)
|
||||
{
|
||||
return bounds.Contains(otherBounds.min) && bounds.Contains(otherBounds.max);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks to see whether point is closer to bounds or otherBounds
|
||||
/// </summary>
|
||||
/// <param name="bounds"></param>
|
||||
/// <param name="point"></param>
|
||||
/// <param name="otherBounds"></param>
|
||||
/// <returns></returns>
|
||||
public static bool CloserToPoint(this Bounds bounds, Vector3 point, Bounds otherBounds)
|
||||
{
|
||||
Vector3 distToClosestPoint1 = bounds.ClosestPoint(point) - point;
|
||||
Vector3 distToClosestPoint2 = otherBounds.ClosestPoint(point) - point;
|
||||
|
||||
if (distToClosestPoint1.magnitude == distToClosestPoint2.magnitude)
|
||||
{
|
||||
Vector3 toCenter1 = point - bounds.center;
|
||||
Vector3 toCenter2 = point - otherBounds.center;
|
||||
return (toCenter1.magnitude <= toCenter2.magnitude);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return (distToClosestPoint1.magnitude <= distToClosestPoint2.magnitude);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Static Functions
|
||||
/// <summary>
|
||||
/// Returns the vector which is used to represent and invalid bounds size.
|
||||
/// </summary>
|
||||
private static Vector3 GetInvalidBoundsSize()
|
||||
{
|
||||
return new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
|
||||
}
|
||||
#endregion
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5efea67edcf80b0449581ae0f6830192
|
||||
timeCreated: 1488770793
|
||||
guid: c679c9491158b924db809ed039ef813e
|
||||
timeCreated: 1513100550
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
|
@ -1,4 +1,6 @@
|
|||
using System;
|
||||
// Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace HoloToolkit.Unity
|
|
@ -10,7 +10,6 @@ namespace HoloToolkit.Unity
|
|||
public static class EventSystemExtensions
|
||||
{
|
||||
private static readonly List<RaycastResult> RaycastResults = new List<RaycastResult>();
|
||||
private static readonly List<ComparableRaycastResult> ComparableRaycastResults = new List<ComparableRaycastResult>();
|
||||
private static readonly RaycastResultComparer RaycastResultComparer = new RaycastResultComparer();
|
||||
|
||||
/// <summary>
|
||||
|
@ -20,22 +19,30 @@ namespace HoloToolkit.Unity
|
|||
/// <returns>RaycastResult if hit, or an empty RaycastResult if nothing was hit</returns>
|
||||
public static RaycastResult Raycast(this EventSystem eventSystem, PointerEventData pointerEventData, LayerMask[] layerMasks)
|
||||
{
|
||||
RaycastResults.Clear();
|
||||
eventSystem.RaycastAll(pointerEventData, RaycastResults);
|
||||
return PrioritizeRaycastResult(layerMasks);
|
||||
}
|
||||
|
||||
private static RaycastResult PrioritizeRaycastResult(LayerMask[] layerMaskPrio)
|
||||
private static RaycastResult PrioritizeRaycastResult(LayerMask[] priority)
|
||||
{
|
||||
ComparableRaycastResults.Clear();
|
||||
foreach (var raycastResult in RaycastResults)
|
||||
ComparableRaycastResult maxResult = default(ComparableRaycastResult);
|
||||
|
||||
for (var i = 0; i < RaycastResults.Count; i++)
|
||||
{
|
||||
if (raycastResult.gameObject == null) { continue; }
|
||||
var layerMaskIndex = raycastResult.gameObject.layer.FindLayerListIndex(layerMaskPrio);
|
||||
if (RaycastResults[i].gameObject == null) { continue; }
|
||||
|
||||
var layerMaskIndex = RaycastResults[i].gameObject.layer.FindLayerListIndex(priority);
|
||||
if (layerMaskIndex == -1) { continue; }
|
||||
ComparableRaycastResults.Add(new ComparableRaycastResult(raycastResult, layerMaskIndex));
|
||||
|
||||
var result = new ComparableRaycastResult(RaycastResults[i], layerMaskIndex);
|
||||
|
||||
if (maxResult.RaycastResult.module == null || RaycastResultComparer.Compare(maxResult, result) < 0)
|
||||
{
|
||||
maxResult = result;
|
||||
}
|
||||
}
|
||||
return ComparableRaycastResults.MaxOrDefault(RaycastResultComparer).RaycastResult;
|
||||
|
||||
return maxResult.RaycastResult;
|
||||
}
|
||||
}
|
||||
}
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче