Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Container system overhaul #1088

Merged
merged 18 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 28 additions & 25 deletions Assets/Content/Data/DefaultPrefabObjects.asset
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ MonoBehaviour:
m_Name: DefaultPrefabObjects
m_EditorClassIdentifier:
_prefabs:
- {fileID: 1871071288925904272, guid: b7976a98a25be4543ba45f1d5e26c072, type: 3}
- {fileID: 562230263738288595, guid: 06a27ffa07c1c754c9590607a5a80030, type: 3}
- {fileID: 562230263738288595, guid: 59f05e8a3a1d4b94eb5222aed605e260, type: 3}
- {fileID: 8203177977882359099, guid: 6ab4ce7059d374a4498481e1385c222e, type: 3}
- {fileID: 3206407796921847736, guid: 3335d001fdfff824aa859b98f2fe564e, type: 3}
- {fileID: 9154675693299657064, guid: af039f84b4a245049b5b62799af01384, type: 3}
- {fileID: 3227132888119106738, guid: 7bbb74a7ffc8cae44baa886de43c586b, type: 3}
- {fileID: 2930813178971533500, guid: 1c3eed1ea37ecc1448e41270cdc63486, type: 3}
- {fileID: 1871071288925904272, guid: add4d1bc2d874d94782d6b8c912af5e2, type: 3}
- {fileID: 7942135432533076774, guid: 84a5596b28f449e49bb34741abf89d30, type: 3}
- {fileID: -4994790824565799921, guid: a28267798293970468ab30803632a3f7, type: 3}
Expand All @@ -22,6 +28,7 @@ MonoBehaviour:
- {fileID: -752502555905215929, guid: 11a2276338ebc64429dfc565b491e437, type: 3}
- {fileID: -5633820156739102180, guid: 4c966398d6624164c910cd29c1faa980, type: 3}
- {fileID: -7828078595381397262, guid: 50dd6be959d44844ab1abf8a3f2adb01, type: 3}
- {fileID: -7828078595381397262, guid: d07b5fba3896ff448855d6e54356c365, type: 3}
- {fileID: -2900075557854325373, guid: 45d13347efae0f54882e0e56dd770bb1, type: 3}
- {fileID: -7727686409064562107, guid: 92d3eb280886ba74cb1e19f4e01669a7, type: 3}
- {fileID: -7727686409064562107, guid: 2b932aed8c9bdb54da3d5a0274fe9927, type: 3}
Expand All @@ -34,31 +41,8 @@ MonoBehaviour:
- {fileID: -7727686409064562107, guid: 693d4d98b3a090b458d23261f6c77d94, type: 3}
- {fileID: -7727686409064562107, guid: 05582ec649a27b64c85729877d9e344d, type: 3}
- {fileID: -7727686409064562107, guid: d211f90919bc28a4e8def76cb07197ba, type: 3}
- {fileID: 9154675693299657064, guid: af039f84b4a245049b5b62799af01384, type: 3}
- {fileID: 562230263738288595, guid: 06a27ffa07c1c754c9590607a5a80030, type: 3}
- {fileID: 562230263738288595, guid: 59f05e8a3a1d4b94eb5222aed605e260, type: 3}
- {fileID: 8203177977882359099, guid: 6ab4ce7059d374a4498481e1385c222e, type: 3}
- {fileID: -1308347259443233487, guid: 821d0946be816bb42a0eed24631d57ee, type: 3}
- {fileID: 3815592008771065855, guid: 8686fbdb413e33b4395a775c4f2ba990, type: 3}
- {fileID: -7727686409064562107, guid: 12a989ad41a83a3468d1ae9aff9628d3, type: 3}
- {fileID: 3206407796921847736, guid: 3335d001fdfff824aa859b98f2fe564e, type: 3}
- {fileID: 3227132888119106738, guid: 7bbb74a7ffc8cae44baa886de43c586b, type: 3}
- {fileID: 2930813178971533500, guid: 1c3eed1ea37ecc1448e41270cdc63486, type: 3}
- {fileID: 6999522401175031449, guid: 9b8a1328991fc2846bc55a3d9a82e5c0, type: 3}
- {fileID: 1330758276423851772, guid: 0ef9cea3bb74e6c4788f77e711f92d4d, type: 3}
- {fileID: -7180308641962958576, guid: 501391c27a7f94c4d8c937f00a9ceb9f, type: 3}
- {fileID: 4004765049813284735, guid: df4cf328d472de046bcbc073cbda2868, type: 3}
- {fileID: -3925594391440011444, guid: 75680e6a1df5ff547bdb5b8f116f766b, type: 3}
- {fileID: 866363096200871384, guid: 7a47e5b68d8bab647b3f99ee3af524c7, type: 3}
- {fileID: 3209584612858697896, guid: 6873d7cf62d6ebc42966423161b799f1, type: 3}
- {fileID: -5137155404558150896, guid: 5ecf13819099b014eb5f731155540586, type: 3}
- {fileID: 5717048605554116485, guid: 61201f10ccc2856459a9de99d9cdc52e, type: 3}
- {fileID: -7729870638209327267, guid: 49f2097d4710d114a89821d9164dfce2, type: 3}
- {fileID: -7727686409064562107, guid: de6f06ad18d50134295959f438ba9c5d, type: 3}
- {fileID: -7727686409064562107, guid: 251dc2a5fbda518429c8205c3b62165f, type: 3}
- {fileID: -7727686409064562107, guid: adc07a7f0fee8304691f45a201509b13, type: 3}
- {fileID: -7727686409064562107, guid: 48efd00c91c310e4bb965d025c63b3ba, type: 3}
- {fileID: 1019513474262773944, guid: 06c946c7c639138488b814e4448b82e4, type: 3}
- {fileID: 1871071288925904272, guid: b7976a98a25be4543ba45f1d5e26c072, type: 3}
- {fileID: 3258417366846669140, guid: fa1909e0d40b4cf408ff599df7a2043f, type: 3}
- {fileID: 3258417366846669140, guid: dd3ce5340ed4aba4babae7020f737084, type: 3}
- {fileID: 5958074810027370513, guid: cbe4989d1925276409163212a1ee01b8, type: 3}
Expand All @@ -69,10 +53,29 @@ MonoBehaviour:
- {fileID: -5714630671653109526, guid: 1f96c431e982dc84281c52987a0aac1c, type: 3}
- {fileID: 5177083059232030249, guid: 67dec530733e9f44184e1cc616786768, type: 3}
- {fileID: 4819234911439508660, guid: 11f824c472e04854e95065dda095e8f4, type: 3}
- {fileID: -1308347259443233487, guid: 821d0946be816bb42a0eed24631d57ee, type: 3}
- {fileID: 3815592008771065855, guid: 8686fbdb413e33b4395a775c4f2ba990, type: 3}
- {fileID: -7727686409064562107, guid: de6f06ad18d50134295959f438ba9c5d, type: 3}
- {fileID: -7727686409064562107, guid: 251dc2a5fbda518429c8205c3b62165f, type: 3}
- {fileID: -7727686409064562107, guid: adc07a7f0fee8304691f45a201509b13, type: 3}
- {fileID: -7727686409064562107, guid: 48efd00c91c310e4bb965d025c63b3ba, type: 3}
- {fileID: -7727686409064562107, guid: 12a989ad41a83a3468d1ae9aff9628d3, type: 3}
- {fileID: -7828078595381397262, guid: 98ce0a84deb394b4bbd18f31f368317c, type: 3}
- {fileID: -7828078595381397262, guid: 66f6206faf2f7fb4a993d935c83fc239, type: 3}
- {fileID: 7958861831329766982, guid: d8b0c8d1ddcdeb24d9763054c103c9fe, type: 3}
- {fileID: 7958861831329766982, guid: 79260483ae5d3e04fa272e092b49abac, type: 3}
- {fileID: 7958861831329766982, guid: ff95abc9c2b779340a1b50f1a128a934, type: 3}
- {fileID: 7958861831329766982, guid: 2a63163a4db141744a802f3ff67087db, type: 3}
- {fileID: 7958861831329766982, guid: d9aabfd5d726a7f499b8e360d919eba4, type: 3}
- {fileID: 6999522401175031449, guid: 9b8a1328991fc2846bc55a3d9a82e5c0, type: 3}
- {fileID: 1330758276423851772, guid: 0ef9cea3bb74e6c4788f77e711f92d4d, type: 3}
- {fileID: -7180308641962958576, guid: 501391c27a7f94c4d8c937f00a9ceb9f, type: 3}
- {fileID: 4004765049813284735, guid: df4cf328d472de046bcbc073cbda2868, type: 3}
- {fileID: -3925594391440011444, guid: 75680e6a1df5ff547bdb5b8f116f766b, type: 3}
- {fileID: 866363096200871384, guid: 7a47e5b68d8bab647b3f99ee3af524c7, type: 3}
- {fileID: 3209584612858697896, guid: 6873d7cf62d6ebc42966423161b799f1, type: 3}
- {fileID: -5137155404558150896, guid: 5ecf13819099b014eb5f731155540586, type: 3}
- {fileID: 5717048605554116485, guid: 61201f10ccc2856459a9de99d9cdc52e, type: 3}
- {fileID: -7729870638209327267, guid: 49f2097d4710d114a89821d9164dfce2, type: 3}
- {fileID: 3258417366846669140, guid: 264ea51d92067c14ebc6633999afac78, type: 3}
- {fileID: 4819234911439508660, guid: 1ae18785d74e9fa4699b6f6de889c243, type: 3}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6baf805cce5a6584aaa19181aaf088af, type: 3}
m_Name: ContainerViewedCondition
m_EditorClassIdentifier:
NetworkObject: {fileID: 0}
_id: 0

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 72 additions & 0 deletions Assets/Content/Data/ObserverConditions/ContainerViewedCondition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//The example below does not have many practical uses
//but it shows the bare minimum needed to create a custom condition.
//This condition makes an object only visible if the connections
//ClientId mathes the serialized value, _id.

