Example #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public VehicleDoor(GameObject go, ObjectSyncComponent syncComponent)
        {
            gameObject = go;
            osc        = syncComponent;

            // Rear door of van and vehicle trunks.
            if (go.name == "RearDoor" || go.name == "Bootlid")
            {
                doorType = DoorTypes.RearDoor;
                // Van, Old car.
                if (go.transform.FindChild("doorear"))
                {
                    gameObject = go.transform.FindChild("doorear").gameObject;
                }
                // Ferndale.
                else
                {
                    gameObject = go.transform.FindChild("Bootlid").gameObject;
                }
            }
            // Driver and passenger doors.
            else if (go.name == "doorl" || go.name == "doorr" || go.name == "door(leftx)" || go.name == "door(right)")
            {
                doorType = DoorTypes.DriverDoor;
            }

            hinge        = gameObject.GetComponent <HingeJoint>();
            lastRotation = hinge.angle;
            rigidbody    = gameObject.GetComponent <Rigidbody>();

            HookEvents();
        }
    public void NewLevel(DoorTypes type, int lvl, int sublvl)
    {
        if (gameController == null)
        {
            Start();
        }

        HideDoors();
        if (type == DoorTypes.hub)
        {
            //Volta รก BASE
            bossLevel = false;
            hub       = true;
            HubLevel();
            Debug.Log("BASE level");
        }
        else
        {
            hub = false;
            HubScene.SetActive(false);
            level           = lvl;
            sublevel        = sublvl;
            bossLevel       = (sublevel == gameController.sublevelMax);
            levelMultiplier = savedLevelMultiplier * level;
            totalEnemies    = sublevel * levelMultiplier;
            enemiesToKill   = totalEnemies;
            enemiesSpawned  = 0;
        }
        StartCoroutine(LevelStartTimer());
    }
Example #3
0
 public Door(Vector2 position, float speed, string name, bool on, DoorTypes type)
 {
     Name      = name;
     _door     = new Movable(new RectangleF(32, 128, position.X, position.Y));
     Position  = position;
     _speedMax = speed;
     On        = on;
     _type     = type;
 }
Example #4
0
 public Door(string sprite, int x, int y, string state, int id, DoorTypes type, string linktoarea, int linktodoor, int exitx, int exity, bool sensor) : base(sprite, x, y, state)
 {
     ID          = id;
     Type        = type;
     LinkToArea  = linktoarea;
     LinkToDoor  = linktodoor;
     ExitX       = exitx;
     ExitY       = exity;
     Sensor      = sensor;
     SensorState = false;
 }
 public void SetType(DoorTypes type)
 {
     this.type = type;
     if (type == DoorTypes.hub)
     {
         meshRenderer.material = materials [1];             //white
     }
     else
     {
         meshRenderer.material = materials [0];             //black
     }
 }
Example #6
0
 public void SetType(DoorTypes type)
 {
     this.type = type;
     if (type == DoorTypes.hub)
     {
         meshRenderer.material = materials [1];             //Branco
     }
     else
     {
         meshRenderer.material = materials [0];             //Preto
     }
 }
Example #7
0
 public void LevelUp(DoorTypes type)
 {
     if (type != DoorTypes.hub)
     {
         sublevel++;
         if (sublevel > sublevelMax)
         {
             sublevel = 1;
             level++;
         }
     }
     levelController.NewLevel(type, level, sublevel);
 }
Example #8
0
    public Door CreateDoor(int x, int y, DoorTypes type, DoorStates state, DoorDirections direction)
    {
        Transform parent = this.container.Find("Entities/Doors");

        GameObject obj = GameObject.Instantiate(prefabs.doors[type]);
        obj.transform.SetParent(parent, false);
        obj.name = type.ToString(); //"Item";
        Door door = obj.GetComponent<Door>();
        door.Init(this, x, y, Color.white);

        door.type = type;
        door.state = state;
        door.SetDirection(direction);

        return door;
    }
