Inheritance: ImageEffectBase
示例#1
0
    public void AddRipple(Vector2 _position, float _duration, float _size)
    {
        Ripple ripple;

        if (ripples.Count < rippleMaxCount || ripples.Count <= 0)
        {
            ripple = new Ripple();
            ripples.Add(ripple);
        }
        else
        {
            ripple = ripples[0];
        }

        ripple.position = _position;
        ripple.duration = _duration;
        ripple.progress = 0f;

        ripple.oneOverScale = 1f / Mathf.Clamp(_size, 0.2f, 1f);

        if (currentRippleCoroutine?.running != true)
        {
            currentRippleCoroutine = currentRippleCoroutine.StartCoroutine(this, UpdateRipplesCoroutine());
        }
    }
示例#2
0
        private void Awake()
        {
            rippleTexture = new RenderTexture(new RenderTextureDescriptor
            {
                colorFormat       = RenderTextureFormat.RGHalf,
                dimension         = TextureDimension.Tex2D,
                enableRandomWrite = true,
                width             = SIZE,
                height            = SIZE,
                volumeDepth       = 1,
                msaaSamples       = 1
            });
            rippleTexture.filterMode = FilterMode.Bilinear;
            rippleTexture.wrapMode   = TextureWrapMode.Repeat;
            rippleTexture.Create();
            rippleBuffer = new ComputeBuffer(RIPPLECOUNT, sizeof(Ripple));
            Random r = new Random((uint)Guid.NewGuid().GetHashCode());
            NativeArray <Ripple> ripplesArray = new NativeArray <Ripple>(RIPPLECOUNT, Allocator.Temp);

            for (int i = 0; i < RIPPLECOUNT; ++i)
            {
                Ripple rip = new Ripple
                {
                    position = r.NextUInt2(0, 511),
                    range    = r.NextUInt(1, 5),
                    timeLine = r.NextFloat() * 0.8f
                };
                ripplesArray[i] = rip;
            }
            rippleBuffer.SetData(ripplesArray);
            ripplesArray.Dispose();
        }
示例#3
0
 private void Start()
 {
     ripple = ScriptableObject.CreateInstance <Ripple>();
     ripple.enabled.Override(false);
     ripple.Amount.Override(0f);
     ripple.WaveAmount.Override(10f);
     ripple.WaveSpeed.Override(15f);
     rippleVolume = PostProcessManager.instance.QuickVolume(gameObject.layer, 100f, ripple);
 }
示例#4
0
        void WPRRadioButton_MouseDown(object sender, EventArgs e)
        {
            if (sender is not RadioButton radioButton)
            {
                return;
            }
            Ripple ripple = radioButton.Template.FindName("Ripple", radioButton) as Ripple;

            ripple?.StartRipple();
        }
示例#5
0
        void WPRCheckBox_MouseUp(object sender, EventArgs e)
        {
            if (sender is not CheckBox checkBox)
            {
                return;
            }
            Ripple ripple = checkBox.Template.FindName("Ripple", checkBox) as Ripple;

            ripple?.StartRipple();
        }
 public void QueueRipple(Vector2 position, Color waveData, Vector2 size, RippleShape shape = RippleShape.Square, float rotation = 0f)
 {
     if (!_useRippleWaves || Main.drawToScreen)
     {
         _rippleQueueCount = 0;
     }
     else if (_rippleQueueCount < _rippleQueue.Length)
     {
         _rippleQueue[_rippleQueueCount++] = new Ripple(position, waveData, size, shape, rotation);
     }
 }
        //private bool _animDown = true;
        private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            //_animDown = false;
            var scaleTrans = ((TransformGroup)Ripple.RenderTransform).Children[0];

            ((TransformGroup)Ripple.RenderTransform).Children[1] = new TranslateTransform(e.MouseDevice.GetPosition(this).X - Ripple.Width / 2, e.MouseDevice.GetPosition(this).Y - Ripple.Height / 2);

            scaleTrans.BeginAnimation(ScaleTransform.ScaleXProperty, _scaleRipple);
            scaleTrans.BeginAnimation(ScaleTransform.ScaleYProperty, _scaleRipple);
            Ripple.BeginAnimation(OpacityProperty, _fadeRipple);
            //WindowManager.Dashboard.VM.SelectCharacter((Character)DataContext);
        }
示例#8
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else
     {
         Destroy(gameObject);
         return;
     }
 }
示例#9
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetMouseButtonUp(0))
     {
         if (ripples.Count > 0)
         {
             Ripple newRip = ripples[0];
             ripples.RemoveAt(0);
             newRip.transform.position = (Vector2)cam.ScreenToWorldPoint(Input.mousePosition);
             newRip.StartRipple();
         }
     }
 }
