Beispiel #1
0
        private static void StepLoadSpecialTextures()
        {
            // Load mouse cursor texture
            F.RunExceptionSafe(() =>
            {
                Texture2D mouse = TextureDictionary.Load("fronten_pc").GetDiffuse("mouse",
                                                                                  new TextureLoadParams()
                {
                    makeNoLongerReadable = false
                }).Texture;
                Texture2D mouseFix = new Texture2D(mouse.width, mouse.height);

                for (int x = 0; x < mouse.width; x++)
                {
                    for (int y = 0; y < mouse.height; y++)
                    {
                        mouseFix.SetPixel(x, mouse.height - y - 1, mouse.GetPixel(x, y));
                    }
                }

                mouseFix.Apply();

                Cursor.SetCursor(mouseFix, Vector2.zero, CursorMode.Auto);
            });

            // fist texture
            Weapon.FistTexture = TextureDictionary.Load("hud").GetDiffuse("fist").Texture;


            onLoadSpecialTextures();
        }
 public static Geometry.GeometryParts LoadGeometryParts(VehicleDef vehicleDef)
 {
     return(Geometry.Load(vehicleDef.ModelName,
                          TextureDictionary.Load(vehicleDef.TextureDictionaryName),
                          TextureDictionary.Load("vehicle"),
                          TextureDictionary.Load("misc")));
 }
Beispiel #3
0
        private static void StepLoadSpecialTextures()
        {
            // Load mouse cursor texture
            Texture2D mouse    = TextureDictionary.Load("fronten_pc").GetDiffuse("mouse").Texture;
            Texture2D mouseFix = new Texture2D(mouse.width, mouse.height);

            for (int x = 0; x < mouse.width; x++)
            {
                for (int y = 0; y < mouse.height; y++)
                {
                    mouseFix.SetPixel(x, mouse.height - y - 1, mouse.GetPixel(x, y));
                }
            }

            mouseFix.Apply();
            Cursor.SetCursor(mouseFix, Vector2.zero, CursorMode.Auto);

            // load crosshair texture
            Weapon.CrosshairTexture = TextureDictionary.Load("hud").GetDiffuse("siteM16").Texture;

            // fist texture
            Weapon.FistTexture = TextureDictionary.Load("hud").GetDiffuse("fist").Texture;

            // arrow textures
            var pcbtnsTxd = TextureDictionary.Load("pcbtns");

            UI.HUD.LeftArrowTexture  = pcbtnsTxd.GetDiffuse("left").Texture;
            UI.HUD.RightArrowTexture = pcbtnsTxd.GetDiffuse("right").Texture;
            UI.HUD.UpArrowTexture    = pcbtnsTxd.GetDiffuse("up").Texture;
            UI.HUD.DownArrowTexture  = pcbtnsTxd.GetDiffuse("down").Texture;
        }
Beispiel #4
0
        void LoadCrosshairTexture()
        {
            Texture2D originalTex = TextureDictionary.Load("hud")
                                    .GetDiffuse("siteM16", new TextureLoadParams {
                makeNoLongerReadable = false
            })
                                    .Texture;

            // construct crosshair texture

            int originalWidth  = originalTex.width;
            int originalHeight = originalTex.height;

            Texture2D tex = new Texture2D(originalWidth * 2, originalHeight * 2, TextureFormat.ARGB32, false, true);

            // bottom left
            for (int i = 0; i < originalWidth; i++)
            {
                for (int j = 0; j < originalHeight; j++)
                {
                    tex.SetPixel(i, j, originalTex.GetPixel(i, j));
                }
            }

            // bottom right - flip around X axis
            for (int i = 0; i < originalWidth; i++)
            {
                for (int j = 0; j < originalHeight; j++)
                {
                    tex.SetPixel(originalWidth - i - 1 + originalWidth, j, originalTex.GetPixel(i, j));
                }
            }

            // top left - flip Y axis
            for (int i = 0; i < originalWidth; i++)
            {
                for (int j = 0; j < originalHeight; j++)
                {
                    tex.SetPixel(i, originalHeight - j - 1 + originalHeight, originalTex.GetPixel(i, j));
                }
            }

            // top right - flip both X and Y axes
            for (int i = 0; i < originalWidth; i++)
            {
                for (int j = 0; j < originalHeight; j++)
                {
                    tex.SetPixel(originalWidth - i - 1 + originalWidth, originalHeight - j - 1 + originalHeight, originalTex.GetPixel(i, j));
                }
            }

            tex.Apply(false, true);

            Weapon.CrosshairTexture     = tex;
            this.crosshairImage.enabled = true;
            this.crosshairImage.texture = tex;
        }
