From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Assets/Scripts/Projector/ProjectorsControl.cs | 262 +++++++++++++++++++++ 1 file changed, 262 insertions(+) create mode 100644 Client/Assets/Scripts/Projector/ProjectorsControl.cs (limited to 'Client/Assets/Scripts/Projector/ProjectorsControl.cs') 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(); + 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; + // } + // } + //} + + ///// + ///// The default size of the projector. + ///// + //public float DefaultSize + //{ + // get + // { + // if (projector == null) + // projector = GetComponent(); + + // if (projector != null) + // return projector.orthographicSize; + + // return 0; + // } + + // set + // { + // if (projector == null) + // projector = GetComponent(); + + // if (projector != null) + // projector.orthographicSize = value * Scale; + // } + //} + + ///// + ///// The default texture used by the projector. + ///// + //public Texture DefaultTexture + //{ + // get + // { + // if (projector == null) + // projector = GetComponent(); + + // if (projector != null && projector.material != null) + // return projector.material.GetTexture("_ShadowTex"); + + // return null; + // } + + // set + // { + // if (projector == null) + // projector = GetComponent(); + + // if (projector != null && projector.material != null) + // projector.material.SetTexture("_ShadowTex", value); + // } + //} + + ///// + ///// The default color used by the projector. + ///// + //public Color DefaultColor + //{ + // get + // { + // if (projector == null) + // projector = GetComponent(); + + // if (projector != null && projector.material != null) + // return projector.material.GetColor("_Color"); + + // return Color.black; + // } + + // set + // { + // if (projector == null) + // projector = GetComponent(); + + // if (projector != null && projector.material != null) + // projector.material.SetColor("_Color", value); + // } + //} + + ///// + ///// Adjusts the scale of the current projector based on a defined size value. + ///// + ///// + ///// + //public void SetScale(float size, float scale) + //{ + // Scale = scale; + // DefaultSize = size; + + // pulseMin *= scale; + // pulseMax *= scale; + //} + + ///// + ///// Sets the projectors material. + ///// + ///// + //public void SetMaterial(Material material) + //{ + // if (projector == null) + // projector = GetComponent(); + + // if (projector != null) + // projector.material = material; + //} + + ///// + ///// Updates default values when creating the prefab. + ///// + //public void Initialize() + //{ + // if (projector == null) + // projector = GetComponent(); + + // projector.orthographic = true; + //} + + ///// + ///// Forces an updated to reflect the current values. + ///// + //public void Refresh() + //{ + // Vector3 lastRotation = this.transform.localRotation.eulerAngles; + // this.transform.localRotation = Quaternion.Euler(lastRotation.x, rotation, lastRotation.z); + //} +} -- cgit v1.1-26-g67d0