Code Monkey home page Code Monkey logo

text-juicer's Introduction

Hi ๐Ÿ‘‹, I'm Bruno Mikoski

I have been converting ๐Ÿ• into ๐Ÿ•น in the past 15 years.

Most of my works are related to this

Android iOS CSharp Continuous Integration git unity

Here's some things about me

โœจ Tools I'm most proud of โœจ







๐Ÿ•น Latest Projects ๐Ÿ•น

Project Platforms
Android iOS
Android iOS
Nintendo Switch
More on brunomikoski.myportfolio.com

text-juicer's People

Contributors

brunomikoski avatar pieterpaladin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

text-juicer's Issues

Error when use in bundle

Hello,

I am getting
Assets\TextJuicer\Scripts\Editor\TextJuicerTransformModifierInspector.cs(6,64): error CS0246: The type or namespace name 'Editor' could not be found (are you missing a using directive or an assembly reference?)

such errors when I am trying to build a bundle of a prefab, that have TextJuicerTransformModifier script attached.

Thanks

Reverse & Offset

I'm trying to create an X movement. For now I create 2 texts, one using an enter animation, and the other to create the skip animation. Cloud be easier to add some controls like:

  • Reverse: to invert the animation
  • Delay: to create an offset between enter and skip

I'm playing with this to create the reverse but seems I need something more:

using UnityEngine;

namespace BrunoMikoski.TextJuicer.Effects
{
    [AddComponentMenu("UI/Text Juicer/Effects/X")]
    public class XModifier : VertexModifier
    {
        public bool reverse = false;
        [SerializeField]
        private AnimationCurve curve = new AnimationCurve(new Keyframe(0, 1));

        public override void Apply(CharacterData characterData, ref UIVertex uiVertex)
        {
            if(reverse)
                uiVertex.position.x *= curve.Evaluate(1.0f-characterData.Progress);
            else
                uiVertex.position.x *= curve.Evaluate(characterData.Progress);
        }
    }
}

TextMeshPro

I modified the code to use with TextMesh Pro, but still not able to get the effect.

using BrunoMikoski.TextJuicer.Effects;
using UnityEngine;
using UnityEngine.UI;
using TMPro;

namespace BrunoMikoski.TextJuicer
{
    //[RequireComponent(typeof (Text))]
    [AddComponentMenu("UI/Text Juicer/Juiced Text")]
    public class JuicedText : BaseMeshEffect
    {
        public const string VERSION = "0.0.2";

        [SerializeField]
        private float duration = 1.0f;
        [SerializeField]
        private float delay = 0.01f;
        [SerializeField, Range(0.0f, 1.0f)]
        private float progress;
        [SerializeField]
        private bool playOnEnable = true;
        [SerializeField]
        private bool loop = false;
        [SerializeField]
        private bool playForever = false;

        private CharacterData[] charactersData;
        private float internalTime;
        private bool isDirty;
        private float lastInternalTime;
        private float realTotalAnimationTime;

        private Text textComponent;
        public Text TextComponent
        {
            get
            {
                if (textComponent == null)
                {
                    SetDirty();
                    UpdateComponents();
                }
                return textComponent;
            }
        }

        private TextMeshProUGUI textComponentTMP;
        public TextMeshProUGUI TextComponentTMP
        {
            get
            {
                if (textComponentTMP == null)
                {
                    SetDirty();
                    UpdateComponents();
                }
                return textComponentTMP;
            }
        }

        private VertexModifier[] vertexModifiers;
        private bool isPlaying;

#if UNITY_EDITOR
        protected override void OnValidate()
        {
            SetDirty();
            base.OnValidate();
        }
#endif

        protected override void OnEnable()
        {
            base.OnEnable();
            SetDirty();
            if (Application.isPlaying && playOnEnable)
                Play();
        }

        public override void ModifyMesh(VertexHelper vh)
        {
            int count = vh.currentVertCount;
            if (!IsActive() || count == 0 || isDirty)
            {
                vh.Clear();
                return;
            }

            int characterCount = 0;
            for (int i = 0; i < count; i += 4)
            {
                if (characterCount >= charactersData.Length)
                {
                    vh.Clear();
                    SetDirty();
                    return;
                }

                CharacterData characterData = charactersData[characterCount];
                for (int j = 0; j < 4; j++)
                {
                    UIVertex uiVertex = new UIVertex();
                    vh.PopulateUIVertex(ref uiVertex, i + j);

                    ModifyVertex(characterData, ref uiVertex);

                    vh.SetUIVertex(uiVertex, i + j);
                }
                characterCount += 1;
            }
        }

        private void ModifyVertex(CharacterData characterData, ref UIVertex uiVertex)
        {
            for (int i = 0; i < vertexModifiers.Length; i++)
            {
                VertexModifier vertexModifier = vertexModifiers[i];
                vertexModifier.Apply(characterData, ref uiVertex);
            }
        }

        public void Complete()
        {
            if (isPlaying)
                progress = 1.0f;
        }

        public void Restart()
        {
            internalTime = 0;
            SetDirty();
        }

        public void Play(bool fromBeginning = true)
        {
            if (fromBeginning)
                Restart();

            isPlaying = true;
        }

        public void Stop()
        {
            isPlaying = false;
        }

        private void Update()
        {
            UpdateComponents();
            UpdateTime();
            CheckAnimation();
        }

        private void CheckAnimation()
        {
            if (isPlaying)
            {
                if (internalTime + Time.deltaTime <= realTotalAnimationTime || playForever)
                {
                    internalTime += Time.deltaTime;
                }
                else
                {
                    if (loop)
                    {
                        internalTime = 0;
                    }
                    else
                    {
                        internalTime = realTotalAnimationTime;
                        progress = 1.0f;
                        Stop();
                    }
                }
            }
        }

        private void UpdateTime()
        {
            if (!isPlaying)
            {
                internalTime = progress * realTotalAnimationTime;
            }
            else
            {
                progress = internalTime / realTotalAnimationTime;
            }

            for (int i = 0; i < charactersData.Length; i++)
                charactersData[i].UpdateTime(internalTime);

            if (internalTime != lastInternalTime)
            {
                lastInternalTime = internalTime;
                graphic.SetAllDirty();
            }
        }

        private void UpdateComponents()
        {
            if (isDirty)
            {
                //if(textComponent == null)
                //    textComponent = GetComponent<Text>();

                if (GetComponent<Text>() != null)
                {
                    textComponent = GetComponent<Text>();
                }
                if (GetComponent<TextMeshProUGUI>() != null)
                {
                    textComponentTMP = GetComponent<TextMeshProUGUI>();
                }

                vertexModifiers = GetComponents<VertexModifier>();
                int charCount=0;
                if (textComponent != null)
                {
                    charCount = textComponent.text.Length;
                    Debug.Log(charCount);
                }
                if (textComponentTMP != null)
                {
                    charCount = textComponentTMP.text.Length;
                    Debug.Log(charCount);
                }
                Debug.Log(charCount);
                charactersData = new CharacterData[charCount];

                realTotalAnimationTime = duration +
                                         (charCount * delay);

                for (int i = 0; i < charCount; i++)
                {
                    charactersData[i] = new CharacterData(delay * i,
                        duration, i);
                }

                isDirty = false;
            }
        }

        public void SetDirty()
        {
            isDirty = true;
        }

        public void SetProgress(float targetProgress)
        {
            SetDirty();
            UpdateComponents();
            progress = targetProgress;
            internalTime = progress * realTotalAnimationTime;
        }

        public void SetPlayForever(bool shouldPlayForever)
        {
            playForever = shouldPlayForever;
        }
    }
}

I am unable to find the issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.