Beispiel #5
0
        static Texture2D ConstructCrosshairTexture(string textureName, float sizeMultiplier)
        {
            Texture2D originalTex = TextureDictionary.Load("hud")
                                    .GetDiffuse(textureName, new TextureLoadParams {
                makeNoLongerReadable = false
            })
                                    .Texture;

            return(ConstructCrosshairTexture(originalTex, sizeMultiplier));
        }
Beispiel #6
0
        private static void StepLoadSplashScreen()
        {
            var txd = TextureDictionary.Load("LOADSCS");

            int index1 = Random.Range(1, 15);
            int index2 = Random.Range(1, 15);

            SplashTex1 = txd.GetDiffuse("loadsc" + index1).Texture;
            SplashTex2 = txd.GetDiffuse("loadsc" + index2).Texture;
        }
Beispiel #7
0
        public static void loadTextures()
        {
            for (int i = 0; i < tileCount; i++)
            {
                tiles [i] = TextureDictionary.Load("radar" + ((i < 10) ? "0" : "") + i);
            }

            huds       = TextureDictionary.Load("hud");
            northBlip  = huds.GetDiffuse("radar_north").Texture;
            playerBlip = huds.GetDiffuse("radar_centre").Texture;
        }
Beispiel #8
0
        public static Weapon Load(int modelId)
        {
            WeaponDef def = Item.GetDefinition <WeaponDef> (modelId);

            if (null == def)
            {
                return(null);
            }

            WeaponData weaponData = WeaponData.LoadedWeaponsData.FirstOrDefault(wd => wd.modelId1 == def.Id);

            if (null == weaponData)
            {
                return(null);
            }

            var geoms = Geometry.Load(def.ModelName, def.TextureDictionaryName);

            if (null == geoms)
            {
                return(null);
            }

            if (null == s_weaponsContainer)
            {
                s_weaponsContainer = new GameObject("Weapons");
                //	weaponsContainer.SetActive (false);
            }

            GameObject go = new GameObject(def.ModelName);

            go.transform.SetParent(s_weaponsContainer.transform);

            geoms.AttachFrames(go.transform, MaterialFlags.Default);

            Weapon weapon = AddWeaponComponent(go, weaponData);

            weapon.definition = def;
            weapon.data       = weaponData;
            // cache gun aiming offset
            if (weapon.data.gunData != null)
            {
                weapon.gunAimingOffset = weapon.data.gunData.aimingOffset;
            }

            // load hud texture
            try {
                weapon.HudTexture = TextureDictionary.Load(def.TextureDictionaryName).GetDiffuse(def.TextureDictionaryName + "icon").Texture;
            } catch {
                Debug.LogErrorFormat("Failed to load hud icon for weapon: model {0}, txd {1}", def.ModelName, def.TextureDictionaryName);
            }

            return(weapon);
        }
Beispiel #9
0
        void LoadTextures()
        {
            // load arrow textures
            var pcbtnsTxd = TextureDictionary.Load("pcbtns");

            LeftArrowTexture  = pcbtnsTxd.GetDiffuse("left").Texture;
            RightArrowTexture = pcbtnsTxd.GetDiffuse("right").Texture;
            UpArrowTexture    = pcbtnsTxd.GetDiffuse("up").Texture;
            DownArrowTexture  = pcbtnsTxd.GetDiffuse("down").Texture;

            LoadCrosshairTexture();
        }
Beispiel #10
0
        private void LoadGameTextures()
        {
            LoadMapTexture();

            var huds = TextureDictionary.Load("hud");

            NorthBlip         = huds.GetDiffuse("radar_north").Texture;
            PlayerBlip        = huds.GetDiffuse("radar_centre").Texture;
            WaypointTexture   = huds.GetDiffuse("radar_waypoint").Texture;
            VehicleTexture    = huds.GetDiffuse("radar_impound").Texture;
            GreenHouseTexture = huds.GetDiffuse("radar_propertyG").Texture;

            northImage.sprite   = Sprite.Create(NorthBlip, new Rect(0, 0, NorthBlip.width, NorthBlip.height), new Vector2(NorthBlip.width, NorthBlip.height) / 2);
            playerImage.texture = this.PlayerBlip;
            mapImage.texture    = MapTexture;
        }
Beispiel #11
0
        private void LoadGameTextures()
        {
            MapTexture = new Texture2D(mapSize, mapSize, TextureFormat.ARGB32, false, true);

            TextureLoadParams textureLoadParams = new TextureLoadParams()
            {
                makeNoLongerReadable = false
            };

            for (int i = 0; i < tileCount; i++)
            {
                // Offset
                int y = ((i / tileEdge) + 1) * texSize,
                    x = (i % tileEdge) * texSize;

                string name    = "radar" + ((i < 10) ? "0" : "") + i;
                var    texDict = TextureDictionary.Load(name);

                Texture2D tex = texDict.GetDiffuse(name, textureLoadParams).Texture;

                for (int ii = 0; ii < texSize; ++ii)
                {
                    for (int jj = 0; jj < texSize; ++jj)
                    {
                        MapTexture.SetPixel(x + ii, texSize - (y + jj) - 1, tex.GetPixel(ii, jj));
                    }
                }

                // unload the texture (don't destroy it, because it can be a dummy texture)
            }

            MapTexture.Apply(false, true);

            var huds = TextureDictionary.Load("hud");

            NorthBlip         = huds.GetDiffuse("radar_north").Texture;
            PlayerBlip        = huds.GetDiffuse("radar_centre").Texture;
            WaypointTexture   = huds.GetDiffuse("radar_waypoint").Texture;
            VehicleTexture    = huds.GetDiffuse("radar_impound").Texture;
            GreenHouseTexture = huds.GetDiffuse("radar_propertyG").Texture;

            northImage.sprite   = Sprite.Create(NorthBlip, new Rect(0, 0, NorthBlip.width, NorthBlip.height), new Vector2(NorthBlip.width, NorthBlip.height) / 2);
            playerImage.texture = this.PlayerBlip;
            mapImage.texture    = MapTexture;
        }
        public static void loadTextures()
        {
            for (int i = 0; i < tileCount; i++)
            {
                string name    = "radar" + ((i < 10) ? "0" : "") + i;
                var    texDict = TextureDictionary.Load(name);

                Texture2D tex = texDict.GetDiffuse(name).Texture;
                tex.filterMode = FilterMode.Point;

                tiles[i] = texDict;
            }

            huds       = TextureDictionary.Load("hud");
            northBlip  = huds.GetDiffuse("radar_north").Texture;
            playerBlip = huds.GetDiffuse("radar_centre").Texture;

            //Debug.Log(new Vector2(playerBlip.width, playerBlip.height));
        }
Beispiel #13
0
        void LoadMapTexture()
        {
            MapTexture = new Texture2D(mapSize, mapSize, TextureFormat.ARGB32, false, true);

            if (Config.Get <bool>("skip_minimap_load"))
            {
                return;
            }

            TextureLoadParams textureLoadParams = new TextureLoadParams()
            {
                makeNoLongerReadable = false
            };

            for (int i = 0; i < tileCount; i++)
            {
                // Offset
                int y = ((i / tileEdge) + 1) * texSize,
                    x = (i % tileEdge) * texSize;

                string name    = "radar" + ((i < 10) ? "0" : "") + i;
                var    texDict = TextureDictionary.Load(name);

                Texture2D tex = texDict.GetDiffuse(name, textureLoadParams).Texture;

                for (int ii = 0; ii < texSize; ++ii)
                {
                    for (int jj = 0; jj < texSize; ++jj)
                    {
                        MapTexture.SetPixel(x + ii, texSize - (y + jj) - 1, tex.GetPixel(ii, jj));
                    }
                }

                // unload the texture (don't destroy it, because it can be a dummy texture)
            }

            MapTexture.Apply(false, true);
        }
Beispiel #14
0
        public static Weapon Load(int modelId)
        {
            WeaponDef def = Item.GetDefinition <WeaponDef> (modelId);

            if (null == def)
            {
                return(null);
            }

            WeaponData weaponData = WeaponData.LoadedWeaponsData.FirstOrDefault(wd => wd.modelId1 == def.Id);

            if (null == weaponData)
            {
                return(null);
            }

            var geoms = Geometry.Load(def.ModelName, def.TextureDictionaryName);

            if (null == geoms)
            {
                return(null);
            }

            if (null == s_weaponsContainer)
            {
                s_weaponsContainer = new GameObject("Weapons");
                //	weaponsContainer.SetActive (false);
            }

            GameObject go = new GameObject(def.ModelName);

            go.transform.SetParent(s_weaponsContainer.transform);

            geoms.AttachFrames(go.transform, MaterialFlags.Default);

            Weapon weapon = AddWeaponComponent(go, weaponData);

            weapon.definition = def;
            weapon.data       = weaponData;
            // cache gun aiming offset
            if (weapon.data.gunData != null)
            {
                weapon.gunAimingOffset = weapon.data.gunData.aimingOffset;
            }

            // load hud texture
            try {
                weapon.HudTexture = TextureDictionary.Load(def.TextureDictionaryName).GetDiffuse(def.TextureDictionaryName + "icon").Texture;
            } catch {
                Debug.LogErrorFormat("Failed to load hud icon for weapon: model {0}, txd {1}", def.ModelName, def.TextureDictionaryName);
            }

            // weapon sound
            F.RunExceptionSafe(() => {
                if (weaponSoundIndexes.ContainsKey(modelId))
                {
                    var audioSource         = go.GetOrAddComponent <AudioSource> ();
                    audioSource.playOnAwake = false;
                    Debug.LogFormat("loading weapon sound, bank index {0}", weaponSoundIndexes [modelId]);
                    var audioClip = Audio.AudioManager.CreateAudioClipFromSfx("GENRL", 136, 0,
                                                                              Audio.AudioManager.SfxGENRL137Timings[weaponSoundIndexes [modelId]]);
                    audioSource.clip     = audioClip;
                    weapon.m_audioSource = audioSource;
                }
            });

            weapon.InitWeapon();

            return(weapon);
        }
Beispiel #15
0
        private void Initialize(VehicleDef def, int[] colors = null)
        {
            Definition = def;

            if (colors != null && colors[0] != -1)
            {
                SetColors(colors);
            }
            else
            {
                var defaultClrs = CarColors.GetCarDefaults(Definition.ModelName);

                if (defaultClrs != null)
                {
                    SetColors(defaultClrs[UnityEngine.Random.Range(0, defaultClrs.Count)]);
                }
                else
                {
                    Debug.LogWarningFormat("No colours defined for {0}!", def.GameName);
                }
            }

            name = Definition.GameName;

            _geometryParts = Geometry.Load(Definition.ModelName,
                                           TextureDictionary.Load(Definition.TextureDictionaryName),
                                           TextureDictionary.Load("vehicle"),
                                           TextureDictionary.Load("misc"));

            _frames = _geometryParts.AttachFrames(transform, MaterialFlags.Vehicle);

            var wheelFrame = _frames.FirstOrDefault(x => x.Name == "wheel");

            if (wheelFrame == null)
            {
                Debug.LogWarningFormat("No wheels defined for {0}!", def.GameName);
                Destroy(gameObject);
                return;
            }

            foreach (var frame in _frames)
            {
                if (!frame.Name.StartsWith("wheel_"))
                {
                    continue;
                }
                if (!frame.Name.EndsWith("_dummy"))
                {
                    continue;
                }

                var childFrames = _frames.Where(x => x.ParentIndex == frame.Index);

                // disable all children of wheel dummies
                foreach (var childFrame in childFrames)
                {
                    childFrame.gameObject.SetActive(false);
                }

                var wheelAlignment = GetWheelAlignment(frame.Name);

                Wheel inst;

                // see if this wheel dummy has a wheel child
                var wheel = childFrames.FirstOrDefault(x => x.Name == "wheel");

                if (wheel == null)
                {
                    var copy = Instantiate(wheelFrame.transform);
                    copy.SetParent(frame.transform, false);

                    _wheels.Add(inst = new Wheel
                    {
                        Alignment = wheelAlignment,
                        Parent    = frame.transform,
                        Child     = copy,
                    });
                }
                else
                {
                    // all children of wheel dummies get set to inactive so activate this one
                    wheel.gameObject.SetActive(true);

                    _wheels.Add(inst = new Wheel
                    {
                        Alignment = wheelAlignment,
                        Parent    = frame.transform,
                        Child     = wheel.transform,
                    });
                }

                if (inst.IsLeftHand)
                {
                    frame.transform.Rotate(Vector3.up, 180.0f);
                }

                inst.Complement = _wheels.FirstOrDefault(x =>
                                                         (x.Alignment & WheelAlignment.LeftRightMask) != (inst.Alignment & WheelAlignment.LeftRightMask) &&
                                                         (x.Alignment & WheelAlignment.FrontMidRearMask) == (inst.Alignment & WheelAlignment.FrontMidRearMask));

                if (inst.Complement != null)
                {
                    inst.Complement.Complement = inst;
                }
            }

            InitializePhysics();

            foreach (var pair in _frames.Where(x => x.Name.StartsWith("door_")))
            {
                var doorAlignment = GetDoorAlignment(pair.Name);

                if (doorAlignment == DoorAlignment.None)
                {
                    continue;
                }

                var hinge = pair.gameObject.AddComponent <HingeJoint>();
                hinge.axis      = Vector3.up;
                hinge.useLimits = true;

                var limit = 90.0f * ((doorAlignment == DoorAlignment.LeftFront || doorAlignment == DoorAlignment.LeftRear) ? 1.0f : -1.0f);
                hinge.limits = new JointLimits {
                    min = Mathf.Min(0, limit), max = Mathf.Max(0, limit),
                };
                hinge.connectedBody = gameObject.GetComponent <Rigidbody>();
            }

            var frontSeat = GetPart("ped_frontseat");
            var backSeat  = GetPart("ped_backseat");

            if (frontSeat != null)
            {
                var frontSeatMirror = new GameObject("ped_frontseat").transform;
                frontSeatMirror.SetParent(frontSeat.parent, false);
                frontSeatMirror.localPosition = Vector3.Scale(frontSeat.localPosition, new Vector3(-1f, 1f, 1f));

                if (frontSeat.localPosition.x > 0f)
                {
                    AttachSeat(frontSeat, SeatAlignment.FrontRight);
                    AttachSeat(frontSeatMirror, SeatAlignment.FrontLeft);
                }
                else
                {
                    AttachSeat(frontSeatMirror, SeatAlignment.FrontRight);
                    AttachSeat(frontSeat, SeatAlignment.FrontLeft);
                }

                DriverTransform = GetSeat(SeatAlignment.FrontLeft).Parent;
            }

            if (backSeat != null)
            {
                var backSeatMirror = new GameObject("ped_backseat").transform;
                backSeatMirror.SetParent(backSeat.parent, false);
                backSeatMirror.localPosition = Vector3.Scale(backSeat.localPosition, new Vector3(-1f, 1f, 1f));

                if (backSeat.localPosition.x > 0f)
                {
                    AttachSeat(backSeat, SeatAlignment.BackRight);
                    AttachSeat(backSeatMirror, SeatAlignment.BackLeft);
                }
                else
                {
                    AttachSeat(backSeatMirror, SeatAlignment.BackRight);
                    AttachSeat(backSeat, SeatAlignment.BackLeft);
                }
            }

            // Add vehicle damage

            //GameObject carObject = GameObject.Find(Definition.GameName.ToLower());

            //Debug.Log(gameObject.name);

            var dam = gameObject.AddComponent <VehicleDamage>();

            dam.damageParts           = new Transform[] { transform.GetChild(0).Find("engine") };
            dam.deformMeshes          = gameObject.GetComponentsInChildren <MeshFilter>();
            dam.displaceParts         = gameObject.GetComponentsInChildren <Transform>().Where(x => x.GetComponent <Frame>() != null || x.GetComponent <FrameContainer>() != null).ToArray();
            dam.damageFactor          = VehicleAPI.constDamageFactor;
            dam.collisionIgnoreHeight = -.4f;
            dam.collisionTimeGap      = .1f;

            //OptimizeVehicle();

            dam.deformColliders = gameObject.GetComponentsInChildren <MeshCollider>();

            // Implemented: Add lights

            Transform headlights = this.GetComponentWithName <Transform>("headlights"),
                      taillights = this.GetComponentWithName <Transform>("taillights");

            Vehicle vh = gameObject.GetComponent <Vehicle>();

            if (headlights != null)
            {
                m_frontLeftLight  = VehicleAPI.SetCarLight(vh, headlights, VehicleLight.FrontLeft);
                m_frontRightLight = VehicleAPI.SetCarLight(vh, headlights, VehicleLight.FrontRight);
            }

            if (taillights != null)
            {
                m_rearLeftLight  = VehicleAPI.SetCarLight(vh, taillights, VehicleLight.RearLeft);
                m_rearRightLight = VehicleAPI.SetCarLight(vh, taillights, VehicleLight.RearRight);
            }

            // Apply Light sources

            directionalLightsMat = Resources.Load <Material>("Materials/directionalLight");
            VehicleAPI.SetLightSources(gameObject, directionalLightsMat);

            m_frontLeftLightOk  = m_frontLeftLight != null;
            m_frontRightLightOk = m_frontRightLight != null;
            m_rearLeftLightOk   = m_rearLeftLight != null;
            m_rearRightLightOk  = m_rearRightLight != null;

            gameObject.SetLayerRecursive(Layer);
        }
        public static void LoadFonts()
        {
            for (int i = 1; i < 3; i++)
            {
                Texture2D fontTexture = TextureDictionary.Load("fonts").GetDiffuse($"font{i}", new TextureLoadParams()
                {
                    makeNoLongerReadable = false
                }).Texture;
                Texture2D flippedTexture = FlipTexture(fontTexture);

                Font font = Resources.Load <Font>($"font{i}");

                font.material = new Material(Shader.Find("Standard"))
                {
                    mainTexture = flippedTexture
                };

                CharacterInfo[] characterInfo = new CharacterInfo[94];

                float xSpacing = 32;
                float ySpacing = 40;

                float x = 1;
                float y = 480;

                float letterSize = 30f;

                Rect vertRect = new Rect(0, 10, 10, -10);

                //whitespace character
                characterInfo[0].index   = 32;
                characterInfo[0].advance = 7;
                characterInfo[0].vert    = vertRect;
                characterInfo[0].uv      = new Rect(0, 0, letterSize / flippedTexture.width, letterSize / flippedTexture.height);

                for (int j = 1; j < characterInfo.Length; j++)
                {
                    characterInfo[j].index   = 32 + j;
                    characterInfo[j].advance = GetAdvanceForIndex(i, characterInfo[j].index);
                    characterInfo[j].vert    = vertRect;
                    if (i == 1)
                    {
                        characterInfo[j].uv = new Rect((x * xSpacing) / flippedTexture.width, (y - 4) / flippedTexture.height, letterSize / flippedTexture.width, letterSize / flippedTexture.height);
                    }
                    else
                    {
                        characterInfo[j].uv = new Rect((x * xSpacing) / flippedTexture.width, (y - 4) / flippedTexture.height, letterSize / flippedTexture.width, (letterSize + 5) / flippedTexture.height);
                    }

                    x++;
                    if (x >= 16)
                    {
                        x  = 0;
                        y -= ySpacing;
                    }
                }

                font.characterInfo = characterInfo;
                _loadedFonts.Add(font);

                Font secondaryFont = Resources.Load <Font>($"font{i + 2}");
                secondaryFont.material = font.material;

                x = 0;
                y = 120;

                int  index = 0;
                bool skip  = false;
                for (int j = 1; j < 38; j++)
                {
                    if (skip)
                    {
                        characterInfo[j].index = 96 + index;
                    }
                    else
                    {
                        characterInfo[j].index = 48 + index;
                    }

                    characterInfo[j].advance = GetAdvanceForIndexSecondary(i, characterInfo[j].index);
                    characterInfo[j].vert    = vertRect;
                    characterInfo[j].uv      = new Rect((x * xSpacing) / flippedTexture.width, (y - 7) / flippedTexture.height, letterSize / flippedTexture.width, (letterSize + 7) / flippedTexture.height);

                    x++;
                    if (x >= 16)
                    {
                        x  = 0;
                        y -= ySpacing;
                    }

                    index++;
                    if (index == 10 && !skip)
                    {
                        skip  = true;
                        index = 0;
                    }
                }

                index = 0;

                x = 10;
                y = 120;
                //assign capital letters
                for (int j = 38; j < 65; j++)
                {
                    characterInfo[j].index   = 64 + index;
                    characterInfo[j].advance = GetAdvanceForIndexSecondary(i, characterInfo[j].index);
                    characterInfo[j].vert    = vertRect;
                    characterInfo[j].uv      = new Rect((x * xSpacing) / flippedTexture.width, (y - 7) / flippedTexture.height, letterSize / flippedTexture.width, (letterSize + 7) / flippedTexture.height);

                    x++;
                    if (x >= 16)
                    {
                        x  = 0;
                        y -= ySpacing;
                    }

                    index++;
                }

                secondaryFont.characterInfo = characterInfo;
                _loadedFonts.Add(secondaryFont);
            }
        }
