public override Matrix2x3 GetSymbolLocalTransform(HashedString symbol, out bool symbolVisible) { if (curAnimFrameIdx != -1 && batch != null) { KAnim.Anim.Frame frame = batch.group.data.GetFrame(curAnimFrameIdx); if (frame != KAnim.Anim.Frame.InvalidFrame) { for (int i = 0; i < frame.numElements; i++) { int num = frame.firstElementIdx + i; if (num < batch.group.data.frameElements.Count) { KAnim.Anim.FrameElement frameElement = batch.group.data.frameElements[num]; if (frameElement.symbol == symbol) { symbolVisible = true; return(frameElement.transform); } } } } } symbolVisible = false; return(Matrix2x3.identity); }
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); }
public static void UpdateBlinking(Instance smi, float dt) { int currentFrameIndex = smi.eyes.GetCurrentFrameIndex(); KAnimBatch batch = smi.eyes.GetBatch(); if (currentFrameIndex != -1 && batch != null) { KAnim.Anim.Frame frame = smi.eyes.GetBatch().group.data.GetFrame(currentFrameIndex); if (!(frame == KAnim.Anim.Frame.InvalidFrame)) { HashedString hash = HashedString.Invalid; for (int i = 0; i < frame.numElements; i++) { int num = frame.firstElementIdx + i; if (num < batch.group.data.frameElements.Count) { KAnim.Anim.FrameElement frameElement = batch.group.data.frameElements[num]; if (!(frameElement.symbol == HashedString.Invalid)) { hash = frameElement.symbol; break; } } } smi.GetComponent <SymbolOverrideController>().AddSymbolOverride(HASH_SNAPTO_EYES, smi.eyes.AnimFiles[0].GetData().build.GetSymbol(hash), 3); } } }
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 void WriteAnimData(int start_index, float[] data) { List <KAnim.Anim.Frame> animFrames = GetAnimFrames(); List <KAnim.Anim.FrameElement> animFrameElements = GetAnimFrameElements(); int num = 1 + ((animFrames.Count != 0) ? animFrames.Count : symbolFrameInstances.Count); if (animFrames.Count == 0 && symbolFrameInstances.Count == 0 && animFrameElements.Count == 0) { Debug.LogError("Eh, no data " + animFrames.Count + " " + symbolFrameInstances.Count + " " + animFrameElements.Count); } data[start_index++] = (float)num; data[start_index++] = (float)animFrames.Count; data[start_index++] = (float)animFrameElements.Count; data[start_index++] = (float)symbolFrameInstances.Count; if (animFrames.Count == 0) { for (int i = 0; i < symbolFrameInstances.Count; i++) { WriteAnimFrame(data, start_index, i, i, 1, i); start_index += 4; } for (int j = 0; j < symbolFrameInstances.Count; j++) { WriteAnimFrameElement(data, start_index, j, j, Matrix2x3.identity, Color.white, 0); start_index += 16; } } else { for (int k = 0; k < animFrames.Count; k++) { Write(data, start_index, k, animFrames[k]); start_index += 4; } for (int l = 0; l < animFrameElements.Count; l++) { KAnim.Anim.FrameElement element = animFrameElements[l]; if (element.symbol == KGlobalAnimParser.MISSING_SYMBOL) { WriteAnimFrameElement(data, start_index, -1, l, Matrix2x3.identity, Color.white, 0); } else { KAnim.Build.Symbol buildSymbol = GetBuildSymbol(element.symbolIdx); if (buildSymbol == null) { Debug.LogError("Missing symbol for Anim Frame Element: [" + HashCache.Get().Get(element.symbol) + ": " + element.symbol + "]"); } int frameIdx = buildSymbol.GetFrameIdx(element.frame); Write(data, start_index, frameIdx, l, element); } start_index += 16; } } }
private void Write(float[] data, int startIndex, int symbolFrameIdx, int thisFrameIndex, KAnim.Anim.FrameElement element) { WriteAnimFrameElement(data, startIndex, symbolFrameIdx, thisFrameIndex, element.transform, element.multColour, element.flags); }
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); }
public static void ParseAnimData(KBatchGroupData data, HashedString fileNameHash, FastReader reader, KAnimFileData animFile) { CheckHeader("ANIM", reader); uint num = reader.ReadUInt32(); Assert(num == 5, "Invalid anim.bytes version"); reader.ReadInt32(); reader.ReadInt32(); int num2 = reader.ReadInt32(); animFile.maxVisSymbolFrames = 0; animFile.animCount = 0; animFile.frameCount = 0; animFile.elementCount = 0; animFile.firstAnimIndex = data.anims.Count; animFile.animBatchTag = data.groupID; data.animIndex.Add(fileNameHash, data.anims.Count); animFile.firstElementIndex = data.frameElements.Count; for (int i = 0; i < num2; i++) { KAnim.Anim anim = new KAnim.Anim(animFile, data.anims.Count); anim.name = reader.ReadKleiString(); string text = animFile.name + "." + anim.name; anim.id = text; HashCache.Get().Add(anim.name); HashCache.Get().Add(text); anim.hash = anim.name; anim.rootSymbol.HashValue = reader.ReadInt32(); anim.frameRate = reader.ReadSingle(); anim.firstFrameIdx = data.animFrames.Count; anim.numFrames = reader.ReadInt32(); anim.totalTime = (float)anim.numFrames / anim.frameRate; anim.scaledBoundingRadius = 0f; for (int j = 0; j < anim.numFrames; j++) { KAnim.Anim.Frame item = default(KAnim.Anim.Frame); float num3 = reader.ReadSingle(); float num4 = reader.ReadSingle(); float num5 = reader.ReadSingle(); float num6 = reader.ReadSingle(); item.bbox = new AABB3(new Vector3(num3 - num5 * 0.5f, 0f - (num4 + num6 * 0.5f), 0f) * 0.005f, new Vector3(num3 + num5 * 0.5f, 0f - (num4 - num6 * 0.5f), 0f) * 0.005f); float num7 = Math.Max(Math.Abs(item.bbox.max.x), Math.Abs(item.bbox.min.x)); float num8 = Math.Max(Math.Abs(item.bbox.max.y), Math.Abs(item.bbox.min.y)); float num9 = Math.Max(num7, num8); anim.unScaledSize.x = Math.Max(anim.unScaledSize.x, num7 / 0.005f); anim.unScaledSize.y = Math.Max(anim.unScaledSize.y, num8 / 0.005f); anim.scaledBoundingRadius = Math.Max(anim.scaledBoundingRadius, Mathf.Sqrt(num9 * num9 + num9 * num9)); item.idx = data.animFrames.Count; item.firstElementIdx = data.frameElements.Count; item.numElements = reader.ReadInt32(); int num10 = 0; for (int k = 0; k < item.numElements; k++) { KAnim.Anim.FrameElement item2 = default(KAnim.Anim.FrameElement); item2.fileHash = fileNameHash; item2.symbol = new KAnimHashedString(reader.ReadInt32()); item2.frame = reader.ReadInt32(); item2.folder = new KAnimHashedString(reader.ReadInt32()); item2.flags = reader.ReadInt32(); float a = reader.ReadSingle(); float b = reader.ReadSingle(); float g = reader.ReadSingle(); float r = reader.ReadSingle(); item2.multColour = new Color(r, g, b, a); float m = reader.ReadSingle(); float m2 = reader.ReadSingle(); float m3 = reader.ReadSingle(); float m4 = reader.ReadSingle(); float m5 = reader.ReadSingle(); float m6 = reader.ReadSingle(); reader.ReadSingle(); item2.transform.m00 = m; item2.transform.m01 = m3; item2.transform.m02 = m5; item2.transform.m10 = m2; item2.transform.m11 = m4; item2.transform.m12 = m6; int symbolIndex = data.GetSymbolIndex(item2.symbol); if (symbolIndex == -1) { num10++; item2.symbol = MISSING_SYMBOL; } else { item2.symbolIdx = symbolIndex; data.frameElements.Add(item2); animFile.elementCount++; } } item.numElements -= num10; data.animFrames.Add(item); animFile.frameCount++; } data.AddAnim(anim); animFile.animCount++; } Debug.Assert(num2 == animFile.animCount); data.animCount[fileNameHash] = animFile.animCount; animFile.maxVisSymbolFrames = Math.Max(animFile.maxVisSymbolFrames, reader.ReadInt32()); data.UpdateMaxVisibleSymbols(animFile.maxVisSymbolFrames); ParseHashTable(reader); }
// This method syncs the object to the transform of the neck snap point in the dupe void LateUpdate() { bool symbolVisible = false; if (dupeAnim.CurrentAnim != null) { var batch = dupeAnim.GetBatch(); var frame = batch.group.data.GetFrame(dupeAnim.GetCurrentFrameIndex()); if (frame != KAnim.Anim.Frame.InvalidFrame) { for (int i = 0; i < frame.numElements; i++) { int num = frame.firstElementIdx + i; if (num < batch.group.data.frameElements.Count) { KAnim.Anim.FrameElement frameElement = batch.group.data.frameElements[num]; if (frameElement.symbol == symbol) { if (frameElement.frame == 0) { if (facing <= 0) { myAnim.Play(front_anim); facing = 1; } } else { if (facing >= 0) { myAnim.Play(back_anim); facing = -1; } } } } } } symbolVisible = dupeAnim.GetSymbolVisiblity(symbol); bool unusedBool; Matrix2x3 symbolLocalTransform = dupeAnim.GetSymbolLocalTransform(symbol, out unusedBool); Vector3 position = dupeAnim.transform.GetPosition(); if (symbolVisible && (previousMatrix != symbolLocalTransform || position != previousPosition)) { previousMatrix = symbolLocalTransform; previousPosition = position; Matrix2x3 overrideTransformMatrix = dupeAnim.GetTransformMatrix() * symbolLocalTransform; float z = base.transform.GetPosition().z; base.transform.SetPosition(overrideTransformMatrix.MultiplyPoint(offset)); Vector3 v = dupeAnim.FlipX ? Vector3.left : Vector3.right; Vector3 v2 = dupeAnim.FlipY ? Vector3.down : Vector3.up; base.transform.up = overrideTransformMatrix.MultiplyVector(v2); base.transform.right = overrideTransformMatrix.MultiplyVector(v); if (myAnim != null) { myAnim.GetBatchInstanceData()?.SetOverrideTransformMatrix(overrideTransformMatrix); } base.transform.SetPosition(new Vector3(base.transform.GetPosition().x, base.transform.GetPosition().y, z)); myAnim.Offset = dupeAnim.Offset; myAnim.SetDirty(); } } if (myAnim != null && symbolVisible != myAnim.enabled) { myAnim.enabled = symbolVisible; } }