备份CatanBuilding瘦身独立工程
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace CW.Common
|
||||
{
|
||||
/// <summary>This component allows you to freely rotate the current GameObject using local rotations.</summary>
|
||||
[HelpURL(CwShared.HelpUrlPrefix + "CwCameraLook")]
|
||||
[AddComponentMenu(CwShared.ComponentMenuPrefix + "Camera Look")]
|
||||
public class CwCameraLook : MonoBehaviour
|
||||
{
|
||||
/// <summary>Is this component currently listening for inputs?</summary>
|
||||
public bool Listen { set { listen = value; } get { return listen; } } [SerializeField] private bool listen = true;
|
||||
|
||||
/// <summary>How quickly the rotation transitions from the current to the target value (-1 = instant).</summary>
|
||||
public float Damping { set { damping = value; } get { return damping; } } [SerializeField] private float damping = 10.0f;
|
||||
|
||||
/// <summary>How quickly the mouse/finger movements rotate the camera.</summary>
|
||||
public float Sensitivity { set { sensitivity = value; } get { return sensitivity; } } [SerializeField] private float sensitivity = 1.0f;
|
||||
|
||||
/// <summary>The keys/fingers required to pitch down/up.</summary>
|
||||
public CwInputManager.Axis PitchControls { set { pitchControls = value; } get { return pitchControls; } } [SerializeField] private CwInputManager.Axis pitchControls = new CwInputManager.Axis(1, true, CwInputManager.AxisGesture.VerticalDrag, -10.0f, KeyCode.None, KeyCode.None, KeyCode.None, KeyCode.None, 45.0f);
|
||||
|
||||
/// <summary>The keys/fingers required to yaw left/right.</summary>
|
||||
public CwInputManager.Axis YawControls { set { yawControls = value; } get { return yawControls; } } [SerializeField] private CwInputManager.Axis yawControls = new CwInputManager.Axis(1, true, CwInputManager.AxisGesture.HorizontalDrag, 10.0f, KeyCode.None, KeyCode.None, KeyCode.None, KeyCode.None, 45.0f);
|
||||
|
||||
/// <summary>The keys/fingers required to roll left/right.</summary>
|
||||
public CwInputManager.Axis RollControls { set { rollControls = value; } get { return rollControls; } } [SerializeField] private CwInputManager.Axis rollControls = new CwInputManager.Axis(2, true, CwInputManager.AxisGesture.Twist, 1.0f, KeyCode.E, KeyCode.Q, KeyCode.None, KeyCode.None, 45.0f);
|
||||
|
||||
[System.NonSerialized]
|
||||
private Quaternion remainingDelta = Quaternion.identity;
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
CwInputManager.EnsureThisComponentExists();
|
||||
}
|
||||
|
||||
protected virtual void OnDisable()
|
||||
{
|
||||
//oldMousePositionSet = false;
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
if (listen == true)
|
||||
{
|
||||
AddToDelta();
|
||||
}
|
||||
|
||||
DampenDelta();
|
||||
}
|
||||
|
||||
protected virtual void OnApplicationFocus(bool focus)
|
||||
{
|
||||
//oldMousePositionSet = false;
|
||||
}
|
||||
|
||||
private void AddToDelta()
|
||||
{
|
||||
// Get delta from binds
|
||||
var delta = default(Vector3);
|
||||
|
||||
delta.x = pitchControls.GetValue(Time.deltaTime);
|
||||
delta.y = yawControls.GetValue(Time.deltaTime);
|
||||
delta.z = rollControls.GetValue(Time.deltaTime);
|
||||
|
||||
delta *= sensitivity;
|
||||
|
||||
// Store old rotation
|
||||
var oldRotation = transform.localRotation;
|
||||
|
||||
// Rotate
|
||||
transform.Rotate(delta.x, delta.y, 0.0f, Space.Self);
|
||||
|
||||
transform.Rotate(0.0f, 0.0f, delta.z, Space.Self);
|
||||
|
||||
// Add to remaining
|
||||
remainingDelta *= Quaternion.Inverse(oldRotation) * transform.localRotation;
|
||||
|
||||
// Revert rotation
|
||||
transform.localRotation = oldRotation;
|
||||
}
|
||||
|
||||
private void DampenDelta()
|
||||
{
|
||||
// Dampen remaining delta
|
||||
var factor = CwHelper.DampenFactor(damping, Time.deltaTime);
|
||||
var newDelta = Quaternion.Slerp(remainingDelta, Quaternion.identity, factor);
|
||||
|
||||
// Rotate by difference
|
||||
transform.localRotation = transform.localRotation * Quaternion.Inverse(newDelta) * remainingDelta;
|
||||
|
||||
// Update remaining
|
||||
remainingDelta = newDelta;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
namespace CW.Common
|
||||
{
|
||||
using UnityEditor;
|
||||
using TARGET = CwCameraLook;
|
||||
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(TARGET))]
|
||||
public class CwCameraLook_Editor : CwEditor
|
||||
{
|
||||
protected override void OnInspector()
|
||||
{
|
||||
TARGET tgt; TARGET[] tgts; GetTargets(out tgt, out tgts);
|
||||
|
||||
Draw("listen", "Is this component currently listening for inputs?");
|
||||
Draw("damping", "How quickly the rotation transitions from the current to the target value (-1 = instant).");
|
||||
|
||||
Separator();
|
||||
|
||||
Draw("pitchControls", "The keys/fingers required to pitch down/up.");
|
||||
Draw("yawControls", "The keys/fingers required to yaw left/right.");
|
||||
Draw("rollControls", "The keys/fingers required to roll left/right.");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f6d5316b170fe34e886c05572b3006e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,111 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace CW.Common
|
||||
{
|
||||
/// <summary>This component allows you to freely move the current GameObject based on mouse/finger drags.</summary>
|
||||
[HelpURL(CwShared.HelpUrlPrefix + "CwCameraMove")]
|
||||
[AddComponentMenu(CwShared.ComponentMenuPrefix + "Camera Move")]
|
||||
public class CwCameraMove : MonoBehaviour
|
||||
{
|
||||
/// <summary>Is this component currently listening for inputs?</summary>
|
||||
public bool Listen { set { listen = value; } get { return listen; } } [SerializeField] private bool listen = true;
|
||||
|
||||
/// <summary>How quickly the position transitions from the current to the target value (-1 = instant).</summary>
|
||||
public float Damping { set { damping = value; } get { return damping; } } [SerializeField] private float damping = 10.0f;
|
||||
|
||||
/// <summary>The movement speed will be multiplied by this.</summary>
|
||||
public float Sensitivity { set { sensitivity = value; } get { return sensitivity; } } [SerializeField] private float sensitivity = 1.0f;
|
||||
|
||||
/// <summary>The keys/fingers required to move left/right.</summary>
|
||||
public CwInputManager.Axis HorizontalControls { set { horizontalControls = value; } get { return horizontalControls; } } [SerializeField] private CwInputManager.Axis horizontalControls = new CwInputManager.Axis(2, false, CwInputManager.AxisGesture.HorizontalDrag, 1.0f, KeyCode.A, KeyCode.D, KeyCode.LeftArrow, KeyCode.RightArrow, 100.0f);
|
||||
|
||||
/// <summary>The keys/fingers required to move backward/forward.</summary>
|
||||
public CwInputManager.Axis DepthControls { set { depthControls = value; } get { return depthControls; } } [SerializeField] private CwInputManager.Axis depthControls = new CwInputManager.Axis(2, false, CwInputManager.AxisGesture.HorizontalDrag, 1.0f, KeyCode.S, KeyCode.W, KeyCode.DownArrow, KeyCode.UpArrow, 100.0f);
|
||||
|
||||
/// <summary>The keys/fingers required to move down/up.</summary>
|
||||
public CwInputManager.Axis VerticalControls { set { verticalControls = value; } get { return verticalControls; } } [SerializeField] private CwInputManager.Axis verticalControls = new CwInputManager.Axis(3, false, CwInputManager.AxisGesture.HorizontalDrag, 1.0f, KeyCode.F, KeyCode.R, KeyCode.None, KeyCode.None, 100.0f);
|
||||
|
||||
[System.NonSerialized]
|
||||
private Vector3 remainingDelta;
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
CwInputManager.EnsureThisComponentExists();
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
if (listen == true)
|
||||
{
|
||||
AddToDelta();
|
||||
}
|
||||
|
||||
DampenDelta();
|
||||
}
|
||||
|
||||
private void AddToDelta()
|
||||
{
|
||||
// Get delta from binds
|
||||
var delta = default(Vector3);
|
||||
|
||||
delta.x = horizontalControls.GetValue(Time.deltaTime);
|
||||
delta.y = verticalControls .GetValue(Time.deltaTime);
|
||||
delta.z = depthControls .GetValue(Time.deltaTime);
|
||||
|
||||
// Store old position
|
||||
var oldPosition = transform.position;
|
||||
|
||||
// Translate
|
||||
transform.Translate(delta * sensitivity * Time.deltaTime, Space.Self);
|
||||
|
||||
// Add to remaining
|
||||
var acceleration = transform.position - oldPosition;
|
||||
|
||||
remainingDelta += acceleration;
|
||||
|
||||
// Revert position
|
||||
transform.position = oldPosition;
|
||||
}
|
||||
|
||||
private void DampenDelta()
|
||||
{
|
||||
// Dampen remaining delta
|
||||
var factor = CwHelper.DampenFactor(damping, Time.deltaTime);
|
||||
var newDelta = Vector3.Lerp(remainingDelta, Vector3.zero, factor);
|
||||
|
||||
// Translate by difference
|
||||
transform.position += remainingDelta - newDelta;
|
||||
|
||||
// Update remaining
|
||||
remainingDelta = newDelta;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
namespace CW.Common
|
||||
{
|
||||
using UnityEditor;
|
||||
using TARGET = CwCameraMove;
|
||||
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(TARGET))]
|
||||
public class CwCameraMove_Editor : CwEditor
|
||||
{
|
||||
protected override void OnInspector()
|
||||
{
|
||||
TARGET tgt; TARGET[] tgts; GetTargets(out tgt, out tgts);
|
||||
|
||||
Draw("listen", "Is this component currently listening for inputs?");
|
||||
Draw("damping", "How quickly the rotation transitions from the current to the target value (-1 = instant).");
|
||||
Draw("sensitivity", "The movement speed will be multiplied by this.");
|
||||
|
||||
Separator();
|
||||
|
||||
Draw("horizontalControls", "The keys/fingers required to move right/left.");
|
||||
Draw("depthControls", "The keys/fingers required to move backward/forward.");
|
||||
Draw("verticalControls", "The keys/fingers required to move down/up.");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4cabc7c514a17ca41a6c62cc43dcb94d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,93 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace CW.Common
|
||||
{
|
||||
/// <summary>This component allows you to rotate the current GameObject using local Euler rotations, allowing you to create a typical FPS camera system, or orbital camera system.</summary>
|
||||
[HelpURL(CwShared.HelpUrlPrefix + "CwCameraPivot")]
|
||||
[AddComponentMenu(CwShared.ComponentMenuPrefix + "Camera Pivot")]
|
||||
public class CwCameraPivot : MonoBehaviour
|
||||
{
|
||||
/// <summary>Is this component currently listening for inputs?</summary>
|
||||
public bool Listen { set { listen = value; } get { return listen; } } [SerializeField] private bool listen = true;
|
||||
|
||||
/// <summary>How quickly the position transitions from the current to the target value (-1 = instant).</summary>
|
||||
public float Damping { set { damping = value; } get { return damping; } } [SerializeField] private float damping = 10.0f;
|
||||
|
||||
/// <summary>The keys/fingers required to pitch down/up.</summary>
|
||||
public CwInputManager.Axis PitchControls { set { pitchControls = value; } get { return pitchControls; } } [SerializeField] private CwInputManager.Axis pitchControls = new CwInputManager.Axis(1, true, CwInputManager.AxisGesture.VerticalDrag, -0.1f, KeyCode.None, KeyCode.None, KeyCode.None, KeyCode.None, 45.0f);
|
||||
|
||||
/// <summary>The keys/fingers required to yaw left/right.</summary>
|
||||
public CwInputManager.Axis YawControls { set { yawControls = value; } get { return yawControls; } } [SerializeField] private CwInputManager.Axis yawControls = new CwInputManager.Axis(1, true, CwInputManager.AxisGesture.HorizontalDrag, 0.1f, KeyCode.None, KeyCode.None, KeyCode.None, KeyCode.None, 45.0f);
|
||||
|
||||
[System.NonSerialized]
|
||||
private Vector3 remainingDelta;
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
CwInputManager.EnsureThisComponentExists();
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
if (listen == true)
|
||||
{
|
||||
AddToDelta();
|
||||
}
|
||||
|
||||
DampenDelta();
|
||||
}
|
||||
|
||||
private void AddToDelta()
|
||||
{
|
||||
remainingDelta.x += pitchControls.GetValue(Time.deltaTime);
|
||||
remainingDelta.y += yawControls .GetValue(Time.deltaTime);
|
||||
}
|
||||
|
||||
private void DampenDelta()
|
||||
{
|
||||
// Dampen remaining delta
|
||||
var factor = CwHelper.DampenFactor(damping, Time.deltaTime);
|
||||
var newDelta = Vector3.Lerp(remainingDelta, Vector3.zero, factor);
|
||||
|
||||
// Rotate by difference
|
||||
var euler = transform.localEulerAngles;
|
||||
|
||||
euler.x = -Mathf.DeltaAngle(euler.x, 0.0f);
|
||||
|
||||
euler += remainingDelta - newDelta;
|
||||
|
||||
euler.x = Mathf.Clamp(euler.x, -89.0f, 89.0f);
|
||||
|
||||
transform.localEulerAngles = euler;
|
||||
|
||||
// Update remaining
|
||||
remainingDelta = newDelta;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
namespace CW.Common
|
||||
{
|
||||
using UnityEditor;
|
||||
using TARGET = CwCameraPivot;
|
||||
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(TARGET))]
|
||||
public class CwCameraPivot_Editor : CwEditor
|
||||
{
|
||||
protected override void OnInspector()
|
||||
{
|
||||
TARGET tgt; TARGET[] tgts; GetTargets(out tgt, out tgts);
|
||||
|
||||
Draw("listen", "Is this component currently listening for inputs?");
|
||||
Draw("damping", "How quickly the rotation transitions from the current to the target value (-1 = instant).");
|
||||
|
||||
Separator();
|
||||
|
||||
Draw("pitchControls", "The keys/fingers required to pitch down/up.");
|
||||
Draw("yawControls", "The keys/fingers required to yaw left/right.");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4c5a919098a173e40a35fd1c493ae39e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,213 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace CW.Common
|
||||
{
|
||||
/// <summary>This component is used by all the demo scenes to perform common tasks. Including modifying the current scene to make it look consistent between different rendering pipelines.</summary>
|
||||
[ExecuteInEditMode]
|
||||
[AddComponentMenu("")]
|
||||
public class CwDemo : MonoBehaviour
|
||||
{
|
||||
/// <summary>If you enable this setting and your project is running with the new InputSystem then the <b>EventSystem's InputModule</b> component will be upgraded.</summary>
|
||||
public bool UpgradeInputModule { set { upgradeInputModule = value; } get { return upgradeInputModule; } } [SerializeField] private bool upgradeInputModule = true;
|
||||
|
||||
/// <summary>If you enable this setting and your project is running with HDRP then a <b>Volume</b> component will be added to the scene that adjusts the camera exposure to match the other pipelines.</summary>
|
||||
public bool ChangeExposureInHDRP { set { changeExposureInHDRP = value; } get { return changeExposureInHDRP; } } [SerializeField] private bool changeExposureInHDRP = true;
|
||||
|
||||
/// <summary>If you enable this setting and your project is running with HDRP then a <b>Volume</b> component will be added to the scene that adjusts the background to match the other pipelines.</summary>
|
||||
public bool ChangeVisualEnvironmentInHDRP { set { changeVisualEnvironmentInHDRP = value; } get { return changeVisualEnvironmentInHDRP; } } [SerializeField] private bool changeVisualEnvironmentInHDRP = true;
|
||||
|
||||
/// <summary>If you enable this setting and your project is running with HDRP then a <b>Volume</b> component will be added to the scene that adjusts the fog to match the other pipelines.</summary>
|
||||
public bool ChangeFogInHDRP { set { changeFogInHDRP = value; } get { return changeFogInHDRP; } } [SerializeField] private bool changeFogInHDRP = true;
|
||||
|
||||
/// <summary>If you enable this setting and your project is running with HDRP then a <b>Volume</b> component will be added to the scene that adjusts the clouds to match the other pipelines.</summary>
|
||||
public bool ChangeCloudsInHDRP { set { changeCloudsInHDRP = value; } get { return changeCloudsInHDRP; } } [SerializeField] private bool changeCloudsInHDRP = true;
|
||||
|
||||
/// <summary>If you enable this setting and your project is running with HDRP then a <b>Volume</b> component will be added to the scene that adjusts the motion blur to match the other pipelines.</summary>
|
||||
public bool ChangeMotionBlurInHDRP { set { changeMotionBlurInHDRP = value; } get { return changeMotionBlurInHDRP; } } [SerializeField] private bool changeMotionBlurInHDRP = true;
|
||||
|
||||
/// <summary>If you enable this setting and your project is running with HDRP then any lights missing the <b>HDAdditionalLightData</b> component will have it added.</summary>
|
||||
public bool UpgradeLightsInHDRP { set { upgradeLightsInHDRP = value; } get { return upgradeLightsInHDRP; } } [SerializeField] private bool upgradeLightsInHDRP = true;
|
||||
|
||||
/// <summary>If you enable this setting and your project is running with HDRP then any cameras missing the <b>HDAdditionalCameraData</b> component will have it added.</summary>
|
||||
public bool UpgradeCamerasInHDRP { set { upgradeCamerasInHDRP = value; } get { return upgradeCamerasInHDRP; } } [SerializeField] private bool upgradeCamerasInHDRP = true;
|
||||
|
||||
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
if (upgradeInputModule == true)
|
||||
{
|
||||
TryUpgradeEventSystem();
|
||||
}
|
||||
|
||||
if (CwHelper.IsURP == true)
|
||||
{
|
||||
TryApplyURP();
|
||||
}
|
||||
|
||||
if (CwHelper.IsHDRP == true)
|
||||
{
|
||||
TryApplyHDRP();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void TryApplyURP()
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void TryApplyHDRP()
|
||||
{
|
||||
if (changeExposureInHDRP == true || changeVisualEnvironmentInHDRP == true || changeFogInHDRP == true)
|
||||
{
|
||||
TryCreateVolume();
|
||||
}
|
||||
|
||||
if (upgradeLightsInHDRP == true)
|
||||
{
|
||||
TryUpgradeLights();
|
||||
}
|
||||
|
||||
if (upgradeCamerasInHDRP == true)
|
||||
{
|
||||
TryUpgradeCameras();
|
||||
}
|
||||
}
|
||||
|
||||
private void TryCreateVolume()
|
||||
{
|
||||
#if __HDRP__
|
||||
var volume = GetComponent<Volume>();
|
||||
|
||||
if (volume == null)
|
||||
{
|
||||
volume = gameObject.AddComponent<Volume>();
|
||||
}
|
||||
|
||||
var profile = volume.profile;
|
||||
|
||||
if (profile == null)
|
||||
{
|
||||
profile = ScriptableObject.CreateInstance<VolumeProfile>();
|
||||
|
||||
profile.hideFlags = HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor;
|
||||
}
|
||||
|
||||
if (profile.components.Count == 0)
|
||||
{
|
||||
name = "Demo (Volume Added)";
|
||||
|
||||
if (changeExposureInHDRP == true)
|
||||
{
|
||||
var exposure = profile.Add<UnityEngine.Rendering.HighDefinition.Exposure>(true);
|
||||
|
||||
exposure.fixedExposure.value = 14.0f;
|
||||
}
|
||||
|
||||
if (changeVisualEnvironmentInHDRP == true)
|
||||
{
|
||||
var visualEnvironment = profile.Add<UnityEngine.Rendering.HighDefinition.VisualEnvironment>(true);
|
||||
|
||||
visualEnvironment.skyType.value = 0;
|
||||
}
|
||||
|
||||
if (changeFogInHDRP == true)
|
||||
{
|
||||
var fog = profile.Add<UnityEngine.Rendering.HighDefinition.Fog>(true);
|
||||
|
||||
fog.enabled.value = false;
|
||||
}
|
||||
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
if (changeCloudsInHDRP == true)
|
||||
{
|
||||
var clouds = profile.Add<UnityEngine.Rendering.HighDefinition.VolumetricClouds>(true);
|
||||
|
||||
clouds.enable.value = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (changeMotionBlurInHDRP == true)
|
||||
{
|
||||
var motionBlur = profile.Add<UnityEngine.Rendering.HighDefinition.MotionBlur>(true);
|
||||
|
||||
motionBlur.intensity.value = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
volume.profile = profile;
|
||||
#endif
|
||||
}
|
||||
|
||||
private void TryUpgradeLights()
|
||||
{
|
||||
#if __HDRP__
|
||||
foreach (var light in CwHelper.FindObjectsByType<Light>())
|
||||
{
|
||||
if (light.GetComponent<UnityEngine.Rendering.HighDefinition.HDAdditionalLightData>() == null)
|
||||
{
|
||||
light.gameObject.AddComponent<UnityEngine.Rendering.HighDefinition.HDAdditionalLightData>();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private void TryUpgradeCameras()
|
||||
{
|
||||
#if __HDRP__
|
||||
foreach (var camera in CwHelper.FindObjectsByType<Camera>())
|
||||
{
|
||||
if (camera.GetComponent<UnityEngine.Rendering.HighDefinition.HDAdditionalCameraData>() == null)
|
||||
{
|
||||
var hdCamera = camera.gameObject.AddComponent<UnityEngine.Rendering.HighDefinition.HDAdditionalCameraData>();
|
||||
|
||||
hdCamera.backgroundColorHDR = Color.black;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private void TryUpgradeEventSystem()
|
||||
{
|
||||
#if UNITY_EDITOR && ENABLE_INPUT_SYSTEM && __INPUTSYSTEM__
|
||||
var module = CwHelper.FindAnyObjectByType<UnityEngine.EventSystems.StandaloneInputModule>();
|
||||
|
||||
if (module != null)
|
||||
{
|
||||
module.gameObject.AddComponent<UnityEngine.InputSystem.UI.InputSystemUIInputModule>();
|
||||
|
||||
DestroyImmediate(module);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
namespace CW.Common
|
||||
{
|
||||
using UnityEditor;
|
||||
using TARGET = CwDemo;
|
||||
|
||||
[CustomEditor(typeof(TARGET))]
|
||||
public class CwDemo_Editor : CwEditor
|
||||
{
|
||||
protected override void OnInspector()
|
||||
{
|
||||
TARGET tgt; TARGET[] tgts; GetTargets(out tgt, out tgts);
|
||||
|
||||
Draw("upgradeInputModule", "If you enable this setting and your project is running with the new InputSystem then the EventSystem's InputModule component will be upgraded.");
|
||||
|
||||
Separator();
|
||||
|
||||
Draw("changeExposureInHDRP", "If you enable this setting and your project is running with HDRP then a Volume component will be added to this GameObject that adjusts the camera exposure to match the other pipelines.");
|
||||
Draw("changeVisualEnvironmentInHDRP", "If you enable this setting and your project is running with HDRP then a Volume component will be added to this GameObject that adjusts the background to match the other pipelines.");
|
||||
Draw("changeFogInHDRP", "If you enable this setting and your project is running with HDRP then a Volume component will be added to the scene that adjusts the fog to match the other pipelines.");
|
||||
Draw("changeCloudsInHDRP", "If you enable this setting and your project is running with HDRP then a Volume component will be added to the scene that adjusts the clouds to match the other pipelines.");
|
||||
Draw("changeMotionBlurInHDRP", "If you enable this setting and your project is running with HDRP then a <b>Volume</b> component will be added to the scene that adjusts the motion blur to match the other pipelines.");
|
||||
Draw("upgradeLightsInHDRP", "If you enable this setting and your project is running with HDRP then any lights missing the HDAdditionalLightData component will have it added.");
|
||||
Draw("upgradeCamerasInHDRP", "If you enable this setting and your project is running with HDRP then any cameras missing the HDAdditionalCameraData component will have it added.");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a5270a8e97f926a4bbcf95d4fa31866d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,245 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace CW.Common
|
||||
{
|
||||
/// <summary>This component turns the current UI element into a button that links to the specified action.</summary>
|
||||
[ExecuteInEditMode]
|
||||
[HelpURL(CwShared.HelpUrlPrefix + "CwDemoButton")]
|
||||
[AddComponentMenu(CwShared.ComponentMenuPrefix + "Demo Button")]
|
||||
public class CwDemoButton : MonoBehaviour, IPointerDownHandler
|
||||
{
|
||||
public enum LinkType
|
||||
{
|
||||
PreviousScene,
|
||||
NextScene,
|
||||
Publisher,
|
||||
URL,
|
||||
Isolate
|
||||
}
|
||||
|
||||
public enum ToggleType
|
||||
{
|
||||
KeepSelected,
|
||||
ToggleSelection,
|
||||
SelectPrevious
|
||||
}
|
||||
|
||||
/// <summary>The action that will be performed when this UI element is clicked.</summary>
|
||||
public LinkType Link { set { link = value; } get { return link; } } [SerializeField] private LinkType link;
|
||||
|
||||
/// <summary>The URL that will be opened.</summary>
|
||||
public string UrlTarget { set { urlTarget = value; } get { return urlTarget; } } [SerializeField] private string urlTarget;
|
||||
|
||||
/// <summary>If this GameObject is active, then the button will be faded in.</summary>
|
||||
public Transform IsolateTarget { set { isolateTarget = value; } get { return isolateTarget; } } [SerializeField] private Transform isolateTarget;
|
||||
|
||||
/// <summary>If this button is already selected and you click/tap it again, what should happen?</summary>
|
||||
public ToggleType IsolateToggle { set { isolateToggle = value; } get { return isolateToggle; } } [SerializeField] private ToggleType isolateToggle;
|
||||
|
||||
[System.NonSerialized]
|
||||
private CanvasGroup cachedCanvasGroup;
|
||||
|
||||
[System.NonSerialized]
|
||||
private Transform previousChild;
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
cachedCanvasGroup = GetComponent<CanvasGroup>();
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
var group = GetComponent<CanvasGroup>();
|
||||
|
||||
if (group != null)
|
||||
{
|
||||
var alpha = 1.0f;
|
||||
|
||||
switch (link)
|
||||
{
|
||||
case LinkType.PreviousScene:
|
||||
case LinkType.NextScene:
|
||||
{
|
||||
alpha = GetCurrentLevel() >= 0 && GetLevelCount() > 1 ? 1.0f : 0.0f;
|
||||
}
|
||||
break;
|
||||
case LinkType.Isolate:
|
||||
{
|
||||
if (isolateTarget != null)
|
||||
{
|
||||
alpha = isolateTarget.gameObject.activeInHierarchy == true ? 1.0f : 0.5f;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
group.alpha = alpha;
|
||||
group.blocksRaycasts = alpha > 0.0f;
|
||||
group.interactable = alpha > 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
switch (link)
|
||||
{
|
||||
case LinkType.PreviousScene:
|
||||
{
|
||||
var index = GetCurrentLevel();
|
||||
|
||||
if (index >= 0)
|
||||
{
|
||||
if (--index < 0)
|
||||
{
|
||||
index = GetLevelCount() - 1;
|
||||
}
|
||||
|
||||
LoadLevel(index);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case LinkType.NextScene:
|
||||
{
|
||||
var index = GetCurrentLevel();
|
||||
|
||||
if (index >= 0)
|
||||
{
|
||||
if (++index >= GetLevelCount())
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
|
||||
LoadLevel(index);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case LinkType.Publisher:
|
||||
{
|
||||
Application.OpenURL("https://carloswilkes.com");
|
||||
}
|
||||
break;
|
||||
|
||||
case LinkType.URL:
|
||||
{
|
||||
if (string.IsNullOrEmpty(urlTarget) == false)
|
||||
{
|
||||
Application.OpenURL(urlTarget);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case LinkType.Isolate:
|
||||
{
|
||||
if (isolateTarget != null)
|
||||
{
|
||||
var parent = isolateTarget.transform.parent;
|
||||
var active = isolateTarget.gameObject.activeSelf;
|
||||
|
||||
foreach (Transform child in parent.transform)
|
||||
{
|
||||
if (child.gameObject.activeSelf == true)
|
||||
{
|
||||
if (child != isolateTarget)
|
||||
{
|
||||
previousChild = child;
|
||||
}
|
||||
|
||||
child.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
switch (isolateToggle)
|
||||
{
|
||||
case ToggleType.KeepSelected:
|
||||
{
|
||||
isolateTarget.gameObject.SetActive(true);
|
||||
}
|
||||
break;
|
||||
|
||||
case ToggleType.ToggleSelection:
|
||||
{
|
||||
isolateTarget.gameObject.SetActive(active == false);
|
||||
}
|
||||
break;
|
||||
|
||||
case ToggleType.SelectPrevious:
|
||||
{
|
||||
if (active == true && previousChild != null)
|
||||
{
|
||||
previousChild.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
isolateTarget.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static int GetCurrentLevel()
|
||||
{
|
||||
var scene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
|
||||
var index = scene.buildIndex;
|
||||
|
||||
if (index >= 0)
|
||||
{
|
||||
if (UnityEngine.SceneManagement.SceneManager.GetSceneByBuildIndex(index).handle != scene.handle)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
private static int GetLevelCount()
|
||||
{
|
||||
return UnityEngine.SceneManagement.SceneManager.sceneCountInBuildSettings;
|
||||
}
|
||||
|
||||
private static void LoadLevel(int index)
|
||||
{
|
||||
UnityEngine.SceneManagement.SceneManager.LoadScene(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
namespace CW.Common
|
||||
{
|
||||
using UnityEditor;
|
||||
using TARGET = CwDemoButton;
|
||||
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(TARGET))]
|
||||
public class CwDemoButton_Editor : CwEditor
|
||||
{
|
||||
protected override void OnInspector()
|
||||
{
|
||||
TARGET tgt; TARGET[] tgts; GetTargets(out tgt, out tgts);
|
||||
|
||||
Draw("link", "The action that will be performed when this UI element is clicked.");
|
||||
|
||||
BeginIndent();
|
||||
if (Any(tgts, t => t.Link == CwDemoButton.LinkType.URL))
|
||||
{
|
||||
Draw("urlTarget", "The URL that will be opened.", "Target");
|
||||
}
|
||||
if (Any(tgts, t => t.Link == CwDemoButton.LinkType.Isolate))
|
||||
{
|
||||
Draw("isolateTarget", "If this GameObject is active, then the button will be faded in.", "Target");
|
||||
Draw("isolateToggle", "If this button is already selected and you click/tap it again, what should happen?", "Toggle");
|
||||
}
|
||||
EndIndent();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 207d6a51d513da54db00bf553470072f
|
||||
timeCreated: 1574550986
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,124 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using CW.Common;
|
||||
|
||||
namespace CW.Common
|
||||
{
|
||||
/// <summary>This component allows you to quickly build a UI button to activate only this GameObject when clicked.</summary>
|
||||
[HelpURL(CwShared.HelpUrlPrefix + "CwDemoButtonBuilder")]
|
||||
[AddComponentMenu(CwShared.ComponentMenuPrefix + "Demo Button Builder")]
|
||||
public class CwDemoButtonBuilder : MonoBehaviour
|
||||
{
|
||||
/// <summary>The built button will be based on this prefab.</summary>
|
||||
public GameObject ButtonPrefab { set { buttonPrefab = value; } get { return buttonPrefab; } } [SerializeField] private GameObject buttonPrefab;
|
||||
|
||||
/// <summary>The built button will be placed under this transform.</summary>
|
||||
public RectTransform ButtonRoot { set { buttonRoot = value; } get { return buttonRoot; } } [SerializeField] private RectTransform buttonRoot;
|
||||
|
||||
/// <summary>The icon given to this button.</summary>
|
||||
public Sprite Icon { set { icon = value; } get { return icon; } } [SerializeField] private Sprite icon;
|
||||
|
||||
/// <summary>The icon will be tinted by this.</summary>
|
||||
public Color Color { set { color = value; } get { return color; } } [SerializeField] private Color color = Color.white;
|
||||
|
||||
/// <summary>Use a different name for the button text?</summary>
|
||||
public string OverrideName { set { overrideName = value; } get { return overrideName; } } [SerializeField] [Multiline(3)] private string overrideName;
|
||||
|
||||
[SerializeField]
|
||||
private GameObject clone;
|
||||
|
||||
[ContextMenu("Build")]
|
||||
public void Build()
|
||||
{
|
||||
if (clone != null)
|
||||
{
|
||||
DestroyImmediate(clone);
|
||||
}
|
||||
|
||||
if (buttonPrefab != null)
|
||||
{
|
||||
clone = DoInstantiate();
|
||||
|
||||
clone.name = name;
|
||||
|
||||
var image = clone.GetComponent<Image>();
|
||||
|
||||
if (image != null)
|
||||
{
|
||||
image.sprite = icon;
|
||||
image.color = color;
|
||||
}
|
||||
|
||||
var title = clone.GetComponentInChildren<Text>();
|
||||
|
||||
if (title != null)
|
||||
{
|
||||
title.text = string.IsNullOrEmpty(overrideName) == false ? overrideName : name;
|
||||
}
|
||||
|
||||
var isolate = clone.GetComponent<CwDemoButton>();
|
||||
|
||||
if (isolate != null)
|
||||
{
|
||||
isolate.IsolateTarget = transform;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ContextMenu("Build All")]
|
||||
public void BuildAll()
|
||||
{
|
||||
foreach (var builder in transform.parent.GetComponentsInChildren<CwDemoButtonBuilder>(true))
|
||||
{
|
||||
builder.Build();
|
||||
}
|
||||
}
|
||||
|
||||
private GameObject DoInstantiate()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (Application.isPlaying == false)
|
||||
{
|
||||
return (GameObject)UnityEditor.PrefabUtility.InstantiatePrefab(buttonPrefab, buttonRoot);
|
||||
}
|
||||
#endif
|
||||
return Instantiate(buttonPrefab, buttonRoot, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
namespace PaintIn3D
|
||||
{
|
||||
using UnityEditor;
|
||||
using TARGET = CwDemoButtonBuilder;
|
||||
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(TARGET))]
|
||||
public class CwDemoButtonBuilder_Editor : CwEditor
|
||||
{
|
||||
protected override void OnInspector()
|
||||
{
|
||||
TARGET tgt; TARGET[] tgts; GetTargets(out tgt, out tgts);
|
||||
|
||||
Draw("buttonPrefab", "The built button will be based on this prefab.");
|
||||
Draw("buttonRoot", "The built button will be placed under this transform.");
|
||||
|
||||
Separator();
|
||||
|
||||
Draw("icon", "The icon given to this button.");
|
||||
Draw("color", "The icon will be tinted by this.");
|
||||
Draw("overrideName", "Use a different name for the button text?");
|
||||
|
||||
Separator();
|
||||
|
||||
if (Button("Build All") == true)
|
||||
{
|
||||
Undo.RecordObjects(tgts, "Build All");
|
||||
|
||||
tgt.BuildAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee2055732bd5a4a4a8f4fe43e20eca6e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,103 @@
|
||||
using UnityEngine;
|
||||
using CW.Common;
|
||||
|
||||
namespace CW.Common
|
||||
{
|
||||
/// <summary>This component allows you to control a Camera component's depthTextureMode setting.</summary>
|
||||
[ExecuteInEditMode]
|
||||
[DisallowMultipleComponent]
|
||||
[RequireComponent(typeof(Camera))]
|
||||
[AddComponentMenu("CW/Common/CW Depth Texture Mode")]
|
||||
public class CwDepthTextureMode : MonoBehaviour
|
||||
{
|
||||
/// <summary>The depth mode that will be applied to the camera.</summary>
|
||||
public DepthTextureMode DepthMode { set { depthMode = value; UpdateDepthMode(); } get { return depthMode; } } [SerializeField] private DepthTextureMode depthMode = DepthTextureMode.None;
|
||||
|
||||
[System.NonSerialized]
|
||||
private Camera cachedCamera;
|
||||
|
||||
public void UpdateDepthMode()
|
||||
{
|
||||
if (cachedCamera == null) cachedCamera = GetComponent<Camera>();
|
||||
|
||||
cachedCamera.depthTextureMode = depthMode;
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
UpdateDepthMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
namespace CW.Common
|
||||
{
|
||||
using UnityEditor;
|
||||
using TARGET = CwDepthTextureMode;
|
||||
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(TARGET))]
|
||||
public class CwDepthTextureMode_Editor : CwEditor
|
||||
{
|
||||
protected override void OnInspector()
|
||||
{
|
||||
TARGET tgt; TARGET[] tgts; GetTargets(out tgt, out tgts);
|
||||
|
||||
Draw("depthMode", "The depth mode that will be applied to the camera.");
|
||||
}
|
||||
|
||||
public static void RequireDepth()
|
||||
{
|
||||
var found = false;
|
||||
|
||||
foreach (var camera in Camera.allCameras)
|
||||
{
|
||||
var mask = camera.depthTextureMode;
|
||||
|
||||
if (mask == DepthTextureMode.DepthNormals || ((int)mask & 1) != 0)
|
||||
{
|
||||
found = true; break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found == false)
|
||||
{
|
||||
CwEditor.Separator();
|
||||
|
||||
if (Camera.main != null)
|
||||
{
|
||||
if (WritesDepth(Camera.main) == false)
|
||||
{
|
||||
if (CwEditor.HelpButton("This component requires your camera to render a Depth Texture, but it doesn't.", UnityEditor.MessageType.Error, "Fix", 50.0f) == true)
|
||||
{
|
||||
CwHelper.GetOrAddComponent<CwDepthTextureMode>(Camera.main.gameObject).DepthMode = DepthTextureMode.Depth;
|
||||
|
||||
CwHelper.SelectAndPing(Camera.main);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CwEditor.Error("This component requires your camera to render a Depth Texture, but none of the cameras in your scene do. This can be fixed with the SgtDepthTextureMode component.");
|
||||
|
||||
foreach (var camera in Camera.allCameras)
|
||||
{
|
||||
if (CwHelper.Enabled(camera) == true)
|
||||
{
|
||||
CwHelper.GetOrAddComponent<CwDepthTextureMode>(camera.gameObject).DepthMode = DepthTextureMode.Depth;
|
||||
|
||||
CwHelper.SelectAndPing(camera);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool WritesDepth(Camera camera)
|
||||
{
|
||||
return camera != null && camera.depthTextureMode == DepthTextureMode.DepthNormals || ((int)camera.depthTextureMode & 1) != 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 543105670369c7e49b28b587c69ad997
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,115 @@
|
||||
using UnityEngine;
|
||||
using CW.Common;
|
||||
|
||||
namespace CW.Common
|
||||
{
|
||||
/// <summary>This component will change the light intensity based on the current render pipeline.</summary>
|
||||
[ExecuteInEditMode]
|
||||
[RequireComponent(typeof(Light))]
|
||||
[AddComponentMenu("CW/Common/CW Light Intensity")]
|
||||
public class CwLightIntensity : MonoBehaviour
|
||||
{
|
||||
/// <summary>All light values will be multiplied by this before use.</summary>
|
||||
public float Multiplier { set { multiplier = value; } get { return multiplier; } } [SerializeField] private float multiplier = 1.0f;
|
||||
|
||||
/// <summary>This allows you to control the intensity of the attached light when using the <b>Standard</b> rendering pipeline.
|
||||
/// -1 = The attached light intensity will not be modified.</summary>
|
||||
public float IntensityInStandard { set { intensityInStandard = value; } get { return intensityInStandard; } } [SerializeField] private float intensityInStandard = 1.0f;
|
||||
|
||||
/// <summary>This allows you to control the intensity of the attached light when using the <b>URP</b> rendering pipeline.
|
||||
/// -1 = The attached light intensity will not be modified.</summary>
|
||||
public float IntensityInURP { set { intensityInURP = value; } get { return intensityInURP; } } [SerializeField] private float intensityInURP = 1.0f;
|
||||
|
||||
/// <summary>This allows you to control the intensity of the attached light when using the <b>HDRP</b> rendering pipeline.
|
||||
/// -1 = The attached light intensity will not be modified.</summary>
|
||||
public float IntensityInHDRP { set { intensityInHDRP = value; } get { return intensityInHDRP; } } [SerializeField] private float intensityInHDRP = 120000.0f;
|
||||
|
||||
[System.NonSerialized]
|
||||
private Light cachedLight;
|
||||
|
||||
[System.NonSerialized]
|
||||
private bool cachedLightSet;
|
||||
|
||||
#if __HDRP__
|
||||
[System.NonSerialized]
|
||||
private UnityEngine.Rendering.HighDefinition.HDAdditionalLightData cachedLightData;
|
||||
#endif
|
||||
|
||||
public Light CachedLight
|
||||
{
|
||||
get
|
||||
{
|
||||
if (cachedLightSet == false)
|
||||
{
|
||||
cachedLight = GetComponent<Light>();
|
||||
cachedLightSet = true;
|
||||
}
|
||||
|
||||
return cachedLight;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
if (CwHelper.IsBIRP == true)
|
||||
{
|
||||
ApplyIntensity(intensityInStandard);
|
||||
}
|
||||
else if (CwHelper.IsURP == true)
|
||||
{
|
||||
ApplyIntensity(intensityInURP);
|
||||
}
|
||||
else if (CwHelper.IsHDRP == true)
|
||||
{
|
||||
ApplyIntensity(intensityInHDRP);
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyIntensity(float intensity)
|
||||
{
|
||||
if (intensity >= 0.0f)
|
||||
{
|
||||
if (cachedLightSet == false)
|
||||
{
|
||||
cachedLight = GetComponent<Light>();
|
||||
cachedLightSet = true;
|
||||
}
|
||||
|
||||
#if __HDRP__
|
||||
if (cachedLightData == null)
|
||||
{
|
||||
cachedLightData = GetComponent<UnityEngine.Rendering.HighDefinition.HDAdditionalLightData>();
|
||||
}
|
||||
|
||||
if (cachedLightData != null)
|
||||
{
|
||||
cachedLightData.SetIntensity(intensity * multiplier, UnityEngine.Rendering.HighDefinition.LightUnit.Lux);
|
||||
}
|
||||
#else
|
||||
cachedLight.intensity = intensity * multiplier;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
namespace CW.Common
|
||||
{
|
||||
using UnityEditor;
|
||||
using TARGET = CwLightIntensity;
|
||||
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(TARGET))]
|
||||
public class P3dLight_Editor : CwEditor
|
||||
{
|
||||
protected override void OnInspector()
|
||||
{
|
||||
Draw("multiplier", "All light values will be multiplied by this before use.");
|
||||
Draw("intensityInStandard", "This allows you to control the intensity of the attached light when using the Standard rendering pipeline.\n\n-1 = The attached light intensity will not be modified.");
|
||||
Draw("intensityInURP", "This allows you to control the intensity of the attached light when using the URP rendering pipeline.\n\n-1 = The attached light intensity will not be modified.");
|
||||
Draw("intensityInHDRP", "This allows you to control the intensity of the attached light when using the HDRP rendering pipeline.\n\n-1 = The attached light intensity will not be modified.");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c97b30f38749284eab37996f9f5bd2a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,44 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace CW.Common
|
||||
{
|
||||
/// <summary>This component rotates the current <b>Transform</b>.</summary>
|
||||
[HelpURL(CwShared.HelpUrlPrefix + "CwRotate")]
|
||||
[AddComponentMenu(CwShared.ComponentMenuPrefix + "Rotate")]
|
||||
public class CwRotate : MonoBehaviour
|
||||
{
|
||||
/// <summary>The speed of the rotation in degrees per second.</summary>
|
||||
public Vector3 AngularVelocity { set { angularVelocity = value; } get { return angularVelocity; } } [SerializeField] private Vector3 angularVelocity = Vector3.up;
|
||||
|
||||
/// <summary>The rotation space.</summary>
|
||||
public Space RelativeTo { set { relativeTo = value; } get { return relativeTo; } } [SerializeField] private Space relativeTo;
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
transform.Rotate(angularVelocity * Time.deltaTime, relativeTo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
namespace CW.Common
|
||||
{
|
||||
using UnityEditor;
|
||||
using TARGET = CwRotate;
|
||||
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(TARGET))]
|
||||
public class CwRotate_Editor : CwEditor
|
||||
{
|
||||
protected override void OnInspector()
|
||||
{
|
||||
TARGET tgt; TARGET[] tgts; GetTargets(out tgt, out tgts);
|
||||
|
||||
BeginError(Any(tgts, t => t.AngularVelocity.magnitude == 0.0f));
|
||||
Draw("angularVelocity", "The speed of the rotation in degrees per second.");
|
||||
EndError();
|
||||
Draw("relativeTo", "The rotation space.");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92ede0252ef7e92459ff5df2a16cd28e
|
||||
timeCreated: 1526027124
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user