当前位置: 首页>>代码示例>>C#>>正文


C# GameObject.Count方法代码示例

本文整理汇总了C#中GameObject.Count方法的典型用法代码示例。如果您正苦于以下问题:C# GameObject.Count方法的具体用法?C# GameObject.Count怎么用?C# GameObject.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GameObject的用法示例。


在下文中一共展示了GameObject.Count方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StartLevel

    public void StartLevel(GameObject[] playerShips)
    {
        int shipCount = playerShips.Count(s => s != null);
        int shipsPlaced = 0;

        if (playerShips[0] != null)
        {
            playerShips[0].transform.position = new Vector3(0, SpawnDistanceToCenter);
            playerShips[0].transform.RotateAround(new Vector3(0, 0, 0), Vector3.forward, (360f / shipCount) * shipsPlaced++ + 45);
            playerShips[0].SetActive(true);
        }
        if (playerShips[1] != null)
        {
            playerShips[1].transform.position = new Vector3(0, SpawnDistanceToCenter);
            playerShips[1].transform.RotateAround(new Vector3(0, 0, 0), Vector3.forward, (360f / shipCount) * shipsPlaced++ + 45);
            playerShips[1].SetActive(true);
        }
        if (playerShips[2] != null)
        {
            playerShips[2].transform.position = new Vector3(0, SpawnDistanceToCenter);
            playerShips[2].transform.RotateAround(new Vector3(0, 0, 0), Vector3.forward, (360f / shipCount) * shipsPlaced++ + 45);
            playerShips[2].SetActive(true);
        }
        if (playerShips[3] != null)
        {
            playerShips[3].transform.position = new Vector3(0, SpawnDistanceToCenter);
            playerShips[3].transform.RotateAround(new Vector3(0, 0, 0), Vector3.forward, (360f / shipCount) * shipsPlaced++ + 45);
            playerShips[3].SetActive(true);
        }
    }
开发者ID:oscarlosu,项目名称:GameDesignProject,代码行数:30,代码来源:BlackHoleController.cs

示例2: GenRecipes

    void GenRecipes()
    {
        tier_ingredient = new List<HashSet<Ingredients>>();
        System.Random rnd = new System.Random((int)System.DateTime.Now.Ticks);
        if (tier_GmO == null)
        {
            tier_GmO = new List<HashSet<GameObject>>(new HashSet<GameObject>[] { });
            foreach (Transform tiers in base_ingredients.transform)
            {
                HashSet<GameObject> h = new HashSet<GameObject>();
                tier_GmO.Add(h);
                foreach (Transform ingredient in tiers)
                {
                    h.Add(ingredient.gameObject);
                }
            }
        }
        stat_ingredient = new Dictionary<Ingredients.stats, HashSet<Ingredients>>();
        part_ingredient = new Dictionary<Ingredients.bodyParts, HashSet<Ingredients>>();
        var values = System.Enum.GetValues(typeof(Ingredients.bodyParts));
        foreach(Ingredients.bodyParts value in values)
        {
            part_ingredient.Add(value, new HashSet<Ingredients>());
        }
        values = System.Enum.GetValues(typeof(Ingredients.stats));
        foreach (Ingredients.stats value in values)
        {
            stat_ingredient.Add(value, new HashSet<Ingredients>());
        }
        for (int x = 0; x < tier_GmO.Count; x++)
        {
            List<GameObject> ingredient_l = GetIngredientsTier(x);
            GameObject[] stats = new GameObject[ingredient_l.Count];
            int[] parts_n = new int[5];
            int[] parts_v = { 2, 3, 5 };
            for (int y = 0; y < 5; y++)
            {
                parts_n[y] = 1;
                for (int z = 0; z < 2; z++)
                {
                    int chk = rnd.Next(0, ingredient_l.Count);
                    stats[y*2+z] = ingredient_l[chk];
                    ingredient_l.RemoveAt(chk);
                }

            }
            for (int y = 0; y < 3; y++)
            {
                for (int a = 0; a < 3 || (y >= 2 && a < 4); a++)
                {
                    int min = parts_n.Min();
                    int count = 0;
                    if (min > 1)
                    {
                        count = parts_n.Where(elem => elem < 6 && elem % parts_v[y] > 0).Count();
                        min = 5;
                    }
                    else
                    {
                        count = parts_n.Where(elem => elem < 2).Count();
                        min = 1;
                    }
                    int chk = rnd.Next(0, count);
                    int ct = 0;
                    for (int z = 0; z < parts_n.Count(); z++)
                    {
                        if (ct == chk && parts_n[z] <= min && parts_n[z] % parts_v[y] > 0)
                        {
                            parts_n[z] *= parts_v[y];
                            break;
                        }
                        if (parts_n[z] <= min && parts_n[z] % parts_v[y] > 0)
                        {
                            ct++;
                        }
                    }
                }
            }
            HashSet<Ingredients> tier_set = new HashSet<Ingredients>();
            for (int y = 0; y < stats.Count(); y++)
            {
                foreach(int prime in parts_v)
                {
                    if(parts_n[y/2] % prime == 0)
                    {
                        Ingredients temp = new Ingredients(stats[y].name, y / 2, prime, x, stats[y]);
                        tier_set.Add(temp);
                        name_ingredient.Add(stats[y].name, temp);
                        stat_ingredient[((Ingredients.stats)(y / 2))].Add(temp);
                        part_ingredient[((Ingredients.bodyParts)prime)].Add(temp);
                        parts_n[y / 2] /= prime;
                        break;
                    }
                }
            }
            tier_ingredient.Add(tier_set);
        }
    }
开发者ID:BluShine,项目名称:BackalleySummoner,代码行数:98,代码来源:Recipes.cs

示例3: ItemSetup

	// You can choose to have random items be created or pass in a chosen list.
	// If no list is provided, then random items are chosen.
	// This gets called from ItemSpawner after it spawns this itemStorer
	// gameObject.
	public void ItemSetup(bool large, int areaNumber, GameObject[] manualItemsChosen = null)
	{
		myAreaNumber = areaNumber;
		if(manualItemsChosen == null || manualItemsChosen.Count() == 0)
		{
			if(!large) // A small itemStorer was created.
			{
				// Half values.
				transform.localScale = Vector3.one * 0.5f;
				_totalItemsToCarry = Random.Range(1, 3); // Hold up to 2 when small.
				health = Mathf.RoundToInt(health * 0.5f);
			}
			else _totalItemsToCarry = Random.Range(3, 5); // Hold up to 4 when large.
			// More random choices with a higher appear rate. Very_High = 5 and
			// Very_Low = 1
			_maxRandomToChooseFrom = (int)Manager_Game.ItemAppearRate;
			itemsCanDrop = new List<GameObject>();
			for(int i = 0; i < _maxRandomToChooseFrom || itemsCanDrop.Count == _totalItemsToCarry; i++)
			{
				if(Random.value > 0.6f)
				{
					itemsCanDrop.Add(Manager_Game.instance.ICPrefabs[Random.Range(0, Manager_Game.instance.ICPrefabs.Count)]);
					continue;
				}
				if(Random.value > 0.5f)
				{
					itemsCanDrop.Add(Manager_Game.instance.ITPrefabs[Random.Range(0, Manager_Game.instance.ITPrefabs.Count)]);
					continue;
				}
				itemsCanDrop.Add(Manager_Game.instance.IWPrefabs[Random.Range(0, Manager_Game.instance.IWPrefabs.Count)]);
			}
		}
		else // Manually items chosen to choose from
		{
			List<GameObject> itemsToCreate = manualItemsChosen.ToList();

			if(!large)
			{
				// If small we will remove half of the amount of items we have.
				transform.localScale = Vector3.one * 0.5f;
				if(itemsToCreate.Count > 1)
				{
					_totalItemsToCarry = Mathf.RoundToInt(itemsToCreate.Count / 2);
					for(int i = 0; i < _totalItemsToCarry; i++)
					{
						if(i != _totalItemsToCarry - 1)
						{
							// Random chance of removing this one if we aren't at the
							// end.
							if(Random.value > 0.5f)
								itemsToCreate.RemoveAt(i);
						}
						else itemsToCreate.RemoveAt(i);
					}
				}
			}
			// Large so keep all items chosen.
			else _totalItemsToCarry = itemsToCreate.Count;
			itemsCanDrop = itemsToCreate;
		}
		GetComponent<Rigidbody>().drag = large ? 20 : 10;
	}
