Exemplo n.º 1
0
    private void OnCollisionEnter(Collision collision)
    {
        DoorProp door = collision.collider.GetComponent <DoorProp>();

        if (door != null)
        {
            Renderer renderer = door.GetComponent <Renderer>();
            if (door.safe)
            {
                renderer.material.SetColor("_Color", new Color(0.0f, 1.0f, 0.0f, 1.0f));
            }
            else if (!door.safe)
            {
                renderer.material.SetColor("_Color", new Color(0.0f, 0.0f, 0.0f, 1.0f));
            }
        }
    }
Exemplo n.º 2
0
    private void OnGUI()
    {
        filePath = GUI.TextField(new Rect(800, 50, 300, 30), filePath, 25);
        if (GUI.Button(new Rect(1100, 50, 200, 30), "Load"))
        {
            if (filePath != "")
            {
                readTextFile(filePath);

                for (int i = 0; i < numOfDoors; i++)
                {
                    DoorProp newInstance = Instantiate(door, new Vector3(-50.0f + (i * 5.0f), 2.0f, 10.0f), Quaternion.identity);
                    Renderer renderer    = newInstance.GetComponent <Renderer>();
                    DoorType doorProp    = DoorType.NotHotNotNoisy;

                    float randomNum  = Random.Range(0.0f, 100.0f);
                    float currentNum = 0.0f;
                    if (randomNum <= (currentNum += DoorProps.HotNoisySafe))
                    {
                        doorProp         = DoorType.HotNoisy;
                        newInstance.safe = true;
                    }
                    else if (randomNum <= (currentNum += DoorProps.HotNoisyNSafe))
                    {
                        doorProp         = DoorType.HotNoisy;
                        newInstance.safe = false;
                    }
                    else if (randomNum <= (currentNum += DoorProps.HotNNoisySafe))
                    {
                        doorProp         = DoorType.HotNotNoisy;
                        newInstance.safe = true;
                    }
                    else if (randomNum <= (currentNum += DoorProps.HotNNoisyNSafe))
                    {
                        doorProp         = DoorType.HotNotNoisy;
                        newInstance.safe = false;
                    }
                    else if (randomNum <= (currentNum += DoorProps.NHotNoisySafe))
                    {
                        doorProp         = DoorType.NotHotNoisy;
                        newInstance.safe = true;
                    }
                    else if (randomNum <= (currentNum += DoorProps.NHotNoisyNSafe))
                    {
                        doorProp         = DoorType.NotHotNoisy;
                        newInstance.safe = false;
                    }
                    else if (randomNum <= (currentNum += DoorProps.NHotNNoisySafe))
                    {
                        doorProp         = DoorType.NotHotNotNoisy;
                        newInstance.safe = true;
                    }
                    else if (randomNum <= (currentNum += DoorProps.NHotNNoisyNSafe))
                    {
                        doorProp         = DoorType.NotHotNotNoisy;
                        newInstance.safe = false;
                    }

                    Debug.Log(i + ", " + randomNum + ", " + currentNum + ", " + doorProp);

                    switch (doorProp)
                    {
                    case DoorType.HotNoisy:
                        renderer.material.SetColor("_Color", new Color(1.0f, 0.0f, 1.0f, 1.0f));
                        break;

                    case DoorType.HotNotNoisy:
                        renderer.material.SetColor("_Color", new Color(1.0f, 0.0f, 0.0f, 1.0f));
                        break;

                    case DoorType.NotHotNoisy:
                        renderer.material.SetColor("_Color", new Color(0.0f, 0.0f, 1.0f, 1.0f));
                        break;

                    case DoorType.NotHotNotNoisy:
                        renderer.material.SetColor("_Color", new Color(0.5f, 0.5f, 0.5f, 1.0f));
                        break;

                    default:
                        break;
                    }

                    doors.Add(newInstance);
                }

                foreach (DoorProp Door in doors)
                {
                    Door.transform.parent = this.transform;
                }
            }
        }
    }