Beispiel #17
0
        static void StaticUpdate()
        {
            if (HasLoaded)
            {
                return;
            }

            switch (loadingStatus)
            {
            case 0:
                Debug.Log("Started loading GTA.");
                archivePaths = Config.GetPaths("archive_paths");
                break;

            case 1:
                using (Utilities.Profiler.Start("Archive load time")) {
                    List <IArchive> listArchives = new List <IArchive> ();
                    foreach (var path in archivePaths)
                    {
                        if (File.Exists(path))
                        {
                            listArchives.Add(ArchiveManager.LoadImageArchive(path));
                        }
                        else if (Directory.Exists(path))
                        {
                            listArchives.Add(ArchiveManager.LoadLooseArchive(path));
                        }
                        else
                        {
                            Debug.Log("Archive not found: " + path);
                        }
                    }
                    archives = listArchives.FindAll(a => a != null).ToArray();
                }
                break;

            case 2:
                using (Utilities.Profiler.Start("Collision load time")) {
                    int numCollisionFiles = 0;
                    foreach (var archive in archives)
                    {
                        foreach (var colFile in archive.GetFileNamesWithExtension(".col"))
                        {
                            CollisionFile.Load(colFile);
                            numCollisionFiles++;
                        }
                    }
                    Debug.Log("Number of collision files " + numCollisionFiles);
                }
                break;

            case 3:
                using (Utilities.Profiler.Start("Item info load time")) {
                    foreach (var path in Config.GetPaths("item_paths"))
                    {
                        var ext = Path.GetExtension(path).ToLower();
                        switch (ext)
                        {
                        case ".dat":
                            Item.ReadLoadList(path);
                            break;

                        case ".ide":
                            Item.ReadIde(path);
                            break;

                        case ".ipl":
                            Item.ReadIpl(path);
                            break;
                        }
                    }
                }
                break;

            case 4:
                using (Utilities.Profiler.Start("Handling info load time")) {
                    Handling.Load(Config.GetPath("handling_path"));
                }
                break;

            case 5:
                using (Utilities.Profiler.Start("Animation group info load time")) {
                    foreach (var path in Config.GetPaths("anim_groups_paths"))
                    {
                        AnimationGroup.Load(path);
                    }
                }
                break;

            case 6:
                using (Utilities.Profiler.Start("Car color info load time")) {
                    CarColors.Load(Config.GetPath("car_colors_path"));
                }
                break;

            case 7:
                using (Utilities.Profiler.Start("special texture load time")) {
                    MiniMap.loadTextures();

                    // Load mouse cursor texture
                    Texture2D mouse    = TextureDictionary.Load("fronten_pc").GetDiffuse("mouse").Texture;
                    Texture2D mouseFix = new Texture2D(mouse.width, mouse.height);
                    for (int x = 0; x < mouse.width; x++)
                    {
                        for (int y = 0; y < mouse.height; y++)
                        {
                            mouseFix.SetPixel(x, mouse.height - y - 1, mouse.GetPixel(x, y));
                        }
                    }
                    mouseFix.Apply();
                    Cursor.SetCursor(mouseFix, Vector2.zero, CursorMode.Auto);
                }
                HasLoaded = true;
                Debug.Log("GTA loading finished.");
                break;
            }

            loadingStatus++;
        }
        private void Initialize(VehicleDef def, int[] colors = null)
        {
            Definition = def;

            if (colors != null && colors[0] != -1)
            {
                SetColors(colors);
            }
            else
            {
                var defaultClrs = CarColors.GetCarDefaults(Definition.ModelName);

                if (defaultClrs != null)
                {
                    SetColors(defaultClrs[UnityEngine.Random.Range(0, defaultClrs.Count)]);
                }
                else
                {
                    Debug.LogWarningFormat("No colours defined for {0}!", def.GameName);
                }
            }

            name = Definition.GameName;

            _geometryParts = Geometry.Load(Definition.ModelName,
                                           TextureDictionary.Load(Definition.TextureDictionaryName),
                                           TextureDictionary.Load("vehicle"),
                                           TextureDictionary.Load("misc"));

            _frames = _geometryParts.AttachFrames(transform, MaterialFlags.Vehicle);

            var wheelFrame = _frames.FirstOrDefault(x => x.Name == "wheel");

            if (wheelFrame == null)
            {
                Debug.LogWarningFormat("No wheels defined for {0}!", def.GameName);
                Destroy(gameObject);
                return;
            }

            foreach (var frame in _frames)
            {
                if (!frame.Name.StartsWith("wheel_"))
                {
                    continue;
                }
                if (!frame.Name.EndsWith("_dummy"))
                {
                    continue;
                }

                var childFrames = _frames.Where(x => x.ParentIndex == frame.Index);

                // disable all children of wheel dummies
                foreach (var childFrame in childFrames)
                {
                    childFrame.gameObject.SetActive(false);
                }

                var wheelAlignment = GetWheelAlignment(frame.Name);

                Wheel inst;

                // see if this wheel dummy has a wheel child
                var wheel = childFrames.FirstOrDefault(x => x.Name == "wheel");

                if (wheel == null)
                {
                    var copy = Instantiate(wheelFrame.transform);
                    copy.SetParent(frame.transform, false);

                    _wheels.Add(inst = new Wheel {
                        Alignment = wheelAlignment,
                        Parent    = frame.transform,
                        Child     = copy,
                    });
                }
                else
                {
                    // all children of wheel dummies get set to inactive so activate this one
                    wheel.gameObject.SetActive(true);

                    _wheels.Add(inst = new Wheel {
                        Alignment = wheelAlignment,
                        Parent    = frame.transform,
                        Child     = wheel.transform,
                    });
                }

                if (inst.IsLeftHand)
                {
                    frame.transform.Rotate(Vector3.up, 180.0f);
                }

                inst.Complement = _wheels.FirstOrDefault(x =>
                                                         (x.Alignment & WheelAlignment.LeftRightMask) != (inst.Alignment & WheelAlignment.LeftRightMask) &&
                                                         (x.Alignment & WheelAlignment.FrontMidRearMask) == (inst.Alignment & WheelAlignment.FrontMidRearMask));

                if (inst.Complement != null)
                {
                    inst.Complement.Complement = inst;
                }
            }

            InitializePhysics();

            foreach (var pair in _frames.Where(x => x.Name.StartsWith("door_")))
            {
                var doorAlignment = GetDoorAlignment(pair.Name);

                if (doorAlignment == DoorAlignment.None)
                {
                    continue;
                }

                var hinge = pair.gameObject.AddComponent <HingeJoint>();
                hinge.axis      = Vector3.up;
                hinge.useLimits = true;

                var limit = 90.0f * ((doorAlignment == DoorAlignment.LeftFront || doorAlignment == DoorAlignment.LeftRear) ? 1.0f : -1.0f);
                hinge.limits = new JointLimits {
                    min = Mathf.Min(0, limit), max = Mathf.Max(0, limit),
                };
                hinge.connectedBody = gameObject.GetComponent <Rigidbody>();
            }

            var frontSeat = GetPart("ped_frontseat");
            var backSeat  = GetPart("ped_backseat");

            if (frontSeat != null)
            {
                var frontSeatMirror = new GameObject("ped_frontseat").transform;
                frontSeatMirror.SetParent(frontSeat.parent, false);
                frontSeatMirror.localPosition = Vector3.Scale(frontSeat.localPosition, new Vector3(-1f, 1f, 1f));

                if (frontSeat.localPosition.x > 0f)
                {
                    AttachSeat(frontSeat, SeatAlignment.FrontRight);
                    AttachSeat(frontSeatMirror, SeatAlignment.FrontLeft);
                }
                else
                {
                    AttachSeat(frontSeatMirror, SeatAlignment.FrontRight);
                    AttachSeat(frontSeat, SeatAlignment.FrontLeft);
                }

                DriverTransform = GetSeat(SeatAlignment.FrontLeft).Parent;
            }

            if (backSeat != null)
            {
                var backSeatMirror = new GameObject("ped_backseat").transform;
                backSeatMirror.SetParent(backSeat.parent, false);
                backSeatMirror.localPosition = Vector3.Scale(backSeat.localPosition, new Vector3(-1f, 1f, 1f));

                if (backSeat.localPosition.x > 0f)
                {
                    AttachSeat(backSeat, SeatAlignment.BackRight);
                    AttachSeat(backSeatMirror, SeatAlignment.BackLeft);
                }
                else
                {
                    AttachSeat(backSeatMirror, SeatAlignment.BackRight);
                    AttachSeat(backSeat, SeatAlignment.BackLeft);
                }
            }

            gameObject.SetLayerRecursive(Layer);
        }
