Beispiel #1
0
        /// <summary>
        /// Ensure all required dependencies are added for this NST to work. Can be called often in edit mode, and should be.
        /// </summary>
        /// <param name="nst"></param>
        /// <param name="silence"></param>
        public static void EnsureAllNSTDependencies(this NetworkSyncTransform nst, SerializedObject serializedObject, bool silence = false)
        {
            EnsureSceneNetLibDependencies();

            if (Application.isPlaying)
            {
                return;
            }

            // If user tried to put NST where it shouldn't be... remove it and all of the required components it added.
            if (nst.transform.parent != null)
            {
                XDebug.LogError("NetworkSyncTransform must be on the root of an prefab object.");
                nst.nstElementsEngine = nst.transform.GetComponent <NSTElementsEngine>();

                NSTNetAdapter.RemoveAdapter(nst);

                Object.DestroyImmediate(nst);

                if (nst.nstElementsEngine != null)
                {
                    Object.DestroyImmediate(nst.nstElementsEngine);
                    EditorUtility.SetDirty(nst.gameObject);
                }
                return;
            }

            nst.nstElementsEngine = NSTElementsEngine.EnsureExistsOnRoot(nst.transform, false);

            nst.na = EditorUtils.EnsureRootComponentExists <NSTNetAdapter>(nst.gameObject, false);

            //AddRewindEngine(nst);

            //// Add this NST to the prefab spawn list (and as player prefab if none exists yet) as an idiot prevention
            NSTNetAdapter.AddAsRegisteredPrefab(nst.gameObject, true, silence);
            return;
        }