示例#10
0
    public void AddRipple(Vector3 pos)
    {
        if(ripples.Count < rippleCount){
            Ripple ripple = new Ripple();
            ripple.positionScale = new Vector4(((pos.x + rippleOffset.x)/rippleScale.x)+.5f,
                                               ((pos.z+rippleOffset.y)/rippleScale.y)+.5f,
                                               growSize,growSize);
            ripple.scaleSpeed = (growRate * 0.99f) + ((Random.value * growRate) * 0.01f);
            ripple.rippleStrength = Random.value * 0.95f + 0.05f;

            ripples.Add(ripple);
        }
    }
示例#11
0
        private static void ListBoxMouseButtonEvent(object sender, MouseButtonEventArgs mouseButtonEventArgs)
        {
            var senderElement = (UIElement)sender;

            if (!GetIsToggle(senderElement))
            {
                return;
            }

            var point  = mouseButtonEventArgs.GetPosition(senderElement);
            var result = VisualTreeHelper.HitTest(senderElement, point);

            if (result == null)
            {
                return;
            }

            ListBoxItem listBoxItem = null;
            Ripple      ripple      = null;

            foreach (var dependencyObject in result.VisualHit.GetVisualAncestry().TakeWhile(_ => listBoxItem == null))
            {
                listBoxItem = dependencyObject as ListBoxItem;
                if (ripple == null)
                {
                    ripple = dependencyObject as Ripple;
                }
            }

            if (listBoxItem == null)
            {
                return;
            }

            if (listBoxItem.IsSelected == true)
            {
                return;
            }

            listBoxItem.SetCurrentValue(ListBoxItem.IsSelectedProperty, !listBoxItem.IsSelected);
            mouseButtonEventArgs.Handled = true;

            if (ripple != null && listBoxItem.IsSelected)
            {
                ripple.RaiseEvent(new MouseButtonEventArgs(mouseButtonEventArgs.MouseDevice, mouseButtonEventArgs.Timestamp, mouseButtonEventArgs.ChangedButton)
                {
                    RoutedEvent = Control.PreviewMouseLeftButtonDownEvent, Source = ripple
                }
                                  );
            }
        }
示例#12
0
 public override void Draw(IDrawAPI drawAPI)
 {
     if (drawAPI is VertexBatch v)
     {
         if (paddingBorderInfo == null)
         {
             paddingBorderInfo = Border.GetPaddingBorderDrawInfo(v.primitiveType, position, width, height, roundCorner, paddingColor, quality);
         }
         if (borderColor != default && borderInfo == null)
         {
             borderInfo = Border.GetBorderDrawInfo(PrimitiveType.LineStrip, position, width, height, roundCorner, borderColor, quality);
             borderInfo.primitiveType = PrimitiveType.LineStrip;
         }
         if (shadowColor != default)
         {
             for (int i = 0; i < 6 / shadowDepth; i++)
             {
                 v.Draw(paddingBorderInfo.Transform(delegate(int z, Vertex v)
                 {
                     return(new Vertex(v.Position.XY() + new Vector2(0, i * 2), shadowColor * 0.05f));
                 }));
             }
         }
         v.Draw(paddingBorderInfo);
         font?.DrawString(v, text, position + new Vector2(width, height) / 2, textColor, CenterType.MiddleCenter, textScale);
         if (highLightTimer != 0)
         {
             v.Draw(paddingBorderInfo.Transform(delegate(int z, Vertex v)
             {
                 return(new Vertex(v.Position, highLightColor * 0.2f * highLightTimer));
             }));
         }
         if (rippleTimer > 0)
         {
             Ripple.DrawRound(v, (int)Helper.Lerp(2 * width + height, 0, 3 + rippleTimer * 0.75f, 4), position, ripplePos, width, height, Color.Transparent.LerpTo(rippleColor, rippleTimer, 1), roundCorner, 1, quality * 3);
         }
         rippleTimer *= 0.95f;
         if (rippleTimer < 0.01f)
         {
             rippleTimer = 0;
         }
         if (borderInfo != null)
         {
             v.Draw(borderInfo);
         }
     }
 }
示例#13
0
    public void CreateRipple(float centerX, float centerZ, float maxRadius, float thickness, string sourceTag)
    {
        Ripple newRipple = ripples[oldestRippleIndex];

        newRipple.centerX    = centerX;
        newRipple.centerZ    = centerZ;
        newRipple.currRadius = 0f;
        newRipple.maxRadius  = maxRadius;
        newRipple.thickness  = thickness;
        newRipple.isActive   = true;
        newRipple.sourceTag  = sourceTag;

        oldestRippleIndex++;
        if (oldestRippleIndex >= maxNumRipples)
        {
            oldestRippleIndex = 0;
        }
    }
