Exemple #1
0
    public void UpdateChildren(List <uint> NewInternalNetIDs)
    {
        OpenSprites.Clear();
        List <SpriteHandler> SHS = new List <SpriteHandler>();

        InternalNetIDs = NewInternalNetIDs;
        foreach (var ID in InternalNetIDs)
        {
            if (NetworkIdentity.spawned.ContainsKey(ID) && NetworkIdentity.spawned[ID] != null)
            {
                var OB = NetworkIdentity.spawned[ID].gameObject.transform;

                var SH = OB.GetComponent <SpriteHandler>();

                var Net = SpriteHandlerManager.GetRecursivelyANetworkBehaviour(SH.gameObject);
                SpriteHandlerManager.UnRegisterHandler(Net, SH);
                SHS.Add(SH);
                SH.name          = Regex.Replace(SH.name, @"\(.*\)", "").Trim();
                OB.parent        = CustomisationSprites.transform;
                OB.localScale    = Vector3.one;
                OB.localPosition = Vector3.zero;
                OB.localRotation = Quaternion.identity;

                SpriteHandlerManager.RegisterHandler(Net, SH);
                var SNO = OB.GetComponent <SpriteHandlerNorder>();

                if (OpenSprites.Contains(SNO) == false)
                {
                    OpenSprites.Add(SNO);
                }
            }
        }

        RequestForceSpriteUpdate.Send(SpriteHandlerManager.Instance, SHS);
    }
