コード例 #1
0
        public void ApplyTextures()
        {
            foreach (MultiplayerRemoteTexture mpTex in multiplayerTextures)
            {
                if (mpTex.saved && !mpTex.loaded && !(mpTex.infoType == GearInfoType.Body))
                {
                    mpTex.LoadFromFileMainThread(this);
                }
                else if (mpTex.saved && !mpTex.loaded && mpTex.textureType.Equals("head", StringComparison.InvariantCultureIgnoreCase))
                {
                    MultiplayerRemoteTexture bodyTex = multiplayerTextures.Find((t) => t.textureType.Equals("body", StringComparison.InvariantCultureIgnoreCase));
                    if (bodyTex != null)
                    {
                        UnityModManagerNet.UnityModManager.Logger.Log($"Updating body textures for {this.bodyType} id: {this.playerID}");

                        bodyTex.loaded = true;
                        mpTex.loaded   = true;

                        TextureChange[] headChange = { new TextureChange("albedo", mpTex.fileLocation) };
                        TextureChange[] bodyChange = { new TextureChange("albedo", bodyTex.fileLocation) };

                        List <MaterialChange> materialChanges = new List <MaterialChange>();
                        materialChanges.Add(new MaterialChange("body", bodyChange));
                        materialChanges.Add(new MaterialChange("head", headChange));

                        CharacterBodyInfo bodyInfo = new CharacterBodyInfo("MP Temp body", this.bodyType, true, materialChanges, new string[0]);

                        characterCustomizer.EquipGear(bodyInfo);
                    }
                }
            }
        }
コード例 #2
0
        public void ParseTextureStream(byte[] inTextureStream)
        {
            ushort currentMessage = BitConverter.ToUInt16(inTextureStream, 0);
            ushort totalMessages  = BitConverter.ToUInt16(inTextureStream, 2);

            for (int i = 4; i < inTextureStream.Length; i++)
            {
                gearStream.Add(inTextureStream[i]);
            }

            this.debugWriter.WriteLine($"Texture {currentMessage}/{totalMessages}");

            if (currentMessage != totalMessages)
            {
                return;
            }
            this.debugWriter.WriteLine($"Finished Texture loading");

            byte[] textureStream = gearStream.ToArray();

            ushort bodyTypeLen = BitConverter.ToUInt16(textureStream, 0);

            this.bodyType = Encoding.UTF8.GetString(textureStream, 2, bodyTypeLen);

            UnityModManagerNet.UnityModManager.Logger.Log($"Attempting to equip body with name length {bodyTypeLen} and name: {bodyType}!");

            CharacterBodyInfo bodyInfo = new CharacterBodyInfo("MP Temp body", this.bodyType, false, null, new string[0]);

            characterCustomizer.EquipGear(bodyInfo);

            int readBytes = 2 + bodyTypeLen;

            while (readBytes < textureStream.Length - 1)
            {
                UnityModManagerNet.UnityModManager.Logger.Log($"Read {readBytes} bytes of {textureStream.Length}");
                bool         customTex   = textureStream[readBytes] == 1 ? true : false;
                GearInfoType texInfotype = (GearInfoType)textureStream[readBytes + 1];

                readBytes += 2;
                if (customTex)
                {
                    ushort typeLen = BitConverter.ToUInt16(textureStream, readBytes);
                    int    dataLen = BitConverter.ToInt32(textureStream, readBytes + 2);

                    string texType = Encoding.UTF8.GetString(textureStream, readBytes + 6, typeLen);
                    readBytes += 6 + typeLen;

                    byte[] texData = new byte[dataLen];
                    Array.Copy(textureStream, readBytes, texData, 0, dataLen);
                    readBytes += dataLen;

                    MultiplayerRemoteTexture newTexture = new MultiplayerRemoteTexture(customTex, "", texType, texInfotype, this.debugWriter);
                    multiplayerTextures.Add(newTexture);
                    newTexture.SaveTexture(this.playerID, texData);
                }
            }
        }
