internal static void SetupIDs(NetworkIdentity identity)
        {
            var         wrapper = new IdentityWrapper(identity);
            PrefabStage stage;

            if (PrefabUtility.IsPartOfPrefabAsset(identity.gameObject))
            {
                wrapper.ClearSceneId();
                AssignAssetID(identity);
            }
            // Unity calls OnValidate for prefab and other scene objects based on that prefab
            //
            // are we modifying THIS prefab, or just a scene object based on the prefab?
            //   * GetCurrentPrefabStage = 'are we editing ANY prefab?'
            //   * GetPrefabStage(go) = 'are we editing THIS prefab?'
            else if ((stage = PrefabStageUtility.GetCurrentPrefabStage()) != null)
            {
                // nested if, we want to do nothing if we are not the prefab being edited
                if (PrefabStageUtility.GetPrefabStage(identity.gameObject) != null)
                {
                    wrapper.ClearSceneId();
                    AssignAssetID(identity, GetStagePath(stage));
                }
            }
            else if (SceneObjectWithPrefabParent(identity, out GameObject parent))
            {
                AssignSceneID(identity);
                AssignAssetID(identity, parent);
            }
            else
            {
                AssignSceneID(identity);
                wrapper.PrefabHash = 0;
            }
        }
        /// <summary>
        /// Ensures that a NetworkIdentity has a Random Unique ID
        /// </summary>
        /// <param name="identity"></param>
        /// <remarks>
        /// We use a random id here instead of index because the order of `FindObjectOfType` might change if something in the scene changes
        /// <para>
        /// Id must be assigned at edit time. This is to make sure they are the the same between builds
        /// </para>
        /// </remarks>
        static void AssignSceneID(NetworkIdentity identity)
        {
            // Only generate at editor time
            if (Application.isPlaying)
            {
                return;
            }

            var wrapper = new IdentityWrapper(identity);

            if (wrapper.SceneId == 0 || IsDuplicate(identity, wrapper.SceneId))
            {
                // clear in any case, because it might have been a duplicate
                wrapper.ClearSceneId();

                // Dont generate when building
                // this Will Cause a new Random ID for each build
                // we need to generate it as edit time
                if (BuildPipeline.isBuildingPlayer)
                {
                    throw new InvalidOperationException($"Scene {identity.gameObject.scene.path} needs to be opened and resaved before building, because the scene object {identity.name} has no valid sceneId yet.");
                }

                int randomId = GetRandomUInt();

                // only assign if not a duplicate of an existing scene id (small chance, but possible)
                if (!IsDuplicate(identity, randomId))
                {
                    wrapper.SceneId = randomId;
                }
            }

            // Add to dictionary so we can keep track of ID for duplicates
            sceneIds[wrapper.SceneId] = identity;
        }
Beispiel #3
0
 public IssueVM(IdentityWrapper<Project, Sprint, Issue> issue, int comments, int attachments, string assignee)
 {
     Issue = issue;
     Comments = comments;
     Attachments = attachments;
     Assignee = assignee;
 }
        static void AssignAssetID(NetworkIdentity identity, string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                // dont log warning here, sometimes prefab has no asset path
                return;
            }

            var wrapper = new IdentityWrapper(identity);

            wrapper.PrefabHash = path.GetStableHashCode();
        }
        internal static IdentityWrapper GetInstance()
        {
            var real = new Identity();

            RealInstanceFactory(ref real);
            var instance = (IdentityWrapper)IdentityWrapper.GetWrapper(real);

            InstanceFactory(ref instance);
            if (instance == null)
            {
                Assert.Inconclusive("Could not Create Test Instance");
            }
            return(instance);
        }
        /// <summary>
        /// Sets the scene hash on the NetworkIdentity
        /// <para>This will stop duplciate ID if the scene is duplicated</para>
        /// <para>NOTE: Only call this from NetworkScenePostProcess</para>
        /// </summary>
        /// <param name="identity"></param>
        // todo: can we call this from OnValidate instead? will that work with scene duplications?
        internal static void SetSceneHash(NetworkIdentity identity)
        {
            var wrapper = new IdentityWrapper(identity);

            // get deterministic scene hash
            int pathHash = GetSceneHash(identity);

            wrapper.SceneHash = pathHash;

            // log it. this is incredibly useful to debug sceneId issues.
            if (logger.LogEnabled())
            {
                logger.Log($"{identity.name} in scene={identity.gameObject.scene.name} scene index hash({pathHash:X}) scene id: {wrapper.SceneId:X}");
            }
        }
 static partial void InstanceFactory(ref IdentityWrapper instance, [CallerMemberName] string callerName = "");
Beispiel #8
0
 protected bool Equals(IdentityWrapper <T> other)
 {
     return(EqualityComparer <T> .Default.Equals(instance, other.instance));
 }