Exemplo n.º 1
0
        public PhysicalObjectComponent GetGameObject(GameObject gao = null)
        {
            if (gao == null)
            {
                gao = new GameObject("PO @ " + Offset);
            }
            else
            {
                gao.name += " - PO @ " + Offset;
            }
            PhysicalObjectComponent poc = gao.AddComponent <PhysicalObjectComponent>();

            if (visual.Value != null)
            {
                GameObject child = visual.Value.GetGameObject(GeometricObject.Type.Visual);
                child.transform.SetParent(gao.transform);
                child.name = "[Visual] " + child.name;
                poc.visual = child;
            }
            if (collide.Value != null && collide.Value.mesh.Value != null)
            {
                GameObject child = collide.Value.mesh.Value.GetGameObject(GeometricObject.Type.Collide);
                child.transform.SetParent(gao.transform);
                child.name  = "[Collide] " + child.name;
                poc.collide = child;
                poc.collide.SetActive(false);
            }
            poc.Init(MapLoader.Loader.controller);
            return(poc);
        }
Exemplo n.º 2
0
            public GameObject GetGameObject(PhysicalObjectCollisionMapping[] collision, out GameObject[] bones, Entry morphEntry = null, float morphProgress = 0f)
            {
                bones = null;
                GameObject gao = geo?.GetGameObject(out bones, morphObject: morphEntry?.geo, morphProgress: morphProgress);

                if (gao != null)
                {
                    GameObject wrapper = new GameObject(gao.name + " - Wrapper");
                    if (morphProgress > 0 || morphEntry != null)
                    {
                        gao.name += " - Morph Progress: " + morphProgress;
                    }
                    gao.transform.SetParent(wrapper.transform);
                    gao.transform.localPosition = Vector3.zero;
                    gao.transform.localRotation = Quaternion.identity;
                    gao.transform.localScale    = Vector3.one;
                    PhysicalObjectComponent poc = wrapper.AddComponent <PhysicalObjectComponent>();
                    poc.visual = gao;
                    if (collision != null)
                    {
                        PhysicalObjectCollisionMapping cm = collision.FirstOrDefault(c => c.off_poListEntry == offset);
                        if (cm != null && cm.geo_collide != null)
                        {
                            GameObject cgao = cm.geo_collide.GetGameObject();
                            cgao.transform.SetParent(wrapper.transform);
                            cgao.transform.localPosition = Vector3.zero;
                            cgao.transform.localRotation = Quaternion.identity;
                            cgao.transform.localScale    = Vector3.one;
                            poc.collide = cgao;
                        }
                    }
                    poc.Init(MapLoader.Loader.controller);
                    return(wrapper);
                }
                else
                {
                    return(gao);
                }
            }
Exemplo n.º 3
0
        public GameObject GetGameObject()
        {
            GameObject gao = new GameObject(type + " @ " + Offset);

            if (FileSystem.mode == FileSystem.Mode.Web)
            {
                gao.name = type.ToString();
            }

            SuperObjectComponent soc = gao.AddComponent <SuperObjectComponent>();

            gao.layer = LayerMask.NameToLayer("SuperObject");
            soc.soPS1 = this;
            MapLoader.Loader.controller.superObjects.Add(soc);

            if (type != Type.IPO)
            {
                matrix1?.Apply(gao);
            }

            /*if (.Value != null) {
             *      if (data.Value is PhysicalObject) {
             *              PhysicalObjectComponent poc = ((PhysicalObject)data.Value).GetGameObject(gao);
             *      } else if (data.Value is Sector) {
             *              SectorComponent sc = ((Sector)data.Value).GetGameObject(gao);
             *      }
             * }*/
            if (type == Type.IPO)
            {
                PhysicalObjectComponent poc = gao.AddComponent <PhysicalObjectComponent>();
                LevelHeader             h   = (Load as R2PS1Loader).levelHeader;
                int ind = (dataIndex >> 1);
                if (ind >= h.geometricObjectsStatic.entries.Length)
                {
                    throw new Exception("IPO SO data index was too high! " + h.geometricObjectsStatic.entries.Length + " - " + dataIndex);
                }
                gao.name = gao.name + " - " + ind;
                GameObject g = h.geometricObjectsStatic.GetGameObject(ind, null, out _);
                if (g != null)
                {
                    poc.visual = g;
                    g.transform.SetParent(gao.transform);
                    g.transform.localPosition = Vector3.zero;
                    g.transform.localRotation = Quaternion.identity;
                }
                if (h.ipoCollision != null && h.ipoCollision.Length > ind)
                {
                    GameObject c = h.ipoCollision[ind].GetGameObject();
                    if (c != null)
                    {
                        poc.collide = c;
                        c.transform.SetParent(gao.transform);
                        c.transform.localPosition = Vector3.zero;
                        c.transform.localRotation = Quaternion.identity;
                    }
                }
                poc.Init(MapLoader.Loader.controller);
            }
            else if (type == Type.Perso)
            {
                LevelHeader h = (Load as R2PS1Loader).levelHeader;
                if (dataIndex >= h.persos.Length)
                {
                    throw new Exception("Perso SO data index was too high! " + h.persos.Length + " - " + dataIndex);
                }
                gao.name = gao.name + " - " + dataIndex;
                PS1PersoBehaviour ps1Perso = h.persos[dataIndex].GetGameObject(gao);
                ps1Perso.superObject = this;
            }
            else if (type == Type.Sector)
            {
                LevelHeader h = (Load as R2PS1Loader).levelHeader;
                if (dataIndex >= h.sectors.Length)
                {
                    throw new Exception("Sector SO data index was too high! " + h.sectors.Length + " - " + dataIndex);
                }
                gao.name = gao.name + " - " + dataIndex;
                SectorComponent sect = h.sectors[dataIndex].GetGameObject(gao);
            }
            if (children != null)
            {
                foreach (SuperObject so in children)
                {
                    if (so != null)
                    {
                        GameObject soGao = so.GetGameObject();
                        if (soGao != null)
                        {
                            soc.Children.Add(soGao.GetComponent <SuperObjectComponent>());
                            soGao.transform.SetParent(gao.transform);
                            if (so.type != Type.IPO)
                            {
                                so.matrix1?.Apply(soGao);
                            }
                            else
                            {
                                soGao.transform.localPosition = Vector3.zero;
                                soGao.transform.localRotation = Quaternion.identity;
                            }
                        }
                    }
                }
            }
            return(gao);
        }