예제 #1
0
        public static void Read(BinaryReader message)
        {
            string propertyName = message.ReadString();
            MaterialPropertyType propertyType = (MaterialPropertyType)message.ReadByte();

            switch (propertyType)
            {
            case MaterialPropertyType.Color:
                Shader.SetGlobalColor(propertyName, message.ReadColor());
                break;

            case MaterialPropertyType.Float:
            case MaterialPropertyType.Range:
                Shader.SetGlobalFloat(propertyName, message.ReadSingle());
                break;

            case MaterialPropertyType.Texture:
            {
                Texture texture;
                if (AssetService.Instance.TryDeserializeTexture(message, out texture))
                {
                    Shader.SetGlobalTexture(propertyName, texture);
                }
            }
            break;

            case MaterialPropertyType.Vector:
                Shader.SetGlobalVector(propertyName, message.ReadVector4());
                break;

            case MaterialPropertyType.Matrix:
                Shader.SetGlobalMatrix(propertyName, message.ReadMatrix4x4());
                break;
            }
        }
예제 #2
0
        private int GetAlignedPropertySize(MaterialPropertyType propertyType)
        {
            switch (propertyType)
            {
            case MaterialPropertyType.Int:
                return(AlignSize(sizeof(int), alignment));

            case MaterialPropertyType.Float:
                return(AlignSize(sizeof(float), alignment));

            case MaterialPropertyType.Vector2:
                return(AlignSize(Vector2.SizeInBytes, alignment));

            case MaterialPropertyType.Vector3:
                return(AlignSize(Vector3.SizeInBytes, alignment));

            case MaterialPropertyType.Vector4:
                return(AlignSize(Vector4.SizeInBytes, alignment));

            case MaterialPropertyType.Matrix2:
                return(AlignSize(sizeof(float) * 4, alignment));

            case MaterialPropertyType.Matrix3:
                return(AlignSize(sizeof(float) * 9, alignment));

            case MaterialPropertyType.Matrix4:
                return(AlignSize(sizeof(float) * 16, alignment));

            case MaterialPropertyType.Texture:
                return(AlignSize(sizeof(long), alignment));

            default:
                throw new Exception("Invalid property type!");
            }
        }
    private static float _GetMaterialProperty(Material obj, MaterialPropertyType pType, string paramName)
    {
        Vector2 offs;

        switch (pType)
        {
        case MaterialPropertyType.TextureOffset_X:
            offs = obj.mainTextureOffset;
            return(offs.x);

        case MaterialPropertyType.TextureOffset_Y:
            offs = obj.mainTextureOffset;
            return(offs.y);

        case MaterialPropertyType.TextureScale_X:
            offs = obj.mainTextureScale;
            return(offs.x);

        case MaterialPropertyType.TextureScale_Y:
            offs = obj.mainTextureScale;
            return(offs.y);

        case MaterialPropertyType.Float:
            if (paramName != null && paramName.Length > 0)
            {
                return(obj.GetFloat(paramName));
            }
            break;
        }

        return(0.0f);
    }
    private static float _GetColor(Material obj, MaterialPropertyType pType, string paramName)
    {
        Color c;

        if(paramName == null || paramName.Length == 0) {
            c = obj.color;
        } else {
            c = obj.GetColor(paramName);
        }

        switch(pType) {
        case MaterialPropertyType.Color_R:
            return c.r;
        case MaterialPropertyType.Color_G:
            return c.g;
        case MaterialPropertyType.Color_B:
            return c.b;
        case MaterialPropertyType.Color_RGB:
            return c.r;
        case MaterialPropertyType.Color_A:
            return c.a;
        case MaterialPropertyType.Color_R_Relative:
            return c.r;
        case MaterialPropertyType.Color_G_Relative:
            return c.g;
        case MaterialPropertyType.Color_B_Relative:
            return c.b;
        case MaterialPropertyType.Color_RGB_Relative:
            return c.r;
        case MaterialPropertyType.Color_A_Relative:
            return c.a;
        }

        return 0.0f;
    }
            public bool HasValue(int propertyId, MaterialPropertyType materialPropertyType)
            {
                switch (materialPropertyType)
                {
                case MaterialPropertyType.Color:
                    return(HasValue(propertyId, unityPropertyBlock.GetColor));

                case MaterialPropertyType.Float:
                case MaterialPropertyType.Range:
                    return(HasValue(propertyId, unityPropertyBlock.GetFloat));

                case MaterialPropertyType.Matrix:
                    return(HasValue(propertyId, unityPropertyBlock.GetMatrix));

                case MaterialPropertyType.Texture:
                    return(HasValue(propertyId, unityPropertyBlock.GetTexture));

                case MaterialPropertyType.Vector:
                    return(HasValue(propertyId, unityPropertyBlock.GetVector));

                case MaterialPropertyType.RenderQueue:
                case MaterialPropertyType.ShaderKeywords:
                    return(false);

                default:
                    throw new InvalidOperationException();
                }
            }
예제 #6
0
 /// <summary>
 /// Lerps a material's color to a target color over time.
 /// </summary>
 /// <param name="aMaterial">The material instance</param>
 /// <param name="aTime">How long should this take?</param>
 /// <param name="aTarget">What color are we going to?</param>
 /// <param name="aPropertyType">What is the property's type?</param>
 /// <param name="aPropertyName">What is the property's name?</param>
 /// <param name="aTargetColor">If it's a color, what color are we going to</param>
 /// <param name="aTargetValue">If it's a float, what float are we going to</param>
 /// <param name="aScaledTime">Should this be affected by scaled time?</param>
 /// <param name="aCallback">Now what?</param>
 public void LerpMaterialProptery(Material aMaterial, float aTime, MaterialPropertyType aPropertyType, string aPropertyName, Color aTargetColor = default(Color), float aTargetFloat = 0f, bool aScaledTime = true, AnimationCurve aCurve = null, System.Action aCallback = null, bool aAllowMultiple = false)
 {
     if (aAllowMultiple && !RegisterObject(aMaterial))
     {
         return;
     }
     StartCoroutine(CoLerpMaterialProptery(aMaterial, aTime, aPropertyType, aPropertyName, aTargetColor, aTargetFloat, aScaledTime, aCurve, aCallback));
 }