Example #9
0
    public GameObject CreateDoor(DoorTypes type, Transform parent, Vector3 position, Quaternion rotation, int region)
    {
        GameObject door = null;

        if (doors.Length > 0)
        {
            door = SearchResource(doors, (int)type, maxDoorIndex);
            if (door)
            {
                door.transform.parent        = parent;
                door.transform.localPosition = position;
                door.transform.localRotation = rotation;
            }
        }
        return(door);
    }
        /// <summary>
        /// Finds all doors of type across multiple door collections.
        /// </summary>
        /// <param name="doorCollections">Door collections.</param>
        /// <param name="type">Type of door to search for.</param>
        /// <returns>Array of matching doors.</returns>
        public static StaticDoor[] FindDoorsInCollections(DaggerfallStaticDoors[] doorCollections, DoorTypes type)
        {
            List <StaticDoor> doorsOut = new List <StaticDoor>();

            foreach (var collection in doorCollections)
            {
                for (int i = 0; i < collection.Doors.Length; i++)
                {
                    if (collection.Doors[i].doorType == type)
                    {
                        StaticDoor newDoor = collection.Doors[i];
                        newDoor.ownerPosition = collection.transform.position;
                        newDoor.ownerRotation = collection.transform.rotation;
                        doorsOut.Add(newDoor);
                    }
                }
            }

            return(doorsOut.ToArray());
        }
        /// <summary>
        /// Find closest door to player position in world space.
        /// </summary>
        /// <param name="playerPos">Player position in world space.</param>
        /// <param name="record">Door record index.</param>
        /// <param name="doorPosOut">Position of closest door in world space.</param>
        /// <param name="doorIndexOut">Door index in Doors array of closest door.</param>
        /// <returns></returns>
        public bool FindClosestDoorToPlayer(Vector3 playerPos, int record, out Vector3 doorPosOut, out int doorIndexOut, DoorTypes requiredDoorType = DoorTypes.None)
        {
            // Init output
            doorPosOut   = Vector3.zero;
            doorIndexOut = -1;

            // Must have door array
            if (Doors == null)
            {
                return(false);
            }

            // Find closest door to player position
            float minDistance = float.MaxValue;
            bool  found       = false;

            for (int i = 0; i < Doors.Length; i++)
            {
                // Must be of door type if set
                if (requiredDoorType != DoorTypes.None && Doors[i].doorType != requiredDoorType)
                {
                    continue;
                }

                // Check if door belongs to same building record or accept any record
                if (record == -1 || Doors[i].recordIndex == record)
                {
                    // Get this door centre in world space
                    Vector3 centre = transform.rotation * Doors[i].buildingMatrix.MultiplyPoint3x4(Doors[i].centre) + transform.position;

                    // Check distance and save closest
                    float distance = Vector3.Distance(playerPos, centre);
                    if (distance < minDistance)
                    {
                        doorPosOut   = centre;
                        doorIndexOut = i;
                        minDistance  = distance;
                        found        = true;
                    }
                }
            }

            return(found);
        }