コード例 #3
0
        public void ApplyTextures()
        {
            if (this.receivedTextures && !this.loadedTextures && GameManagement.GameStateMachine.Instance.CurrentState.GetType() != typeof(GameManagement.ReplayState))
            {
                characterCustomizer.RemoveAllGear();
                characterCustomizer.RemoveAllGear(true);

                Transform[] ignoredObjects = characterCustomizer.WheelParents.Union(characterCustomizer.TruckHangerParents).Union(characterCustomizer.TruckBaseParents).Append(characterCustomizer.DeckParent).Append(characterCustomizer.ClothingParent).ToArray();
                foreach (Transform t in ignoredObjects)
                {
                    Transform[] childrenTransforms = t.GetComponentsInChildren <Transform>();
                    if (childrenTransforms == null || childrenTransforms.Length == 0)
                    {
                        continue;
                    }
                    foreach (Transform t2 in childrenTransforms)
                    {
                        if (t2 == null || t2.gameObject == null)
                        {
                            continue;
                        }
                        if (t2.gameObject.layer == LayerMask.NameToLayer("Character") || t2.gameObject.layer == LayerMask.NameToLayer("Skateboard"))
                        {
                            if (!ignoredObjects.Contains(t2))
                            {
                                GameObject.Destroy(t2.gameObject);
                            }
                        }
                    }
                }

                bool loadedBodyInfo = false;

                foreach (MultiplayerRemoteTexture mpTex in multiplayerTextures)
                {
                    if (mpTex.saved && !mpTex.loaded && !(mpTex.infoType == GearInfoType.Body))
                    {
                        mpTex.LoadFromFileMainThread(this);
                    }
                    else if (mpTex.saved && !mpTex.loaded && mpTex.textureType.Equals("head", StringComparison.InvariantCultureIgnoreCase))
                    {
                        MultiplayerRemoteTexture bodyTex = multiplayerTextures.Find((t) => t.textureType.Equals("body", StringComparison.InvariantCultureIgnoreCase));
                        if (bodyTex != null)
                        {
                            UnityModManagerNet.UnityModManager.Logger.Log($"Updating body textures for {this.bodyType} id: {this.playerID}");

                            bodyTex.loaded = true;
                            mpTex.loaded   = true;

                            TextureChange[] headChange = { new TextureChange("albedo", mpTex.fileLocation) };
                            TextureChange[] bodyChange = { new TextureChange("albedo", bodyTex.fileLocation) };

                            List <MaterialChange> materialChanges = new List <MaterialChange>();
                            materialChanges.Add(new MaterialChange("body", bodyChange));
                            materialChanges.Add(new MaterialChange("head", headChange));

                            CharacterBodyInfo bodyInfo = new CharacterBodyInfo("MP Temp body", this.bodyType, true, materialChanges, new string[0]);

                            characterCustomizer.EquipGear(bodyInfo);

                            loadedBodyInfo = true;
                        }
                    }
                }

                if (!loadedBodyInfo)
                {
                    CharacterBodyInfo baseBodyInfo = new CharacterBodyInfo("MP Temp body", this.bodyType, false, null, new string[0]);
                    characterCustomizer.EquipGear(baseBodyInfo);
                }

                loadedTextures = true;
            }
        }
コード例 #4
0
        override public void ConstructPlayer()
        {
            //Create a new root object for the player
            this.player = GameObject.Instantiate <GameObject>(ReplayEditorController.Instance.playbackController.gameObject);

            UnityEngine.Object.DontDestroyOnLoad(this.player);
            this.player.name = "New Player";
            this.player.transform.SetParent(null);
            this.player.transform.position = PlayerController.Instance.transform.position;
            this.player.transform.rotation = PlayerController.Instance.transform.rotation;
            debugWriter.WriteLine("Created New Player");

            this.replayController = this.player.GetComponentInChildren <ReplayPlaybackController>();

            this.bones = replayController.playbackTransforms.ToArray();

            this.player.SetActive(true);

            this.board = this.player.transform.Find("Skateboard").gameObject;
            this.board.transform.position = new Vector3(0, 0, 0);
            this.board.name = "New Player Board";

            this.skater = this.player.transform.Find("NewSkater").gameObject;
            this.skater.transform.position = new Vector3(0, 0, 0);
            this.skater.name = "New Player Skater";

            debugWriter.WriteLine("created everything");

            Traverse.Create(characterCustomizer).Field("_bonesDict").SetValue(bones.ToDictionary((Transform t) => t.name));
            characterCustomizer.enabled = true;

            foreach (GearPrefabController gearPrefabController in this.player.GetComponentsInChildren <GearPrefabController>())
            {
                GameObject.Destroy(gearPrefabController.gameObject);
            }

            characterCustomizer.LoadLastPlayer();
            characterCustomizer.SetShoesVisible(true);

            this.usernameObject = new GameObject("Username Object");
            this.usernameObject.transform.SetParent(this.player.transform, false);
            this.usernameObject.transform.localScale = new Vector3(-0.01f, 0.01f, 1f);
            this.usernameObject.AddComponent <MeshRenderer>();
            this.usernameObject.GetComponent <MeshRenderer>().material = Resources.FindObjectsOfTypeAll <Font>()[0].material;
            this.usernameText           = this.usernameObject.AddComponent <TextMesh>();
            this.usernameText.text      = username;
            this.usernameText.fontSize  = 256;
            this.usernameText.font      = Resources.FindObjectsOfTypeAll <Font>()[0];
            this.usernameText.color     = Color.black;
            this.usernameText.alignment = TextAlignment.Center;

            this.shirtMPTex = new MultiplayerRemoteTexture(MPTextureType.Shirt, this.debugWriter);
            this.pantsMPTex = new MultiplayerRemoteTexture(MPTextureType.Pants, this.debugWriter);
            this.hatMPTex   = new MultiplayerRemoteTexture(MPTextureType.Hat, this.debugWriter);
            this.shoesMPTex = new MultiplayerRemoteTexture(MPTextureType.Shoes, this.debugWriter);

            this.deckMPTex  = new MultiplayerRemoteTexture(MPTextureType.Deck, this.debugWriter);
            this.gripMPTex  = new MultiplayerRemoteTexture(MPTextureType.Grip, this.debugWriter);
            this.wheelMPTex = new MultiplayerRemoteTexture(MPTextureType.Wheels, this.debugWriter);
            this.truckMPTex = new MultiplayerRemoteTexture(MPTextureType.Trucks, this.debugWriter);

            this.headMPTex = new MultiplayerRemoteTexture(MPTextureType.Head, this.debugWriter);
            this.bodyMPTex = new MultiplayerRemoteTexture(MPTextureType.Body, this.debugWriter);
        }