Exemple #2
0
        private void RemoveSprites(PlayerSprites sprites, LivingHealthMasterBase livingHealth)
        {
            for (var i = RelatedPresentSprites.Count - 1; i >= 0; i--)
            {
                var bodyPartSprite = RelatedPresentSprites[i];
                if (IsSurface || BodyPartItemInheritsSkinColor)
                {
                    sprites.SurfaceSprite.Remove(bodyPartSprite);
                }

                RelatedPresentSprites.Remove(bodyPartSprite);
                sprites.Addedbodypart.Remove(bodyPartSprite);
                SpriteHandlerManager.UnRegisterHandler(sprites.GetComponent <NetworkIdentity>(),
                                                       bodyPartSprite.baseSpriteHandler);
                Destroy(bodyPartSprite.gameObject);
            }

            livingHealth.InternalNetIDs.Remove(intName);
        }
        /*
         *      private void ValidateHideFlag(ClothingHideFlags hideFlag, string name)
         *      {
         *              // Check if dictionary has entry about such clothing item name
         *              if (!clothes.ContainsKey(name))
         *              {
         *                      Logger.LogError($"Can't find {name} clothingItem linked to {hideFlag}", Category.PlayerInventory);
         *                      return;
         *              }
         *
         *              // Enable or disable based on hide flag
         *              var isVisible = !hideClothingFlags.HasFlag(hideFlag);
         *              clothes[name].gameObject.SetActive(isVisible);
         *      }
         */

        public void UpdateChildren(List <IntName> NewInternalNetIDs)
        {
            List <SpriteHandler> SHS = new List <SpriteHandler>();

            foreach (var ID in NewInternalNetIDs)
            {
                bool Contains = false;
                foreach (var InetID in InternalNetIDs)
                {
                    if (InetID.Name == ID.Name)
                    {
                        Contains = true;
                    }
                }

                if (Contains == false)
                {
                    if (CustomNetworkManager.Instance.allSpawnablePrefabs.Count > ID.Int)
                    {
                        var OB       = Instantiate(CustomNetworkManager.Instance.allSpawnablePrefabs[ID.Int], this.CustomisationSprites.transform).transform;
                        var Net      = SpriteHandlerManager.GetRecursivelyANetworkBehaviour(OB.gameObject);
                        var Handlers = OB.GetComponentsInChildren <SpriteHandler>();

                        foreach (var SH in Handlers)
                        {
                            SpriteHandlerManager.UnRegisterHandler(Net, SH);
                        }

                        OB.SetParent(this.CustomisationSprites.transform);
                        OB.name          = ID.Name;
                        OB.localScale    = Vector3.one;
                        OB.localPosition = Vector3.zero;
                        OB.localRotation = Quaternion.identity;



                        var SNO = OB.GetComponent <SpriteHandlerNorder>();
                        if (OpenSprites.Contains(SNO) == false)
                        {
                            OpenSprites.Add(SNO);
                        }

                        foreach (var SH in Handlers)
                        {
                            SHS.Add(SH);
                            SpriteHandlerManager.RegisterHandler(Net, SH);
                        }
                    }
                }
            }

            foreach (var ID in InternalNetIDs)
            {
                bool Contains = false;
                foreach (var InetID in NewInternalNetIDs)
                {
                    if (InetID.Name == ID.Name)
                    {
                        Contains = true;
                    }
                }

                if (Contains == false)
                {
                    foreach (var bodyPartSpritese in OpenSprites.ToArray())
                    {
                        if (bodyPartSpritese.name == ID.Name)
                        {
                            OpenSprites.Remove(bodyPartSpritese);
                            Destroy(bodyPartSpritese.gameObject);
                        }
                    }
                }
            }

            foreach (var SNO in OpenSprites)
            {
                foreach (var internalNetID in NewInternalNetIDs)
                {
                    if (internalNetID.Name == SNO.name)
                    {
                        SNO.UpdateData(internalNetID.Data);
                    }
                }
            }

            InternalNetIDs = NewInternalNetIDs;
        }
        public void SetupSprites()
        {
            CustomisationStorage customisationStorage = null;

            if (ThisCharacter.SerialisedBodyPartCustom == null)
            {
                //TODO : (Max) - Fix SerialisedBodyPartCustom being null on Dummy players
                Logger.LogWarning($"{gameObject} has spawned with null bodyPart customizations. This error should only appear for Dummy players only.");
                return;
            }

            foreach (var Custom in ThisCharacter.SerialisedBodyPartCustom)
            {
                if (livingHealthMasterBase.name == Custom.path)
                {
                    customisationStorage = Custom;
                    break;
                }
            }

            if (customisationStorage != null)
            {
                BodyPartDropDownOrgans.PlayerBodyDeserialise(null, customisationStorage.Data, livingHealthMasterBase);
            }

            foreach (var bodyPart in livingHealthMasterBase.BodyPartList)
            {
                SubSetBodyPart(bodyPart, "");
            }

            PlayerHealthData SetRace = null;

            foreach (var Race in RaceSOSingleton.Instance.Races)
            {
                if (Race.name == ThisCharacter.Species)
                {
                    SetRace = Race;
                }
            }

            List <IntName> ToClient = new List <IntName>();

            foreach (var Customisation in SetRace.Base.CustomisationSettings)
            {
                ExternalCustomisation externalCustomisation = null;
                foreach (var EC in ThisCharacter.SerialisedExternalCustom)
                {
                    if (EC.Key == Customisation.CustomisationGroup.name)
                    {
                        externalCustomisation = EC;
                    }
                }

                if (externalCustomisation == null)
                {
                    continue;
                }


                var Net = SpriteHandlerManager.GetRecursivelyANetworkBehaviour(this.gameObject);
                var SpriteHandlerNorder = Instantiate(ToInstantiateSpriteCustomisation.gameObject, CustomisationSprites.transform)
                                          .GetComponent <SpriteHandlerNorder>();
                SpriteHandlerManager.UnRegisterHandler(Net, SpriteHandlerNorder.SpriteHandler);

                SpriteHandlerNorder.transform.localPosition = Vector3.zero;
                SpriteHandlerNorder.name = Customisation.CustomisationGroup.ThisType.ToString();
                SpriteHandlerManager.RegisterHandler(Net, SpriteHandlerNorder.SpriteHandler);

                var newone = new IntName();
                newone.Int =
                    CustomNetworkManager.Instance.IndexLookupSpawnablePrefabs[ToInstantiateSpriteCustomisation.gameObject];

                newone.Name = Customisation.CustomisationGroup.ThisType.ToString();
                ToClient.Add(newone);

                OpenSprites.Add(SpriteHandlerNorder);
                //SubSetBodyPart
                foreach (var Sprite_s in Customisation.CustomisationGroup.PlayerCustomisations)
                {
                    if (Sprite_s.Name == externalCustomisation.SerialisedValue.SelectedName)
                    {
                        SpriteHandlerNorder.SpriteHandler.SetSpriteSO(Sprite_s.SpriteEquipped);
                        SpriteHandlerNorder.SetSpriteOrder(new SpriteOrder(Customisation.CustomisationGroup.SpriteOrder));
                        newone.Data = JsonConvert.SerializeObject(new SpriteOrder(SpriteHandlerNorder.SpriteOrder));
                        Color setColor = Color.black;
                        ColorUtility.TryParseHtmlString(externalCustomisation.SerialisedValue.Colour, out setColor);
                        setColor.a = 1;
                        SpriteHandlerNorder.SpriteHandler.SetColor(setColor);
                    }
                }
            }
            GetComponent <RootBodyPartController>().PlayerSpritesData = JsonConvert.SerializeObject(ToClient);

            SetSurfaceColour();
            OnDirectionChange(directional.CurrentDirection);
        }