Пример #1
0
        public override void OnEnable()
        {
            headerName  = HeaderElementAddonName;
            headerColor = HeaderElementAddonColor;
            base.OnEnable();

            _target = (NSTElementComponent)target;
            _target.nstElementsEngine = NSTElementsEngine.EnsureExistsOnRoot(_target.transform, false);
            nstElementsEngine         = _target.nstElementsEngine;


            // First make sure this is unique for this gameobject
            MakeAllNamesUnique(_target.gameObject);
        }
Пример #2
0
        private void AddAllDependencies(bool silence = false)
        {
            headerName  = HeaderNSTName;
            headerColor = HeaderNSTColor;
            base.OnEnable();

            nst = (NetworkSyncTransform)target;

            // Add this NST to the prefab spawn list (and as player prefab if none exists yet) as an idiot prevention
            if (!Application.isPlaying)
            {
                MasterNetAdapter.AddAsRegisteredPrefab(nst.gameObject, silence);
            }


            // 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)
            {
                Debug.LogError("NetworkSyncTransform must be on the root of an prefab object.");
                nst.nstElementsEngine = nst.transform.GetComponent <NSTElementsEngine>();

                NSTNetAdapter.RemoveAdapter(nst);

                DestroyImmediate(nst);

                if (nst.nstElementsEngine != null)
                {
                    DestroyImmediate(nst.nstElementsEngine);
                }

                return;
            }

            nst.na = NSTNetAdapter.EnsureNstAdapterExists(nst.gameObject);

            nst.nstSettings       = NSTSettings.EnsureExistsInScene(NSTSettings.DEFAULT_GO_NAME);
            nst.nstElementsEngine = NSTElementsEngine.EnsureExistsOnRoot(nst.transform, false);
            NSTMaster.EnsureExistsInScene("NST Master");
        }
Пример #3
0
        /// <summary>
        /// Ensure all required dependencies are added for this NST to work. Can be called often in edit mode, and should be. Returns false
        /// if a DestroyImmediate was invoked.
        /// </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)
            {
                DebugX.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);             //NSTNetAdapter.AddAsRegisteredPrefab(nst.gameObject, silence);
            return;
        }