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


C# GameObject.ToList方法代码示例

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


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

示例1: initializePlayers

    private void initializePlayers()
    {
        currentPlayers = new List<GameObject>();
        GameObject[] players = GameObject.FindGameObjectsWithTag("Player");

        GameObject ghostPlayer = null;

        for (int i = 0; i < players.Length; ++i)
        {
            int playerReadyArrayIndex = players[i].GetComponent<Human>().playerNum - 1;

            if (!isPlayerReadyArray[playerReadyArrayIndex])
            {
                players[i].SetActive(false);
                Camera.main.GetComponent<NewCameraBehavior>().targets.Remove(players[i]);
            }
            else
            {
                if (playerReadyArrayIndex == ghostPlayerIndex)
                {
                    if (!isGhostAI)
                    {
                        ghostPlayer = (GameObject)GameObject.Instantiate(ghostPrefab, players[i].transform.position, players[i].transform.rotation);
                        ghostPlayer.GetComponent<Ghost>().playerNum = players[i].GetComponent<Human>().playerNum;
                        ghostPlayer.gameObject.tag = "Ghost";

                        if (!CatMode)
                        {
                            ghostPlayer.GetComponentInChildren<Text>().text = "P" + (ghostPlayerIndex + 1);
                        }
                        else
                        {
                            ghostPlayer.GetComponentInChildren<Text>().text = "MEOW";
                        }

                        ghostPlayer.GetComponentInChildren<FadeOnTimeScale1>().timeScale = .45f;
                        Camera.main.gameObject.GetComponent<NewCameraBehavior>().targets.Remove(players[i]);
                        Destroy(players[i]);
                    }
                    else
                    {
                        ghostPlayer = (GameObject)GameObject.Instantiate(ghostAIPrefab, players[i].transform.position, players[i].transform.rotation);
                        Camera.main.gameObject.GetComponent<NewCameraBehavior>().targets.Remove(players[i]);
                        Destroy(players[i]);
                    }
                }
                else
                {
                    currentPlayers.Add(players[i]);
                }
            }
        }

        if (_SpriteSorter != null)
        {
            GameObject[]sortedPlayerList = new GameObject[4];

            foreach (GameObject playerObject in currentPlayers)
            {
                _SpriteSorter.AddToAllLists(playerObject.GetComponent<SpriteRenderer>());

                //sorts player list
                if (playerObject.name.Contains("1"))
                    sortedPlayerList[0] =  playerObject;
                else if (playerObject.name.Contains("2"))
                    sortedPlayerList[1] = playerObject;
                else if (playerObject.name.Contains("3"))
                    sortedPlayerList[2] = playerObject;
                else if (playerObject.name.Contains("4"))
                    sortedPlayerList[3] = playerObject;
            }

            currentPlayers = sortedPlayerList.ToList();

        }

        currentPlayers[ghostPlayerIndex] = ghostPlayer;

        for (int i = 0; i < currentPlayers.Count; i++)
        {
            if(currentPlayers[i] != null && currentPlayers[i].gameObject.tag != "Ghost")
            {
                Human playerHuman = currentPlayers[i].GetComponent<Human>();

                if(!SceneStartedInEditor)
                    playerHuman.IsFemaleWizard = isFemaleCharacter[i];

                if (playerColorPalettes[i] == null)
                {
                    if (playerHuman.IsFemaleWizard)
                        playerColorPalettes[i] = womanColorPalettes[i];
                    else
                        playerColorPalettes[i] = oldieColorPalettes[i];
                }

                VerifyCorrectAnimController(i);

                PaletteSwapper currentPlayer_PS = currentPlayers[i].GetComponent<PaletteSwapper>();
                currentPlayer_PS.currentPalette = playerColorPalettes[i];
                currentPlayer_PS.SwapColors_Custom(currentPlayer_PS.currentPalette);
//.........这里部分代码省略.........
开发者ID:Mrbransky,项目名称:Kissy_Ghost,代码行数:101,代码来源:GameManager.cs

示例2: 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

示例3: BuildPlatform


//.........这里部分代码省略.........
        if (orientation == 0)
        {
            System.Array.Resize(ref orderedObjects, orderedObjects.Length + 1);
            orderedObjects[objArrayPos] = endLeft;
            objArrayPos++;

            System.Array.Resize(ref orderedObjects, orderedObjects.Length + 1);
            orderedObjects[objArrayPos] = endRight;
            objArrayPos++;
        }

        else
        {
            System.Array.Resize(ref orderedObjects, orderedObjects.Length + 1);
            orderedObjects[objArrayPos] = endTop;
            objArrayPos++;

            System.Array.Resize(ref orderedObjects, orderedObjects.Length + 1);
            orderedObjects[objArrayPos] = endBottom;
            objArrayPos++;
        }

        //Add doors to ordered array
        if (doors.Count > 0)
        {
            foreach (GameObject door in doors)
            {
                System.Array.Resize(ref orderedObjects, orderedObjects.Length + 1);
                orderedObjects[objArrayPos] = door;
                objArrayPos++;
            }
        }

        //Order array from left to right
        orderedObjects = orderedObjects.OrderBy(go => go.transform.position.x).ToArray();

        //Get leftmost and rightmost objects
        GameObject objectLeft = orderedObjects[0];
        GameObject objectRight = orderedObjects[orderedObjects.Length - 1];

        float start, end;

        if (objectLeft.GetComponent<Collider2D>())
            start = objectLeft.GetComponent<Collider2D>().bounds.max.x;

        else
            start = objectLeft.transform.position.x;

        if (objectRight.GetComponent<Collider2D>())
            end = objectRight.GetComponent<Collider2D>().bounds.min.x;

        else
            end = objectRight.transform.position.x;

        float difference = end - start;

        //Remove End objects from array
        List<GameObject> o = orderedObjects.ToList();
        o.RemoveAt(0);
        o.RemoveAt(o.Count - 1);

        orderedObjects = o.ToArray();

        ////Position Doors and Ends
        foreach (GameObject orderedObject in orderedObjects)
        {
            float objectSizeX = orderedObject.GetComponent<Collider2D>().bounds.size.x;
            float objectExtentsX = orderedObject.GetComponent<Collider2D>().bounds.extents.x;
            float totalObjectLength = objectSizeX * orderedObjects.Length;
            float leftOverSpace = difference - totalObjectLength;

            if (orientation == 0)
            {
                orderedObject.transform.position = new Vector3(start + objectExtentsX + (leftOverSpace / (orderedObjects.Length + 1)), orderedObject.transform.position.y, orderedObject.transform.position.z);
                start = orderedObject.GetComponent<Collider2D>().bounds.max.x;
            }

            else
            {
                orderedObject.transform.position = new Vector3(start + objectExtentsX + 0.15f + (leftOverSpace / (orderedObjects.Length + 1)), orderedObject.transform.position.y, orderedObject.transform.position.z);
                start = orderedObject.GetComponent<Collider2D>().bounds.max.x;
            }
        }

        if (orientation == 1)
            platformParent.transform.Rotate(0, 0, -90);

        if (buildMidSections)
            BuildPlatformMidSections(platformParent);

        //Parent to room
        if (selectedRoom)
        {
            platformParent.transform.SetParent(selectedRoom.transform);
            platformParent.transform.localPosition = new Vector3(0, 0, 0);
        }


        Selection.activeGameObject = platformParent;
    }
开发者ID:NoManAlone,项目名称:No-Man-Alone-Vertical-Slice---Scripts,代码行数:101,代码来源:PlatformBuilder.cs


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