Beispiel #1
0
        void OnEnable()
        {
            if (target == null)
            {
                Debug.LogWarning("NetworkBehaviourInspector had no target object");
                return;
            }

            // If target's base class is changed from NetworkBehaviour to MonoBehaviour
            // then Unity temporarily keep using this Inspector causing things to break
            if (!(target is NetworkBehaviour))
            {
                return;
            }

            Type scriptClass = target.GetType();

            syncVarNames = new List <string>();
            foreach (FieldInfo field in InspectorHelper.GetAllFields(scriptClass, typeof(NetworkBehaviour)))
            {
                if (field.IsSyncVar() && field.IsVisibleField())
                {
                    syncVarNames.Add(field.Name);
                }
            }

            syncListDrawer = new SyncListDrawer(serializedObject.targetObject);

            syncsAnything = SyncsAnything(scriptClass);
        }
Beispiel #2
0
        // does this type sync anything? otherwise we don't need to show syncInterval
        bool SyncsAnything(Type scriptClass)
        {
            // check for all SyncVar fields, they don't have to be visible
            foreach (FieldInfo field in InspectorHelper.GetAllFields(scriptClass, typeof(NetworkBehaviour)))
            {
                if (field.IsSyncVar())
                {
                    return(true);
                }
            }

            // has OnSerialize that is not in NetworkBehaviour?
            // then it either has a syncvar or custom OnSerialize. either way
            // this means we have something to sync.
            MethodInfo method = scriptClass.GetMethod("OnSerialize");

            if (method != null && method.DeclaringType != typeof(NetworkBehaviour))
            {
                return(true);
            }

            // SyncObjects are serialized in NetworkBehaviour.OnSerialize, which
            // is always there even if we don't use SyncObjects. so we need to
            // search for SyncObjects manually.
            // Any SyncObject should be added to syncObjects when unity creates an
            // object so we can cheeck length of list so see if sync objects exists
            FieldInfo         syncObjectsField = scriptClass.GetField("syncObjects", BindingFlags.NonPublic | BindingFlags.Instance);
            List <SyncObject> syncObjects      = (List <SyncObject>)syncObjectsField.GetValue(serializedObject.targetObject);

            return(syncObjects.Count > 0);
        }
Beispiel #3
0
 public SyncListDrawer(UnityEngine.Object targetObject)
 {
     this.targetObject = targetObject;
     syncListFields    = new List <SyncListField>();
     foreach (FieldInfo field in InspectorHelper.GetAllFields(targetObject.GetType(), typeof(NetworkBehaviour)))
     {
         if (field.IsSyncObject() && field.IsVisibleSyncObject())
         {
             syncListFields.Add(new SyncListField(field));
         }
     }
 }
 public SyncObjectCollectionsDrawer(UnityEngine.Object targetObject)
 {
     this.targetObject          = targetObject;
     syncObjectCollectionFields = new List <SyncObjectCollectionField>();
     foreach (FieldInfo field in InspectorHelper.GetAllFields(targetObject.GetType(), typeof(NetworkBehaviour)))
     {
         // only draw SyncObjects that are IEnumerable (SyncList/Set/Dictionary)
         if (field.IsVisibleSyncObject() &&
             field.ImplementsInterface <SyncObject>() &&
             field.ImplementsInterface <IEnumerable>())
         {
             syncObjectCollectionFields.Add(new SyncObjectCollectionField(field));
         }
     }
 }
Beispiel #5
0
        void OnEnable()
        {
            if (target == null)
            {
                Debug.LogWarning("NetworkBehaviourInspector had no target object", serializedObject.context); return;
            }

            Type scriptClass = target.GetType();

            syncVarNames = new List <string>();
            foreach (FieldInfo field in InspectorHelper.GetAllFields(scriptClass, typeof(NetworkBehaviour)))
            {
                if (field.IsSyncVar() && field.IsVisibleField())
                {
                    syncVarNames.Add(field.Name);
                }
            }

            syncListDrawer = new SyncListDrawer(serializedObject.targetObject);

            syncsAnything = SyncsAnything(scriptClass);
        }