void OnInitialize() { try { transform.position = new Vector3(-m_proto.m_header.m_pos.x, m_proto.m_header.m_pos.y, m_proto.m_header.m_pos.z); foreach (RTOBOA obj in m_myOBJS = RTOBOA.GetByDoorID((int)m_proto.m_doorID & 0x0FFF)) { Round2.Generated.Binary.OBOA.Package l_pkg = obj.m_proto; m_rotations.Add(m_proto.m_header.m_rot); gameObject.name = m_proto.m_doorType + "::" + m_proto.m_doorID + "(" + m_proto.m_keyID + ")"; Round2.Generated.Binary.DOOR l_doorClass = Round2.Generated.Binary.DOOR.PendDoorClass(m_proto.m_doorType); obj.SetOBANInput(l_doorClass.m_OBAN_link_10.Value); if (l_pkg != null) { Round2.Generated.Binary.OBAN.Package l_frame0 = l_doorClass.m_OBAN_link_10.Value.m_pkg_80[0]; Vector3 l_rot = new Oni.Quaternion(l_frame0.m_x_rot_0, l_frame0.m_y_rot_4, l_frame0.m_z_rot_8, l_frame0.m_w_rot_C).UnityQuaternionRaw().eulerAngles; m_rotations.Add(l_rot); obj.transform.position = new Vector3(-l_pkg.m_x_pos_20, l_pkg.m_y_pos_24, l_pkg.m_z_pos_28); Oni.Vector3 l_scale; Oni.Vector3 l_pos; Oni.Quaternion l__rot; m_rotations.Add(l__rot.UnityQuaternionRaw().eulerAngles); l_doorClass.m_OBAN_link_10.Value.InitialTransform.Decompose(out l_scale, out l__rot, out l_pos); //more looks like a hack. Still works fine. obj.transform.rotation = Quaternion.Euler(m_rotations[0]) * Quaternion.Euler(m_rotations[1]) * Quaternion.Euler(180, 0, 0); } GameObject l_pivot = new GameObject("pivot"); l_pivot.transform.parent = transform; l_pivot.transform.position = obj.transform.position; l_pivot.transform.rotation = obj.transform.rotation; obj.transform.parent = l_pivot.transform; if (obj.m_proto.m_door_id_14 > 0 && ((int)obj.m_proto.m_door_id_14 & 0x1000) != 0) { //l_pivot.name += " # mirror "; l_pivot.transform.rotation *= Quaternion.Euler(180, 180, 0); } obj.gameObject.SetActive(true); } SphereCollider l_sc = gameObject.AddComponent <SphereCollider>(); l_sc.radius = Mathf.Sqrt(m_proto.m_activationRadius) / 2f; l_sc.center = Vector3.up * (l_sc.radius); l_sc.isTrigger = true; } catch (System.Exception ee) { Debug.LogException(ee, this); } }
public void BuildONCC(Oni.InstanceDescriptor l__oncc) { M3GM[] l_bodyParts = new M3GM[19]; GameObject[] l_gs = new GameObject[19]; m_singleton = this; { int l_i = 0; foreach (Round2.Generated.Binary.TRGA.Package pkg in this.m_TRBS_link_C3C.Value.m_TRCM_link_18.Value.m_TRGA_link_5C.Value.m_pkg_20) { l_bodyParts[l_i++] = pkg.m_M3GM_link_0.Value; } } { int l_i = 0; foreach (M3GM m in l_bodyParts) { Texture2D m_tex = this.m_TRMA_link_C40.Value.m_pkg_20[l_i].m_TXMP_link_0.Value.Surface_0; l_gs[l_i] = new GameObject(((Bodyparts)l_i).ToString()); l_gs[l_i].AddComponent <MeshFilter>().mesh = m.UnityMesh; (l_gs[l_i++].AddComponent <MeshRenderer>().material = new Material(Shader.Find("TwoSidedDiffuse"))).mainTexture = m_tex; } } { int l_i = 0; string child = ""; string parent = ""; string sibling = ""; int l_latestParent = 0; int l_nextChainStart = 0; List <int> l_childs = new List <int>(); List <int> l_siblings = new List <int>(); foreach (TRIA.Package pkg in this.m_TRBS_link_C3C.Value.m_TRCM_link_18.Value.m_TRIA_link_64.Value.m_pkg_20) { child += "|" + pkg.m_Major_joint_1; sibling += "|" + pkg.m_Minor_joint_2; parent += "|" + pkg.m_Not_used_0; l_childs.Add(pkg.m_Major_joint_1); l_siblings.Add(pkg.m_Minor_joint_2); if (pkg.m_Major_joint_1 != 0) { l_gs[pkg.m_Major_joint_1].transform.parent = l_gs[l_i].transform; } if (pkg.m_Minor_joint_2 != 0) { l_gs[pkg.m_Minor_joint_2].transform.parent = l_gs[l_i].transform.parent; } l_i++; } Debug.Log(parent); Debug.Log(child); Debug.Log(sibling); l_i = 0; foreach (TRTA.Package pkg in this.m_TRBS_link_C3C.Value.m_TRCM_link_18.Value.m_TRTA_link_60.Value.m_pkg_20) { l_gs[l_i++].transform.localPosition = new UnityEngine.Vector3(-pkg.m_x_position_0, pkg.m_y_position_4, pkg.m_z_position_8); } int stub = this.m_TRAC_link_C88.Value.m_pkg_20.Length; Oni.Game.CharacterClass l_oncc = Oni.Game.CharacterClass.Read(l__oncc); foreach (Oni.InstanceDescriptor animdes in l_oncc.Animations) { Oni.Totoro.Animation l_tram = Oni.Totoro.AnimationDatReader.Read(animdes); AddAnimInfo(animdes.Name, l_tram); string l_clipname = animdes.Name; if (l_tram.FrameSize != 6)//TODO: fix? { continue; } AnimationClipHolder.Hold(animdes.Name, controller => { Debug.LogWarning("building clip : " + l_clipname); bool frameSize = l_tram.FrameSize == 6; AnimationClip l_clip = new AnimationClip(); l_clip.name = l_clipname; for (int i = 0; i < l_tram.Rotations.Count; i++) { Keyframe[] l_kFrx = new Keyframe[l_tram.Rotations[i].Count]; Keyframe[] l_kFry = new Keyframe[l_tram.Rotations[i].Count]; Keyframe[] l_kFrz = new Keyframe[l_tram.Rotations[i].Count]; Keyframe[] l_kFrw = new Keyframe[l_tram.Rotations[i].Count]; int l_duration = 0; for (int j = 0; j < l_tram.Rotations[i].Count; j++) { UnityEngine.Quaternion _l_q; if (!frameSize) { Oni.Quaternion l_q = new Oni.Quaternion(l_tram.Rotations[i][j].Rotation); _l_q = UnityEngine.Quaternion.Euler(Oni.MathHelper.ToDegrees(l_q.ToEulerXYZ().X), Oni.MathHelper.ToDegrees(l_q.ToEulerXYZ().Y), Oni.MathHelper.ToDegrees(l_q.ToEulerXYZ().Z)); } else { Oni.Quaternion qq = Oni.Quaternion.CreateFromEulerXYZ(l_tram.Rotations[i][j].Rotation.X, -l_tram.Rotations[i][j].Rotation.Y, -l_tram.Rotations[i][j].Rotation.Z); _l_q = new UnityEngine.Quaternion(qq.X, qq.Y, qq.Z, qq.W); } l_kFrx[j] = new Keyframe(l_duration * 0.0166666675f, _l_q.x); l_kFry[j] = new Keyframe(l_duration * 0.0166666675f, _l_q.y); l_kFrz[j] = new Keyframe(l_duration * 0.0166666675f, _l_q.z); l_kFrw[j] = new Keyframe(l_duration * 0.0166666675f, _l_q.w); l_duration = l_duration + l_tram.Rotations[i][j].Duration; } System.Text.StringBuilder sb = new System.Text.StringBuilder(); string l_path = ""; l_path = ""; sb.Remove(0, sb.Length); sb.Append(((Bodyparts)i).ToString()); l_path = ""; for (Transform _i = l_gs[i].transform.parent; _i.parent != null; _i = _i.transform.parent) { sb.Insert(0, '/'); sb.Insert(0, _i.name); } l_path = sb.ToString(); l_clip.SetCurve(l_path, typeof(Transform), "m_LocalRotation.x", new AnimationCurve(l_kFrx)); l_clip.SetCurve(l_path, typeof(Transform), "m_LocalRotation.y", new AnimationCurve(l_kFry)); l_clip.SetCurve(l_path, typeof(Transform), "m_LocalRotation.z", new AnimationCurve(l_kFrz)); l_clip.SetCurve(l_path, typeof(Transform), "m_LocalRotation.w", new AnimationCurve(l_kFrw)); } List <float> posXList = new List <float>(); List <float> posYList = new List <float>(); List <float> posZList = new List <float>(); for (int k = 0; k < l_tram.Velocities.Count; k++) { posXList.Add(-l_tram.Velocities[k].X); if (l_tram.Heights.Count <= k) { posYList.Add(0); } else { posYList.Add(l_tram.Heights[k]); } posZList.Add(l_tram.Velocities[k].Y); } { float _iien = 0; float timer = 0; l_clip.SetCurve("", typeof(GUIANIMCONTROL), "m_motionVector.x", new AnimationCurve(posXList.ConvertAll <Keyframe>(frame => { Keyframe res = new Keyframe(timer += 0.0166666675f, frame / 0.0166666675f); return(res); }).ToArray())); } { float _iien = 0; float timer = 0; l_clip.SetCurve("pelvis", typeof(Transform), "m_LocalPosition.y", new AnimationCurve(posYList.ConvertAll <Keyframe>(frame => { Keyframe res = new Keyframe(timer += 0.0166666675f, frame); _iien = frame; return(res); }).ToArray())); } { float _iien = 0; float timer = 0; l_clip.SetCurve("", typeof(GUIANIMCONTROL), "m_motionVector.z", new AnimationCurve(posZList.ConvertAll <Keyframe>(frame => { Keyframe res = new Keyframe(timer += 0.0166666675f, frame / 0.0166666675f); return(res); }).ToArray())); AnimationEvent ev = null; l_clip.AddEvent(ev = new AnimationEvent() { objectReferenceParameter = controller, functionName = "OnActionFrame", time = timer - 1 / 60f, stringParameter = l_clipname }); // m_events.Add(desc.Name, ev); } l_clip.EnsureQuaternionContinuity(); l_clip.wrapMode = WrapMode.ClampForever; return(l_clip); }); } } GameObject l_parent = new GameObject(); l_gs[0].transform.parent = l_parent.transform; Debug.Log("added", l_parent.AddComponent <GUIANIMCONTROL>()); Camera.allCameras[0].transform.parent = l_parent.transform; CharacterController l_cc = l_parent.AddComponent <CharacterController>(); l_cc.radius = 4; l_cc.center = UnityEngine.Vector3.up * 9; l_cc.height = 18; l_parent.AddComponent <Animation>(); }
internal static Quaternion UnityQuaternionRaw(this Oni.Quaternion @this) { return(new Quaternion(@this.X, @this.Y, @this.Z, @this.W)); }