コード例 #1
0
ファイル: Spawner.cs プロジェクト: yazici/FRONTIERS
        public static IEnumerator Spawn(SpawnPoint spawnPoint, SpawnerStateSetting setting, Location location, WIGroup spawnGroup, System.Random random)
        {
            switch (setting.Type)
            {
            case SpawnerType.WorldItems:
            default:
                WorldItem  newSpawnedItem = null;
                WICategory cat            = null;
                if (WorldItems.Get.Category(setting.CategoryName, out cat))
                {
                    spawnPoint.Transform.Position.y += setting.UpVectorPadding;
                    if (WorldItems.CloneRandomFromCategory(cat, spawnGroup, spawnPoint.Transform, setting.Flags, setting.NumTimesSpawned, setting.NumAttempts, out newSpawnedItem))
                    {
                        //adjust spawn point
                        spawnPoint.Transform.Rotation    = spawnPoint.Transform.Rotation + newSpawnedItem.Props.Global.BaseRotation;
                        spawnPoint.Transform.Position.y += setting.UpVectorPadding;
                        //apply to newly spawned item
                        newSpawnedItem.Props.Local.Transform.CopyFrom(spawnPoint.Transform);
                        if (setting.DropThenFreeze)
                        {
                            newSpawnedItem.Props.Local.FreezeOnStartup = false;
                            newSpawnedItem.Props.Local.FreezeOnSleep   = true;
                            newSpawnedItem.gameObject.AddComponent <FreezeOnSleep> ().worlditem = newSpawnedItem;
                        }
                        else
                        {
                            yield return(null);
                        }
                        if (!string.IsNullOrEmpty(setting.SendMessageToSpawnedItem))
                        {
                            //Debug.Log ("Sending message to item: " + setting.SendMessageToSpawnedItem);
                            newSpawnedItem.SendMessage(setting.SendMessageToSpawnedItem, SendMessageOptions.DontRequireReceiver);
                        }
                    }
                    else
                    {
                        //Debug.Log ("Couldn't clone from category " + setting.CategoryName);
                    }
                }
                else
                {
                    //Debug.Log ("Couldn't get category " + setting.CategoryName);
                }
                break;

            case SpawnerType.Characters:
                //TEMP just use bandit camp since that's the only thing that uses spawners for characters
                BanditCamp camp = null;
                if (location.worlditem.Is <BanditCamp> (out camp))
                {
                    Character character = null;
                    //if we've gotten this far we must have found or created a node, so assume it's there
                    if (Characters.SpawnRandomCharacter(spawnPoint.nodeState.actionNode, camp.State.TemplateName, setting.Flags, location.LocationGroup, out character))
                    {
                        camp.AddBandit(character);
                    }
                }
                break;


            case SpawnerType.Creatures:
                spawnPoint.Transform.Position.y += setting.UpVectorPadding;
                CreatureDen den = null;
                if (location.worlditem.Is <CreatureDen> (out den))
                {
                    Creature creature = null;
                    Creatures.SpawnCreature(den, spawnGroup, spawnPoint.Transform.Position, out creature);
                }
                break;
            }
            yield break;
        }