Пример #1
0
        private void InternalSpawn()
        {
            if (useCooldown.Value)
            {
                currentCooldown.Value = EiRandom.Range(MinCooldown, MaxCooldown);
            }

            if (destroyOldObject && spawnedReference != null)
            {
                Destroy(spawnedReference);
            }
            spawnedReference = prefabToSpawn.Instantiate(SpawnPosition, SpawnRotation, SpawnScale);

            var entity = spawnedReference.GetComponent <EiEntity>();

            if (entity)
            {
                entity.SubscribeOnDeath(OnEntityDestroyed);
            }

            onSpawned.Trigger();
            onSpawnedObject.Trigger(spawnedReference);
        }
Пример #2
0
        public void Instantiate(byte[] data)
        {
            EiBuffer buffer   = new EiBuffer(data);
            var      unpack   = (EiNetworkInstantiateMask)buffer.ReadByte();
            var      prefabId = buffer.ReadInt();
            var      viewId   = buffer.ReadInt();
            var      ownerId  = buffer.ReadInt();
            EiPrefab prefab   = Eitrum.Database.EiPrefabDatabase.Instance [prefabId];

            // Calculate Unpack type
            Vector3    position = unpack.HasFlag(EiNetworkInstantiateMask.Position) ? buffer.ReadVector3() : Vector3.zero;
            Quaternion rotation = unpack.HasFlag(EiNetworkInstantiateMask.Rotation) ? buffer.ReadQuaternion() : Quaternion.identity;
            float      scale    = unpack.HasFlag(EiNetworkInstantiateMask.Scale) ? buffer.ReadFloat() : 1f;
            Vector3    scale3D  = unpack.HasFlag(EiNetworkInstantiateMask.Scale3D) ? buffer.ReadVector3() : new Vector3(scale, scale, scale);
            Transform  parent   = null;

            if (unpack.HasFlag(EiNetworkInstantiateMask.Parent))
            {
                var parentViewId = buffer.ReadInt();
                var parentView   = EiNetworkView.Find(parentViewId);
                if (parentView)
                {
                    parent = parentView.transform;
                }
            }

            // Instantiate Prefab
            var go   = prefab.Instantiate(position, rotation, scale3D, parent);
            var view = go.GetComponent <EiNetworkView> ();

            if (view)
            {
                EiNetworkView.SetViewId(view, viewId);
                EiNetworkView.SetOwnerId(view, ownerId);
                EiNetworkView.SetNetwork(view, this);
            }
        }
Пример #3
0
 public static GameObject Instantiate(EiPrefab prefab)
 {
     return(prefab.Instantiate());
 }
Пример #4
0
 public static GameObject Instantiate(EiPrefab prefab, Vector3 position, Quaternion rotation)
 {
     return(prefab.Instantiate(position, rotation));
 }
Пример #5
0
 public static GameObject Instantiate(EiPrefab prefab, Vector3 position, Quaternion rotation, Vector3 scale, Transform parent)
 {
     return(prefab.Instantiate(position, rotation, scale, parent));
 }