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 static Sprite GetUISpriteFromMultiObjectAnim(KAnimFile animFile, string animName = "ui", bool centered = false, string symbolName = "") { Tuple <KAnimFile, string, bool> key = new Tuple <KAnimFile, string, bool>(animFile, animName, centered); if (knownUISprites.ContainsKey(key)) { return(knownUISprites[key]); } if ((UnityEngine.Object)animFile == (UnityEngine.Object)null) { DebugUtil.LogWarningArgs(animName, "missing Anim File"); return(null); } KAnimFileData data = animFile.GetData(); if (data == null) { DebugUtil.LogWarningArgs(animName, "KAnimFileData is null"); return(null); } if (data.build == null) { return(null); } KAnim.Anim.Frame frame = KAnim.Anim.Frame.InvalidFrame; for (int i = 0; i < data.animCount; i++) { KAnim.Anim anim = data.GetAnim(i); if (anim.name == animName) { frame = anim.GetFrame(data.batchTag, 0); } } if (!frame.IsValid()) { DebugUtil.LogWarningArgs($"missing '{animName}' anim in '{animFile}'"); return(null); } if (data.elementCount == 0) { return(null); } KAnim.Anim.FrameElement frameElement = default(KAnim.Anim.FrameElement); if (string.IsNullOrEmpty(symbolName)) { symbolName = animName; } frameElement = data.FindAnimFrameElement(symbolName); KAnim.Build.Symbol symbol = data.build.GetSymbol(frameElement.symbol); if (symbol == null) { DebugUtil.LogWarningArgs(animFile.name, animName, "placeSymbol [", frameElement.symbol, "] is missing"); return(null); } int frame2 = frameElement.frame; KAnim.Build.SymbolFrameInstance frame3 = symbol.GetFrame(frame2); KAnim.Build.SymbolFrame symbolFrame = frame3.symbolFrame; if (symbolFrame == null) { DebugUtil.LogWarningArgs(animName, "SymbolFrame [", frameElement.frame, "] is missing"); return(null); } Texture2D texture = data.build.GetTexture(0); float x = symbolFrame.uvMin.x; float x2 = symbolFrame.uvMax.x; float y = symbolFrame.uvMax.y; float y2 = symbolFrame.uvMin.y; int num = (int)((float)texture.width * Mathf.Abs(x2 - x)); int num2 = (int)((float)texture.height * Mathf.Abs(y2 - y)); float num3 = Mathf.Abs(symbolFrame.bboxMax.x - symbolFrame.bboxMin.x); Rect rect = default(Rect); rect.width = (float)num; rect.height = (float)num2; rect.x = (float)(int)((float)texture.width * x); rect.y = (float)(int)((float)texture.height * y); float pixelsPerUnit = 100f; if (num != 0) { pixelsPerUnit = 100f / (num3 / (float)num); } Sprite sprite = Sprite.Create(texture, rect, (!centered) ? Vector2.zero : new Vector2(0.5f, 0.5f), pixelsPerUnit, 0u, SpriteMeshType.FullRect); sprite.name = $"{texture.name}:{animName}:{frameElement.frame.ToString()}:{centered}"; knownUISprites[key] = sprite; return(sprite); }