Beispiel #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);
    }
Beispiel #2
0
    void Awake()
    {
        if (Application.isPlaying)
        {
            spriteRenderer = GetComponent <SpriteRenderer>();
            image          = GetComponent <Image>();
            if (image != null)
            {
                // unity doesn't support property blocks on ui renderers, so this is a workaround
                image.material = Instantiate(image.material);
            }
            variantIndex = initialVariantIndex;

            if (NetworkThis)
            {
                networkIdentity = SpriteHandlerManager.GetRecursivelyANetworkBehaviour(gameObject);
                SpriteHandlerManager.RegisterHandler(networkIdentity, this);
            }

            if (randomInitialSprite && CatalogueCount > 0)
            {
                ChangeSprite(UnityEngine.Random.Range(0, CatalogueCount), NetworkThis);
            }
            else if (PresentSpriteSet != null)
            {
                if (pushTextureOnStartUp)
                {
                    PushTexture(false);
                }
            }
        }
    }
Beispiel #3
0
    private void OnEnable()
    {
        if (Application.isPlaying && NetworkThis)
        {
            NetworkIdentity = SpriteHandlerManager.GetRecursivelyANetworkBehaviour(this.gameObject)?.netIdentity;
            SpriteHandlerManager.RegisterHandler(this.NetworkIdentity, this);
        }

        GetImageComponent();
        OnSpriteChanged?.Invoke(CurrentSprite);
    }
 private void Awake()
 {
     if (spriteHandlerManager == null)
     {
         spriteHandlerManager = this;
     }
     else
     {
         Destroy(this);
     }
 }
Beispiel #5
0
    private void OnEnable()
    {
        if (Application.isPlaying && NetworkThis)
        {
            NetworkIdentity = SpriteHandlerManager.GetRecursivelyANetworkBehaviour(this.gameObject);
            SpriteHandlerManager.RegisterHandler(this.NetworkIdentity, this);
        }

        GetImageComponent();
        OnSpriteChanged?.Invoke(CurrentSprite);

        PushTexture(false);         // TODO: animations don't resume when sprite object is disabled and re-enabled, this is a workaround
    }
    private void Awake()
    {
        if (spriteHandlerManager == null)
        {
            spriteHandlerManager = this;
        }
        else
        {
            Destroy(this);
        }

        if (SpriteCatalogue.ResistantCatalogue.Count == 0)
        {
            new Task(SpriteCatalogue.Instance.GenerateResistantCatalogue).Start();
        }
    }
Beispiel #7
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);
        }
Beispiel #8
0
    public static NetMessage Send(SpriteHandlerManager spriteHandlerManager, List <SpriteHandler> ToUpdate)
    {
        if (CustomNetworkManager.Instance._isServer == true)
        {
            return(new NetMessage());
        }
        var TOSend = new List <SpriteHandlerIdentifier>();

        foreach (var SH in ToUpdate)
        {
            TOSend.Add(new SpriteHandlerIdentifier(SH.GetMasterNetID().netId, SH.name));
        }

        var msg = new NetMessage()
        {
            SpriteHandlerManager = spriteHandlerManager.GetComponent <NetworkIdentity>().netId,
            Data = JsonConvert.SerializeObject(TOSend)
        };

        Send(msg);
        return(msg);
    }
Beispiel #9
0
    private void NetUpdate(
        SpriteDataSO NewSpriteDataSO = null,
        int NewVariantIndex          = -1,
        int NewCataloguePage         = -1,
        bool NewPushTexture          = false,
        bool NewEmpty           = false,
        bool NewPushClear       = false,
        bool NewClearPallet     = false,
        Color?NewSetColour      = null,
        List <Color> NewPalette = null)
    {
        if (NetworkThis == false)
        {
            return;
        }
        if (SpriteHandlerManager.Instance == null)
        {
            return;
        }
        if (NetworkIdentity == null)
        {
            if (this?.gameObject == null)
            {
                return;
            }
            var NetID = SpriteHandlerManager.GetRecursivelyANetworkBehaviour(this.gameObject);
            if (NetID == null)
            {
                Logger.LogError("Was unable to find A NetworkBehaviour for ",
                                Category.SpriteHandler);
                return;
            }
            ;

            NetworkIdentity = NetID.netIdentity;
            if (NetworkIdentity == null)
            {
                var gamename = "";
                if (this?.gameObject != null)
                {
                    gamename = gameObject.name;
                }
                Logger.LogError("Was unable to find A NetworkBehaviour for " + gamename,
                                Category.SpriteHandler);
            }
        }

        if (CustomNetworkManager.Instance._isServer == false)
        {
            return;
        }

        SpriteHandlerManager.SpriteChange spriteChange = null;

        if (SpriteHandlerManager.Instance.QueueChanges.ContainsKey(this))
        {
            spriteChange = SpriteHandlerManager.Instance.QueueChanges[this];
        }
        else
        {
            spriteChange = SpriteHandlerManager.GetSpriteChange();
        }

        if (NewSpriteDataSO != null)
        {
            if (NewSpriteDataSO.setID == -1)
            {
                Logger.Log("NewSpriteDataSO NO ID!" + NewSpriteDataSO.name);
            }
            if (spriteChange.Empty)
            {
                spriteChange.Empty = false;
            }
            spriteChange.PresentSpriteSet = NewSpriteDataSO.setID;
        }

        if (NewVariantIndex != -1)
        {
            spriteChange.VariantIndex = NewVariantIndex;
        }

        if (NewCataloguePage != -1)
        {
            spriteChange.CataloguePage = NewCataloguePage;
        }

        if (NewPushTexture)
        {
            if (spriteChange.PushClear)
            {
                spriteChange.PushClear = false;
            }
            spriteChange.PushTexture = NewPushTexture;
        }

        if (NewEmpty)
        {
            if (spriteChange.PresentSpriteSet != -1)
            {
                spriteChange.PresentSpriteSet = -1;
            }
            spriteChange.Empty = NewEmpty;
        }

        if (NewPushClear)
        {
            if (spriteChange.PushTexture)
            {
                spriteChange.PushTexture = false;
            }
            spriteChange.PushClear = NewPushClear;
        }

        if (NewClearPallet)
        {
            if (spriteChange.Pallet != null)
            {
                spriteChange.Pallet = null;
            }
            spriteChange.ClearPallet = NewClearPallet;
        }

        if (NewSetColour != null)
        {
            spriteChange.SetColour = NewSetColour;
        }

        if (NewPalette != null)
        {
            if (spriteChange.ClearPallet)
            {
                spriteChange.ClearPallet = false;
            }
            spriteChange.Pallet = NewPalette;
        }

        if (NetworkIdentity.netId == 0)
        {
            //Logger.Log("ID hasn't been set for " + this.transform.parent);
            StartCoroutine(WaitForNetInitialisation(spriteChange));
        }
        else
        {
            SpriteHandlerManager.Instance.QueueChanges[this] = spriteChange;
        }
    }
        /*
         *      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);
        }