summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/Projector
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-01-25 14:28:30 +0800
committerchai <chaifix@163.com>2021-01-25 14:28:30 +0800
commit6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch)
tree7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/Projector
+scripts
Diffstat (limited to 'Client/Assets/Scripts/Projector')
-rw-r--r--Client/Assets/Scripts/Projector/ProjectorsControl.cs262
-rw-r--r--Client/Assets/Scripts/Projector/ProjectorsControl.cs.meta8
-rw-r--r--Client/Assets/Scripts/Projector/ShapeProjectorsControl.cs107
-rw-r--r--Client/Assets/Scripts/Projector/ShapeProjectorsControl.cs.meta8
4 files changed, 385 insertions, 0 deletions
diff --git a/Client/Assets/Scripts/Projector/ProjectorsControl.cs b/Client/Assets/Scripts/Projector/ProjectorsControl.cs
new file mode 100644
index 00000000..7949c37e
--- /dev/null
+++ b/Client/Assets/Scripts/Projector/ProjectorsControl.cs
@@ -0,0 +1,262 @@
+using UnityEngine;
+using System.Collections.Generic;
+
+[ExecuteInEditMode]
+[RequireComponent(typeof(Projector))]
+public class ProjectorsControl : MonoBehaviour
+{
+ //public delegate void TransitionCompleted();
+ //public event TransitionCompleted OnPulseCompleted;
+
+ #region variables
+
+ private Projector projector;
+
+ public bool enableAnim = false;
+ public Color color = Color.white;
+ public float falloff = 1.0f;
+ public float amplify = 1.0f;
+ public float argAccuracy = 0.01f;
+
+
+ private Texture texture = null;
+
+ private Material projectorMat;
+ private Color innerColor = Color.white;
+ private Vector4 innerArg = new Vector4(1.0f, 1.0f, 0, 0);
+ private Texture innerTexture = null;
+
+ 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)
+ {
+ if (projectorMat.HasProperty("_Color"))
+ innerColor = projectorMat.GetColor("_Color");
+ if (projectorMat.HasProperty("_Args"))
+ innerArg = projectorMat.GetVector("_Args");
+ if (projectorMat.HasProperty("_ShadowTex"))
+ innerTexture = projectorMat.GetTexture("_ShadowTex");
+ }
+ }
+ }
+
+ void Update()
+ {
+ if (enableAnim && projectorMat != null)
+ {
+ //color
+ float deltaR = Mathf.Abs(innerColor.r - color.r);
+ float deltaG = Mathf.Abs(innerColor.g - color.g);
+ float deltaB = Mathf.Abs(innerColor.b - color.b);
+ float deltaA = Mathf.Abs(innerColor.a - color.a);
+
+ if (deltaR >= colorT || deltaG >= colorT || deltaB >= colorT || deltaA >= colorT)
+ {
+ innerColor = color;
+ projectorMat.SetColor("_Color", color);
+ }
+
+ float deltaFalloff = Mathf.Abs(innerArg.x - falloff);
+ float deltaAmp = Mathf.Abs(innerArg.y - amplify);
+ if (deltaFalloff >= argAccuracy || deltaAmp > argAccuracy)
+ {
+ innerArg.x = falloff;
+ innerArg.y = amplify;
+ projectorMat.SetVector("_Args", innerArg);
+ }
+
+ if (texture != null && innerTexture != texture)
+ {
+ innerTexture = texture;
+ projectorMat.SetTexture("_ShadowTex", innerTexture);
+ }
+ }
+ }
+ //void FixedUpdate()
+ //{
+ // if (rotate)
+ // transform.Rotate(Vector3.forward * rotationSpeed * rotationOffset * Time.deltaTime);
+
+ // if (pulse)
+ // {
+ // float pulseSize = projector.orthographicSize;
+ // float stepAmount = Time.deltaTime * pulseSpeed;
+
+ // if (!pulseFlip)
+ // pulseSize = Mathf.Lerp(pulseSize, pulseMax, stepAmount);
+ // else
+ // pulseSize = Mathf.Lerp(pulseSize, pulseMin, stepAmount);
+
+
+ // if (pulseTime < 1)
+ // pulseTime += stepAmount;
+ // else
+ // {
+ // pulseTime = 0;
+
+ // if (pulseLoop)
+ // pulseFlip = !pulseFlip;
+ // else
+ // pulse = false;
+
+ // if (OnPulseCompleted != null)
+ // OnPulseCompleted();
+ // }
+
+ // projector.orthographicSize = pulseSize;
+ // }
+
+ // if (colorBlend && colors.Count > 0)
+ // {
+ // float stepAmount = Time.deltaTime * colorSpeed;
+
+ // projector.material.color = Color.Lerp(projector.material.color, colors[colorIndex], stepAmount);
+
+ // if (colorTime < 1)
+ // colorTime += stepAmount;
+ // else
+ // {
+ // colorTime = 0;
+
+ // if (colorIndex < colors.Count - 1)
+ // colorIndex++;
+ // else
+ // colorIndex = 0;
+ // }
+ // }
+ //}
+
+ ///// <summary>
+ ///// The default size of the projector.
+ ///// </summary>
+ //public float DefaultSize
+ //{
+ // get
+ // {
+ // if (projector == null)
+ // projector = GetComponent<Projector>();
+
+ // if (projector != null)
+ // return projector.orthographicSize;
+
+ // return 0;
+ // }
+
+ // set
+ // {
+ // if (projector == null)
+ // projector = GetComponent<Projector>();
+
+ // if (projector != null)
+ // projector.orthographicSize = value * Scale;
+ // }
+ //}
+
+ ///// <summary>
+ ///// The default texture used by the projector.
+ ///// </summary>
+ //public Texture DefaultTexture
+ //{
+ // get
+ // {
+ // if (projector == null)
+ // projector = GetComponent<Projector>();
+
+ // if (projector != null && projector.material != null)
+ // return projector.material.GetTexture("_ShadowTex");
+
+ // return null;
+ // }
+
+ // set
+ // {
+ // if (projector == null)
+ // projector = GetComponent<Projector>();
+
+ // if (projector != null && projector.material != null)
+ // projector.material.SetTexture("_ShadowTex", value);
+ // }
+ //}
+
+ ///// <summary>
+ ///// The default color used by the projector.
+ ///// </summary>
+ //public Color DefaultColor
+ //{
+ // get
+ // {
+ // if (projector == null)
+ // projector = GetComponent<Projector>();
+
+ // if (projector != null && projector.material != null)
+ // return projector.material.GetColor("_Color");
+
+ // return Color.black;
+ // }
+
+ // set
+ // {
+ // if (projector == null)
+ // projector = GetComponent<Projector>();
+
+ // if (projector != null && projector.material != null)
+ // projector.material.SetColor("_Color", value);
+ // }
+ //}
+
+ ///// <summary>
+ ///// Adjusts the scale of the current projector based on a defined size value.
+ ///// </summary>
+ ///// <param name="size"></param>
+ ///// <param name="scale"></param>
+ //public void SetScale(float size, float scale)
+ //{
+ // Scale = scale;
+ // DefaultSize = size;
+
+ // pulseMin *= scale;
+ // pulseMax *= scale;
+ //}
+
+ ///// <summary>
+ ///// Sets the projectors material.
+ ///// </summary>
+ ///// <param name="material"></param>
+ //public void SetMaterial(Material material)
+ //{
+ // if (projector == null)
+ // projector = GetComponent<Projector>();
+
+ // if (projector != null)
+ // projector.material = material;
+ //}
+
+ ///// <summary>
+ ///// Updates default values when creating the prefab.
+ ///// </summary>
+ //public void Initialize()
+ //{
+ // if (projector == null)
+ // projector = GetComponent<Projector>();
+
+ // projector.orthographic = true;
+ //}
+
+ ///// <summary>
+ ///// Forces an updated to reflect the current values.
+ ///// </summary>
+ //public void Refresh()
+ //{
+ // Vector3 lastRotation = this.transform.localRotation.eulerAngles;
+ // this.transform.localRotation = Quaternion.Euler(lastRotation.x, rotation, lastRotation.z);
+ //}
+}
diff --git a/Client/Assets/Scripts/Projector/ProjectorsControl.cs.meta b/Client/Assets/Scripts/Projector/ProjectorsControl.cs.meta
new file mode 100644
index 00000000..7a7f17a6
--- /dev/null
+++ b/Client/Assets/Scripts/Projector/ProjectorsControl.cs.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 4d078b507f8161445adfc0a29d7da3f5
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
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);
+ }
+ }
+
+ }
+ }
+}
diff --git a/Client/Assets/Scripts/Projector/ShapeProjectorsControl.cs.meta b/Client/Assets/Scripts/Projector/ShapeProjectorsControl.cs.meta
new file mode 100644
index 00000000..92d5fe14
--- /dev/null
+++ b/Client/Assets/Scripts/Projector/ShapeProjectorsControl.cs.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: d2f3e500554c1d64e84d4ce0a04f2936
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData: