From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Scripts/Projector/ShapeProjectorsControl.cs | 107 +++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 Client/Assets/Scripts/Projector/ShapeProjectorsControl.cs (limited to 'Client/Assets/Scripts/Projector/ShapeProjectorsControl.cs') diff --git a/Client/Assets/Scripts/Projector/ShapeProjectorsControl.cs b/Client/Assets/Scripts/Projector/ShapeProjectorsControl.cs new file mode 100644 index 00000000..a260fa1e --- /dev/null +++ b/Client/Assets/Scripts/Projector/ShapeProjectorsControl.cs @@ -0,0 +1,107 @@ +using UnityEngine; +using System.Collections.Generic; + +[ExecuteInEditMode] +[RequireComponent(typeof(Projector))] +public class ShapeProjectorsControl : MonoBehaviour +{ + #region variables + + private Projector projector; + + public bool enableAnim = false; + public Color tintColor = Color.red; + public Color outlineColor = Color.white; + + public float colorTransition = 1.1f; + public float colorScale = 1.0f; + public float outlineWidth = 0.1f; + public float outlineScale = 1.0f; + public float angle = 0.0f; + public float argAccuracy = 0.01f; + + private Material projectorMat; + + private Color innerTintColor = Color.red; + private Color innerOutlineColor = Color.white; + + private Vector4 innerArg = new Vector4(1.01f, 1.0f, 0.1f, 1.0f); + private float innerAngle = 0.0f; + + private bool hasAngle = false; + private static float colorT = 1 / 256.0f; + #endregion + + void Awake() + { + if (projector == null) + projector = GetComponent(); + if (projector != null) + { + projectorMat = projector.material; + if (projectorMat != null) + { + innerTintColor = projectorMat.GetColor("_TintColor"); + innerOutlineColor = projectorMat.GetColor("_OutlineColor"); + innerArg = projectorMat.GetVector("_Arg"); + hasAngle = projectorMat.HasProperty("_Angle"); + if (hasAngle) + innerAngle = projectorMat.GetFloat("_Angle"); + } + } + } + + void Update() + { + if (enableAnim && projectorMat != null) + { + //color + float deltaR = Mathf.Abs(innerTintColor.r - tintColor.r); + float deltaG = Mathf.Abs(innerTintColor.g - tintColor.g); + float deltaB = Mathf.Abs(innerTintColor.b - tintColor.b); + float deltaA = Mathf.Abs(innerTintColor.a - tintColor.a); + + if (deltaR >= colorT || deltaG >= colorT || deltaB >= colorT || deltaA >= colorT) + { + innerTintColor = tintColor; + projectorMat.SetColor("_TintColor", tintColor); + } + deltaR = Mathf.Abs(innerOutlineColor.r - outlineColor.r); + deltaG = Mathf.Abs(innerOutlineColor.g - outlineColor.g); + deltaB = Mathf.Abs(innerOutlineColor.b - outlineColor.b); + deltaA = Mathf.Abs(innerOutlineColor.a - outlineColor.a); + + if (deltaR >= colorT || deltaG >= colorT || deltaB >= colorT || deltaA >= colorT) + { + innerOutlineColor = outlineColor; + projectorMat.SetColor("_OutlineColor", outlineColor); + } + + float deltaColorTransition = Mathf.Abs(innerArg.x - colorTransition); + float deltaColorScale = Mathf.Abs(innerArg.y - colorScale); + float deltaOutlineWidth = Mathf.Abs(innerArg.z - outlineWidth); + float deltaOutlineScale = Mathf.Abs(innerArg.w - outlineScale); + + if (deltaColorTransition >= argAccuracy || + deltaColorScale > argAccuracy|| + deltaOutlineWidth > argAccuracy || + deltaOutlineScale > argAccuracy) + { + innerArg.x = colorTransition; + innerArg.y = colorScale; + innerArg.z = outlineWidth; + innerArg.w = outlineScale; + projectorMat.SetVector("_Arg", innerArg); + } + if (hasAngle) + { + float deltaAngle = Mathf.Abs(innerAngle - angle); + if (deltaAngle >= argAccuracy) + { + projectorMat.SetFloat("_Angle", angle); + } + } + + } + } +} -- cgit v1.1-26-g67d0