diff options
Diffstat (limited to 'Assets/Scripts')
39 files changed, 942 insertions, 99 deletions
diff --git a/Assets/Scripts/Curve3D.meta b/Assets/Scripts/Camera.meta index fef1c5e7..139bddae 100644 --- a/Assets/Scripts/Curve3D.meta +++ b/Assets/Scripts/Camera.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ad8b718b6b700d8419838dad07158567 +guid: 10934c4669147044897200abc6f23a05 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Scripts/Camera/LensEffectHandler.cs b/Assets/Scripts/Camera/LensEffectHandler.cs new file mode 100644 index 00000000..63114535 --- /dev/null +++ b/Assets/Scripts/Camera/LensEffectHandler.cs @@ -0,0 +1,35 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[RequireComponent(typeof(Camera))] +public class LensEffectHandler : MonoBehaviour +{ + Camera m_Camera; + + public delegate void RenderEventHandler(); + public event RenderEventHandler onPreCull; + public event RenderEventHandler onPreRender; + public event RenderEventHandler onPostRender; + + private void OnEable() + { + m_Camera = GetComponent<Camera>(); + } + + private void OnPreCull() + { + onPreCull?.Invoke(); + } + + private void OnPreRender() + { + onPreRender?.Invoke(); + } + + private void OnPostRender() + { + onPostRender?.Invoke(); + } + +} diff --git a/Assets/Scripts/Camera/LensEffectHandler.cs.meta b/Assets/Scripts/Camera/LensEffectHandler.cs.meta new file mode 100644 index 00000000..cf914200 --- /dev/null +++ b/Assets/Scripts/Camera/LensEffectHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 058dffdf2041d7d43902a7c301296bb2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Camera/MainCamera.cs b/Assets/Scripts/Camera/MainCamera.cs new file mode 100644 index 00000000..f439cf22 --- /dev/null +++ b/Assets/Scripts/Camera/MainCamera.cs @@ -0,0 +1,153 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +// 主相机 +[ExecuteAlways] +public class MainCamera : SingletonMB<MainCamera> +{ + #region inspector + [Serializable] + public struct Region + { + [SerializeField] public float l; + [SerializeField] public float r; + [SerializeField] public float t; + [SerializeField] public float b; + } + + public new Camera camera { get; private set; } + + public Vector3 offset = Vector3.zero; + + [SerializeField] private float z; + + [SerializeField] private Region region; + + [SerializeField] private float moveSpeed; + + [SerializeField] private AnimationCurve speedCurve; + + [SerializeField] private float threshold; + #endregion + + private LensEffectHandler m_LensEffectHandler; + public LensEffectHandler lensEffectHandler + { + get + { + if (m_LensEffectHandler == null) + m_LensEffectHandler = this.gameObject.GetOrAddComponent<LensEffectHandler>(); + return m_LensEffectHandler; + } + } + + private Vector2 position2D + { + get + { + return transform.position; + } + set + { + transform.position = new Vector3(value.x, value.y, transform.position.z); + } + } + + private Vector3 position + { + get + { + return transform.position; + } + set + { + transform.position = value; + } + } + + protected override void Awake() + { + base.Awake(); + camera = gameObject.GetComponent<Camera>(); + } + + private void Start() + { + Vector3 pos = transform.position; + pos.z = this.z; + transform.position = pos; + + Quaternion rot = Quaternion.LookRotation(Vector3.forward); + transform.rotation = rot; + } + + void FollowPlayerCharacter() + { + if (UnitManager.Instance == null || UnitManager.Instance.pc == null) + return; + + Region region = this.region; + + //if (!UnitManager.Instance.pc.isTowardRight) + //{ + // region.l = -this.region.r; + // region.r = -this.region.l; + //} + + Vector3 camPos = position; + + Vector3 worldPos = UnitManager.Instance.pc.transform.position + offset; + + Vector2 viewPos = ((Vector2)camera.WorldToViewportPoint(worldPos)) * 2 - Vector2.one; + + Vector3 dir = (worldPos - camPos).normalized; + float dest = (worldPos - camPos).magnitude; + float curve = speedCurve.Evaluate((threshold - Mathf.Clamp(dest, 0f, threshold)) / threshold); + Vector3 move = curve * dir * moveSpeed * Time.deltaTime; + + if (IsInRegion(viewPos, region)) + { + if(!IsInCenter(viewPos)) + { + position2D = camPos + move; + if((worldPos - position).magnitude <= 0.1f) + { + position2D = worldPos; + } + } + return; + } + position2D = camPos + move; + if ((worldPos - position).magnitude <= 0.1f) + { + position2D = worldPos; + } + } + + bool IsInRegion(Vector2 p, Region region) + { + return p.x > region.l + && p.x < region.r + && p.y > region.b + && p.y < region.t; + } + + bool IsInCenter(Vector2 p) + { + return p.x == (region.l + region.r) / 2 && p.y == (region.t + region.b) / 2; + } + + void Update() + { + FollowPlayerCharacter(); + } + + public void OnGUI() + { + if(MainCameraDebug.OnGUIHandlers != null) + MainCameraDebug.OnGUIHandlers.Invoke(); + } + +}
\ No newline at end of file diff --git a/Assets/Scripts/Scene/MainCamera.cs.meta b/Assets/Scripts/Camera/MainCamera.cs.meta index 1ad6678e..1ad6678e 100644 --- a/Assets/Scripts/Scene/MainCamera.cs.meta +++ b/Assets/Scripts/Camera/MainCamera.cs.meta diff --git a/Assets/Scripts/Camera/MainCameraDebug.cs b/Assets/Scripts/Camera/MainCameraDebug.cs new file mode 100644 index 00000000..7a8382ee --- /dev/null +++ b/Assets/Scripts/Camera/MainCameraDebug.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class MainCameraDebug +{ + public static Action OnGUIHandlers; + +} diff --git a/Assets/Scripts/Camera/MainCameraDebug.cs.meta b/Assets/Scripts/Camera/MainCameraDebug.cs.meta new file mode 100644 index 00000000..71e9cdb8 --- /dev/null +++ b/Assets/Scripts/Camera/MainCameraDebug.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 31f8e21379e822447b55a74c799469f6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Data/EnumDefine.cs b/Assets/Scripts/Data/EnumDefine.cs new file mode 100644 index 00000000..ad55986f --- /dev/null +++ b/Assets/Scripts/Data/EnumDefine.cs @@ -0,0 +1,22 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + + +// unit image effect枚举 +public enum EImageEffectMaterails +{ + MotionBlur, + Glitch, + ColorDrift, +} + +public enum EShader +{ + Blur, + + + SolidColor, + +} + diff --git a/Assets/Scripts/Data/EnumDefine.cs.meta b/Assets/Scripts/Data/EnumDefine.cs.meta new file mode 100644 index 00000000..a8332e9b --- /dev/null +++ b/Assets/Scripts/Data/EnumDefine.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e8e2ae14bb9405d47a5b2ff142dcff1a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Data/StaticDefine.cs b/Assets/Scripts/Data/StaticDefine.cs index 833b3ec1..236e0621 100644 --- a/Assets/Scripts/Data/StaticDefine.cs +++ b/Assets/Scripts/Data/StaticDefine.cs @@ -2,20 +2,26 @@ using System.Collections.Generic;
using UnityEngine;
-public enum EImageEffectMaterails
-{
- MotionBlur,
- Glitch,
- ColorDrift,
-}
-
public static class StaticDefine
{
+ // unit image用到的材质
public static Dictionary<EImageEffectMaterails, string/*path*/> imageEffectMaterails = new Dictionary<EImageEffectMaterails, string>() {
- { EImageEffectMaterails.MotionBlur, "Assets/Bundle/Materials/Unit/ImageEffect/unit_img_motionBlur.mat"},
+ { EImageEffectMaterails.MotionBlur, "Assets/Bundle/Materials/Unit/ImageEffect/unit_img_motion_blur.mat"},
{ EImageEffectMaterails.Glitch, "Assets/Bundle/Materials/Unit/ImageEffect/unit_img_glitch.mat"},
};
- public static string bundleManifest = "bundles"; // Assets/Resources/bundles.json
+
+ public struct ShaderDefine
+ {
+ public ShaderDefine(string n, string p) { name = n; path = p; }
+ public string name;
+ public string path;
+ }
+ public static Dictionary<EShader, ShaderDefine> shaders = new Dictionary<EShader, ShaderDefine> {
+ { EShader.Blur, new ShaderDefine("Erika/Common/Image/Blur", "")},
+ { EShader.SolidColor, new ShaderDefine("Erika/Common/SolidColor", "") },
+ };
+
+ public static string bundleManifest = "bundles"; // Assets/Resources/bundles.json
}
diff --git a/Assets/Scripts/Drone.meta b/Assets/Scripts/Editor.meta index 694cff70..b8bb2b0e 100644 --- a/Assets/Scripts/Drone.meta +++ b/Assets/Scripts/Editor.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ec3412151f8a72a41b2ed21316763399 +guid: c08fbb77c6ad1ed4c9499d0fcb73773f folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Scripts/Editor/InspectorUtility.cs b/Assets/Scripts/Editor/InspectorUtility.cs new file mode 100644 index 00000000..5c1e6e05 --- /dev/null +++ b/Assets/Scripts/Editor/InspectorUtility.cs @@ -0,0 +1,169 @@ +using UnityEngine; +using UnityEditor; +using System; +using System.Collections.Generic; +using System.IO; + +/// <summary> +/// Collection of tools and helpers for drawing inspectors +/// </summary> +public class InspectorUtility +{ + /// <summary>Put multiple properties on a single inspector line, with + /// optional label overrides. Passing null as a label (or sublabel) override will + /// cause the property's displayName to be used as a label. For no label at all, + /// pass GUIContent.none.</summary> + /// <param name="rect">Rect in which to draw</param> + /// <param name="label">Main label</param> + /// <param name="props">Properties to place on the line</param> + /// <param name="subLabels">Sublabels for the properties</param> + public static void MultiPropertyOnLine( + Rect rect, + GUIContent label, + SerializedProperty[] props, GUIContent[] subLabels) + { + if (props == null || props.Length == 0) + return; + + const int hSpace = 2; + int indentLevel = EditorGUI.indentLevel; + float labelWidth = EditorGUIUtility.labelWidth; + + float totalSubLabelWidth = 0; + int numBoolColumns = 0; + List<GUIContent> actualLabels = new List<GUIContent>(); + for (int i = 0; i < props.Length; ++i) + { + GUIContent sublabel = new GUIContent(props[i].displayName, props[i].tooltip); + if (subLabels != null && subLabels.Length > i && subLabels[i] != null) + sublabel = subLabels[i]; + actualLabels.Add(sublabel); + totalSubLabelWidth += GUI.skin.label.CalcSize(sublabel).x; + if (i > 0) + totalSubLabelWidth += hSpace; + // Special handling for toggles, or it looks stupid + if (props[i].propertyType == SerializedPropertyType.Boolean) + { + totalSubLabelWidth += rect.height; + ++numBoolColumns; + } + } + + float subFieldWidth = rect.width - labelWidth - totalSubLabelWidth; + float numCols = props.Length - numBoolColumns; + float colWidth = numCols == 0 ? 0 : subFieldWidth / numCols; + + // Main label. If no first sublabel, then main label must take on that + // role, for mouse dragging value-scrolling support + int subfieldStartIndex = 0; + if (label == null) + label = new GUIContent(props[0].displayName, props[0].tooltip); + if (actualLabels[0] != GUIContent.none) + rect = EditorGUI.PrefixLabel(rect, label); + else + { + rect.width = labelWidth + colWidth; + EditorGUI.PropertyField(rect, props[0], label); + rect.x += rect.width + hSpace; + subfieldStartIndex = 1; + } + + for (int i = subfieldStartIndex; i < props.Length; ++i) + { + EditorGUI.indentLevel = 0; + EditorGUIUtility.labelWidth = GUI.skin.label.CalcSize(actualLabels[i]).x; + if (props[i].propertyType == SerializedPropertyType.Boolean) + { + rect.width = EditorGUIUtility.labelWidth + rect.height; + props[i].boolValue = EditorGUI.ToggleLeft(rect, actualLabels[i], props[i].boolValue); + } + else + { + rect.width = EditorGUIUtility.labelWidth + colWidth; + EditorGUI.PropertyField(rect, props[i], actualLabels[i]); + } + rect.x += rect.width + hSpace; + } + + EditorGUIUtility.labelWidth = labelWidth; + EditorGUI.indentLevel = indentLevel; + } + + /// <summary> + /// Normalize a curve so that each of X and Y axes ranges from 0 to 1 + /// </summary> + /// <param name="curve">Curve to normalize</param> + /// <returns>The normalized curve</returns> + public static AnimationCurve NormalizeCurve(AnimationCurve curve) + { + Keyframe[] keys = curve.keys; + if (keys.Length > 0) + { + float minTime = keys[0].time; + float maxTime = minTime; + float minVal = keys[0].value; + float maxVal = minVal; + for (int i = 0; i < keys.Length; ++i) + { + minTime = Mathf.Min(minTime, keys[i].time); + maxTime = Mathf.Max(maxTime, keys[i].time); + minVal = Mathf.Min(minVal, keys[i].value); + maxVal = Mathf.Max(maxVal, keys[i].value); + } + float range = maxTime - minTime; + float timeScale = range < 0.0001f ? 1 : 1 / range; + range = maxVal - minVal; + float valScale = range < 1 ? 1 : 1 / range; + float valOffset = 0; + if (range < 1) + { + if (minVal > 0 && minVal + range <= 1) + valOffset = minVal; + else + valOffset = 1 - range; + } + for (int i = 0; i < keys.Length; ++i) + { + keys[i].time = (keys[i].time - minTime) * timeScale; + keys[i].value = ((keys[i].value - minVal) * valScale) + valOffset; + } + curve.keys = keys; + } + return curve; + } + + /// <summary> + /// Remove the "Cinemachine" prefix, then call the standard Unity Nicify. + /// </summary> + /// <param name="name">The name to nicify</param> + /// <returns>The nicified name</returns> + public static string NicifyClassName(string name) + { + if (name.StartsWith("Cinemachine")) + name = name.Substring(11); // Trim the prefix + return ObjectNames.NicifyVariableName(name); + } + + // Temporarily here + /// <summary> + /// Create a game object. Uses ObjectFactory if the Unity version is sufficient. + /// </summary> + /// <param name="name">Name to give the object</param> + /// <param name="types">Optional components to add</param> + /// <returns></returns> + public static GameObject CreateGameObject(string name, params Type[] types) + { + return ObjectFactory.CreateGameObject(name, types); + } + + /// <summary> + /// Force a repaint of the Game View + /// </summary> + /// <param name="unused">Like it says</param> + public static void RepaintGameView(UnityEngine.Object unused = null) + { + EditorApplication.QueuePlayerLoopUpdate(); + UnityEditorInternal.InternalEditorUtility.RepaintAllViews(); + } + +} diff --git a/Assets/Scripts/Editor/InspectorUtility.cs.meta b/Assets/Scripts/Editor/InspectorUtility.cs.meta new file mode 100644 index 00000000..f2152bda --- /dev/null +++ b/Assets/Scripts/Editor/InspectorUtility.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ae9f2927fa60f654889df3571b579c86 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Editor/MainCameraEditor.cs b/Assets/Scripts/Editor/MainCameraEditor.cs new file mode 100644 index 00000000..437303a0 --- /dev/null +++ b/Assets/Scripts/Editor/MainCameraEditor.cs @@ -0,0 +1,45 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + +[CustomEditor(typeof(MainCamera))] +public class MainCameraEditor : Editor +{ + + private void OnEnable() + { + MainCameraDebug.OnGUIHandlers -= OnGameViewGUI; + MainCameraDebug.OnGUIHandlers += OnGameViewGUI; + } + + private void OnDisable() + { + MainCameraDebug.OnGUIHandlers -= OnGameViewGUI; + + InspectorUtility.RepaintGameView(); + } + + public override void OnInspectorGUI() + { + base.OnInspectorGUI(); + } + + private void OnGameViewGUI() + { + MainCamera camera = target as MainCamera; + if (camera == null) + return; + + //Matrix4x4 oldMatrix = GUI.matrix; + //Rect cameraRect = new Rect(0, 0, 500, 500); + + //GUI.matrix = Matrix4x4.Translate(cameraRect.min); + + ////GUILayout.Button("test"); + //GUI.DrawTexture(new Rect(0, 0, 30, 30), Texture2D.whiteTexture); + + //GUI.matrix = oldMatrix; + } + +} diff --git a/Assets/Scripts/Editor/MainCameraEditor.cs.meta b/Assets/Scripts/Editor/MainCameraEditor.cs.meta new file mode 100644 index 00000000..76d6d4b1 --- /dev/null +++ b/Assets/Scripts/Editor/MainCameraEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: eeb2aab4ac403f9429e87defed16c4a5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Props.meta b/Assets/Scripts/Props.meta deleted file mode 100644 index bb96602e..00000000 --- a/Assets/Scripts/Props.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: f299520ed9fcf4a45858ad4ef5a8d5d1 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Robot.meta b/Assets/Scripts/Robot.meta deleted file mode 100644 index 0b5a087e..00000000 --- a/Assets/Scripts/Robot.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 7c09ca1609552d24bbe697d1516f8aa9 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Scene/MainCamera.cs b/Assets/Scripts/Scene/MainCamera.cs deleted file mode 100644 index 45399ceb..00000000 --- a/Assets/Scripts/Scene/MainCamera.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-
-public class MainCamera : SingletonMB<MainCamera>
-{
- public new Camera camera { get; private set; }
-
- public Vector3 offset = Vector3.zero;
-
- protected override void Awake()
- {
- base.Awake();
- camera = gameObject.GetComponent<Camera>();
- }
-
- void Update()
- {
- if (TestErika.Instance.erika.unitController == null)
- {
- return;
- }
- Vector3 pos = transform.position;
- pos.x = TestErika.Instance.erika.unitController.transform.position.x;
- pos.y = TestErika.Instance.erika.unitController.transform.position.y;
- transform.position = pos + offset;
- }
-
-}
\ No newline at end of file diff --git a/Assets/Scripts/Unit/AI/Actions.meta b/Assets/Scripts/Unit/AI/Actions.meta deleted file mode 100644 index 9b4ad463..00000000 --- a/Assets/Scripts/Unit/AI/Actions.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 971e9d55b8bc0894eb6a110fb962000b -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Unit/AI/Conditionals.meta b/Assets/Scripts/Unit/AI/Conditionals.meta deleted file mode 100644 index 70a86da5..00000000 --- a/Assets/Scripts/Unit/AI/Conditionals.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 85b7e0c7ed1d12f42a5178bfbf3d934c -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Unit/Components/UnitAfterImage.cs b/Assets/Scripts/Unit/Components/UnitAfterImage.cs index 369f63c9..622e87ba 100644 --- a/Assets/Scripts/Unit/Components/UnitAfterImage.cs +++ b/Assets/Scripts/Unit/Components/UnitAfterImage.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using UnityEngine; +// Unit残影,通过复制avatar实现 + public class AfterImageSpawner { private float m_CurTime; diff --git a/Assets/Scripts/Unit/Components/UnitImageEffect.cs b/Assets/Scripts/Unit/Components/UnitImageEffect.cs index 4681826f..fcdd5c1f 100644 --- a/Assets/Scripts/Unit/Components/UnitImageEffect.cs +++ b/Assets/Scripts/Unit/Components/UnitImageEffect.cs @@ -1,7 +1,9 @@ using System.Collections; using System.Collections.Generic; -using UnityEngine; - +using UnityEngine;
+
+// Unit的一种后处理效果,渲染到一个RT上,对这个RT做效果
+
public class UnitImageEffectHolder { public float size; @@ -30,7 +32,6 @@ public class UnitImageEffectHandle public UnitImageEffectEndCallback onStop; } -//Unit后处理效果 public class UnitImageEffect : UnitComponent { public List<UnitImageEffectHandle> effects = new List<UnitImageEffectHandle>(); @@ -125,9 +126,10 @@ public class UnitImageEffect : UnitComponent holder.gameObject.transform.position = Vector3.zero; holders.Add(holder); holder = null; - } - - + }
+
+ //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
public void ShowMotionBlur(float lifeTime, float angle, float distance) { UnitImageEffectHandle handle = m_HandlePool.Get(); diff --git a/Assets/Scripts/Unit/Components/UnitLensEffect.cs b/Assets/Scripts/Unit/Components/UnitLensEffect.cs new file mode 100644 index 00000000..4b710aa4 --- /dev/null +++ b/Assets/Scripts/Unit/Components/UnitLensEffect.cs @@ -0,0 +1,128 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Rendering; + +//https://docs.unity3d.com/ScriptReference/Rendering.RenderTargetIdentifier.html + +// Unit效果之一,镜头效果,通过command buffer实现 + +//public class MaterailEntry +//{ +// public Material material; +//} + +public class UnitLensEffect : UnitComponent +{ + private List<RendererProxy> renderers; + + private static ObjectPool<CommandBuffer> m_CommandBufferPool = new ObjectPool<CommandBuffer>(null, null); + + CommandBuffer m_CommandBuffer; + + public override void Initialize() + { + base.Initialize(); + + renderers = new List<RendererProxy>(); + } + + public override void OnPostInitialize() + { + base.OnPostInitialize(); + + IBodyRendererAgent body = owner.unitRender.body; + if (body == null || body.renderers == null) + return; + for (int i = 0; i < body.renderers.Length; ++i) + { + var renderer = body.renderers[i]; + if (renderer == null) + continue; + RendererProxy proxy = renderer.renderer.gameObject.GetOrAddComponent<RendererProxy>(); + proxy.Initialize(renderer); + proxy.onWillRenderObject = OnWillRenderObject; + proxy.onRenderObject = OnRenderObject; + renderers.Add(proxy); + } + + m_CommandBuffer = ClaimCommandBuffer(); + + MainCamera.Instance.lensEffectHandler.onPreCull += OnWillRenderUnit; + MainCamera.Instance.lensEffectHandler.onPostRender += OnRenderUnit; + } + + public override void Release() + { + base.Release(); + + MainCamera.Instance.lensEffectHandler.onPreRender -= OnWillRenderUnit; + MainCamera.Instance.lensEffectHandler.onPostRender -= OnRenderUnit; + } + + private void OnWillRenderUnit() + { + m_CommandBuffer.Clear(); + + MainCamera.Instance.camera.AddCommandBuffer(CameraEvent.BeforeImageEffectsOpaque, m_CommandBuffer); + } + + private void OnRenderUnit() + { + + MainCamera.Instance.camera.RemoveCommandBuffer(CameraEvent.BeforeImageEffectsOpaque, m_CommandBuffer); + } + + private void OnWillRenderObject(BodyPartRenderer renderer) + { + //Camera cam = SceneManager.Instance.mainCamera; + //if (cam == null) + // return; + //Material mat = new Material(Shader.Find(StaticDefine.shaders[EShader.SolidColor].name)); + //mat.SetColor("_Color", Color.red); + + //Matrix4x4 obj2Wod = Matrix4x4.identity; + ////obj2Wod = TransformUtility.GetLocalToWorldMatrixRootBone(owner.unitDetail.rootBone.transform); + //Vector3 pos = owner.unitDetail.rootBone.transform.position; + //Quaternion rot = owner.unitDetail.rootBone.transform.rotation; + //obj2Wod = MatrixUtility.RotateAndTranslate(pos, rot); + //mat.SetMatrix("_ObjectToWorld", obj2Wod); + //mat.SetTexture("_MainTex", renderer.renderer.material.GetTexture("_MainTex")); + + //cb.Clear(); + //cb.name = "Unit Renderer"; + + //// create render texture for glow map + //int tempID = Shader.PropertyToID("_Temp1"); + //cb.GetTemporaryRT(tempID, -1, -1, 24, FilterMode.Bilinear); + //cb.SetRenderTarget(tempID); + //cb.ClearRenderTarget(true, true, new Color(0, 0, 0, 0)); + //cb.DrawRenderer(renderer.renderer, mat); + + //cb.SetRenderTarget(BuiltinRenderTextureType.CameraTarget); + //Material blur = new Material(Shader.Find(StaticDefine.shaders[EShader.Blur].name)); + //cb.Blit(tempID, BuiltinRenderTextureType.CameraTarget, blur); + + //cam.AddCommandBuffer(CameraEvent.AfterImageEffectsOpaque, cb); + } + + private void OnRenderObject(BodyPartRenderer renderer) + { + //Camera cam = SceneManager.Instance.mainCamera; + //cam.RemoveCommandBuffer(CameraEvent.AfterImageEffectsOpaque, cb); + } + + static CommandBuffer ClaimCommandBuffer() + { + CommandBuffer cb = m_CommandBufferPool.Get(); + cb.Clear(); + return cb; + } + + static void ReleaseCommandBuffer(ref CommandBuffer cb) + { + m_CommandBufferPool.Release(cb); + cb = null; + } + +} diff --git a/Assets/Scripts/Unit/Components/UnitLensEffect.cs.meta b/Assets/Scripts/Unit/Components/UnitLensEffect.cs.meta new file mode 100644 index 00000000..5a91ee87 --- /dev/null +++ b/Assets/Scripts/Unit/Components/UnitLensEffect.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d2d69fdca26298548ba2c146496c33c3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Unit/Components/UnitPostEffect.cs b/Assets/Scripts/Unit/Components/UnitPostEffect.cs new file mode 100644 index 00000000..ad98ff6a --- /dev/null +++ b/Assets/Scripts/Unit/Components/UnitPostEffect.cs @@ -0,0 +1,15 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class UnitPostEffect : UnitComponent +{ + + public override void Initialize() + { + base.Initialize(); + } + + + +}
\ No newline at end of file diff --git a/Assets/Scripts/Unit/Components/UnitPostEffect.cs.meta b/Assets/Scripts/Unit/Components/UnitPostEffect.cs.meta new file mode 100644 index 00000000..d91936b9 --- /dev/null +++ b/Assets/Scripts/Unit/Components/UnitPostEffect.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a7d49a2074b33d342beb20900188941d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Unit/Components/UnitRender.cs b/Assets/Scripts/Unit/Components/UnitRender.cs index d1ea0ffb..a5822ffe 100644 --- a/Assets/Scripts/Unit/Components/UnitRender.cs +++ b/Assets/Scripts/Unit/Components/UnitRender.cs @@ -6,6 +6,7 @@ using UnityEngine; [DisallowMultipleComponent] public class UnitRender : UnitComponent { + public IBodyRendererAgent body { get { return m_Body; } } private IBodyRendererAgent m_Body; public Renderer mainRenderer
@@ -34,13 +35,13 @@ public class UnitRender : UnitComponent LayerMask mask = LayerMask.GetMask("PlayerCharacter");
if (!isVisible)
{
- SceneManager.Instance.mainCamera.cullingMask &= ~mask.value;
+ //SceneManager.Instance.mainCamera.cullingMask &= ~mask.value;
}
else
{
- SceneManager.Instance.mainCamera.cullingMask |= mask.value;
- }
- } + //SceneManager.Instance.mainCamera.cullingMask |= mask.value;
+ }
+ } public void SetVisibilityInAllCameras(bool isVisible)
{
@@ -49,12 +50,12 @@ public class UnitRender : UnitComponent if (isVisible)
{
- mainRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On;
- }
- else
+ //mainRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On;
+ }
+ else
{
- mainRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.ShadowsOnly;
- }
- } + //mainRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.ShadowsOnly;
+ }
+ } -} +}
diff --git a/Assets/Scripts/Unit/Controller/PCController.cs b/Assets/Scripts/Unit/Controller/PCController.cs index 4c665e7a..90520017 100644 --- a/Assets/Scripts/Unit/Controller/PCController.cs +++ b/Assets/Scripts/Unit/Controller/PCController.cs @@ -8,11 +8,13 @@ public class PCController : UnitController {
public static PCController instance;
- public UnitAfterImage unitAfterImage;
-
+ #region Unit的三种效果
+ public UnitAfterImage unitAfterImage;
public UnitImageEffect unitImageEffect;
+ public UnitLensEffect unitLensEffect;
+ #endregion
- public override UnitType type { get { return UnitType.PC; } }
+ public override UnitType type { get { return UnitType.PC; } }
private void Awake()
{
@@ -34,7 +36,11 @@ public class PCController : UnitController unitImageEffect = GetOrAddUnitComponent<UnitImageEffect>();
unitImageEffect.Initialize();
- }
+
+ unitLensEffect = GetOrAddUnitComponent<UnitLensEffect>();
+ unitLensEffect.Initialize();
+
+ }
public override void Update()
{
diff --git a/Assets/Scripts/Managers/Physics.meta b/Assets/Scripts/Unit/LensEffect.meta index 2296b3f8..ad9ac741 100644 --- a/Assets/Scripts/Managers/Physics.meta +++ b/Assets/Scripts/Unit/LensEffect.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 603d4624aaedd794cb89497954a83f4a +guid: 3d1f1847b55e52a448151b0186678736 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Scripts/Unit/LensEffect/RendererProxy.cs b/Assets/Scripts/Unit/LensEffect/RendererProxy.cs new file mode 100644 index 00000000..17d8d611 --- /dev/null +++ b/Assets/Scripts/Unit/LensEffect/RendererProxy.cs @@ -0,0 +1,33 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[RequireComponent(typeof(Renderer))] +public class RendererProxy : MonoBehaviour +{ + public delegate void OnWillRenderObjectHandler(BodyPartRenderer renderer); + public OnWillRenderObjectHandler onWillRenderObject; + + public delegate void OnRenderObjectHandler(BodyPartRenderer renderer); + public OnRenderObjectHandler onRenderObject; + + BodyPartRenderer bodyPartRenderer; + + public void Initialize(BodyPartRenderer renderer) + { + bodyPartRenderer = renderer; + } + + void OnWillRenderObject() + { + if(onWillRenderObject != null) + onWillRenderObject(bodyPartRenderer); + } + + void OnRenderObject() + { + if(onRenderObject != null) + onRenderObject(bodyPartRenderer); + } + +} diff --git a/Assets/Scripts/Unit/LensEffect/RendererProxy.cs.meta b/Assets/Scripts/Unit/LensEffect/RendererProxy.cs.meta new file mode 100644 index 00000000..5f8c904e --- /dev/null +++ b/Assets/Scripts/Unit/LensEffect/RendererProxy.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 81836ced17364c94d8130f6eeb2bf115 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Unit/TimelineEventProxy.cs b/Assets/Scripts/Unit/TimelineEventProxy.cs index 9e41e30e..866c6d3b 100644 --- a/Assets/Scripts/Unit/TimelineEventProxy.cs +++ b/Assets/Scripts/Unit/TimelineEventProxy.cs @@ -51,8 +51,14 @@ public partial class TimelineEventProxy EventGame_TimeScale, // 缩放时间
EventMesh_ImageEffect_MotionBlur, // 运动模糊 - EventMesh_ImageEffect_Glitch, // glitch - EventMesh_AfterImage, // 角色残像
+ EventMesh_ImageEffect_Glitch, // glitch
+
+ EventMesh_LensEffect_Bloom, // bloom
+ EventMesh_LensEffect_MotionBlur, // motionBlur
+
+ EventMesh_PostEffect_Curly, //
+
+ EventMesh_AfterImage, // 角色残像
EventMesh_AfterImageStop, // 角色残像停止事件
EventMesh_FadeIn, // 角色透明度
EventMesh_FadeOut, // 角色透明度 diff --git a/Assets/Scripts/Unit/UnitDetail.cs b/Assets/Scripts/Unit/UnitDetail.cs index 3f7f23e9..09eefa51 100644 --- a/Assets/Scripts/Unit/UnitDetail.cs +++ b/Assets/Scripts/Unit/UnitDetail.cs @@ -125,8 +125,8 @@ public class BodyPartRenderer public interface IBodyRendererAgent
{
- BodyPartRenderer mainRenderer { get; }
- BodyPartRenderer[] renderers{ get; }
+ BodyPartRenderer mainRenderer { get; }
+ BodyPartRenderer[] renderers { get; }
} public interface IBodyJointAgent
@@ -142,7 +142,10 @@ public interface IBodyJointAgent [DisallowMultipleComponent] public class UnitDetail : MonoBehaviour, IBodyRendererAgent, IBodyJointAgent { - public bool showGizmos; + public bool showGizmos;
+
+ [FormerlySerializedAs("root")] + public Transform rootBone; [Tooltip("残影用的prefab")] public string afterImageAvatarPath;
diff --git a/Assets/Scripts/Utils/MatrixUtility.cs b/Assets/Scripts/Utils/MatrixUtility.cs new file mode 100644 index 00000000..f3d865f2 --- /dev/null +++ b/Assets/Scripts/Utils/MatrixUtility.cs @@ -0,0 +1,42 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public static class MatrixUtility +{ + + public static void SetTR(ref this Matrix4x4 matrix, Vector3 pos, Quaternion q) + { + matrix = q.ToMatrix(); + matrix[12] = pos[0]; + matrix[13] = pos[1]; + matrix[14] = pos[2]; + } + + public static void SetTRS2(ref this Matrix4x4 matrix, Vector3 pos, Quaternion q, Vector3 s) + { + matrix = q.ToMatrix(); + + matrix[0] *= s[0]; + matrix[1] *= s[0]; + matrix[2] *= s[0]; + matrix[4] *= s[1]; + matrix[5] *= s[1]; + matrix[6] *= s[1]; + matrix[8] *= s[2]; + matrix[9] *= s[2]; + matrix[10] *= s[2]; + matrix[12] = pos[0]; + matrix[13] = pos[1]; + matrix[14] = pos[2]; + + } + + public static Matrix4x4 RotateAndTranslate(Vector3 pos, Quaternion q) + { + Matrix4x4 m = new Matrix4x4(); + m.SetTR(pos, q); + return m; + } + +} diff --git a/Assets/Scripts/Utils/MatrixUtility.cs.meta b/Assets/Scripts/Utils/MatrixUtility.cs.meta new file mode 100644 index 00000000..746a5d82 --- /dev/null +++ b/Assets/Scripts/Utils/MatrixUtility.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4f4a4958b670de143b1189fc304ace4a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Utils/QuaternionUtility.cs b/Assets/Scripts/Utils/QuaternionUtility.cs new file mode 100644 index 00000000..d491b1fe --- /dev/null +++ b/Assets/Scripts/Utils/QuaternionUtility.cs @@ -0,0 +1,51 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public static class QuaternionUtility +{ + + public static Matrix4x4 ToMatrix(ref this Quaternion q) + { + Matrix4x4 m = new Matrix4x4(); + + // Precalculate coordinate products + float x = q.x * 2.0F; + float y = q.y * 2.0F; + float z = q.z * 2.0F; + float xx = q.x * x; + float yy = q.y * y; + float zz = q.z * z; + float xy = q.x * y; + float xz = q.x * z; + float yz = q.y * z; + float wx = q.w * x; + float wy = q.w * y; + float wz = q.w * z; + + // Calculate 3x3 matrix from orthonormal basis + m[0] = 1.0f - (yy + zz); + m[1] = xy + wz; + m[2] = xz - wy; + m[3] = 0.0F; + + m[4] = xy - wz; + m[5] = 1.0f - (xx + zz); + m[6] = yz + wx; + m[7] = 0.0F; + + m[8] = xz + wy; + m[9] = yz - wx; + m[10] = 1.0f - (xx + yy); + m[11] = 0.0F; + + m[12] = 0.0F; + m[13] = 0.0F; + m[14] = 0.0F; + m[15] = 1.0F; + + return m; + } + + +} diff --git a/Assets/Scripts/Utils/QuaternionUtility.cs.meta b/Assets/Scripts/Utils/QuaternionUtility.cs.meta new file mode 100644 index 00000000..49d589fc --- /dev/null +++ b/Assets/Scripts/Utils/QuaternionUtility.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 789820cb2898f6f488d8b3bfdf94ab00 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Utils/TransformUtility.cs b/Assets/Scripts/Utils/TransformUtility.cs new file mode 100644 index 00000000..62a28ece --- /dev/null +++ b/Assets/Scripts/Utils/TransformUtility.cs @@ -0,0 +1,54 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public static class TransformUtility +{ + + public static Matrix4x4 GetLocalToWorldMatrix(Transform transform) + { + Matrix4x4 mat = Matrix4x4.identity; + while(transform != null) + { + Matrix4x4 m = Matrix4x4.identity; + m.SetTRS2(transform.localPosition, transform.localRotation, transform.localScale); + mat = m * mat; + transform = transform.parent; + } + + return mat; + } + + public static Matrix4x4 GetLocalToWorldMatrixNoScale(Transform transform) + { + Matrix4x4 mat = Matrix4x4.identity; + while (transform != null) + { + Matrix4x4 m = Matrix4x4.identity; + m.SetTR(transform.localPosition, transform.localRotation); + mat = m * mat; + transform = transform.parent; + } + + return mat; + } + + public static Matrix4x4 GetLocalToWorldMatrixRootBone(Transform transform) + { + //Matrix4x4 mat = Matrix4x4.identity; + //while (transform != null) + //{ + // Matrix4x4 m = Matrix4x4.identity; + // m = Matrix4x4.Rotate(transform.localRotation); + // mat = m * mat; + // transform = transform.parent; + //} + //mat.SetColumn(3, new Vector4(trans.position.x, trans.position.y, trans.position.z, 1)); + + Matrix4x4 mat = Matrix4x4.Rotate(transform.rotation); + mat.SetColumn(3, new Vector4(transform.position.x, transform.position.y, transform.position.z, 1)); + + return mat; + } + +}
\ No newline at end of file diff --git a/Assets/Scripts/Utils/TransformUtility.cs.meta b/Assets/Scripts/Utils/TransformUtility.cs.meta new file mode 100644 index 00000000..bda7ca18 --- /dev/null +++ b/Assets/Scripts/Utils/TransformUtility.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 00b07ec5a54ffcc44a9af249df119257 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |