Beispiel #1
0
    public void Clear()
    {
        GameObject     symbolObject = null;
        SMBlackToColor symbolSM     = null;

        if (symbolAmount > 0)
        {
            for (int i = 0; i < symbolAmount; i++)
            {
                symbolTransforms[i] = null;
                symbolRenderers[i]  = null;
                symbolSM            = symbolSMs[i];
                if (symbolSM != null)
                {
                    symbolSM.Clear();
                    symbolSMs[i] = null;
                }
                symbolObject = symbolObjects[i];
                if (symbolObject != null)
                {
                    Destroy(symbolObject);
                    symbolObjects[i] = null;
                }
            }
            symbolWidths     = null;
            symbolTransforms = null;
            symbolRenderers  = null;
            symbolSMs        = null;
            symbolObjects    = null;
            symbolAmount     = 0;
        }
        value = null;
    }
Beispiel #2
0
    private void UpdateSymbolAmount()
    {
        int newSymbolAmount   = 0;
        int additionalSymbols = 0;

        GameObject[]     newSymbolObjects    = null;
        SpriteRenderer[] newSymbolRenderers  = null;
        SMBlackToColor[] newSymbolSMs        = null;
        Transform[]      newSymbolTransforms = null;
        float[]          newSymbolWidths     = null;
        GameObject       newSymbolObject     = null;
        SpriteRenderer   newSymbolRenderer   = null;
        SMBlackToColor   newSymbolSM         = null;
        Transform        newSymbolTransform  = null;
        float            newSymbolWidth      = 0f;

        if (value != null)
        {
            newSymbolAmount = value.Length;
        }
        if (symbolAmount != newSymbolAmount)
        {
            if (symbolAmount < newSymbolAmount)
            {
                additionalSymbols   = newSymbolAmount - symbolAmount;
                newSymbolObjects    = new GameObject[additionalSymbols];
                newSymbolRenderers  = new SpriteRenderer[additionalSymbols];
                newSymbolSMs        = new SMBlackToColor[additionalSymbols];
                newSymbolTransforms = new Transform[additionalSymbols];
                newSymbolWidths     = new float[additionalSymbols];
                for (int i = 0; i < additionalSymbols; i++)
                {
                    newSymbolObject   = new GameObject("CharacterSymbol" + (symbolAmount + i));
                    newSymbolRenderer = newSymbolObject.AddComponent <SpriteRenderer>();

                    /*halmeida - the mere assignment of a material to the material property of a renderer does not cause material
                     * instantiation. It's just a pointer assignment. If we were to assign a material from the material property of
                     * a renderer, however, a clone of the material would be created.*/
                    if (fontModMaterial != null)
                    {
                        newSymbolRenderer.material = fontModMaterial;
                    }
                    //Debug.Log("Debug : SpritedString : Materials before shader = "+Resources.FindObjectsOfTypeAll(typeof(Material)).Length+".");
                    newSymbolSM = newSymbolObject.AddComponent <SMBlackToColor>();
                    //Debug.Log("Debug : SpritedString : Materials after shader = "+Resources.FindObjectsOfTypeAll(typeof(Material)).Length+".");

                    /*halmeida - the awake of this component does a material assignment from the renderer's material property,
                     * causing a material clone to be created. That's why we need to call the clear function of the component later.*/
                    newSymbolTransform = newSymbolObject.transform;
                    if (newSymbolTransform != null)
                    {
                        newSymbolTransform.SetParent(gameObject.transform, false);
                    }
                    newSymbolObjects[i]    = newSymbolObject;
                    newSymbolRenderers[i]  = newSymbolRenderer;
                    newSymbolSMs[i]        = newSymbolSM;
                    newSymbolTransforms[i] = newSymbolTransform;
                    newSymbolWidths[i]     = newSymbolWidth;
                }
                UsefulFunctions.IncreaseArrayWithArray <GameObject>(ref symbolObjects, newSymbolObjects);
                UsefulFunctions.IncreaseArrayWithArray <SpriteRenderer>(ref symbolRenderers, newSymbolRenderers);
                UsefulFunctions.IncreaseArrayWithArray <SMBlackToColor>(ref symbolSMs, newSymbolSMs);
                UsefulFunctions.IncreaseArrayWithArray <Transform>(ref symbolTransforms, newSymbolTransforms);
                UsefulFunctions.IncreaseArrayWithArray <float>(ref symbolWidths, newSymbolWidths);
                newSymbolObjects    = null;
                newSymbolRenderers  = null;
                newSymbolSMs        = null;
                newSymbolTransforms = null;
                newSymbolWidths     = null;
            }
            else
            {
                if ((symbolObjects != null) && (symbolRenderers != null) && (symbolTransforms != null) && (symbolWidths != null) &&
                    (symbolSMs != null))
                {
                    if ((symbolObjects.Length == symbolAmount) && (symbolRenderers.Length == symbolAmount) &&
                        (symbolTransforms.Length == symbolAmount) && (symbolWidths.Length == symbolAmount) &&
                        (symbolSMs.Length == symbolAmount))
                    {
                        for (int i = newSymbolAmount; i < symbolAmount; i++)
                        {
                            symbolTransforms[i] = null;
                            newSymbolSM         = symbolSMs[i];
                            if (newSymbolSM != null)
                            {
                                newSymbolSM.Clear();
                                symbolSMs[i] = null;
                            }
                            symbolRenderers[i] = null;
                            newSymbolObject    = symbolObjects[i];
                            if (newSymbolObject != null)
                            {
                                Destroy(newSymbolObject);
                                symbolObjects[i] = null;
                            }
                        }
                        newSymbolObjects    = new GameObject[newSymbolAmount];
                        newSymbolRenderers  = new SpriteRenderer[newSymbolAmount];
                        newSymbolSMs        = new SMBlackToColor[newSymbolAmount];
                        newSymbolTransforms = new Transform[newSymbolAmount];
                        newSymbolWidths     = new float[newSymbolAmount];
                        for (int i = 0; i < newSymbolAmount; i++)
                        {
                            newSymbolObjects[i]    = symbolObjects[i];
                            newSymbolRenderers[i]  = symbolRenderers[i];
                            newSymbolSMs[i]        = symbolSMs[i];
                            newSymbolTransforms[i] = symbolTransforms[i];
                            newSymbolWidths[i]     = symbolWidths[i];
                        }
                        symbolObjects       = newSymbolObjects;
                        symbolRenderers     = newSymbolRenderers;
                        symbolSMs           = newSymbolSMs;
                        symbolTransforms    = newSymbolTransforms;
                        symbolWidths        = newSymbolWidths;
                        newSymbolObjects    = null;
                        newSymbolRenderers  = null;
                        newSymbolSMs        = null;
                        newSymbolTransforms = null;
                        newSymbolWidths     = null;
                    }
                }
            }
            symbolAmount = newSymbolAmount;
        }
    }