예제 #7
0
    IEnumerator CoLerpMaterialProptery(Material aMaterial, float aTime, MaterialPropertyType aPropertyType, string aPropertyName, Color aTargetColor = default(Color), float aTargetValue = 0f, bool scaledTime = true, AnimationCurve aCurve = null, System.Action aCallback = null)
    {
        if (aCurve == null)
        {
            aCurve = Juice.Instance.Linear;
        }

        float startTime        = Time.time;
        float percentCompleted = 0;
        Color startColor       = Color.white;
        float startFloat       = 0;

        switch (aPropertyType)
        {
        case MaterialPropertyType.Color:
            startColor = aMaterial.GetColor(aPropertyName);
            break;

        case MaterialPropertyType.Float:
            startFloat = aMaterial.GetFloat(aPropertyName);
            break;

        default:
            break;
        }

        while (percentCompleted < 1)
        {
            percentCompleted = (Time.time - startTime) / aTime;
            switch (aPropertyType)
            {
            case MaterialPropertyType.Color:
                aMaterial.SetColor(aPropertyName, Color.Lerp(startColor, aTargetColor, aCurve.Evaluate(percentCompleted)));
                break;

            case MaterialPropertyType.Float:
                aMaterial.SetFloat(aPropertyName, Mathf.Lerp(startFloat, aTargetValue, aCurve.Evaluate(percentCompleted)));
                break;

            default:
                break;
            }

            yield return(new WaitForEndOfFrame());

            if (aMaterial == null)
            {
                DeregisterObject(aMaterial);
                yield break;
            }
        }
        DeregisterObject(aMaterial);
        mCallbacks.Add(aCallback);
        yield break;
    }
예제 #8
0
        private MaterialProperty GetOrAddProperty(string name, MaterialPropertyType type)
        {
            var prop = Properties.FirstOrDefault(x => x.Name == name);

            if (prop == null)
            {
                Properties.Add(prop = new MaterialProperty {
                    Name = name
                });
            }
            prop.Type = type;
            return(prop);
        }
예제 #9
0
        private static void AddProperty(JArray properties, string name, MaterialPropertyType type, JToken value)
        {
            var existing = properties.FirstOrDefault(x => (string)x["name"] == name);

            if (existing != null)
            {
                existing["type"]  = (int)type;
                existing["value"] = value;
                return;
            }

            properties.Add(new JObject {
                { "name", name }, { "type", (int)type }, { "value", value }
            });
        }
    private static float _GetColor(Material obj, MaterialPropertyType pType, string paramName)
    {
        Color c;

        if (paramName == null || paramName.Length == 0)
        {
            c = obj.color;
        }
        else
        {
            c = obj.GetColor(paramName);
        }

        switch (pType)
        {
        case MaterialPropertyType.Color_R:
            return(c.r);

        case MaterialPropertyType.Color_G:
            return(c.g);

        case MaterialPropertyType.Color_B:
            return(c.b);

        case MaterialPropertyType.Color_RGB:
            return(c.r);

        case MaterialPropertyType.Color_A:
            return(c.a);

        case MaterialPropertyType.Color_R_Relative:
            return(c.r);

        case MaterialPropertyType.Color_G_Relative:
            return(c.g);

        case MaterialPropertyType.Color_B_Relative:
            return(c.b);

        case MaterialPropertyType.Color_RGB_Relative:
            return(c.r);

        case MaterialPropertyType.Color_A_Relative:
            return(c.a);
        }

        return(0.0f);
    }
    private static void _UpdateColor(Material obj, MaterialPropertyType pType, float val, string paramName)
    {
        Color c;

        if (paramName == null || paramName.Length == 0)
        {
            c = obj.color;
        }
        else
        {
            c = obj.GetColor(paramName);
        }

        switch (pType)
        {
        case MaterialPropertyType.Color_R:
            c.r = val;
            break;

        case MaterialPropertyType.Color_G:
            c.g = val;
            break;

        case MaterialPropertyType.Color_B:
            c.b = val;
            break;

        case MaterialPropertyType.Color_RGB:
            c.r = val;
            c.g = val;
            c.b = val;
            break;

        case MaterialPropertyType.Color_A:
            c.a = val;
            break;
        }

        if (paramName == null || paramName.Length == 0)
        {
            obj.color = c;
        }
        else
        {
            obj.SetColor(paramName, c);
        }
    }
    private static void _UpdateColorRelative(Material obj, MaterialPropertyType pType, float val, string paramName)
    {
        Color c;

        if (paramName == null || paramName.Length == 0)
        {
            c = obj.color;
        }
        else
        {
            c = obj.GetColor(paramName);
        }

        switch (pType)
        {
        case MaterialPropertyType.Color_R_Relative:
            c.r = Mathf.Clamp01(c.r + val);
            break;

        case MaterialPropertyType.Color_G_Relative:
            c.g = Mathf.Clamp01(c.g + val);
            break;

        case MaterialPropertyType.Color_B_Relative:
            c.b = Mathf.Clamp01(c.b + val);
            break;

        case MaterialPropertyType.Color_RGB_Relative:
            c.r = Mathf.Clamp01(c.r + val);
            c.g = Mathf.Clamp01(c.g + val);
            c.b = Mathf.Clamp01(c.b + val);
            break;

        case MaterialPropertyType.Color_A_Relative:
            c.a = Mathf.Clamp01(c.a + val);
            break;
        }

        if (paramName == null || paramName.Length == 0)
        {
            obj.color = c;
        }
        else
        {
            obj.SetColor(paramName, c);
        }
    }
예제 #13
0
        public static ValueDropdownList <string> ShaderPropertyNames(Material mat, MaterialPropertyType type)
        {
            switch (type)
            {
            case MaterialPropertyType.FLOAT:
                return(ShaderFloatPropertyNames(mat));

            case MaterialPropertyType.COLOR:
                return(ShaderColorPropertyNames(mat));

            case MaterialPropertyType.TEXTURE:
                return(ShaderTexturePropertyNames(mat));

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
 public static float GetMaterialValue(Material obj, MaterialPropertyType pType, string paramName )
 {
     if( pType == MaterialPropertyType.Color_R 	||
     pType == MaterialPropertyType.Color_G 		||
     pType == MaterialPropertyType.Color_B 		||
     pType == MaterialPropertyType.Color_RGB 	||
     pType == MaterialPropertyType.Color_A 		||
     pType == MaterialPropertyType.Color_G_Relative 		||
     pType == MaterialPropertyType.Color_B_Relative 		||
     pType == MaterialPropertyType.Color_RGB_Relative 	||
     pType == MaterialPropertyType.Color_A_Relative 		)
     {
         return _GetColor(obj, pType, paramName);
     }
     else {
         return _GetMaterialProperty(obj, pType, paramName);
     }
 }
 public static float GetMaterialValue(Material obj, MaterialPropertyType pType, string paramName)
 {
     if (pType == MaterialPropertyType.Color_R ||
         pType == MaterialPropertyType.Color_G ||
         pType == MaterialPropertyType.Color_B ||
         pType == MaterialPropertyType.Color_RGB ||
         pType == MaterialPropertyType.Color_A ||
         pType == MaterialPropertyType.Color_G_Relative ||
         pType == MaterialPropertyType.Color_B_Relative ||
         pType == MaterialPropertyType.Color_RGB_Relative ||
         pType == MaterialPropertyType.Color_A_Relative)
     {
         return(_GetColor(obj, pType, paramName));
     }
     else
     {
         return(_GetMaterialProperty(obj, pType, paramName));
     }
 }
 public static void UpdateMaterial(Material obj, MaterialPropertyType pType, float val, string paramName )
 {
     if( pType == MaterialPropertyType.Color_R 	||
     pType == MaterialPropertyType.Color_G 		||
     pType == MaterialPropertyType.Color_B 		||
     pType == MaterialPropertyType.Color_RGB 	||
     pType == MaterialPropertyType.Color_A 		)
     {
         _UpdateColor(obj, pType, val, paramName);
     }
     else if( pType == MaterialPropertyType.Color_R_Relative 	||
     pType == MaterialPropertyType.Color_G_Relative 		||
     pType == MaterialPropertyType.Color_B_Relative 		||
     pType == MaterialPropertyType.Color_RGB_Relative 	||
     pType == MaterialPropertyType.Color_A_Relative 		)
     {
         _UpdateColorRelative(obj, pType, val, paramName);
     }
     else {
         _UpdateMaterialProperty(obj, pType, val, paramName);
     }
 }
    private static void _UpdateMaterialProperty(Material obj, MaterialPropertyType pType, float val, string paramName)
    {
        Vector2 offs;

        switch (pType)
        {
        case MaterialPropertyType.TextureOffset_X:
            offs   = obj.mainTextureOffset;
            offs.x = val;
            obj.mainTextureOffset = offs;
            break;

        case MaterialPropertyType.TextureOffset_Y:
            offs   = obj.mainTextureOffset;
            offs.y = val;
            obj.mainTextureOffset = offs;
            break;

        case MaterialPropertyType.TextureScale_X:
            offs   = obj.mainTextureScale;
            offs.x = val;
            obj.mainTextureScale = offs;
            break;

        case MaterialPropertyType.TextureScale_Y:
            offs   = obj.mainTextureScale;
            offs.y = val;
            obj.mainTextureScale = offs;
            break;

        case MaterialPropertyType.Float:
            if (paramName != null && paramName.Length > 0)
            {
                obj.SetFloat(paramName, val);
            }
            break;
        }
    }
예제 #18
0
        public TSSMaterialProperty(MaterialPropertyType propertyType)
        {
            type = propertyType;
            name = "_Property";
            switch (propertyType)
            {
            case MaterialPropertyType.single: singleValues = new float[TSSItemBase.stateCount] {
                    0, 1
            }; break;

            case MaterialPropertyType.integer: integerValues = new int[TSSItemBase.stateCount] {
                    0, 1
            }; break;

            case MaterialPropertyType.color: colorValues = new Color[TSSItemBase.stateCount] {
                    Color.white, Color.white
            }; break;

            case MaterialPropertyType.colorHDR: colorValues = new Color[TSSItemBase.stateCount] {
                    Color.white, Color.white
            }; break;

            case MaterialPropertyType.vector2: vector2values = new Vector2[TSSItemBase.stateCount]; break;

            case MaterialPropertyType.vector3: vector3values = new Vector3[TSSItemBase.stateCount]; break;

            case MaterialPropertyType.vector4: vector4values = new Vector4[TSSItemBase.stateCount]; break;

            case MaterialPropertyType.curve: curve = AnimationCurve.EaseInOut(0, 0, 1, 1); break;

            case MaterialPropertyType.gradient:
                gradient = new Gradient()
                {
                    colorKeys = new GradientColorKey[] { new GradientColorKey(Color.black, 0), new GradientColorKey(Color.white, 1) }
                };
                break;
            }
        }
 public static void UpdateMaterial(Material obj, MaterialPropertyType pType, float val, string paramName)
 {
     if (pType == MaterialPropertyType.Color_R ||
         pType == MaterialPropertyType.Color_G ||
         pType == MaterialPropertyType.Color_B ||
         pType == MaterialPropertyType.Color_RGB ||
         pType == MaterialPropertyType.Color_A)
     {
         _UpdateColor(obj, pType, val, paramName);
     }
     else if (pType == MaterialPropertyType.Color_R_Relative ||
              pType == MaterialPropertyType.Color_G_Relative ||
              pType == MaterialPropertyType.Color_B_Relative ||
              pType == MaterialPropertyType.Color_RGB_Relative ||
              pType == MaterialPropertyType.Color_A_Relative)
     {
         _UpdateColorRelative(obj, pType, val, paramName);
     }
     else
     {
         _UpdateMaterialProperty(obj, pType, val, paramName);
     }
 }
예제 #20
0
 public TextureMaterialProperty(MaterialPropertyType type, int textureId, int index) : base(type, textureId)
 {
     DataIndex = index;
 }
예제 #21
0
	/// <summary>
	/// Lerps a material's color to a target color over time.
	/// </summary>
	/// <param name="aMaterial">The material instance</param>
	/// <param name="aTime">How long should this take?</param>
	/// <param name="aTarget">What color are we going to?</param>
	/// <param name="aPropertyType">What is the property's type?</param>
	/// <param name="aPropertyName">What is the property's name?</param>
	/// <param name="aTargetColor">If it's a color, what color are we going to</param>
	/// <param name="aTargetValue">If it's a float, what float are we going to</param>
	/// <param name="aScaledTime">Should this be affected by scaled time?</param>
	/// <param name="aCallback">Now what?</param>
	public void LerpMaterialProptery(Material aMaterial, float aTime, MaterialPropertyType aPropertyType, string aPropertyName, Color aTargetColor = default(Color), float aTargetFloat = 0f, bool aScaledTime = true, AnimationCurve aCurve = null, System.Action aCallback = null, bool aAllowMultiple = false)
	{
		if (aAllowMultiple && !RegisterObject(aMaterial)) return;
		StartCoroutine(CoLerpMaterialProptery(aMaterial, aTime, aPropertyType, aPropertyName, aTargetColor, aTargetFloat, aScaledTime, aCurve, aCallback));
	}
    private static void _UpdateColor(Material obj, MaterialPropertyType pType, float val, string paramName)
    {
        Color c;

        if(paramName == null || paramName.Length == 0) {
            c = obj.color;
        } else {
            c = obj.GetColor(paramName);
        }

        switch(pType) {
        case MaterialPropertyType.Color_R:
            c.r = val;
        break;
        case MaterialPropertyType.Color_G:
            c.g = val;
        break;
        case MaterialPropertyType.Color_B:
            c.b = val;
        break;
        case MaterialPropertyType.Color_RGB:
            c.r = val;
            c.g = val;
            c.b = val;
        break;
        case MaterialPropertyType.Color_A:
            c.a = val;
        break;
        }

        if(paramName == null || paramName.Length == 0) {
            obj.color = c;
        } else {
            obj.SetColor(paramName, c);
        }
    }
예제 #23
0
        public override GameAsset ReadFromStream(BinaryReader reader)
        {
            string name   = reader.ReadString();
            Shader shader = (Shader)AssetManager.Assets[reader.ReadString()];

            int propertiesCount = reader.ReadInt32();

            MaterialProperty[] properties = new MaterialProperty[propertiesCount];
            object[]           propData   = new object[propertiesCount];
            for (int i = 0; i < propertiesCount; i++)
            {
                string propName = reader.ReadString();
                MaterialPropertyType propertyType = (MaterialPropertyType)reader.ReadInt32();

                switch (propertyType)
                {
                case MaterialPropertyType.Int:
                    propData[i] = reader.ReadInt32();
                    break;

                case MaterialPropertyType.Float:
                    propData[i] = reader.ReadSingle();
                    break;

                case MaterialPropertyType.Vector2:
                    propData[i] = ReadStruct <Vector2>(reader);
                    break;

                case MaterialPropertyType.Vector3:
                    propData[i] = ReadStruct <Vector3>(reader);
                    break;

                case MaterialPropertyType.Vector4:
                    propData[i] = ReadStruct <Vector4>(reader);
                    break;

                case MaterialPropertyType.Matrix2:
                    propData[i] = ReadStruct <Matrix2>(reader);
                    break;

                case MaterialPropertyType.Matrix3:
                    propData[i] = ReadStruct <Matrix3>(reader);
                    break;

                case MaterialPropertyType.Matrix4:
                    propData[i] = ReadStruct <Matrix4>(reader);
                    break;

                case MaterialPropertyType.Texture:
                    string texID = reader.ReadString();
                    propData[i] = !string.IsNullOrEmpty(texID) ? AssetManager.Assets[texID] : null;
                    break;
                }

                properties[i] = new MaterialProperty(propName, propertyType);
            }

            Material material = new Material(name, shader, properties);

            for (int i = 0; i < propertiesCount; i++)
            {
                MaterialProperty property = properties[i];

                switch (properties[i].PropertyType)
                {
                case MaterialPropertyType.Int:
                    material.SetInt(property.Name, (int)propData[i]);
                    break;

                case MaterialPropertyType.Float:
                    material.SetFloat(property.Name, (float)propData[i]);
                    break;

                case MaterialPropertyType.Vector2:
                    material.SetVector2(property.Name, (Vector2)propData[i]);
                    break;

                case MaterialPropertyType.Vector3:
                    material.SetVector3(property.Name, (Vector3)propData[i]);
                    break;

                case MaterialPropertyType.Vector4:
                    material.SetVector4(property.Name, (Vector4)propData[i]);
                    break;

                case MaterialPropertyType.Matrix2:
                    material.SetMatrix2(property.Name, (Matrix2)propData[i]);
                    break;

                case MaterialPropertyType.Matrix3:
                    material.SetMatrix3(property.Name, (Matrix3)propData[i]);
                    break;

                case MaterialPropertyType.Matrix4:
                    material.SetMatrix4(property.Name, (Matrix4)propData[i]);
                    break;

                case MaterialPropertyType.Texture:
                    material.SetTexture(property.Name, (Texture)propData[i]);
                    break;
                }
            }

            material.UpdateBuffer();

            return(material);
        }
예제 #24
0
	IEnumerator CoLerpMaterialProptery(Material aMaterial, float aTime, MaterialPropertyType aPropertyType, string aPropertyName, Color aTargetColor = default(Color), float aTargetValue = 0f, bool scaledTime = true, AnimationCurve aCurve = null, System.Action aCallback = null)
	{
		if (aCurve == null)
			aCurve = Juice.Instance.Linear;

		float startTime = Time.time;
		float percentCompleted = 0;
		Color startColor = Color.white;
		float startFloat = 0;

		switch (aPropertyType) {
		case MaterialPropertyType.Color:
			startColor = aMaterial.GetColor (aPropertyName);
			break;
		case MaterialPropertyType.Float:
			startFloat = aMaterial.GetFloat (aPropertyName);
			break;
		default:
			break;
		}

		while (percentCompleted < 1)
		{
			percentCompleted = (Time.time - startTime) / aTime;
			switch (aPropertyType) {
			case MaterialPropertyType.Color:
				aMaterial.SetColor (aPropertyName, Color.Lerp (startColor, aTargetColor, aCurve.Evaluate (percentCompleted)));
				break;
			case MaterialPropertyType.Float:
				aMaterial.SetFloat (aPropertyName, Mathf.Lerp (startFloat, aTargetValue, aCurve.Evaluate (percentCompleted)));
				break;
			default:
				break;
			}

			yield return new WaitForEndOfFrame();
			if (aMaterial == null)
			{
				DeregisterObject(aMaterial);
				yield break;
			}
		}
		DeregisterObject(aMaterial);
		mCallbacks.Add(aCallback);
		yield break;
	}
예제 #25
0
        private static bool DrawTween(TSSTween tween, List <TSSTween> holder, Object parent, TSSItemValues values)
        {
            GUI.backgroundColor = new Color(0f, 0f, 0f, 0.5f);
            EditorGUILayout.BeginHorizontal(EditorStyles.helpBox);
            GUI.backgroundColor = Color.white;

            EditorGUILayout.BeginVertical();

            EditorGUILayout.BeginHorizontal();
            TSSEditorUtils.DrawGenericProperty(ref tween.enabled, parent);
            EditorGUI.BeginDisabledGroup(!tween.enabled);

            ItemEffect tweenEffect = tween.effect;

            TSSEditorUtils.DrawGenericProperty(ref tween.effect, parent);
            if (tween.effect != tweenEffect)
            {
                if (tween.effect == ItemEffect.property)
                {
                    tween.matProperty = new TSSMaterialProperty(MaterialPropertyType.single);
                }
                if (tween.effect != ItemEffect.property)
                {
                    tween.matProperty = null; tween.matPropertyType = MaterialPropertyType.single;
                }
            }

            EditorGUI.BeginDisabledGroup(tween.direction == TweenDirection.Button);

            if (tween.mode == TweenMode.Multiple)
            {
                EditorGUI.BeginDisabledGroup(tween.direction == TweenDirection.Close);
                TSSEditorUtils.DrawGenericProperty(ref tween.type, TSSEditorUtils.greenColor, null, parent);
                EditorGUI.EndDisabledGroup();

                EditorGUI.BeginDisabledGroup(tween.direction == TweenDirection.Open);
                TSSEditorUtils.DrawGenericProperty(ref tween.closingType, TSSEditorUtils.redColor, null, parent);
                EditorGUI.EndDisabledGroup();
            }
            else
            {
                TSSEditorUtils.DrawGenericProperty(ref tween.type, parent);
            }

            TSSEditorUtils.DrawGenericProperty(ref tween.mode, parent);

            EditorGUI.EndDisabledGroup();

            TweenDirection tweenDirection = tween.direction;

            TSSEditorUtils.DrawGenericProperty(ref tween.direction, parent);
            if (tween.direction != tweenDirection)
            {
                if (tween.direction == TweenDirection.Button)
                {
                    tween.type = TweenType.Custom;
                    tween.mode = TweenMode.Single;
                }
            }

            EditorGUI.EndDisabledGroup();

            if (DrawTweenDeleteButton(tween, holder, parent))
            {
                return(false);
            }

            EditorGUILayout.EndHorizontal();

            EditorGUI.BeginDisabledGroup(!tween.enabled);

            GUILayout.Space(3);

            TSSEditorUtils.DrawMinMaxSliderProperty(ref tween.startPoint, ref tween.endPoint, parent);

            if (tween.mode == TweenMode.Multiple && tween.direction == TweenDirection.OpenClose)
            {
                TSSEditorUtils.DrawSliderProperty(ref tween.blendFactor, parent, blndTweenLabelContent);
            }

            if ((tween.type == TweenType.Custom && tween.direction != TweenDirection.Close) ||
                (tween.mode == TweenMode.Multiple && tween.closingType == TweenType.Custom &&
                 tween.direction != TweenDirection.Open))
            {
                EditorGUILayout.BeginHorizontal();
                TSSEditorUtils.DrawGenericProperty(ref tween.customEase, parent);
                EditorGUILayout.EndHorizontal();
            }

            if (tween.effect == ItemEffect.property)
            {
                EditorGUILayout.BeginVertical();

                EditorGUILayout.BeginHorizontal();

                MaterialPropertyType tssMatPropType = tween.matPropertyType;
                string tssMatPropName = tween.matProperty.name;
                TSSEditorUtils.DrawGenericProperty(ref tween.matPropertyType, parent);
                if (tssMatPropType != tween.matPropertyType)
                {
                    tween.matProperty = new TSSMaterialProperty(tween.matPropertyType);
                }
                tween.matProperty.name = tssMatPropName;

                TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.name, parent);

                EditorGUILayout.EndHorizontal();

                switch (tween.matPropertyType)
                {
                case MaterialPropertyType.single:
                    EditorGUILayout.BeginHorizontal();
                    TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.singleValues[0], TSSEditorUtils.redColor, parent);
                    TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.singleValues[1], TSSEditorUtils.greenColor, parent);
                    EditorGUILayout.EndHorizontal();
                    break;

                case MaterialPropertyType.integer:
                    EditorGUILayout.BeginHorizontal();
                    TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.integerValues[0], TSSEditorUtils.redColor, parent);
                    TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.integerValues[1], TSSEditorUtils.greenColor, parent);
                    EditorGUILayout.EndHorizontal();
                    break;

                case MaterialPropertyType.color:
                    TSSEditorUtils.useHDRcolors = false;
                    EditorGUILayout.BeginHorizontal();
                    TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.colorValues[0], TSSEditorUtils.redColor, parent);
                    TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.colorValues[1], TSSEditorUtils.greenColor, parent);
                    EditorGUILayout.EndHorizontal();
                    break;

                case MaterialPropertyType.colorHDR:
                    TSSEditorUtils.useHDRcolors = true;
                    EditorGUILayout.BeginHorizontal();
                    TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.colorValues[0], TSSEditorUtils.redColor, parent);
                    TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.colorValues[1], TSSEditorUtils.greenColor, parent);
                    EditorGUILayout.EndHorizontal();
                    break;

                case MaterialPropertyType.vector2:
                    TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.vector2values[0], TSSEditorUtils.redColor, parent);
                    TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.vector2values[1], TSSEditorUtils.greenColor, parent);
                    break;

                case MaterialPropertyType.vector3:
                    TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.vector3values[0], TSSEditorUtils.redColor, parent);
                    TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.vector3values[1], TSSEditorUtils.greenColor, parent);
                    break;

                case MaterialPropertyType.vector4:
                    TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.vector4values[0], TSSEditorUtils.redColor, parent);
                    TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.vector4values[1], TSSEditorUtils.greenColor, parent);
                    break;

                case MaterialPropertyType.curve:
                    TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.curve, parent);
                    break;

                case MaterialPropertyType.gradient:
                    TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.gradient, parent);
                    break;
                }

                EditorGUILayout.EndVertical();
            }


            if (TSSPrefsEditor.showTweenProperties)
            {
                EditorGUILayout.BeginVertical();

                switch (tween.effect)
                {
                case ItemEffect.transform:


                    EditorGUILayout.LabelField("Position");
                    EditorGUILayout.BeginVertical();
                    TSSEditorUtils.DrawGenericProperty(ref values.positions[0], TSSEditorUtils.redColor, parent);
                    TSSEditorUtils.DrawGenericProperty(ref values.positions[1], TSSEditorUtils.greenColor, parent);
                    EditorGUILayout.EndVertical();

                    GUILayout.Space(4);

                    EditorGUILayout.LabelField("Rotation");
                    EditorGUILayout.BeginVertical();
                    TSSEditorUtils.DrawGenericProperty(ref values.eulerRotations[0], TSSEditorUtils.redColor, parent);
                    TSSEditorUtils.DrawGenericProperty(ref values.eulerRotations[1], TSSEditorUtils.greenColor, parent);
                    EditorGUILayout.EndVertical();

                    GUILayout.Space(4);

                    EditorGUILayout.LabelField("Scale");
                    EditorGUILayout.BeginVertical();
                    TSSEditorUtils.DrawGenericProperty(ref values.scales[0], TSSEditorUtils.redColor, parent);
                    TSSEditorUtils.DrawGenericProperty(ref values.scales[1], TSSEditorUtils.greenColor, parent);
                    EditorGUILayout.EndVertical();

                    break;

                case ItemEffect.position:

                    TSSEditorUtils.DrawGenericProperty(ref values.positions[0], TSSEditorUtils.redColor, parent);
                    TSSEditorUtils.DrawGenericProperty(ref values.positions[1], TSSEditorUtils.greenColor, parent);

                    break;

                case ItemEffect.rotation:

                    TSSEditorUtils.DrawGenericProperty(ref values.eulerRotations[0], TSSEditorUtils.redColor, parent);
                    TSSEditorUtils.DrawGenericProperty(ref values.eulerRotations[1], TSSEditorUtils.greenColor, parent);

                    break;

                case ItemEffect.scale:

                    TSSEditorUtils.DrawGenericProperty(ref values.scales[0], TSSEditorUtils.redColor, parent);
                    TSSEditorUtils.DrawGenericProperty(ref values.scales[1], TSSEditorUtils.greenColor, parent);

                    break;

                case ItemEffect.directAlpha:

                    EditorGUILayout.BeginHorizontal();
                    TSSEditorUtils.DrawGenericProperty(ref values.alphas[0], TSSEditorUtils.redColor, parent);
                    TSSEditorUtils.DrawGenericProperty(ref values.alphas[1], TSSEditorUtils.greenColor, parent);
                    EditorGUILayout.EndHorizontal();

                    break;

                case ItemEffect.alpha:

                    EditorGUILayout.BeginHorizontal();
                    TSSEditorUtils.DrawGenericProperty(ref values.alphas[0], TSSEditorUtils.redColor, parent);
                    TSSEditorUtils.DrawGenericProperty(ref values.alphas[1], TSSEditorUtils.greenColor, parent);
                    EditorGUILayout.EndHorizontal();

                    break;

                case ItemEffect.color:

                    EditorGUILayout.BeginHorizontal();
                    TSSEditorUtils.useHDRcolors = false;
                    TSSEditorUtils.DrawGenericProperty(ref values.colors[0], TSSEditorUtils.redColor, parent);
                    TSSEditorUtils.DrawGenericProperty(ref values.colors[1], TSSEditorUtils.greenColor, parent);
                    EditorGUILayout.EndHorizontal();

                    break;

                case ItemEffect.imageFill:

                    EditorGUILayout.BeginHorizontal();
                    TSSEditorUtils.DrawGenericProperty(ref values.imageFills[0], TSSEditorUtils.redColor, parent);
                    TSSEditorUtils.DrawGenericProperty(ref values.imageFills[1], TSSEditorUtils.greenColor, parent);
                    EditorGUILayout.EndHorizontal();

                    break;

                case ItemEffect.text:

                    TSSEditorUtils.DrawGenericProperty(ref values.texts[0], TSSEditorUtils.redColor, parent);
                    TSSEditorUtils.DrawGenericProperty(ref values.texts[1], TSSEditorUtils.greenColor, parent);

                    break;

                case ItemEffect.number:

                    EditorGUILayout.BeginHorizontal();
                    TSSEditorUtils.DrawGenericProperty(ref values.numbers[0], TSSEditorUtils.redColor, parent);
                    TSSEditorUtils.DrawGenericProperty(ref values.numbers[1], TSSEditorUtils.greenColor, parent);
                    EditorGUILayout.EndHorizontal();

                    break;

                case ItemEffect.light:
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Color", TSSEditorUtils.max80pxWidth);
                    TSSEditorUtils.DrawGenericProperty(ref values.colors[0], TSSEditorUtils.redColor, parent);
                    TSSEditorUtils.DrawGenericProperty(ref values.colors[1], TSSEditorUtils.greenColor, parent);
                    EditorGUILayout.EndHorizontal();

                    GUILayout.Space(4);

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Intensity", TSSEditorUtils.max80pxWidth);
                    TSSEditorUtils.DrawGenericProperty(ref values.intensities[0], TSSEditorUtils.redColor, parent);
                    TSSEditorUtils.DrawGenericProperty(ref values.intensities[1], TSSEditorUtils.greenColor, parent);
                    EditorGUILayout.EndHorizontal();

                    GUILayout.Space(4);

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Range", TSSEditorUtils.max80pxWidth);
                    TSSEditorUtils.DrawGenericProperty(ref values.lightRange[0], TSSEditorUtils.redColor, parent);
                    TSSEditorUtils.DrawGenericProperty(ref values.lightRange[1], TSSEditorUtils.greenColor, parent);
                    EditorGUILayout.EndHorizontal();

                    break;

                case ItemEffect.range:

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Light", TSSEditorUtils.max80pxWidth);
                    TSSEditorUtils.DrawGenericProperty(ref values.lightRange[0], TSSEditorUtils.redColor, parent);
                    TSSEditorUtils.DrawGenericProperty(ref values.lightRange[1], TSSEditorUtils.greenColor, parent);
                    EditorGUILayout.EndHorizontal();

                    GUILayout.Space(4);

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Collider", TSSEditorUtils.max80pxWidth);
                    TSSEditorUtils.DrawGenericProperty(ref values.sphereRange[0], TSSEditorUtils.redColor, parent);
                    TSSEditorUtils.DrawGenericProperty(ref values.sphereRange[1], TSSEditorUtils.greenColor, parent);
                    EditorGUILayout.EndHorizontal();

                    GUILayout.Space(4);

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Sound", TSSEditorUtils.max80pxWidth);
                    TSSEditorUtils.DrawGenericProperty(ref values.soundRange[0], TSSEditorUtils.redColor, parent);
                    TSSEditorUtils.DrawGenericProperty(ref values.soundRange[1], TSSEditorUtils.greenColor, parent);
                    EditorGUILayout.EndHorizontal();

                    break;
                }

                EditorGUILayout.EndVertical();
            }

            EditorGUI.EndDisabledGroup();

            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(3);

            return(true);
        }
예제 #26
0
 public TextureMaterialProperty(MaterialPropertyType type, Texture t, int index) : base(type, t.Id)
 {
     Texture   = t;
     DataIndex = index;
 }
    private static void _UpdateMaterialProperty(Material obj, MaterialPropertyType pType, float val, string paramName)
    {
        Vector2 offs;

        switch(pType) {
        case MaterialPropertyType.TextureOffset_X:
            offs = obj.mainTextureOffset;
            offs.x = val;
            obj.mainTextureOffset = offs;
        break;
        case MaterialPropertyType.TextureOffset_Y:
            offs = obj.mainTextureOffset;
            offs.y = val;
            obj.mainTextureOffset = offs;
        break;
        case MaterialPropertyType.TextureScale_X:
            offs = obj.mainTextureScale;
            offs.x = val;
            obj.mainTextureScale = offs;
        break;
        case MaterialPropertyType.TextureScale_Y:
            offs = obj.mainTextureScale;
            offs.y = val;
            obj.mainTextureScale = offs;
        break;
        case MaterialPropertyType.Float:
            if(paramName != null && paramName.Length > 0) {
                obj.SetFloat(paramName, val);
            }
        break;
        }
    }
    private static float _GetMaterialProperty(Material obj, MaterialPropertyType pType, string paramName)
    {
        Vector2 offs;

        switch(pType) {
        case MaterialPropertyType.TextureOffset_X:
            offs = obj.mainTextureOffset;
            return offs.x;
        case MaterialPropertyType.TextureOffset_Y:
            offs = obj.mainTextureOffset;
            return offs.y;
        case MaterialPropertyType.TextureScale_X:
            offs = obj.mainTextureScale;
            return offs.x;
        case MaterialPropertyType.TextureScale_Y:
            offs = obj.mainTextureScale;
            return offs.y;
        case MaterialPropertyType.Float:
            if(paramName != null && paramName.Length > 0) {
                return obj.GetFloat(paramName);
            }
            break;
        }

        return 0.0f;
    }
예제 #29
0
 public MaterialProperty(string name, MaterialPropertyType propertyType)
 {
     Name         = name;
     PropertyType = propertyType;
 }
예제 #30
0
 public CubemapMaterialProperty(MaterialPropertyType type, int textureId, int index) : base(type, textureId, index)
 {
 }
        public static void Read(BinaryReader message, Material[] materials, int materialIndex)
        {
            string propertyName = message.ReadString();
            MaterialPropertyType propertyType = (MaterialPropertyType)message.ReadByte();
            Material             mat          = materials[materialIndex];

            DefaultStateSynchronizationPerformanceParameters.Instance?.NotifyMaterialMutated(mat, propertyName);
            switch (propertyType)
            {
            case MaterialPropertyType.Color:
                mat.SetColor(propertyName, message.ReadColor());
                break;

            case MaterialPropertyType.Float:
            case MaterialPropertyType.Range:
                mat.SetFloat(propertyName, message.ReadSingle());
                break;

            case MaterialPropertyType.Texture:
            {
                Texture texture;
                if (AssetService.Instance.TryDeserializeTexture(message, out texture))
                {
                    mat.SetTexture(propertyName, texture);
                    mat.SetTextureScale(propertyName, message.ReadVector2());
                    mat.SetTextureOffset(propertyName, message.ReadVector2());
                }
            }
            break;

            case MaterialPropertyType.Vector:
                mat.SetVector(propertyName, message.ReadVector4());
                break;

            case MaterialPropertyType.Matrix:
                mat.SetMatrix(propertyName, message.ReadMatrix4x4());
                break;

            case MaterialPropertyType.RenderQueue:
                mat.renderQueue = message.ReadInt32();
                break;

            case MaterialPropertyType.ShaderKeywords:
            {
                bool isNotNull = message.ReadBoolean();
                if (isNotNull)
                {
                    int      length         = message.ReadInt32();
                    string[] shaderKeywords = new string[length];
                    for (int i = 0; i < length; i++)
                    {
                        shaderKeywords[i] = message.ReadString();
                    }
                    mat.shaderKeywords = shaderKeywords;
                }
                else
                {
                    mat.shaderKeywords = null;
                }
            }
            break;
            }
        }
예제 #32
0
 public MaterialProperty(MaterialPropertyType type, object data)
 {
     Type = type;
     Data = data;
 }
    private static void _UpdateColorRelative(Material obj, MaterialPropertyType pType, float val, string paramName)
    {
        Color c;

        if(paramName == null || paramName.Length == 0) {
            c = obj.color;
        } else {
            c = obj.GetColor(paramName);
        }

        switch(pType) {
        case MaterialPropertyType.Color_R_Relative:
            c.r = Mathf.Clamp01(c.r + val);
        break;
        case MaterialPropertyType.Color_G_Relative:
            c.g = Mathf.Clamp01(c.g + val);
        break;
        case MaterialPropertyType.Color_B_Relative:
            c.b = Mathf.Clamp01(c.b + val);
        break;
        case MaterialPropertyType.Color_RGB_Relative:
            c.r = Mathf.Clamp01(c.r + val);
            c.g = Mathf.Clamp01(c.g + val);
            c.b = Mathf.Clamp01(c.b + val);
        break;
        case MaterialPropertyType.Color_A_Relative:
            c.a = Mathf.Clamp01(c.a + val);
        break;
        }

        if(paramName == null || paramName.Length == 0) {
            obj.color = c;
        } else {
            obj.SetColor(paramName, c);
        }
    }
