Esempio n. 1
0
        protected override void OnTrigger()
        {
            IEnumerator routine = null;

            switch (type)
            {
            case Type.Color:
                routine = Routines.Lerp(material.color, color, duration, (Color val) => { material.color = val; }, Color.Lerp);
                break;

            case Type.SetFloat:
                routine = Routines.Lerp(material.GetFloat(propertyName), floatValue, duration, (float val) => { material.SetFloat(propertyName, val); }, Routines.Lerp);
                break;

            case Type.SetInteger:
                routine = Routines.Lerp(material.GetInt(propertyName), integerValue, duration, (float val) => { material.SetInt(propertyName, Mathf.CeilToInt(val)); }, Routines.Lerp);
                break;

            case Type.SetTexture:
                routine = Routines.Call(() => { material.SetTexture(propertyName, texture); }, duration);
                break;

            case Type.Lerp:
                routine = Routines.Lerp((float t) => { material.Lerp(material, material2, t); }, duration);
                break;

            default:
                break;
            }

            this.StartCoroutine(routine, "Interpolate");
        }
        //--------------------------------------------------------------------------------------------/
        // Methods
        //--------------------------------------------------------------------------------------------/
        public IEnumerator MakeInterpolateRoutine()
        {
            IEnumerator interpolator = null;

            switch (memberType)
            {
            case ActionProperty.Types.Integer:
            {
                int  currentValue = member.Get <int>();
                bool shouldToggle = (toggle && currentValue == intValue);
                int  nextValue    = shouldToggle ? (int)previousValue : intValue;
                //interpolator = Routines.Lerp(currentValue, nextValue, duration, (float val) => { property.Set(Mathf.CeilToInt(val)); }, Routines.Lerp);
                interpolator  = Routines.Interpolate(currentValue, nextValue, duration, (float val) => { member.Set(Mathf.CeilToInt(val)); }, ease);
                previousValue = currentValue;
            }
            break;

            case ActionProperty.Types.Float:
            {
                float currentValue = member.Get <float>();
                bool  shouldToggle = (toggle && currentValue == floatValue);
                Trace.Script("Previous float " + previousValue + ", Current Float = " + currentValue + ", Float Value = " + floatValue + ", shouldToggle = " + shouldToggle);
                float nextValue = shouldToggle ? (float)previousValue : floatValue;
                //interpolator = Routines.Lerp(currentValue, nextValue, duration, (float val) => { property.Set(val); }, Routines.Lerp);
                interpolator  = Routines.Interpolate(currentValue, nextValue, duration, (float val) => { member.Set(val); }, ease);
                previousValue = currentValue;
            }
            break;

            case ActionProperty.Types.Boolean:
            {
                bool currentValue = member.Get <bool>();
                bool shouldToggle = (toggle && currentValue == boolValue);
                bool nextValue    = shouldToggle ? (bool)previousValue : boolValue;
                interpolator  = Routines.Call(() => { member.Set(nextValue); }, duration);
                previousValue = currentValue;
            }
            break;

            case ActionProperty.Types.Vector2:
            {
                Vector2 currentValue = member.Get <Vector2>();
                bool    shouldToggle = (toggle && currentValue == vector2Value);
                Vector2 nextValue    = shouldToggle ? (Vector2)previousValue : vector2Value;
                //interpolator = Routines.Lerp(currentValue, nextValue, duration, (Vector2 val) => { property.Set(val); }, Vector2.Lerp);
                interpolator  = Routines.Interpolate(currentValue, nextValue, duration, (Vector2 val) => { member.Set(val); }, ease);
                previousValue = currentValue;
            }
            break;

            case ActionProperty.Types.Vector3:
            {
                Vector3 currentValue = member.Get <Vector3>();
                bool    shouldToggle = (toggle && currentValue == vector3Value);
                Vector3 nextValue    = shouldToggle ? (Vector3)previousValue : vector3Value;
                //interpolator = Routines.Lerp(currentValue, nextValue, duration, (Vector3 val) => { property.Set(val); }, Vector3.Lerp);
                interpolator  = Routines.Interpolate(currentValue, nextValue, duration, (Vector3 val) => { member.Set(val); }, ease);
                previousValue = currentValue;
            }
            break;

            case ActionProperty.Types.Vector4:
            {
                Vector4 currentValue = member.Get <Vector4>();
                bool    shouldToggle = (toggle && currentValue == vector4Value);
                Vector4 nextValue    = shouldToggle ? (Vector4)previousValue : vector4Value;
                //interpolator = Routines.Lerp(currentValue, nextValue, duration, (Vector4 val) => { property.Set(val); }, Vector4.Lerp);
                interpolator  = Routines.Interpolate(currentValue, nextValue, duration, (Vector4 val) => { member.Set(val); }, ease);
                previousValue = currentValue;
            }
            break;

            case ActionProperty.Types.Color:
            {
                Color currentValue = member.Get <Color>();
                bool  shouldToggle = (toggle && currentValue == colorValue);
                Color nextValue    = shouldToggle ? (Color)previousValue : colorValue;
                //interpolator = Routines.Lerp(currentValue, nextValue, duration, (Color val) => { property.Set(val); }, Color.Lerp);
                interpolator  = Routines.Interpolate(currentValue, nextValue, duration, (Color val) => { member.Set(val); }, ease);
                previousValue = currentValue;
            }
            break;

            default:
                break;
            }
            return(interpolator);
        }