Exemplo n.º 1
0
    internal static void Instantiate(Round2.Generated.Binary.OBOA.Package proto)
    {
        RTOBOA l_obj = GameObject.CreatePrimitive(PrimitiveType.Plane).AddComponent <RTOBOA>();

        Destroy(l_obj.collider);
        l_obj.m_proto            = proto;
        l_obj.transform.position = new Vector3(-proto.m_x_pos_20, proto.m_y_pos_24, proto.m_z_pos_28);
        l_obj.transform.rotation = new Quaternion(proto.m_x_pos_20, proto.m_y_rot_30, proto.m_z_rot_34, proto.m_w_rot_38);

        if (proto.m_M3GA_link_0.m_lnkId != 0)
        {
            Round2.Generated.Binary.M3GM l_m3gm = proto.m_M3GA_link_0.Value.m_pkg_20[0].m_M3GM_link_0.Value;
            l_obj.GetComponent <MeshFilter>().mesh = l_m3gm.UnityMesh;
            l_obj.gameObject.AddComponent <MeshCollider>().mesh = l_m3gm.UnityMesh;
            l_obj.renderer.material.mainTexture = l_m3gm.m_TXMP_link_24.Value.Surface_0;
        }

        if (proto.m_door_id_14 > 0)
        {
            int l_realdID = proto.m_door_id_14 & 0x0FFF;

            if (!m_doorIDLST.ContainsKey(l_realdID))
            {
                m_doorIDLST.Add(l_realdID, new List <RTOBOA>());
            }

            m_doorIDLST[l_realdID].Add(l_obj);
        }

        l_obj.gameObject.SetActive(false);
    }
Exemplo n.º 2
0
        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>();
        }