//Make a new class which inherits from ObserverCondition.
//ObserverCondition is a scriptable object, so also create an asset
//menu to create a new scriptable object of your condition.
using FishNet.Connection;
using FishNet.Observing;
using SS3D.Core;
using SS3D.Systems.Entities;
using SS3D.Systems.Inventory.Containers;
using System.Linq;
using UnityEngine;

[CreateAssetMenu(menuName = "FishNet/SS3D/Observers/ContainerViewed Condition", fileName = "New ContainerViewed Condition")]
public class ContainerViewedCondition : ObserverCondition
{
/// <summary>
/// ClientId a connection must be to pass the condition.
/// </summary>
[Tooltip("ClientId a connection must be to pass the condition.")]
[SerializeField]
private int _id = 0;

/// <summary>
/// Returns if the object which this condition resides should be visible to connection.
/// </summary>
/// <param name="connection">Connection which the condition is being checked for.</param>
/// <param name="currentlyAdded">True if the connection currently has visibility of this object.</param>
/// <param name="notProcessed">True if the condition was not processed. This can be used to skip processing for performance. While output as true this condition result assumes the previous ConditionMet value.</param>
public override bool ConditionMet(NetworkConnection connection, bool currentlyAdded, out bool notProcessed)
{
var container = NetworkObject.GetComponent<AttachedContainer>();
notProcessed= false;

if (SystemLocator.Get<EntitySystem>().TryGetSpawnedEntity(connection, out Entity entity)
&& container.Container.ObservingPlayers.Contains(entity))
{
return true;
}
return false;

}

/// <summary>
/// True if the condition requires regular updates.
/// </summary>
/// <returns></returns>
public override bool Timed()
{
//A condition should return true for timed
//if you need the requirements checked regularly.
//For example, the distance condition is timed
//because players distances could update regularly.

//Since a clientId does not change, this does not need
//to be a timed condition.
return true;
}

/// <summary>
/// Clones referenced ObserverCondition. This must be populated with your conditions settings.
/// </summary>
/// <returns></returns>
public override ObserverCondition Clone()
{
return this;
}

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading