예제 #1
0
    private int GetRandomPrefabIndex()
    {
        PrefabSet set = ActiveSet;

        if (set?.Prefabs == null || set.Prefabs.Count == 0)
        {
            return(-1);
        }

        IList <PrefabEntry> activePrefabSet = set.Prefabs;
        float selectionValue = Random.value;

        for (int index = 0; index < activePrefabSet.Count; index++)
        {
            PrefabEntry entry = activePrefabSet[index];

            if (entry.OccurrenceFactor > selectionValue)
            {
                return(index);
            }

            selectionValue -= entry.OccurrenceFactor;
        }

        return(activePrefabSet.Count - 1);
    }
        private GameObject Spawn(PrefabEntry entry)
        {
            if (entry.Prefab == null)
            {
                return(null);
            }

            var pool = _spawnPool != null ? _spawnPool : SpawnPool.DefaultPool;
            var go   = pool.Spawn(entry.Prefab.gameObject, this.transform.position, this.transform.rotation, _spawnedObjectParent);

            var dur          = (entry.Duration > 0f) ? entry.Duration : entry.Prefab.main.duration;
            var timeSupplier = (entry.Prefab.main.useUnscaledTime) ? SPTime.Real : SPTime.Normal;

            if (!float.IsNaN(dur) && !float.IsInfinity(dur) && dur >= 0f)
            {
                this.InvokeGuaranteed(() => go.Kill(), dur,
                                      entry.Prefab.main.useUnscaledTime ? SPTime.Real : SPTime.Normal);
            }

            if (_onSpawnedObject != null && _onSpawnedObject.Count > 0)
            {
                _onSpawnedObject.ActivateTrigger(this, go);
            }

            return(go);
        }
예제 #3
0
        public void Add(PrefabEntry prefab)
        {
            if (cache.ContainsKey(prefab.name))
            {
                throw new InvalidOperationException("The prefab name '" + prefab.name + "' already exists");
            }

            cache[prefab.name] = prefab.prefab;
        }
예제 #4
0
        void BuildList(string folder)
        {
            _entries = null;
            DirectoryInfo dir = new DirectoryInfo(folder);

            FileInfo[] files = dir.GetFiles("*.prefab", SearchOption.AllDirectories);

            listView_Prefabs.BeginUpdate();
            listView_Prefabs.Items.Clear();
            if (files == null || files.Length == 0)
            {
                listView_Prefabs.EndUpdate();
                return;
            }

            _entries = new List <PrefabEntry>();
            int iSub = folder.Length;

            foreach (FileInfo f in files)
            {
                PrefabEntry entry = new PrefabEntry();
                _entries.Add(entry);
                entry.PrefabFile = f;

                entry.RelFilename = f.FullName.Substring(iSub);
                ListViewItem item = listView_Prefabs.Items.Add(entry.RelFilename);
                entry.ListItem = item;

                string status    = "<not available>";
                Color  statusCol = Color.Gray;

                entry.VPrefabName = Path.ChangeExtension(f.FullName, ".vprefab");
                FileInfo vprefab = new FileInfo(entry.VPrefabName);
                if (vprefab.Exists)
                {
                    entry.VPrefabFile = vprefab;
                    status            = "Last Export: " + vprefab.LastWriteTime.ToString();
                    statusCol         = Color.Black;
                }
                item.UseItemStyleForSubItems = false;
                ListViewItem.ListViewSubItem subitem = item.SubItems.Add(status);
                subitem.ForeColor = statusCol;

                item.Tag     = entry;
                item.Checked = true;
            }

            listView_Prefabs.EndUpdate();
        }
    public bool CreateObject(string objectName, float x, float y)
    {
        var splitName = objectName.Split(new char[] { ':' });

        PrefabEntry entry = world.prefabNames.GetEntry(splitName[0]);

        if (entry != null)
        {
            GameObject result = GameObject.Instantiate(entry.prefab, new Vector3(x, y, 0.0f), Quaternion.identity, Projectile.projectileParent);
            namedObjects[splitName.Length > 1 ? splitName[1] : splitName[0]] = result;

            return(true);
        }
        else
        {
            Debug.LogError("Could not find prefab named " + objectName);
            return(false);
        }
    }
        private GameObject Spawn(PrefabEntry entry)
        {
            if (entry.Prefab == null)
            {
                return(null);
            }

            var pool = _spawnPool != null ? _spawnPool : SpawnPool.DefaultPool;
            var go   = pool.Spawn(entry.Prefab.gameObject, this.transform.position, this.transform.rotation, _spawnedObjectParent);

            var dur = (entry.Duration == 0f) ? entry.Prefab.main.duration : entry.Duration;

            if (dur > 0f && dur != float.PositiveInfinity)
            {
                GameLoop.Hook.Invoke(go.Kill, dur);
            }

            if (_onSpawnedObject != null && _onSpawnedObject.Count > 0)
            {
                _onSpawnedObject.ActivateTrigger(this, go);
            }

            return(go);
        }
        void BuildList(string folder)
        {
            _entries = null;
              DirectoryInfo dir = new DirectoryInfo(folder);
              FileInfo[] files = dir.GetFiles("*.prefab", SearchOption.AllDirectories);

              listView_Prefabs.BeginUpdate();
              listView_Prefabs.Items.Clear();
              if (files == null || files.Length == 0)
              {
            listView_Prefabs.EndUpdate();
            return;
              }

              _entries = new List<PrefabEntry>();
              int iSub = folder.Length;
              foreach (FileInfo f in files)
              {
            PrefabEntry entry = new PrefabEntry();
            _entries.Add(entry);
            entry.PrefabFile = f;

            entry.RelFilename = f.FullName.Substring(iSub);
            ListViewItem item = listView_Prefabs.Items.Add(entry.RelFilename);
            entry.ListItem = item;

            string status = "<not available>";
            Color statusCol = Color.Gray;

            entry.VPrefabName = Path.ChangeExtension(f.FullName, ".vprefab");
            FileInfo vprefab = new FileInfo(entry.VPrefabName);
            if (vprefab.Exists)
            {
              entry.VPrefabFile = vprefab;
              status = "Last Export: " + vprefab.LastWriteTime.ToString();
              statusCol = Color.Black;
            }
            item.UseItemStyleForSubItems = false;
            ListViewItem.ListViewSubItem subitem = item.SubItems.Add(status);
            subitem.ForeColor = statusCol;

            item.Tag = entry;
            item.Checked = true;
              }

              listView_Prefabs.EndUpdate();
        }