Exemplo n.º 3
0
            private void ReadObject(BinaryReader reader, ref Header header, ref Object newObject, uint offset)
            {
                switch ((ObjectProperty)header.type)
                {
                case ObjectProperty.TypeSpecial:
                {
                    newObject.specialType = (SpecialObjectType)reader.ReadUInt32();
                }
                break;

                case ObjectProperty.TypeNormal:
                {
                    newObject.type = (ObjectType)reader.ReadUInt32();

                    if (newObject.type > 0 && newObject.type < ObjectType.LastType)
                    {
                        newObject.isPatch = false;
                    }
                }
                break;

                case ObjectProperty.Name:
                case ObjectProperty.Name_Special:
                {
                    newObject.name = ReadTerminatedString(reader);
                }
                break;

                case ObjectProperty.SpecialData:
                {
                    switch (newObject.specialType)
                    {
                    case SpecialObjectType.Physical:
                    {
                        reader.BaseStream.Seek(2, SeekOrigin.Current);
                        var newSpecialObject = new PhysicalProp();
                        newSpecialObject.movVal1  = reader.ReadSingle();
                        newSpecialObject.movVal2  = reader.ReadSingle();
                        newSpecialObject.weight   = reader.ReadSingle();
                        newSpecialObject.friction = reader.ReadSingle();
                        newSpecialObject.movVal4  = reader.ReadSingle();
                        newSpecialObject.sound    = reader.ReadInt32();
                        reader.BaseStream.Seek(1, SeekOrigin.Current);
                        newSpecialObject.movVal5 = reader.ReadInt32();
                        newObject.physicalObject = newSpecialObject;
                    }
                    break;

                    case SpecialObjectType.Door:
                    {
                        reader.BaseStream.Seek(5, SeekOrigin.Current);
                        var newSpecialObject = new DoorProp();
                        newSpecialObject.open1      = reader.ReadByte();
                        newSpecialObject.open2      = reader.ReadByte();
                        newSpecialObject.moveAngle  = reader.ReadSingle();
                        newSpecialObject.open       = reader.ReadByte();
                        newSpecialObject.locked     = reader.ReadByte();
                        newSpecialObject.closeSpeed = reader.ReadSingle();
                        newSpecialObject.openSpeed  = reader.ReadSingle();
                        newSpecialObject.openSound  = ReadTerminatedString(reader);
                        reader.BaseStream.Seek((16 - newSpecialObject.openSound.Length - 1), SeekOrigin.Current);
                        newSpecialObject.closeSound = ReadTerminatedString(reader);
                        reader.BaseStream.Seek((16 - newSpecialObject.closeSound.Length - 1), SeekOrigin.Current);
                        newSpecialObject.lockedSound = ReadTerminatedString(reader);
                        reader.BaseStream.Seek((16 - newSpecialObject.lockedSound.Length - 1), SeekOrigin.Current);
                        newSpecialObject.flag = reader.ReadByte();
                        newObject.doorObject  = newSpecialObject;
                    }
                    break;
                    }
                }
                break;

                case ObjectProperty.Model:
                {
                    newObject.modelName = ReadTerminatedString(reader).ToLower().Replace(".i3d", ".4ds");
                }
                break;

                case ObjectProperty.Hidden:
                {
                    newObject.isHidden = true;
                }
                break;

                case ObjectProperty.Position:
                {
                    newObject.pos = ReadVector3(reader);
                    newObject.isPositionPatched = true;
                }
                break;

                case ObjectProperty.Rotation:
                {
                    var rot = ReadQuat(reader);
                    newObject.rot = new Quaternion(rot.y, rot.z, rot.w, -1 * rot.x);
                    newObject.isRotationPatched = true;
                }
                break;

                case ObjectProperty.Position2:
                {
                    newObject.pos2 = ReadVector3(reader);
                    newObject.isPosition2Patched = true;
                }
                break;

                case ObjectProperty.Scale:
                {
                    newObject.scale          = ReadVector3(reader);
                    newObject.isScalePatched = true;
                }
                break;

                case ObjectProperty.Light_Main:
                {
                    uint position = offset;
                    while (position + 6 < offset + header.size)
                    {
                        var lightHeader = ReadHeader(reader);
                        ReadLight(reader, ref lightHeader, ref newObject);
                        position += lightHeader.size;
                    }
                }
                break;

                case ObjectProperty.Parent:
                {
                    var    parentHeader = ReadHeader(reader);
                    Object parentObject = new Object();
                    ReadObject(reader, ref parentHeader, ref parentObject, offset + 6);
                    newObject.parentName      = parentObject.name;
                    newObject.isParentPatched = true;
                }
                break;
                }
            }