예제 #34
0
        public override void Deserialize(Dictionary <PCFResourceType, DataBlockBase> dataBlocks,
                                         UnityNodeBase parentNode,
                                         ResourceResponse resourceResponse,
                                         List <Action <UnityNodeBase> > postInstallActions,
                                         bool optimizedLoad)
        {
            if (!this.isDeserialized)
            {
                ResourceBlock dataBlock = dataBlocks[this.resourceType] as ResourceBlock;
                AssetResource resource  = dataBlock.GetResource(this.referenceID);

                System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
                watch.Start();

                byte[]             metaDataBuffer     = resource.GetMetaData();
                SerializedMaterial serializedMaterial = ProtocolBufferSerializer.DeserializeMaterialData(metaDataBuffer);

                string shaderName = serializedMaterial.ShaderName;
                this.material      = new UnityEngine.Material(Shader.Find(shaderName));
                this.material.name = serializedMaterial.DisplayName;

                ResourceResponse previousRequest = null;

                if (serializedMaterial.MaterialProperties != null)
                {
                    foreach (KeyValuePair <string, SerializedMaterialProperty> pair in serializedMaterial.MaterialProperties)
                    {
                        if (pair.Value != null)
                        {
                            MaterialPropertyType propertyType = (MaterialPropertyType)pair.Value.PropertyType;

                            if (propertyType == MaterialPropertyType.FloatType)
                            {
                                SerializedMaterialFloatProperty floatProperty = pair.Value as SerializedMaterialFloatProperty;
                                this.material.SetFloat(pair.Key, floatProperty.Val);
                            }
                            else if (propertyType == MaterialPropertyType.VectorType)
                            {
                                SerializedMaterialVectorProperty vectorProperty = pair.Value as SerializedMaterialVectorProperty;

                                Vector4 vector = new Vector4(vectorProperty.X, vectorProperty.Y, vectorProperty.Z, vectorProperty.W);
                                this.material.SetVector(pair.Key, vector);
                            }
                            else if (propertyType == MaterialPropertyType.ColorType)
                            {
                                SerializedMaterialColorProperty colorProperty = pair.Value as SerializedMaterialColorProperty;

                                Color color = new Color(colorProperty.R, colorProperty.G, colorProperty.B, colorProperty.A);
                                this.material.SetColor(pair.Key, color);
                            }
                            else if (propertyType == MaterialPropertyType.TextureType)
                            {
                                SerializedMaterialTextureProperty textureProperty = pair.Value as SerializedMaterialTextureProperty;
                                string propertyName = pair.Key;

                                ResourceResponse textureRequest = new ResourceResponse(textureProperty.ReferenceID, (ResourceResponse response) =>
                                {
                                    material.SetTexture(propertyName, response.GetTextureRequest);
                                });

                                if (previousRequest != null)
                                {
                                    textureRequest.SetPreviousResponse(previousRequest);
                                    previousRequest.SetNextResponse(textureRequest);
                                }

                                previousRequest = textureRequest;
                            }
                        }
                    }
                }

                if (previousRequest != null)
                {
                    //Get the first request created.
                    ResourceResponse firstRequest = previousRequest;
                    while (true)
                    {
                        ResourceResponse previous = firstRequest.GetPreviousResponse();

                        if (previous == null)
                        {
                            break;
                        }

                        firstRequest = previous;
                    }

                    //Have each request set by one of the child nodes.
                    for (int i = 0; i < this.ChildNodes.Count; i++)
                    {
                        UnityNodeBase child = this.ChildNodes[i];

                        child.Deserialize(dataBlocks, parentNode, firstRequest, postInstallActions, optimizedLoad);
                    }
                }

                //Finish up and set material to whatever field/object that owns this node.
                ResourceResponse request = resourceResponse.CanHandle(GetReferenceID());
                if (request != null)
                {
                    request.HandleMaterialResponse(this.material);
                }

                watch.Stop();
                //Debug.Log("Time to deserialize material: " + watch.ElapsedMilliseconds);

                this.isDeserialized = true;
            }
        }
예제 #35
0
 public MaterialProperty(MaterialPropertyType type, object data, int order)
 {
     Type  = type;
     Data  = data;
     Order = order;
 }