/// <summary> /// Initializes a new instance of the <see cref="EmaModel"/> class. /// </summary> /// <param name="inscription">Inscription.</param> /// <param name="type">Type.</param> /// <param name="gameObject">Game object.</param> public EmaModel (string inscription, EmaType type, GameObject gameObject) { Inscription = inscription; Type = type; GameObject = gameObject; Position = new SerializableVector3 (gameObject.transform.position); Rotation = new SerializableQuaternion (gameObject.transform.rotation); }
public static EMA_Command Read(byte[] rawBytes, int offset, float[] values, EMA_File emaFile, EmaType _emaType) { EMA_Command command = new EMA_Command(); command.emaType = _emaType; if (emaFile.HasSkeleton) { command.BoneName = emaFile.GetBoneName(BitConverter.ToUInt16(rawBytes, offset + 0)); } else { //This ema has no skeleton, thus no bones command.BoneName = null; } command.I_02 = rawBytes[offset + 2]; BitArray flags_b = new BitArray(new byte[1] { Int4Converter.ToInt4(rawBytes[offset + 3])[1] }); BitArray flags_a = new BitArray(new byte[1] { Int4Converter.ToInt4(rawBytes[offset + 3])[0] }); command.I_03_b1 = flags_b[0]; command.I_03_b2_Int16ForTime = flags_b[1]; command.I_03_b3_Int16ForValueIndex = flags_b[2]; command.I_03_b4 = flags_b[3]; command.I_03_a4 = flags_a[3]; flags_a[3] = false; command.I_03_a = Int4Converter.GetByte(Utils.ConvertToByte(flags_a), 0); command.Keyframes = new ObservableCollection <EMA_Keyframe>(); ushort keyframeCount = BitConverter.ToUInt16(rawBytes, offset + 4); ushort indexOffset = BitConverter.ToUInt16(rawBytes, offset + 6); for (int i = 0; i < keyframeCount; i++) { ushort time; float value; string value2 = null; string value3 = null; string value4 = null; KeyframeFlags flags; if (command.I_03_b2_Int16ForTime) { time = BitConverter.ToUInt16(rawBytes, offset + 8 + (i * 2)); } else { time = rawBytes[offset + 8 + i]; } if (command.I_03_b3_Int16ForValueIndex) { value = values[BitConverter.ToUInt16(rawBytes, offset + indexOffset + (i * 4))]; flags = (KeyframeFlags)BitConverter.ToUInt16(rawBytes, offset + indexOffset + 2 + (i * 4)); int extraOffset = 0; if (flags.HasFlag(KeyframeFlags.QuadraticBezier)) { ushort idx = (ushort)(BitConverter.ToUInt16(rawBytes, offset + indexOffset + (i * 4)) + 1); //idx might be out of range due to a bug with an older version of the parser... so in that case set it to value if (idx <= values.Length - 1) { value2 = values[idx].ToString(); } else { value2 = value.ToString(); } extraOffset++; } if (flags.HasFlag(KeyframeFlags.CubicBezier)) { ushort idx = (ushort)(BitConverter.ToUInt16(rawBytes, offset + indexOffset + (i * 4)) + 1 + extraOffset); //idx might be out of range due to a bug with an older version of the parser... so in that case set it to value if (idx + 1 <= values.Length - 1) { value3 = values[idx].ToString(); value4 = values[idx + 1].ToString(); } else { value3 = value.ToString(); value4 = value.ToString(); } extraOffset++; } } else { value = values[rawBytes[offset + indexOffset + (i * 2)]]; flags = (KeyframeFlags)rawBytes[offset + indexOffset + 1 + (i * 2)]; int extraOffset = 0; if (flags.HasFlag(KeyframeFlags.QuadraticBezier)) { byte idx = (byte)(rawBytes[offset + indexOffset + (i * 2)] + 1); if (idx <= values.Length - 1) { value2 = values[idx].ToString(); } else { value2 = value.ToString(); } } if (flags.HasFlag(KeyframeFlags.CubicBezier)) { byte idx = (byte)(rawBytes[offset + indexOffset + (i * 2)] + 1 + extraOffset); if (idx + 1 <= values.Length - 1) { value3 = values[idx].ToString(); value4 = values[idx + 1].ToString(); } else { value3 = value.ToString(); value4 = value.ToString(); } } } command.Keyframes.Add(new EMA_Keyframe() { Time = time, Value = value, Flags = flags, Value2 = value2, CubicBezier_1 = value3, CubicBezier_2 = value4 }); } return(command); }
/// <summary> /// Gets a pooled ema object based on type. /// </summary> /// <returns>The pooled ema by type.</returns> /// <param name="type">Type.</param> /// <param name="position">Position.</param> /// <param name="rotation">Rotation.</param> private GameObject GetPooledEmaByType (EmaType type, Vector3 position, Quaternion rotation) { if (type == EmaType.Wood) { GameObjectPool emaGameObjectPool = context.GameController.GameObjectPoolManager.GetPool (context.GameController.Prefabs.EmaPrefab); return(emaGameObjectPool.Take (position, rotation)); } else if (type == EmaType.Gold) { GameObjectPool goldEmaGameObjectPool = context.GameController.GameObjectPoolManager.GetPool (context.GameController.Prefabs.GoldEmaPrefab); return(goldEmaGameObjectPool.Take (position, rotation)); } else { throw new UnityException (string.Format ("Unsupported ema type '{0}' passed as argument.", type)); } }