|
| 1 | +#if BELOWZERO |
| 2 | +using System; |
| 3 | +using System.Collections.Generic; |
| 4 | +using NitroxClient.GameLogic.PlayerLogic.PlayerModel.Abstract; |
| 5 | +using NitroxClient.GameLogic.PlayerLogic.PlayerModel.ColorSwap.Strategy; |
| 6 | +using NitroxClient.Unity.Helper; |
| 7 | +using NitroxModel_Subnautica.DataStructures; |
| 8 | +using UnityEngine; |
| 9 | +using static NitroxClient.GameLogic.PlayerLogic.PlayerModel.PlayerEquipmentConstants; |
| 10 | + |
| 11 | +namespace NitroxClient.GameLogic.PlayerLogic.PlayerModel.ColorSwap |
| 12 | +{ |
| 13 | + public class ColdProtectiveSuitColorSwapManager : IColorSwapManager |
| 14 | + { |
| 15 | + public Action<ColorSwapAsyncOperation> CreateColorSwapTask(INitroxPlayer nitroxPlayer) |
| 16 | + { |
| 17 | + GameObject playerModel = nitroxPlayer.PlayerModel; |
| 18 | + Color playerColor = nitroxPlayer.PlayerSettings.PlayerColor.ToUnity(); |
| 19 | + IColorSwapStrategy colorSwapStrategy = new HueSwapper(playerColor); |
| 20 | + |
| 21 | + SkinnedMeshRenderer coldProtectiveHeadRenderer = playerModel.GetRenderer(COLD_PROTECTIVE_HEAD_GAME_OBJECT_NAME); |
| 22 | + coldProtectiveHeadRenderer.material.ApplyClonedTexture(); |
| 23 | + |
| 24 | + SkinnedMeshRenderer coldProtectiveMaskRenderer = playerModel.GetRenderer(COLD_PROTECTIVE_MASK_GAME_OBJECT_NAME); |
| 25 | + coldProtectiveMaskRenderer.material.ApplyClonedTexture(); |
| 26 | + |
| 27 | + SkinnedMeshRenderer coldProtectiveSuitRenderer = playerModel.GetRenderer(COLD_PROTECTIVE_BODY_GAME_OBJECT_NAME); |
| 28 | + coldProtectiveSuitRenderer.material.ApplyClonedTexture(); |
| 29 | + coldProtectiveSuitRenderer.materials[1].ApplyClonedTexture(); |
| 30 | + |
| 31 | + SkinnedMeshRenderer coldProtectiveHandsRenderer = playerModel.GetRenderer(COLD_PROTECTIVE_HANDS_GAME_OBJECT_NAME); |
| 32 | + coldProtectiveHandsRenderer.material.ApplyClonedTexture(); |
| 33 | + |
| 34 | + Color[] headTexturePixels = coldProtectiveHeadRenderer.material.GetMainTexturePixels(); |
| 35 | + Color[] maskTexturePixels = coldProtectiveMaskRenderer.material.GetMainTexturePixels(); |
| 36 | + Color[] suitTexturePixels = coldProtectiveSuitRenderer.material.GetMainTexturePixels(); |
| 37 | + Color[] armsTexturePixels = coldProtectiveSuitRenderer.materials[1].GetMainTexturePixels(); |
| 38 | + Color[] handsTexturePixels = coldProtectiveHandsRenderer.material.GetMainTexturePixels(); |
| 39 | + |
| 40 | + return operation => |
| 41 | + { |
| 42 | + HsvSwapper coldProtectiveSuitFilter = new HsvSwapper(colorSwapStrategy); |
| 43 | + coldProtectiveSuitFilter.SetHueRange(0f, 20f); |
| 44 | + coldProtectiveSuitFilter.SetSaturationRange(45f, 100f); |
| 45 | + coldProtectiveSuitFilter.SwapColors(headTexturePixels); |
| 46 | + coldProtectiveSuitFilter.SwapColors(maskTexturePixels); |
| 47 | + coldProtectiveSuitFilter.SwapColors(suitTexturePixels); |
| 48 | + coldProtectiveSuitFilter.SwapColors(armsTexturePixels); |
| 49 | + coldProtectiveSuitFilter.SwapColors(handsTexturePixels); |
| 50 | + operation.UpdateIndex(COLD_PROTECTIVE_HEAD_INDEX_KEY, headTexturePixels); |
| 51 | + operation.UpdateIndex(COLD_PROTECTIVE_MASK_INDEX_KEY, maskTexturePixels); |
| 52 | + operation.UpdateIndex(COLD_PROTECTIVE_BODY_INDEX_KEY, suitTexturePixels); |
| 53 | + operation.UpdateIndex(COLD_PROTECTIVE_ARMS_INDEX_KEY, armsTexturePixels); |
| 54 | + operation.UpdateIndex(COLD_PROTECTIVE_HANDS_INDEX_KEY, handsTexturePixels); |
| 55 | + }; |
| 56 | + } |
| 57 | + |
| 58 | + public void ApplyPlayerColor(Dictionary<string, Color[]> pixelIndex, INitroxPlayer nitroxPlayer) |
| 59 | + { |
| 60 | + Color[] headPixelIndexes = pixelIndex[COLD_PROTECTIVE_HEAD_INDEX_KEY]; |
| 61 | + Color[] maskPixelIndexes = pixelIndex[COLD_PROTECTIVE_MASK_INDEX_KEY]; |
| 62 | + Color[] suitPixelIndexes = pixelIndex[COLD_PROTECTIVE_BODY_INDEX_KEY]; |
| 63 | + Color[] armsTexturePixels = pixelIndex[COLD_PROTECTIVE_ARMS_INDEX_KEY]; |
| 64 | + Color[] handsPixelIndexes = pixelIndex[COLD_PROTECTIVE_HANDS_INDEX_KEY]; |
| 65 | + |
| 66 | + GameObject playerModel = nitroxPlayer.PlayerModel; |
| 67 | + |
| 68 | + SkinnedMeshRenderer coldProtectiveHeadRenderer = playerModel.GetRenderer(COLD_PROTECTIVE_HEAD_GAME_OBJECT_NAME); |
| 69 | + coldProtectiveHeadRenderer.material.UpdateMainTextureColors(headPixelIndexes); |
| 70 | + |
| 71 | + SkinnedMeshRenderer coldProtectiveMaskRenderer = playerModel.GetRenderer(COLD_PROTECTIVE_MASK_GAME_OBJECT_NAME); |
| 72 | + coldProtectiveMaskRenderer.material.UpdateMainTextureColors(maskPixelIndexes); |
| 73 | + |
| 74 | + SkinnedMeshRenderer coldProtectiveSuitRenderer = playerModel.GetRenderer(COLD_PROTECTIVE_BODY_GAME_OBJECT_NAME); |
| 75 | + coldProtectiveSuitRenderer.material.UpdateMainTextureColors(suitPixelIndexes); |
| 76 | + coldProtectiveSuitRenderer.material.SetTexture("_MainTex", coldProtectiveSuitRenderer.material.mainTexture); |
| 77 | + coldProtectiveSuitRenderer.material.SetTexture("_SpecTex", coldProtectiveSuitRenderer.material.mainTexture); |
| 78 | + |
| 79 | + coldProtectiveSuitRenderer.materials[1].UpdateMainTextureColors(armsTexturePixels); |
| 80 | + coldProtectiveSuitRenderer.materials[1].SetTexture("_MainTex", coldProtectiveSuitRenderer.materials[1].mainTexture); |
| 81 | + coldProtectiveSuitRenderer.materials[1].SetTexture("_SpecTex", coldProtectiveSuitRenderer.materials[1].mainTexture); |
| 82 | + |
| 83 | + SkinnedMeshRenderer reinforcedHandsRenderer = playerModel.GetRenderer(REINFORCED_GLOVES_GAME_OBJECT_NAME); |
| 84 | + reinforcedHandsRenderer.material.UpdateMainTextureColors(handsPixelIndexes); |
| 85 | + } |
| 86 | + } |
| 87 | +} |
| 88 | +#endif |
0 commit comments