示例#14
0
    IEnumerator UpdateRipplesCoroutine()
    {
        while (ripples.Count > 0)
        {
            material.SetVector("_Params1", new Vector4(camera.aspect, 1, 0f, 0));
            material.SetVector("_Params2", new Vector4(1, 1 / camera.aspect, refractionStrength, 0f));

            for (int i = 0; i < rippleMaxCount; i++)
            {
                if (i >= ripples.Count)
                {
                    rippleParamCache[i] = new Vector4(0f, 0f, 0f, -1f);
                    break;
                }

                Ripple  ripple           = ripples[i];
                Vector2 viewportPosition = camera.WorldToViewportPoint(ripple.position);
                rippleParamCache[i] = new Vector4(viewportPosition.x * camera.aspect, viewportPosition.y,
                                                  ripple.progress, ripple.oneOverScale);
            }

            material.SetVectorArray("_Ripples", rippleParamCache);

            float dt = Time.deltaTime;

            for (int i = ripples.Count - 1; i >= 0; i--)
            {
                if (i >= ripples.Count)
                {
                    rippleParamCache[i] = new Vector4(0f, 0f, 0f, -1f);
                    break;
                }
                Ripple ripple = ripples[i];
                ripple.progress += dt / ripple.duration;
                if (ripple.progress >= 1f)
                {
                    ripples.RemoveAt(i);
                }
            }
            yield return(null);
        }
        rippleParamCache[0] = new Vector4(0f, 0f, 0f, -1f);
        material.SetVectorArray("_Ripples", rippleParamCache);
    }
示例#15
0
        public override void Init()
        {
            shader = Resources.Load <ComputeShader>("WaterRippleCompute");

            rippleBuffer = new ComputeBuffer(RIPPLECOUNT, sizeof(Ripple));
            Random r = new Random((uint)Guid.NewGuid().GetHashCode());
            NativeArray <Ripple> ripplesArray = new NativeArray <Ripple>(RIPPLECOUNT, Allocator.Temp);

            for (int i = 0; i < RIPPLECOUNT; ++i)
            {
                Ripple rip = new Ripple
                {
                    position = r.NextUInt2(0, 511),
                    range    = r.NextUInt(1, 5),
                    timeLine = r.NextFloat() * 0.8f
                };
                ripplesArray[i] = rip;
            }
            rippleBuffer.SetData(ripplesArray);
            ripplesArray.Dispose();
        }
示例#16
0
    // Update is called once per frame
    void Update()
    {
        List <Ripple> ripples = rippleManager.getRipples();

        // Draws every ripple on floor
        for (int i = 0; i < maxNumRipples; i++)
        {
            Ripple ripple = ripples[i];
            if (ripple.isActive)
            {
                rippleData[i].x = ripple.centerX;
                rippleData[i].z = ripple.centerZ;
                rippleData[i].y = ripple.currRadius;
                rippleData[i].w = ripple.thickness;
                if (ripple.sourceTag == "Player")
                {
                    rippleColors[i] = playerRippleColor;
                }
                else if (ripple.sourceTag == "Monster")
                {
                    rippleColors[i] = monsterRippleColor;
                }
                else
                {
                    rippleColors[i] = distractorRippleColor;
                }
            }
            else
            {
                rippleData[i].x = 0f;
                rippleData[i].z = 0f;
                rippleData[i].y = 0f;
                rippleData[i].w = 0f;
                rippleColors[i] = transparent;
            }
        }
        _renderer.material.SetVectorArray("_Ripples", rippleData);
        _renderer.material.SetColorArray("_RippleColors", rippleColors);
    }
示例#17
0
    private void Ripple()
    {
        Ripple ripple = Instantiate(ripplePrefab, transform.position, Quaternion.identity, transform) as Ripple;

        ripple.SetValues(rippleRange, rippleTime, waveStrenghCurve, objectMover);
    }
示例#18
0
 public Port(string name, Ripple ripple)
 {
     Name    = name;
     _ripple = ripple;
 }
 // Calculate distance from center of ripple to this object
 protected float calculateDistance(Ripple ripple)
 {
     return(Mathf.Sqrt(
                Mathf.Pow((ripple.centerX - transform.position.x), 2) +
                Mathf.Pow((ripple.centerZ - transform.position.z), 2)));
 }