开发者ID:MMEstrada,项目名称:GoGoGrandmas,代码行数:66,代码来源:ItemStorer.cs

示例4: WaypointsAreValid

    private bool WaypointsAreValid(GameObject[] waypoints)
    {
        //first check whether whey all have a OrderedWaypoint component
        if (!waypoints.All(x => x.GetComponent<OrderedWaypointForEditor>() != null))
        {
            EditorUtility.DisplayDialog("Error", "All waypoints must have an ordered waypoint component", "OK");
            return false;
        }
        //check if all Order fields on the orderwaypoint components are different

        if (waypoints.Count() != waypoints.Select(x=>x.GetComponent<OrderedWaypointForEditor>().Order).Distinct().Count())
        {
            EditorUtility.DisplayDialog("Error", "All waypoints must have a different order", "OK");
            return false;
        }
        return true;
    }
开发者ID:Kingpin0509,项目名称:TowerDefense,代码行数:17,代码来源:LevelExport.cs

示例5: FindTargetClosest

    //find target closest to the unit, from array
    void FindTargetClosest(GameObject[] targets, bool ignoreUnits)
    {
        foundTarget = false;

        //if stunned
        if (myUnit.remainingMove <= 0 && myUnit.actionPoints <= 0 && myUnit.movespeed == 0) {
            return;
        }

        List<Node> shortestPath = new List<Node> ();
        myUnit.currentPath = new List<Node> ();
        float currentPathCost = Mathf.Infinity;
        int tx = 0;
        int ty = 0;

        // for each character, find path
        for (int i = 0; i < targets.Count(); ++i) {
            //get the target
            Unit targetUnit = targets[i].GetComponent<Unit>();
            if (targetUnit != null) {
                //if the target is alive
                if (!targetUnit.isDead && targetUnit != myUnit && targetUnit.isActive) {

                    //find the path to the target
                    myMap.GeneratePathTo(targetUnit.tileX, targetUnit.tileY, ignoreUnits);
                    //if a path was found
                    if (myUnit.currentPath.Count > 0) {
                        //remove the targets node
                        myUnit.currentPath.Remove(myMap.GetNode (targetUnit.tileX, targetUnit.tileY));
                        //remove all unreachable tiles
                        FindFurthestTileInPath();

                        // if the target is next to the unit
                        if (myUnit.currentPath.Count == 0) {
                            // if the current closest isnt already next to
                            if (currentPathCost != 0) {
                                foundTarget = true;
                                // set shortest path
                                shortestPath = myUnit.currentPath;
                                currentPathCost = 0;
                                tx = targetUnit.tileX;
                                ty = targetUnit.tileY;
                            }
                        } //else if the target is closer than the previous
                        else if (myUnit.currentPath.Last().cost < currentPathCost) {
                            // set shortest path
                            foundTarget = true;
                            shortestPath = myUnit.currentPath;
                            currentPathCost = myUnit.currentPath.Last().cost;
                            tx = targetUnit.tileX;
                            ty = targetUnit.tileY;
                        }
                    }
                }
            }
        }

        //set the target
        target = myMap.GetNode (tx, ty);
        myUnit.currentPath = shortestPath;
    }
开发者ID:JohnEz,项目名称:TileBasedEngine,代码行数:62,代码来源:AIBehaviours.cs


注:本文中的GameObject.Count方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。