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); Vector2 startScale = Vector2.zero; if (_Block.isEmpty) { startScale = _CachedTarget.sharedMaterial.GetTextureScale(_CachedPropertyName); } else { Vector4 texST = _Block.GetVector(_CachedPropertyName + "_ST"); startScale = new Vector2(texST.x, texST.y); } switch (_TweenMoveType) { case TweenMoveType.Absolute: break; case TweenMoveType.Relative: _CachedFromValue += startScale; _CachedToValue += startScale; break; case TweenMoveType.ToAbsolute: _CachedFromValue = startScale; break; } }
private void SetRimFactor(float _rimFactor) { for (int i = 0; i < m_rnrRimlights.Length; i++) { m_rnrRimlights[i].GetPropertyBlock(m_MaterialPropertyBlock); Vector4 fadeData = m_MaterialPropertyBlock.GetVector(_RimEffectFadeData); fadeData = GetFadeInterpolateData(fadeData, _rimFactor); m_MaterialPropertyBlock.SetColor(ShaderPropertyDefine._RimColor, m_colRimColor); m_MaterialPropertyBlock.SetFloat(ShaderPropertyDefine._RimPower, m_fRimPower); m_MaterialPropertyBlock.SetVector(_RimEffectFadeData, fadeData); m_rnrRimlights[i].SetPropertyBlock(m_MaterialPropertyBlock); } }
public static Matrix4x4 GetFollowerPose(Renderer ren) { Matrix4x4 M = new Matrix4x4(); MaterialPropertyBlock propblock = new MaterialPropertyBlock(); ren.GetPropertyBlock(propblock); M.SetRow(0, propblock.GetVector("_followerpose1")); M.SetRow(1, propblock.GetVector("_followerpose2")); M.SetRow(2, propblock.GetVector("_followerpose3")); M.SetRow(3, propblock.GetVector("_followerpose4")); return(M); }
public void Transformation(float val) { val *= 0.5f; block.SetVector(property, Vector2.Scale(block.GetVector(property), (val - lastVal) * axis + Vector2.one)); lastVal = val; renderer.SetPropertyBlock(block); }
public void Transformation(float val) { val *= 0.1f; block.SetVector(property, (Vector2)(block.GetVector(property)) + (val - lastVal) * axis); lastVal = val; renderer.SetPropertyBlock(block); }
static int GetVector(IntPtr L) { int count = LuaDLL.lua_gettop(L); Type[] types0 = { typeof(MaterialPropertyBlock), typeof(int) }; Type[] types1 = { typeof(MaterialPropertyBlock), typeof(string) }; if (count == 2 && LuaScriptMgr.CheckTypes(L, types0, 1)) { MaterialPropertyBlock obj = LuaScriptMgr.GetNetObject <MaterialPropertyBlock>(L, 1); int arg0 = (int)LuaScriptMgr.GetNumber(L, 2); Vector4 o = obj.GetVector(arg0); LuaScriptMgr.PushValue(L, o); return(1); } else if (count == 2 && LuaScriptMgr.CheckTypes(L, types1, 1)) { MaterialPropertyBlock obj = LuaScriptMgr.GetNetObject <MaterialPropertyBlock>(L, 1); string arg0 = LuaScriptMgr.GetString(L, 2); Vector4 o = obj.GetVector(arg0); LuaScriptMgr.PushValue(L, o); return(1); } else { LuaDLL.luaL_error(L, "invalid arguments to method: MaterialPropertyBlock.GetVector"); } return(0); }
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); }
public static void Play(this MeshAnimationAsset asset, MaterialPropertyBlock block, string animationName, float speed = 1f, float?normalizedTime = 0f) { MeshAnimationAsset.AnimationData data = null; foreach (var animationData in asset.animationData) { if (animationData.name != animationName) { continue; } data = animationData; break; } if (data == null) { return; } var start = data.startFrame; var length = data.lengthFrames; var s = speed / Mathf.Max(data.lengthSeconds, 0.01f); var time = normalizedTime.HasValue ? Time.timeSinceLevelLoad + Mathf.Clamp01(normalizedTime.Value) * data.lengthSeconds : block.GetVector(AnimationTimeProp).z; block.SetFloat(AnimationLoopProp, data.looping ? 1 : 0); block.SetVector(AnimationTimeProp, new Vector4(start, length, s, time)); }
public override InteractableThemePropertyValue GetProperty(InteractableThemeProperty property) { if (Host == null) { return(emptyValue); } renderer.GetPropertyBlock(propertyBlock); startValue.Reset(); int propId = property.GetShaderPropertyId(); switch (property.Type) { case InteractableThemePropertyValueTypes.Color: startValue.Color = propertyBlock.GetVector(propId); break; case InteractableThemePropertyValueTypes.ShaderFloat: startValue.Float = propertyBlock.GetFloat(propId); break; case InteractableThemePropertyValueTypes.shaderRange: startValue.Float = propertyBlock.GetFloat(propId); break; default: break; } return(startValue); }
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; } }
public override InteractableThemePropertyValue GetProperty(InteractableThemeProperty property) { if (Host == null) { return(new InteractableThemePropertyValue()); } InteractableThemePropertyValue start = new InteractableThemePropertyValue(); string propId = property.GetShaderPropId(); switch (property.Type) { case InteractableThemePropertyValueTypes.Color: start.Color = propertyBlock.GetVector(propId); break; case InteractableThemePropertyValueTypes.ShaderFloat: start.Float = propertyBlock.GetFloat(propId); break; case InteractableThemePropertyValueTypes.shaderRange: start.Float = propertyBlock.GetFloat(propId); break; default: break; } return(start); }
/// <inheritdoc /> public override ThemePropertyValue GetProperty(ThemeStateProperty property) { if (renderer == null) { return(null); } renderer.GetPropertyBlock(propertyBlock); startValue.Reset(); int propId = property.GetShaderPropertyId(); switch (property.Type) { case ThemePropertyTypes.Color: startValue.Color = propertyBlock.GetVector(propId); break; case ThemePropertyTypes.Texture: startValue.Texture = propertyBlock.GetTexture(propId); break; case ThemePropertyTypes.ShaderFloat: case ThemePropertyTypes.ShaderRange: startValue.Float = propertyBlock.GetFloat(propId); break; default: break; } return(startValue); }
IEnumerator GhostExplosion() { float explosionSize = 0; MaterialPropertyBlock blocker = new MaterialPropertyBlock(); m_GhostExplostionRenderer.GetPropertyBlock(blocker); Color color = blocker.GetVector("_Color"); SoundManager.Instance.PlayEvent(SoundEvents.Play_Rvn_Explosion, gameObject); while (explosionSize < m_fGhostExplosionDuration) { explosionSize = Mathf.Lerp(explosionSize, m_fGhostExplosionDuration, Time.deltaTime); explosionSize = explosionSize + 0.1f; color.a = Mathf.Lerp(color.a, 0, Time.deltaTime); blocker.SetColor("_Color", color); m_GhostExplostionRenderer.SetPropertyBlock(blocker); m_GhostExplosion.transform.localScale = m_GhostExplosion.transform.localScale = new Vector3(explosionSize, explosionSize, explosionSize); yield return(null); } Destroy(gameObject); }
void DoGetMaterialColor() { if (color.IsNone) { return; } var colorName = propertyName.Value; if (colorName == "") { colorName = "_Color"; } var go = Fsm.GetOwnerDefaultTarget(gameObject); if (!UpdateCache(go)) { return; } if (renderer.material == null) { LogError("Missing Material!"); return; } renderer.GetPropertyBlock(_propBlock); color.Value = (Color)_propBlock.GetVector(colorName); }
public virtual Color Get_Color(Renderer target, string ColorName) { MaterialPropertyBlock mabb = new MaterialPropertyBlock(); target.GetPropertyBlock(mabb); return(mabb.GetVector(ColorName)); }
protected virtual void UpdateUIMeshFromComponent(Component p_meshComponent) { UIMeshGraphic v_meshGraphic = null; if (p_meshComponent != null) { var v_meshFilter = p_meshComponent as MeshFilter; var v_skinnedRenderer = p_meshComponent as SkinnedMeshRenderer; if (v_meshFilter != null) { v_meshGraphic = v_meshFilter.GetComponent <UIMeshFilter>(); if (v_meshGraphic == null) { v_meshGraphic = v_meshFilter.gameObject.AddComponent <UIMeshFilter>(); v_meshGraphic.hideFlags = HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor; } var v_renderer = v_meshFilter.GetComponent <Renderer>(); v_meshGraphic.material = TryGetMaterialToReplace(v_renderer != null ? v_renderer.sharedMaterial : null); //Try Pick Color Component From Renderer MaterialPropertyBlock if (v_renderer != null) { MaterialPropertyBlock v_propertyBlock = new MaterialPropertyBlock(); v_renderer.GetPropertyBlock(v_propertyBlock); if (!v_propertyBlock.isEmpty) { Vector4 v_colorVector = v_propertyBlock.GetVector("_Color"); if (v_colorVector != Vector4.zero) { v_meshGraphic.color = new Color(v_colorVector.x, v_colorVector.y, v_colorVector.z, v_colorVector.w); } v_meshGraphic.Texture = v_propertyBlock.GetTexture("_MainTex") as Texture2D; } } } if (v_skinnedRenderer != null) { v_meshGraphic = v_skinnedRenderer.GetComponent <UISkinnedMeshFilter>(); if (v_meshGraphic == null) { v_meshGraphic = v_skinnedRenderer.gameObject.AddComponent <UISkinnedMeshFilter>(); } v_meshGraphic.material = TryGetMaterialToReplace(v_skinnedRenderer.sharedMaterial); //Try Pick Color Component From SkinnedRenderer MaterialPropertyBlock MaterialPropertyBlock v_propertyBlock = new MaterialPropertyBlock(); v_skinnedRenderer.GetPropertyBlock(v_propertyBlock); if (!v_propertyBlock.isEmpty) { Vector4 v_colorVector = v_propertyBlock.GetVector("_Color"); if (v_colorVector != Vector4.zero) { v_meshGraphic.color = new Color(v_colorVector.x, v_colorVector.y, v_colorVector.z, v_colorVector.w); } v_meshGraphic.Texture = v_propertyBlock.GetTexture("_MainTex") as Texture2D; } } } }
public override void SetIn() { // Make sure we have a renderer, try to get it otherwise. if (_renderer == null) { _renderer = GetComponent <Renderer>(); } if (_renderer == null) { return; } // Fetch material properties. _renderer.GetPropertyBlock(_propertyBlock); // Fetch color. _inColor = _propertyBlock.GetVector(ShaderColorName); _inStateSet = true; }
public static Color GetColor(GameObject host, int propId) { if (host == null) { return(Color.white); } MaterialPropertyBlock block = InteractableThemeShaderUtils.GetPropertyBlock(host); return(block.GetVector(propId)); }
public Vector4 GetVector( int propertyId) { if (instancedProperties.Contains(propertyId)) { return(materialPropertyBlock.GetVector(propertyId)); } else { return(material.GetVector(propertyId)); } }
public Color GetColor(int propName) { if (mInstancing) { if (mMatPropBlock == null) { return(Color.black); } return(mMatPropBlock.GetVector(propName)); } else { if (mMat == null) { return(Color.black); } return(mMat.GetColor(propName)); } }
void LerpToColorProperty(Color targetColor, string colorProp, float progress) { foreach (SkinnedMeshRenderer meshRenderer in MeshRenderers) { MaterialPropertyBlock props = new MaterialPropertyBlock(); meshRenderer.GetPropertyBlock(props); Color currentColor = props.GetVector(colorProp); currentColor = Color.Lerp(currentColor, targetColor, progress); props.SetColor(colorProp, currentColor); meshRenderer.SetPropertyBlock(props); } }
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(); } } } }
/// <inheritdoc /> public override ThemePropertyValue GetProperty(ThemeStateProperty property) { var result = new ThemePropertyValue(); int propId = property.GetShaderPropertyId(); if (renderer != null) { renderer.GetPropertyBlock(propertyBlock); switch (property.Type) { case ThemePropertyTypes.Color: result.Color = propertyBlock.GetVector(propId); break; case ThemePropertyTypes.Texture: result.Texture = propertyBlock.GetTexture(propId); break; case ThemePropertyTypes.ShaderFloat: case ThemePropertyTypes.ShaderRange: result.Float = propertyBlock.GetFloat(propId); break; default: break; } } else if (graphic != null) { switch (property.Type) { case ThemePropertyTypes.Color: result.Color = graphic.material.GetVector(propId); break; case ThemePropertyTypes.Texture: result.Texture = graphic.material.GetTexture(propId); break; case ThemePropertyTypes.ShaderFloat: case ThemePropertyTypes.ShaderRange: result.Float = graphic.material.GetFloat(propId); break; default: break; } } return(result); }
protected virtual IEnumerator CycleColor(Renderer renderer, MaterialPropertyBlock highlightMaterialPropertyBlock, Color endColor, float duration) { var elapsedTime = 0f; while (elapsedTime <= duration) { elapsedTime += Time.deltaTime; Color startColor = highlightMaterialPropertyBlock.GetVector("_Color"); highlightMaterialPropertyBlock.SetColor("_Color", Color.Lerp(startColor, endColor, (elapsedTime / duration))); highlightMaterialPropertyBlock.SetColor("_EmissionColor", Color.Lerp(startColor, endColor, (elapsedTime / duration))); if (!renderer) { yield break; } renderer.SetPropertyBlock(highlightMaterialPropertyBlock); yield return null; } }
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; } }
public static Tweener DoMaterialVector4To(this Renderer target, string name, Vector4 endValue, float duration, Ease ease = Ease.Linear) { return(DOTween.To(() => { MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock(); target.GetPropertyBlock(materialPropertyBlock); return materialPropertyBlock.GetVector(name); }, (Vector4 value) => { MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock(); target.GetPropertyBlock(materialPropertyBlock); var oldColor = materialPropertyBlock.GetVector(name); oldColor = value; materialPropertyBlock.SetVector(name, oldColor); target.SetPropertyBlock(materialPropertyBlock); }, endValue, duration).SetEase(ease)); }
public static Tweener DOFadeWithMaterialPropertyBlock(this Renderer target, float endValue, float duration, Ease ease = Ease.Linear) { return(DOTween.To(() => { MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock(); target.GetPropertyBlock(materialPropertyBlock); return materialPropertyBlock.GetVector("_Color").w; }, (float value) => { MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock(); target.GetPropertyBlock(materialPropertyBlock); var oldColor = materialPropertyBlock.GetVector("_Color"); oldColor.w = value; materialPropertyBlock.SetVector("_Color", oldColor); target.SetPropertyBlock(materialPropertyBlock); }, endValue, duration).SetEase(ease)); }
/// <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; } } } }
public static int GetVector(IntPtr l) { int result; try { int total = LuaDLL.lua_gettop(l); if (LuaObject.matchType(l, total, 2, typeof(string))) { MaterialPropertyBlock materialPropertyBlock = (MaterialPropertyBlock)LuaObject.checkSelf(l); string name; LuaObject.checkType(l, 2, out name); Vector4 vector = materialPropertyBlock.GetVector(name); LuaObject.pushValue(l, true); LuaObject.pushValue(l, vector); result = 2; } else if (LuaObject.matchType(l, total, 2, typeof(int))) { MaterialPropertyBlock materialPropertyBlock2 = (MaterialPropertyBlock)LuaObject.checkSelf(l); int nameID; LuaObject.checkType(l, 2, out nameID); Vector4 vector2 = materialPropertyBlock2.GetVector(nameID); LuaObject.pushValue(l, true); LuaObject.pushValue(l, vector2); result = 2; } else { LuaObject.pushValue(l, false); LuaDLL.lua_pushstring(l, "No matched override function GetVector to call"); result = 2; } } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
public Color GetColor(int name) { CheckLoad(); return((Color)Block.GetVector(name)); }