diff options
Diffstat (limited to 'Client/Assets/Scripts/Projector/ShapeProjectorsControl.cs')
-rw-r--r-- | Client/Assets/Scripts/Projector/ShapeProjectorsControl.cs | 107 |
1 files changed, 107 insertions, 0 deletions
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<Projector>();
+ 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);
+ }
+ }
+
+ }
+ }
+}
|