Ejemplo n.º 1
0
        /// <summary>
        /// Compares two animation frames.
        /// </summary>
        /// <param name="groupData">The group data to retrieve the frame elements.</param>
        /// <param name="a">The first frame.</param>
        /// <param name="b">The second frame.</param>
        /// <returns>true if they are equal, or false otherwise.</returns>
        private static bool CompareFrames(KBatchGroupData groupData, ref KAnim.Anim.Frame a,
                                          ref KAnim.Anim.Frame b)
        {
            // Each element specifies a frame from a particular symbol, position, tint, and
            // flags
            int  ne    = a.numElements;
            bool equal = ne == b.numElements;

            if (equal)
            {
                int startA = a.firstElementIdx, startB = b.firstElementIdx;
                // If they point to the same elements, they are automatically equal
                if (startA != startB)
                {
                    for (int i = 0; i < ne && equal; i++)
                    {
                        var   elementA = groupData.GetFrameElement(i + startA);
                        var   elementB = groupData.GetFrameElement(i + startB);
                        Color colorA = elementA.multColour, colorB = elementB.multColour;
                        equal = elementA.symbol == elementB.symbol && colorA == colorB &&
                                elementA.symbolIdx == elementB.symbolIdx && elementA.flags ==
                                elementB.flags && elementA.transform == elementB.transform &&
                                elementA.frame == elementB.frame;
                    }
                }
            }
            return(equal);
        }
    private bool ShouldUseSidewaysSymbol(KBatchedAnimController controller)
    {
        KAnim.Anim currentAnim = controller.GetCurrentAnim();
        if (currentAnim == null)
        {
            return(false);
        }
        int currentFrameIndex = controller.GetCurrentFrameIndex();

        if (currentFrameIndex <= 0)
        {
            return(false);
        }
        KBatchGroupData batchGroupData = KAnimBatchManager.Instance().GetBatchGroupData(currentAnim.animFile.animBatchTag);

        KAnim.Anim.Frame frame = batchGroupData.GetFrame(currentFrameIndex);
        for (int i = 0; i < frame.numElements; i++)
        {
            KAnim.Anim.FrameElement frameElement = batchGroupData.GetFrameElement(frame.firstElementIdx + i);
            if (frameElement.symbol == HASH_SNAPTO_EYES && frameElement.frame >= FIRST_SIDEWAYS_FRAME)
            {
                return(true);
            }
        }
        return(false);
    }
    private void ApplyShape(KAnim.Build.Symbol variation_symbol, KBatchedAnimController controller, KAnimFile shapes_file, HashedString symbol_name_in_shape_file, bool should_use_sideways_symbol)
    {
        HashedString hashedString = HASH_NEUTRAL;

        if (currentExpression != null)
        {
            hashedString = currentExpression.face.hash;
        }
        KAnim.Anim anim = null;
        KAnim.Anim.FrameElement frameElement = default(KAnim.Anim.FrameElement);
        bool flag  = false;
        bool flag2 = false;

        for (int i = 0; i < shapes_file.GetData().animCount; i++)
        {
            if (flag)
            {
                break;
            }
            KAnim.Anim anim2 = shapes_file.GetData().GetAnim(i);
            if (anim2.hash == hashedString)
            {
                anim = anim2;
                KAnim.Anim.Frame frame = anim.GetFrame(shapes_file.GetData().build.batchTag, 0);
                for (int j = 0; j < frame.numElements; j++)
                {
                    KBatchGroupData batchGroupData = KAnimBatchManager.Instance().GetBatchGroupData(shapes_file.GetData().animBatchTag);
                    frameElement = batchGroupData.GetFrameElement(frame.firstElementIdx + j);
                    if (!(frameElement.symbol != symbol_name_in_shape_file))
                    {
                        if (flag2 || !should_use_sideways_symbol)
                        {
                            flag = true;
                        }
                        flag2 = true;
                        break;
                    }
                }
            }
        }
        if (anim == null)
        {
            DebugUtil.Assert(false, "Could not find shape for expression: " + HashCache.Get().Get(hashedString));
        }
        if (!flag2)
        {
            DebugUtil.Assert(false, "Could not find shape element for shape:" + HashCache.Get().Get(variation_symbol.hash));
        }
        KAnim.Build.Symbol symbol          = KAnimBatchManager.Instance().GetBatchGroupData(controller.batchGroupID).GetSymbol(symbol_name_in_shape_file);
        KBatchGroupData    batchGroupData2 = KAnimBatchManager.Instance().GetBatchGroupData(variation_symbol.build.batchTag);

        KAnim.Build.SymbolFrameInstance symbol_frame_instance = batchGroupData2.symbolFrameInstances[variation_symbol.firstFrameIdx + frameElement.frame];
        symbol_frame_instance.buildImageIdx = GetComponent <SymbolOverrideController>().GetAtlasIdx(variation_symbol.build.GetTexture(0));
        controller.SetSymbolOverride(symbol.firstFrameIdx, symbol_frame_instance);
    }
    public KAnim.Anim.FrameElement GetAnimFrameElement(int index)
    {
        Debug.Assert(index >= 0 && index < elementCount);
        KBatchGroupData batchGroupData = KAnimBatchManager.Instance().GetBatchGroupData(animBatchTag);

        if (batchGroupData == null)
        {
            Debug.LogErrorFormat("[{0}] No such batch group [{1}]", name, animBatchTag.ToString());
        }
        return(batchGroupData.GetFrameElement(firstElementIndex + index));
    }