Beispiel #19
0
        private void loadTextures()
        {
            mapTexture = new Texture2D(mapSize, mapSize, TextureFormat.ARGB32, false, true);

            string folder = Path.Combine(Application.streamingAssetsPath, "map-chunks");

            if (outputChunks)
            {
                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }
            }

            Debug.Log("Merging all map sprites into one sprite.");
            for (int i = 0; i < tileCount; i++)
            {
                // Offset
                int y = ((i / tileEdge) + 1) * texSize,
                    x = (i % tileEdge) * texSize;

                string name    = "radar" + ((i < 10) ? "0" : "") + i;
                var    texDict = TextureDictionary.Load(name);

                Texture2D tex = texDict.GetDiffuse(name).Texture;

                if (outputChunks)
                {
                    string    id    = name.Substring(5);
                    Texture2D image = new Texture2D(texSize, texSize, TextureFormat.ARGB32, false);

                    for (int xx = 0; xx < texSize; ++xx)
                    {
                        for (int yy = 0; yy < texSize; ++yy)
                        {
                            image.SetPixel(xx, texSize - yy - 1, tex.GetPixel(xx, yy));
                        }
                    }

                    image.Apply();

                    File.WriteAllBytes(Path.Combine(folder, string.Format("{0}.jpg", id)), ImageConversion.EncodeToPNG(image));
                }

                for (int ii = 0; ii < texSize; ++ii)
                {
                    for (int jj = 0; jj < texSize; ++jj)
                    {
                        mapTexture.SetPixel(x + ii, texSize - (y + jj) - 1, tex.GetPixel(ii, jj));
                    }
                }
            }

            Debug.Log("Finished merging minimap!");
            mapTexture.Apply();
            mapSprite = Sprite.Create(mapTexture, new Rect(0, 0, mapTexture.width, mapTexture.height), new Vector2(mapTexture.width, mapTexture.height) / 2);

            if (outputImage)
            {
                File.WriteAllBytes(Path.Combine(Application.streamingAssetsPath, "gta-map.png"), mapTexture.EncodeToPNG());
            }

            circleMask = Resources.Load <Sprite>("Sprites/MapCircle");

            huds            = TextureDictionary.Load("hud");
            northBlip       = huds.GetDiffuse("radar_north").Texture;
            playerBlip      = huds.GetDiffuse("radar_centre").Texture;
            waypointTexture = huds.GetDiffuse("radar_waypoint").Texture;

            Debug.Log("Finished loading minimap textures!");
        }