示例#20
0
 public void rippleFinished(Ripple r)
 {
     ripples.Add(r);
     inUse.Remove(r);
 }
示例#21
0
 /// <summary>
 /// 更新接口
 /// </summary>
 public override void Update()
 {
     if (this.ins != null)
     {
         if (this.doneOccEffect && this.tick % 40 == 0)             //更新材质效果
         {
             if (this.oriMats == null)
             {
                 this.oriMats = new List <Material>();
             }
             if (this.renderers == null)
             {
                 this.renderers = new List <Renderer>();
             }
             if (this.replaceMats == null)
             {
                 this.replaceMats = new Dictionary <string, Material>();
             }
             MeshRenderer[]        componentsInChildren  = this.ins.GetComponentsInChildren <MeshRenderer>();
             SkinnedMeshRenderer[] componentsInChildren2 = this.ins.GetComponentsInChildren <SkinnedMeshRenderer>();
             if (!this.underwater)
             {
                 for (int i = 0; i < componentsInChildren.Length; i++)
                 {
                     MeshRenderer meshRenderer = componentsInChildren[i];
                     if (meshRenderer.sharedMaterial != null && meshRenderer.sharedMaterial.shader.name == DynamicUnit.mainUnitOriShaderName)
                     {
                         if (!this.replaceMats.ContainsKey(meshRenderer.sharedMaterial.name))
                         {
                             this.oriMats.Add(meshRenderer.sharedMaterial);
                             this.renderers.Add(meshRenderer);
                             Material material = new Material(DynamicUnit.mainUnitShader);
                             material.mainTexture        = meshRenderer.sharedMaterial.mainTexture;
                             material.color              = meshRenderer.sharedMaterial.color;
                             material.name               = meshRenderer.sharedMaterial.name;
                             meshRenderer.sharedMaterial = material;
                             this.replaceMats.Add(material.name, material);
                         }
                         else
                         {
                             meshRenderer.sharedMaterial = this.replaceMats[meshRenderer.sharedMaterial.name];
                         }
                     }
                 }
                 for (int i = 0; i < componentsInChildren2.Length; i++)
                 {
                     SkinnedMeshRenderer skinnedMeshRenderer = componentsInChildren2[i];
                     if (skinnedMeshRenderer.sharedMaterial != null && skinnedMeshRenderer.sharedMaterial.shader.name == DynamicUnit.mainUnitOriShaderName)
                     {
                         if (!this.replaceMats.ContainsKey(skinnedMeshRenderer.sharedMaterial.name))
                         {
                             this.oriMats.Add(skinnedMeshRenderer.sharedMaterial);
                             this.renderers.Add(skinnedMeshRenderer);
                             Material material2 = new Material(DynamicUnit.mainUnitShader);
                             material2.mainTexture = skinnedMeshRenderer.sharedMaterial.mainTexture;
                             material2.color       = skinnedMeshRenderer.sharedMaterial.color;
                             material2.name        = skinnedMeshRenderer.sharedMaterial.name;
                             skinnedMeshRenderer.sharedMaterial = material2;
                             this.replaceMats.Add(material2.name, material2);
                         }
                         else
                         {
                             skinnedMeshRenderer.sharedMaterial = this.replaceMats[skinnedMeshRenderer.sharedMaterial.name];
                         }
                     }
                 }
             }
             else
             {
                 for (int i = 0; i < this.renderers.Count; i++)
                 {
                     if (this.renderers[i] != null && this.oriMats[i] != null)
                     {
                         this.renderers[i].sharedMaterial = this.oriMats[i];
                     }
                 }
             }
         }
         if (this.tick % 10 == 0 && this.oldCastShadows != this.castShadows)              //更新接受阴影设置
         {
             MeshRenderer[]        componentsInChildren3 = this.ins.GetComponentsInChildren <MeshRenderer>();
             SkinnedMeshRenderer[] componentsInChildren4 = this.ins.GetComponentsInChildren <SkinnedMeshRenderer>();
             string a = string.Empty;
             if (componentsInChildren3 != null)
             {
                 for (int i = 0; i < componentsInChildren3.Length; i++)
                 {
                     if (componentsInChildren3[i] != null)
                     {
                         if (componentsInChildren3[i].sharedMaterial != null)
                         {
                             a = componentsInChildren3[i].sharedMaterial.shader.name;
                         }
                         if (a == DynamicUnit.mainUnitOriShaderName || a == DynamicUnit.mainUnitOriShaderName)
                         {
                             componentsInChildren3[i].castShadows = this.castShadows;
                         }
                     }
                 }
             }
             if (componentsInChildren4 != null)
             {
                 for (int i = 0; i < componentsInChildren4.Length; i++)
                 {
                     if (componentsInChildren4[i] != null)
                     {
                         if (componentsInChildren4[i].sharedMaterial != null)
                         {
                             a = componentsInChildren4[i].sharedMaterial.shader.name;
                         }
                         if (a == DynamicUnit.mainUnitOriShaderName || a == DynamicUnit.mainUnitOriShaderName)
                         {
                             componentsInChildren4[i].castShadows = this.castShadows;
                         }
                     }
                 }
             }
             this.oldCastShadows = this.castShadows;
         }
         if (Mathf.Abs(this.ins.transform.position.x - this.position.x) > 0.01f || Mathf.Abs(this.ins.transform.position.z - this.position.z) > 0.01f)              //位置移动,更新相关
         {
             if (this.needSampleHeight)
             {
                 this.smHeight   = this.scene.SampleHeight(this.position, true);
                 this.position.y = this.smHeight;
             }
             this.ins.transform.position = this.position;
             if ((this.needScreenPoint || this.mouseEnable) && this.scene.mainCamera)
             {
                 this.scenePoint.x = this.position.x;
                 this.scenePoint.z = this.position.z;
                 this.scenePoint.y = this.position.y + this.scenePointBias;
                 this.screenPoint  = this.scene.mainCamera.WorldToScreenPoint(this.scenePoint);
             }
             if (this.genRipple && this.tick % 4 == 0)                     //是否有水波纹效果
             {
                 if (this.scene.Underwater(this.position))                 //是否水下
                 {
                     this.ripplePos.x = this.position.x;
                     this.ripplePos.z = this.position.z;
                     this.ripplePos.y = this.scene.waterHeight;
                     Ripple.CreateRippleGameObject(this.ripplePos);
                     this.underwater = true;
                 }
                 else
                 {
                     this.underwater = false;
                 }
             }
         }
         if (this.isMainUint)
         {
             this.smHeight               = this.scene.SampleHeight(this.position, true);
             this.position.y             = this.smHeight;
             this.ins.transform.position = this.position;
         }
         if (Mathf.Abs(this.ins.transform.rotation.x - this.rotation.x) > 0.01f || Mathf.Abs(this.ins.transform.rotation.y - this.rotation.y) > 0.01f || Mathf.Abs(this.ins.transform.rotation.z - this.rotation.z) > 0.01f)
         {
             this._rotationDirty = true;
         }
         if (this._rotationDirty)
         {
             this.ins.transform.rotation = this.rotation;
             this._rotationDirty         = false;
         }
     }
     if (this.genRipple && this.tick % this.genRippleDelayTick == 0)
     {
         if (this.scene.Underwater(this.position))
         {
             this.ripplePos.x = this.position.x;
             this.ripplePos.z = this.position.z;
             this.ripplePos.y = this.scene.waterHeight;
             Ripple.CreateRippleGameObject(this.ripplePos);
             this.underwater = true;
         }
         else
         {
             this.underwater = false;
         }
     }
     if (this.bornEffect != null)          //出生特效位置跟随
     {
         this.bornEffect.transform.position = this.position;
     }
     if (this.mDynState == DynamicState.LINK_PARENT || this.mDynState == DynamicState.LINK_PARENT_CHILD)
     {
         for (int j = 0; j < this.linkUnits.Count; j++)               //相关连子unit更新
         {
             if (this.linkUnits[j] != null)
             {
                 this.linkUnits[j].Update(this.position, this.rotation);
             }
         }
     }
     if (this.pathInterrupted)             //如果路径中断
     {
         this.curDelayTick--;
         if (this.curDelayTick < 1 && this.scene.mapPath.pathFindEnd)
         {
             this.FindPathMove(this.pathFindTarget, this.speed, this.continuWithInterr, this.delayTick, true);
         }
     }
     if (this._startMove > 0)
     {
         this._startMove--;
     }
     if (this._endMove > 0)
     {
         this._endMove--;
     }
     if (this.move_type == 0)
     {
         this.UpdateMove();
     }
     else if (this.move_type == 1)
     {
         this.UpdateForce();
     }
     this.tick++;
 }
示例#22
0
 // Use this for initialization
 void Start()
 {
     Instance   = this;
     controller = GameObject.FindGameObjectWithTag("Player").GetComponent <FirstPersonController>();
     InvokeRepeating("MakeRippleGoNow", 1, 1);
 }
示例#23
0
 private void Awake()
 {
     m_Instance = this;
 }