public void On(Color color) { iAlpha = sign.color.a; iColor = block.GetColor(ColorID); fColors.Add(color); factor = 0f; inTransition = true; }
IEnumerator FadeToColor(Color color, float duration) { _renderer.GetPropertyBlock(_propBlock); Color begin = _propBlock.GetColor("_EmissionColor"); float t = 0; while (ColorDifference(_propBlock.GetColor("_EmissionColor"), color) >= 0.01f) { t += Time.deltaTime; _propBlock.SetColor("_EmissionColor", Color.Lerp(begin, color, t * duration)); _renderer.SetPropertyBlock(_propBlock); yield return(null); } }
public static AlphaRef SpineMeshAlpha(MeshRenderer renderer) { AlphaRef r; var mpb = new MaterialPropertyBlock(); mpb.SetColor("_Color", renderer.material.GetColor("_Color")); renderer.SetPropertyBlock(mpb); r = new AlphaRef((c) => { var col = mpb.GetColor("_Color"); col.a = c; mpb.SetColor("_Color", col); renderer.SetPropertyBlock(mpb); }, () => mpb.GetColor("_Color").a); return(r); }
protected override void OnTweenBegin() { _CachedTarget = _Target.value as Renderer; if (_CachedTarget == null && _Target.type == FlexibleType.Constant) { if (_MyRenderer == null) { _MyRenderer = GetComponent <Renderer>(); } _CachedTarget = _MyRenderer; } if (_CachedTarget == null) { return; } _CachedPropertyName = _PropertyName.value; _CachedFromValue = _From.value; _CachedToValue = _To.value; if (_Block == null) { _Block = new MaterialPropertyBlock(); } _CachedTarget.GetPropertyBlock(_Block); Color startColor = Color.clear; if (_Block.isEmpty) { startColor = _CachedTarget.sharedMaterial.GetColor(_CachedPropertyName); } else { #if UNITY_2017_3_OR_NEWER startColor = _Block.GetColor(_CachedPropertyName); #else startColor = _Block.GetVector(_CachedPropertyName); #endif } switch (_TweenMoveType) { case TweenMoveType.Absolute: break; case TweenMoveType.Relative: _CachedFromValue += startColor; _CachedToValue += startColor; break; case TweenMoveType.ToAbsolute: _CachedFromValue = startColor; break; } }
IEnumerator ColorChange() { MaterialPropertyBlock propBlock = new MaterialPropertyBlock(); thisRenderer.GetPropertyBlock(propBlock); Color startColor = propBlock.GetColor("_Color"); Color targetColor = Color.magenta; //laserActivation.gemColor; float timeElapsed = 0; while (timeElapsed < colorLerpTime) { timeElapsed += Time.deltaTime; float t = timeElapsed / colorLerpTime; propBlock.SetColor("_Color", Color.Lerp(startColor, targetColor, t)); thisRenderer.SetPropertyBlock(propBlock); yield return(null); } propBlock.SetColor("_Color", targetColor); thisRenderer.SetPropertyBlock(propBlock); numReceiversActivated++; if (OnReceiverActivated != null) { OnReceiverActivated(); } }
void Update() { if (emissionColor != propertyBlock.GetColor("_EmissionColor")) { propertyBlock.SetColor("_EmissionColor", emissionColor); sr.SetPropertyBlock(propertyBlock); } // Check if within hit range if (IsPlayerInRange() && !hitting && !summoningFlying && !summoningRolling && hitTime + hitCooldown <= Time.time) { hitting = true; animator.SetTrigger("hit"); } else if (IsPlayerInSummonRange() && !hitting && !summoningFlying && !summoningRolling && flyingTime + flyingGolemCooldown <= Time.time) { summoningFlying = true; animator.SetTrigger("summon"); } else if (IsPlayerInSummonRange() && !hitting && !summoningFlying && !summoningRolling && rollingTime + rollingGolemCooldown <= Time.time) { summoningRolling = true; animator.SetTrigger("summon"); } }
public static object GetRuntimeProperty(this Renderer render, int materialIndex, int propertyIndex) { MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock(); render.GetPropertyBlock(propertyBlock); Material material = render.materials[materialIndex]; string name = material.GetPropertyName(propertyIndex); int type = material.GetPropertyType(propertyIndex); switch (type) { case 0: return(propertyBlock.GetColor(name)); case 1: return(propertyBlock.GetVector(name)); case 2: case 3: return(propertyBlock.GetFloat(name)); case 4: return(propertyBlock.GetTexture(name)); } return(null); }
// Get Color from GameObject public static Color GetColor(GameObject go) { MaterialPropertyBlock tmp = new MaterialPropertyBlock(); go.GetComponent <Renderer>().GetPropertyBlock(tmp); return(tmp.GetColor(Color)); }
protected virtual void OnHitObject(Collider c, Vector3 hitPoint, Vector3 hitNormal) { IDamageable objectHit = c.GetComponent <IDamageable>(); if (objectHit != null) { objectHit.TakeHit(damage, hitPoint, transform.forward, transform.forward.normalized * force, speed); } if (c.gameObject.tag == "Player") { if (c.gameObject.GetComponent <PlayerController>().GetState() == PlayerController.State.Invincible) { return; } } Renderer hitRenderer = c.GetComponent <Renderer>(); if (hitRenderer != null) { MaterialPropertyBlock hitBlock = new MaterialPropertyBlock(); ParticleSystem.MainModule main = hitEffect.main; hitRenderer.GetPropertyBlock(hitBlock); main.startColor = hitBlock.GetColor("_BaseColor"); } Instantiate(hitEffect, hitPoint, Quaternion.FromToRotation(Vector3.forward, -transform.forward)); }
void Update() { if (emissionColor != propertyBlock.GetColor("_EmissionColor")) { propertyBlock.SetColor("_EmissionColor", emissionColor); sr.SetPropertyBlock(propertyBlock); } if (dying || stunned) { return; } bool playerInRange = IsPlayerInRange(); if (playerInRange && !awake && !waking) { animator.SetTrigger("wake"); } else if (playerInRange && awake && !rolling && !preparingRoll && !stunned) { rollingDir = player.transform.position.x > transform.position.x ? 1 : -1; animator.SetBool("right", rollingDir == 1); preparingRoll = true; animator.SetTrigger("roll"); } else if (rolling) { float targetVelocityX = rollingDir * speed; velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, accelerationTime); velocity.y += gravity * Time.deltaTime; controller.Move(velocity * Time.deltaTime); // Reset velocity if ceiling or ground is hit if (controller.collisions.above || controller.collisions.below) { velocity.y = 0; } if (rollingDir == 1 && controller.collisions.right || rollingDir == -1 && controller.collisions.left) { velocity.x = 0; rolling = false; stunned = true; animator.SetTrigger("stun"); } CheckCollision(); } // Flip sprite if (sr.flipX != (rollingDir == 1)) { sr.flipX = rollingDir == 1; } }
public IEnumerator TestColorChildrenTheme() { Color state0Color = Color.red; Color state1Color = Color.blue; var defaultStateValues = new List <List <ThemePropertyValue> >() { new List <ThemePropertyValue>() { new ThemePropertyValue() { Color = state0Color }, new ThemePropertyValue() { Color = state1Color }, } }; const int numOfChildren = 3; var parent = new GameObject("Parent"); for (int i = 0; i < numOfChildren; i++) { var childCube = GameObject.CreatePrimitive(PrimitiveType.Cube); childCube.transform.parent = parent.transform; childCube.GetComponent <Renderer>().material.color = Color.white; } yield return(TestTheme <InteractableColorChildrenTheme, AudioSource>(parent, defaultStateValues, (host, theme) => { foreach (Transform child in host.transform) { Assert.AreEqual(Color.white, child.GetComponent <Renderer>().material.color); } }, (theme) => { var block = new MaterialPropertyBlock(); foreach (Transform child in theme.Host.transform) { child.GetComponent <Renderer>().GetPropertyBlock(block); Assert.AreEqual(state0Color, block.GetColor(DefaultColorProperty)); } }, (theme) => { var block = new MaterialPropertyBlock(); foreach (Transform child in theme.Host.transform) { child.GetComponent <Renderer>().GetPropertyBlock(block); Assert.AreEqual(state1Color, block.GetColor(DefaultColorProperty)); } })); }
public void SetFadedState() { Color colourToFade = matPropBlock.GetColor("_Color"); colourToFade.a = 0.5f; matPropBlock.SetColor("_Color", colourToFade); textMesh.color = new Color(textMesh.color.r, textMesh.color.g, textMesh.color.b, 0.5f); }
/// <summary> /// Получить цвет эмиссии материала. /// </summary> /// <param name="mesh">Текущий MeshRenderer.</param> /// <param name="props">Текущий PropertyBlock.</param> public static Color GetMaterialPropertyEmissionColor(MeshRenderer mesh, MaterialPropertyBlock props) { if (!isSetup) { Init(); } mesh.GetPropertyBlock(props); return(props.GetColor(props_EmissionColor)); }
public Color Retrieve(MaterialPropertyBlock inBlock) { Color c = inBlock.GetColor(GetPropertyId()); c.r /= Multiplier.r; c.g /= Multiplier.g; c.b /= Multiplier.b; c.a /= Multiplier.a; return(c); }
public static void OnFixAnimationTime() { var pb = new MaterialPropertyBlock(); var objs = Object.FindObjectsOfType <Animator>(); foreach (var animator in objs) { var acs = AnimationUtility.GetAnimationClips(animator.gameObject); foreach (var animationClip in acs) { animationClip.SampleAnimation(animator.gameObject, 0.0f); } var render = animator.gameObject.GetComponent <Renderer>(); if (render == null) { continue; } render.GetPropertyBlock(pb); var shader = render.material.shader; for (int i = 0; i < shader.GetPropertyCount(); i++) { var type = shader.GetPropertyType(i); switch (type) { case ShaderPropertyType.Color: render.material.SetColor(i, pb.GetColor(i)); break; case ShaderPropertyType.Vector: render.material.SetVector(i, pb.GetVector(i)); break; case ShaderPropertyType.Float: render.material.SetFloat(i, pb.GetFloat(i)); break; case ShaderPropertyType.Range: break; case ShaderPropertyType.Texture: render.material.SetTexture(i, pb.GetTexture(i)); break; default: throw new ArgumentOutOfRangeException(); } } } }
private void SetRendererMaterialAlpha(float alpha) { if (_renderer == null) { return; } _renderer.GetPropertyBlock(_propertyBlock); var color = _propertyBlock.GetColor("_Color"); color.a = alpha; _propertyBlock.SetColor("_Color", color); _renderer.SetPropertyBlock(_propertyBlock); }
public IEnumerator ShapeUpdate() { string entityId = "1"; TestHelpers.CreateSceneEntity(scene, entityId); var entity = scene.entities[entityId]; Assert.IsTrue(entity.meshRootGameObject == null, "entity mesh object should be null as the NFTShape hasn't been initialized yet"); var componentModel = new NFTShape.Model() { src = "ethereum://0x06012c8cf97BEaD5deAe237070F9587f8E7A266d/558536" }; NFTShape component = TestHelpers.SharedComponentCreate <NFTShape, NFTShape.Model>(scene, CLASS_ID.NFT_SHAPE, componentModel); yield return(component.routine); TestHelpers.SharedComponentAttach(component, entity); Assert.IsTrue(entity.meshRootGameObject != null, "entity mesh object should already exist as the NFTShape already initialized"); var nftShape = LoadableShape.GetLoaderForEntity(entity) as LoadWrapper_NFT; var backgroundMaterialPropertyBlock = new MaterialPropertyBlock(); nftShape.loaderController.meshRenderer.GetPropertyBlock(backgroundMaterialPropertyBlock, 1); Assert.IsTrue(backgroundMaterialPropertyBlock.GetColor("_BaseColor") == new Color(0.6404918f, 0.611472f, 0.8584906f), "The NFT frame background color should be the default one"); // Update color and check if it changed componentModel.color = Color.yellow; yield return(TestHelpers.SharedComponentUpdate(component, componentModel)); nftShape.loaderController.meshRenderer.GetPropertyBlock(backgroundMaterialPropertyBlock, 1); Assert.AreEqual(Color.yellow, backgroundMaterialPropertyBlock.GetColor("_BaseColor"), "The NFT frame background color should be yellow"); }
public bool Render(Material decalMaterial, MaterialPropertyBlock partMPB, Camera camera) { if (_projectionEnabled) { _decalMPB.SetFloat(PropertyIDs._RimFalloff, partMPB.GetFloat(PropertyIDs._RimFalloff)); _decalMPB.SetColor(PropertyIDs._RimColor, partMPB.GetColor(PropertyIDs._RimColor)); Graphics.DrawMesh(_targetMesh, target.localToWorldMatrix, decalMaterial, 0, camera, 0, _decalMPB, ShadowCastingMode.Off, true); return(true); } return(false); }
private static void SetValues(Material mat, MaterialPropertyBlock block, ShaderValues[] values) { foreach (var val in values) { if (val.type == "Float") { var _float = block.GetFloat(val.value); mat.SetFloat(val.value, _float); } else if (val.type == "Color") { var _color = block.GetColor(val.value); mat.SetColor(val.value, _color); } } }
void Update() { if (emissionColor != propertyBlock.GetColor("_EmissionColor")) { propertyBlock.SetColor("_EmissionColor", emissionColor); sr.SetPropertyBlock(propertyBlock); } bool playerInRange = IsPlayerInRange(); if (playerInRange && !shooting && shootTime + shootCooldown <= Time.time) { shooting = true; animator.SetTrigger("shoot"); } }
// Updates the HighlightObject for a button // Takes the GameObject of the highlight, whether or not the button is touched, and the color of the highlight private void UpdateHighlight(GameObject control, bool active, MaterialPropertyBlock block) { Renderer render = control.GetComponent <Renderer>(); // Get the renderer of the HighlightObject // If the renderer is enabled, alter the object's opacity if (render.enabled) { Color color = block.GetColor("_BaseColor"); // Get the current color of the object // If the associated button is touched, increase the object's opacity if (active) { // Only increase opacity if it isn't at its maximum if (color.a <= .5f) { color.a += Time.deltaTime * FadeSpeed; } // If the opacity has reached its max, set it to the max (just in case it has gone over) else { color.a = .5f; } } // If the associated button isn't touched, decrease the object's opacity (or disable it) else { // Only decrease opacity if it isn't at its minimum if (color.a >= 0f) { color.a -= Time.deltaTime * FadeSpeed; } // If the opacity has reached its minimum, hide the object else { color.a = 0f; render.enabled = false; } } // Change the color/opacity of the object block.SetColor("_BaseColor", color); // Set the block's opacity to the new opacity render.SetPropertyBlock(block); } // If the object isn't visible, but it's button is touched, make it visible else if (active) { render.enabled = true; } }
protected override void Start() { base.Start(); m_crosshair = gameObject.GetComponentInChildren <GrabbableCrosshair>(); m_renderer = GetRenderer(); m_crosshairManager = FindObjectOfType <GrabManager>(); m_mpb = new MaterialPropertyBlock(); RefreshCrosshair(); initialColor = m_mpb.GetColor(m_materialColorField); if (m_renderer == null) { return; } m_renderer.SetPropertyBlock(m_mpb); }
void Update() { if (emissionColor != propertyBlock.GetColor("_EmissionColor")) { propertyBlock.SetColor("_EmissionColor", emissionColor); bodySr.SetPropertyBlock(propertyBlock); } bool playerInRange = IsPlayerInRange(); if (playerInRange && !dashing && !preparingDash) { animator.SetTrigger("prepareDash"); preparingDash = true; } else if (playerInRange && preparingDash) { // Set direction direction = (player.transform.position - new Vector3(0, 0.2f)) - transform.position; transform.rotation = Quaternion.Euler(0, 0, Vector2.SignedAngle(Vector2.down, direction)); } else if (dashing) { Vector2 targetVelocity = direction.normalized * speed; velocity = Vector2.SmoothDamp(velocity, targetVelocity, ref velocitySmoothing, accelerationTime); // Check for ground collision RaycastHit2D hitGround = Physics2D.Raycast(rayOrigin.position, velocity, velocity.magnitude * Time.deltaTime, groundLayer); if (hitGround) { Debug.Log("Ground!"); Kill(); } // Check for ground collision RaycastHit2D hitPlayer = Physics2D.Raycast(rayOrigin.position, velocity, velocity.magnitude * Time.deltaTime, playerLayer); if (hitPlayer) { player.Damage(); player.Knockback(direction.normalized * playerKnockbackForce); Kill(); } transform.position += (Vector3)velocity * Time.deltaTime; } }
void Populate_ROI_List_fig(IList <ROI> current_rOIs) { foreach (var roi in current_rOIs) { var item = Instantiate(ItemPrefab_ROI.gameObject) as GameObject; var region = item.GetComponentsInChildren <Text>().Single(a => a.name == "Region"); var factor = item.GetComponentsInChildren <Text>().Single(a => a.name == "Factor"); var legend = item.GetComponentsInChildren <Image>().Single(a => a.name == "Legend"); region.text = roi.Region; factor.text = roi.Importance_factor; MaterialPropertyBlock properties = new MaterialPropertyBlock(); Region_obj_holder.GetComponentsInChildren <Transform>().Single(a => a.name.Equals(roi.Region, StringComparison.CurrentCultureIgnoreCase)).GetComponent <Renderer>().GetPropertyBlock(properties); legend.GetComponent <Image>().color = properties.GetColor("_Color"); item.transform.SetParent(Content.transform); } }
void OnTriggerEnter(Collider c) { if (c.gameObject.layer == LayerMask.NameToLayer("Ground")) { Renderer hitRenderer = c.GetComponent <Renderer>(); if (hitRenderer != null) { MaterialPropertyBlock hitBlock = new MaterialPropertyBlock(); ParticleSystem.MainModule main = hitEffect.main; hitRenderer.GetPropertyBlock(hitBlock); main.startColor = hitBlock.GetColor("_BaseColor"); } Instantiate(hitEffect, transform.position, Quaternion.FromToRotation(Vector3.forward, -transform.forward)); enabled = false; GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll; Destroy(gameObject, 2); } }
public void SamplerData() { var binds = AnimationUtility.GetCurveBindings(animationClip); GameObject gameObject = new GameObject("TMP"); gameObject.tag = "EditorOnly"; var renderer = gameObject.AddComponent <MeshRenderer>(); renderer.material = new Material(Shader.Find("HLFx/TextureColorMask")); renderer.GetPropertyBlock(block); for (int i = 0; i <= framesCount; i++) { float time = duration * i / framesCount; animationClip.SampleAnimation(gameObject, time); renderer.GetPropertyBlock(block); glyphMatrix.Add(gameObject.transform.localToWorldMatrix); var color = block.GetColor("_Color"); var colorV = new Vector4(color.r, color.g, color.b, color.a); if (colorV != Vector4.zero) { _Color.Add(colorV); } Debug.Log("color:" + color); } animationDataProperies.Add(new AnimationClipProperty("animationMatrix", ShaderParameter.ParameterTypeMatrix4x4)); if (_Color.Count > 0) { animationDataProperies.Add(new AnimationClipProperty("_Color", ShaderParameter.ParameterTypeFloat4)); } Object.DestroyImmediate(gameObject); }
public void UpdateMaterialProperties(Material material, MaterialPropertyBlock mpb) { if (!material.HasProperty(id)) { return; } switch (type) { case ShaderPropertyType.Color: var color = mpb.GetColor(id); if (color != default(Color)) { material.SetColor(id, color); } break; case ShaderPropertyType.Vector: var vector = mpb.GetVector(id); if (vector != default(Vector4)) { material.SetVector(id, vector); } break; case ShaderPropertyType.Float: case ShaderPropertyType.Range: var value = mpb.GetFloat(id); if (value != default(float)) { material.SetFloat(id, value); } break; case ShaderPropertyType.Texture: var tex = mpb.GetTexture(id); if (tex != default(Texture)) { material.SetTexture(id, tex); } break; } }
private IEnumerator ChangeColor() { Color randomColor; float t; while (true) { randomColor = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);; t = 0; while (t < 1) { _propertyBlock.SetColor("_Color", Color.Lerp(_propertyBlock.GetColor("_Color"), randomColor, t)); _renderer.SetPropertyBlock(_propertyBlock); t += Time.deltaTime * speed; yield return(null); } } }
void Update() { if (emissionColor != propertyBlock.GetColor("_EmissionColor")) { propertyBlock.SetColor("_EmissionColor", emissionColor); sr.SetPropertyBlock(propertyBlock); } bool playerInRange = IsPlayerInRange(); if (playerInRange && !grown && !growing) { growing = true; animator.SetTrigger("grow"); } else if (playerInRange && grown) { Explode(); } }
/// <summary> /// Copy the value from MaterialPropertyBlock to CanvasRenderer (#41) /// </summary> void UpdateAnimatableMaterialProperties() { #if UNITY_EDITOR if (!Application.isPlaying) { return; } #endif if (0 == m_AnimatableProperties.Length) { return; } _renderer.GetPropertyBlock(s_Mpb); for (int i = 0; i < canvasRenderer.materialCount; i++) { var mat = canvasRenderer.GetMaterial(i); foreach (var ap in m_AnimatableProperties) { switch (ap.type) { case ShaderPropertyType.Color: mat.SetColor(ap.id, s_Mpb.GetColor(ap.id)); break; case ShaderPropertyType.Vector: mat.SetVector(ap.id, s_Mpb.GetVector(ap.id)); break; case ShaderPropertyType.Float: case ShaderPropertyType.Range: mat.SetFloat(ap.id, s_Mpb.GetFloat(ap.id)); break; case ShaderPropertyType.Texture: mat.SetTexture(ap.id, s_Mpb.GetTexture(ap.id)); break; } } } }