Example #12
0
        private void LoadVertices(ref ModelData model, float scale)
        {
            const int BuildingDoors         = 74;
            const int DungeonEnterDoors     = 56;
            const int DungeonRuinEnterDoors = 331;
            const int DungeonExitDoors      = 95;

            //const int dungeonFloorRecord = 2;

            // Allocate arrays
            model.Vertices = new Vector3[model.DFMesh.TotalVertices];
            model.Normals  = new Vector3[model.DFMesh.TotalVertices];
            model.UVs      = new Vector2[model.DFMesh.TotalVertices];

            // Static door and dungeon floor lists
            List <ModelDoor> modelDoors = new List <ModelDoor>();
            //List<DFMesh.DFPlane> dungeonFloors = new List<DFMesh.DFPlane>();

            // Loop through all submeshes
            int vertexCount = 0;

            foreach (DFMesh.DFSubMesh dfSubMesh in model.DFMesh.SubMeshes)
            {
                // Get cached material data
                CachedMaterial cm;
                dfUnity.MaterialReader.GetCachedMaterial(dfSubMesh.TextureArchive, dfSubMesh.TextureRecord, 0, out cm);
                Vector2 sz = cm.recordSizes[0];

                // Get texture archive for this submesh as base climate
                int submeshTextureArchive = dfSubMesh.TextureArchive;
                int baseTextureArchive    = (submeshTextureArchive - (submeshTextureArchive / 100) * 100);

                // Get base climate archive for door check
                // All base door textures are > 100, except dungeon ruins doors
                int doorArchive = submeshTextureArchive;
                if (doorArchive > 100 && doorArchive != DungeonRuinEnterDoors)
                {
                    doorArchive = baseTextureArchive;
                }

                // Check if this is a door archive
                bool      doorFound = false;
                DoorTypes doorType  = DoorTypes.None;
                switch (doorArchive)
                {
                case BuildingDoors:
                    doorFound = true;
                    doorType  = DoorTypes.Building;
                    break;

                case DungeonEnterDoors:
                    doorFound = true;
                    doorType  = DoorTypes.DungeonEntrance;
                    break;

                case DungeonRuinEnterDoors:
                    if (dfSubMesh.TextureRecord > 0)        // Dungeon ruins index 0 is just a stone texture
                    {
                        doorFound = true;
                        doorType  = DoorTypes.DungeonEntrance;
                    }
                    break;

                case DungeonExitDoors:
                    doorFound = true;
                    doorType  = DoorTypes.DungeonExit;
                    break;
                }

                //// Check if this is a dungeon floor
                //bool dungeonFloorFound = false;
                //if (baseTextureArchive >= 19 && baseTextureArchive <= 24 && dfSubMesh.TextureRecord == dungeonFloorRecord)
                //    dungeonFloorFound = true;

                // Loop through all planes in this submesh
                int doorCount = 0;
                foreach (DFMesh.DFPlane dfPlane in dfSubMesh.Planes)
                {
                    // If this is a door then each plane is a single door
                    if (doorFound)
                    {
                        // Set door verts
                        DFMesh.DFPoint p0        = dfPlane.Points[0];
                        DFMesh.DFPoint p1        = dfPlane.Points[1];
                        DFMesh.DFPoint p2        = dfPlane.Points[2];
                        ModelDoor      modelDoor = new ModelDoor()
                        {
                            Index = doorCount++,
                            Type  = doorType,
                            Vert0 = new Vector3(p0.X, -p0.Y, p0.Z) * scale,
                            Vert1 = new Vector3(p1.X, -p1.Y, p1.Z) * scale,
                            Vert2 = new Vector3(p2.X, -p2.Y, p2.Z) * scale,
                        };

                        // Set door normal
                        Vector3 u = modelDoor.Vert0 - modelDoor.Vert2;
                        Vector3 v = modelDoor.Vert0 - modelDoor.Vert1;
                        modelDoor.Normal = Vector3.Normalize(Vector3.Cross(u, v));

                        // Add door to list
                        modelDoors.Add(modelDoor);
                    }

                    //// If this a floor then store the polygon
                    //if (dungeonFloorFound)
                    //    dungeonFloors.Add(dfPlane);

                    // Copy each point in this plane to vertex buffer
                    foreach (DFMesh.DFPoint dfPoint in dfPlane.Points)
                    {
                        // Position and normal
                        Vector3 position = new Vector3(dfPoint.X, -dfPoint.Y, dfPoint.Z) * scale;
                        Vector3 normal   = new Vector3(dfPoint.NX, -dfPoint.NY, dfPoint.NZ);

                        // Store vertex data
                        model.Vertices[vertexCount] = position;
                        model.Normals[vertexCount]  = Vector3.Normalize(normal);
                        model.UVs[vertexCount]      = new Vector2((dfPoint.U / sz.x), -(dfPoint.V / sz.y));

                        // Inrement count
                        vertexCount++;
                    }
                }
            }

            // Assign found doors
            model.Doors = modelDoors.ToArray();
            //model.DungeonFloors = dungeonFloors.ToArray();
        }
 public void PlayerDoorCollide(DoorTypes type)
 {
     gameController.LevelUp(type);
     LevelEnd();
 }
        /// <summary>
        /// Finds all doors of type across multiple door collections.
        /// </summary>
        /// <param name="doorCollections">Door collections.</param>
        /// <param name="type">Type of door to search for.</param>
        /// <returns>Array of matching doors.</returns>
        public static StaticDoor[] FindDoorsInCollections(DaggerfallStaticDoors[] doorCollections, DoorTypes type)
        {
            List<StaticDoor> doorsOut = new List<StaticDoor>();
            foreach (var collection in doorCollections)
            {
                for (int i = 0; i < collection.Doors.Length; i++)
                {
                    if (collection.Doors[i].doorType == type)
                    {
                        StaticDoor newDoor = collection.Doors[i];
                        newDoor.ownerPosition = collection.transform.position;
                        newDoor.ownerRotation = collection.transform.rotation;
                        doorsOut.Add(newDoor);
                    }
                }
            }

            return doorsOut.ToArray();
        }