示例#1
0
        public Material CreateMaterial()
        {
            if (collideMaterial != null)
            {
                return(collideMaterial.CreateMaterial());
            }
            Material mat = new Material(MapLoader.Loader.collideMaterial);

            return(mat);
        }
示例#2
0
        public GameObject GetGameObject(GameObject parent, int index, CollideType collideType = CollideType.None)
        {
            GameObject gao = GameObject.CreatePrimitive(PrimitiveType.Sphere);

            gao.name = "Sphere " + index;
            gao.transform.SetParent(parent.transform);
            MeshRenderer mr = gao.GetComponent <MeshRenderer>();

            gao.transform.localPosition = new Vector3(x / 256f, z / 256f, y / 256f);
            gao.transform.localScale    = Vector3.one * (radius / 256f) * 2;          // default Unity sphere radius is 0.5
            gao.layer = LayerMask.NameToLayer("Collide");

            BillboardBehaviour bill = gao.AddComponent <BillboardBehaviour>();

            bill.mode = BillboardBehaviour.LookAtMode.CameraPosXYZ;

            GameMaterial    gm = (Load as R2PS1Loader).levelHeader.gameMaterials?[gameMaterial];
            CollideMaterial cm = gm?.collideMaterial;

            if (cm != null)
            {
                mr.material = cm.CreateMaterial();
            }
            else
            {
                mr.material = new Material(MapLoader.Loader.collideMaterial);
            }
            if (collideType != CollideType.None)
            {
                Color col = mr.material.color;
                mr.material       = new Material(MapLoader.Loader.collideTransparentMaterial);
                mr.material.color = new Color(col.r, col.g, col.b, col.a * 0.7f);
                switch (collideType)
                {
                case CollideType.ZDD:
                    mr.material.SetTexture("_MainTex", Resources.Load <Texture2D>("Textures/zdd")); break;

                case CollideType.ZDM:
                    mr.material.SetTexture("_MainTex", Resources.Load <Texture2D>("Textures/zdm")); break;

                case CollideType.ZDE:
                    mr.material.SetTexture("_MainTex", Resources.Load <Texture2D>("Textures/zde")); break;

                case CollideType.ZDR:
                    mr.material.SetTexture("_MainTex", Resources.Load <Texture2D>("Textures/zdr")); break;
                }
            }
            CollideComponent cc = gao.AddComponent <CollideComponent>();

            cc.collidePS1 = this;
            cc.type       = collideType;

            return(gao);
        }
示例#3
0
        public GameObject GetGameObject(GameObject parent, int index, CollideType collideType = CollideType.None)
        {
            GameObject gao = GameObject.CreatePrimitive(PrimitiveType.Cube);

            gao.name = "Box " + index + " - " + Offset;
            gao.transform.SetParent(parent.transform);
            MeshRenderer mr        = gao.GetComponent <MeshRenderer>();
            Vector3      minVertex = new Vector3(x0, z0, y0) / R2PS1Loader.CoordinateFactor;
            Vector3      maxVertex = new Vector3(x1, z1, y1) / R2PS1Loader.CoordinateFactor;
            Vector3      center    = Vector3.Lerp(minVertex, maxVertex, 0.5f);

            gao.transform.localPosition = center;
            gao.transform.localScale    = maxVertex - minVertex;
            gao.layer = LayerMask.NameToLayer("Collide");

            GameMaterial    gm = (Load as R2PS1Loader).levelHeader.gameMaterials?[gameMaterial];
            CollideMaterial cm = gm?.collideMaterial;

            if (cm != null)
            {
                mr.material = cm.CreateMaterial();
            }
            else
            {
                mr.material = new Material(MapLoader.Loader.collideMaterial);
            }
            if (collideType != CollideType.None)
            {
                Color col = mr.material.color;
                mr.material       = new Material(MapLoader.Loader.collideTransparentMaterial);
                mr.material.color = new Color(col.r, col.g, col.b, col.a * 0.7f);
                switch (collideType)
                {
                case CollideType.ZDD:
                    mr.material.SetTexture("_MainTex", Resources.Load <Texture2D>("Textures/zdd")); break;

                case CollideType.ZDM:
                    mr.material.SetTexture("_MainTex", Resources.Load <Texture2D>("Textures/zdm")); break;

                case CollideType.ZDE:
                    mr.material.SetTexture("_MainTex", Resources.Load <Texture2D>("Textures/zde")); break;

                case CollideType.ZDR:
                    mr.material.SetTexture("_MainTex", Resources.Load <Texture2D>("Textures/zdr")); break;
                }
            }

            CollideComponent cc = gao.AddComponent <CollideComponent>();

            cc.collidePS1 = this;
            cc.type       = collideType;

            return(gao);
        }