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


C# GameObject.OrderBy方法代码示例

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


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

示例1: sortArrayFromName

	/* Take a gameobejct with children in parameters, and sort them by their name */
	public GameObject[] sortArrayFromName(GameObject childArrayToSort)
	{
		GameObject[] _arrayToSort = new GameObject[childArrayToSort.transform.childCount];
		GameObject o;

		for (int i = 0; i < childArrayToSort.transform.childCount; i++)
		{
			o = childArrayToSort.transform.GetChild(i).gameObject;
			_arrayToSort[i] = o;
		}

		_arrayToSort = _arrayToSort.OrderBy(go => go.name).ToArray();
		
		return _arrayToSort;
	}
开发者ID:Kaiymu,项目名称:SpaceBallBlaster,代码行数:16,代码来源:SortGameObjectsChildrenByName.cs

示例2: CreateWalls

    void CreateWalls(GameObject r)
	{
        Bounds roomBounds = r.GetComponent<Collider2D>().bounds;

        List<GameObject> doors = new List<GameObject>();

        if (r.transform.FindChild("Doors"))
        {
            foreach (Transform child in r.transform.FindChild("Doors"))
                doors.Add(child.gameObject);
        }

        GameObject wallsParent = new GameObject("Walls");
        wallsParent.transform.SetParent(r.transform);
        wallsParent.transform.localScale =  new Vector3(1 , 1 , 1);

        Object wallPrefab = Resources.Load ("Wall");
        Sprite wallSprite = Resources.Load<Sprite>("Blue Metal Wall");
		Sprite wallEndSprite = Resources.Load<Sprite>("Blue Metal Wall Corner");
		Sprite consoleCornerSprite = Resources.Load<Sprite>("CV Corner");

        //CREATE CORNERS
        //Corners are used for the placement and sizing of walls. 
        //Corners on walls that are not selected are deleted after walls are created 

        topLeftCorner = (GameObject)PrefabUtility.InstantiatePrefab(wallPrefab);
        topLeftCorner.GetComponent<SpriteRenderer>().sprite = wallEndSprite;
		topLeftCorner.transform.GetChild(0).GetComponent<SpriteRenderer>().sprite = consoleCornerSprite;
        topLeftCorner.name = "Wall Top-Left Corner";
        topLeftCorner.transform.SetParent(wallsParent.transform);
        topLeftCorner.transform.position = new Vector2(r.transform.position.x -roomBounds.extents.x - 0.5f, r.transform.position.y + roomBounds.extents.y + 0.5f);
        topLeftCorner.transform.localScale = new Vector3(1 / r.transform.localScale.x, 1 / r.transform.localScale.y, 1);
       
        topRightCorner = (GameObject)PrefabUtility.InstantiatePrefab(wallPrefab);
        topRightCorner.GetComponent<SpriteRenderer>().sprite = wallEndSprite;
		topRightCorner.transform.GetChild(0).GetComponent<SpriteRenderer>().sprite = consoleCornerSprite;
        topRightCorner.name = "Wall Top-Right Corner";
        topRightCorner.transform.SetParent(wallsParent.transform);
        topRightCorner.transform.position = new Vector2(r.transform.position.x + roomBounds.extents.x + 0.5f, r.transform.position.y + roomBounds.extents.y + 0.5f);
        topRightCorner.transform.localScale = new Vector3(-1 / r.transform.localScale.x, 1 / r.transform.localScale.y, 1);
       
        bottomLeftCorner = (GameObject)PrefabUtility.InstantiatePrefab(wallPrefab);
        bottomLeftCorner.GetComponent<SpriteRenderer>().sprite = wallEndSprite;
		bottomLeftCorner.transform.GetChild(0).GetComponent<SpriteRenderer>().sprite = consoleCornerSprite;
        bottomLeftCorner.name = "Wall Bottom-Left Corner";
        bottomLeftCorner.transform.SetParent(wallsParent.transform);
        bottomLeftCorner.transform.position = new Vector2(r.transform.position.x - roomBounds.extents.x - 0.5f, r.transform.position.y - roomBounds.extents.y - 0.5f);
        bottomLeftCorner.transform.localScale = new Vector3(1 / r.transform.localScale.x, -1 / r.transform.localScale.y, 1);
        
        bottomRightCorner = (GameObject)PrefabUtility.InstantiatePrefab(wallPrefab);
        bottomRightCorner.GetComponent<SpriteRenderer>().sprite = wallEndSprite;
		bottomRightCorner.transform.GetChild(0).GetComponent<SpriteRenderer>().sprite = consoleCornerSprite;
		bottomRightCorner.name = "Wall Bottom-Right Corner";
        bottomRightCorner.transform.SetParent(wallsParent.transform);
        bottomRightCorner.transform.position = new Vector2(r.transform.position.x + roomBounds.extents.x + 0.5f, r.transform.position.y - roomBounds.extents.y - 0.5f);
        bottomRightCorner.transform.localScale = new Vector3(-1 / r.transform.localScale.x, -1 / r.transform.localScale.y, 1);       

        //CREATE WALLS

        //Top Wall
        //Build wall if there is no aligned room selected or if room alignment is not bottom
        if (!roomToAlignTo ||  (roomToAlignTo && toolbarAlignToRoom !=1))
        {
            //Get walls on top and order by position
            GameObject[] orderedGameObjects = new GameObject[1];
            orderedGameObjects[0] = topLeftCorner;
            int objArrayPos = 1;

            if (doors.Count > 0)
            {
                //if door is on top wall add to array
                foreach (GameObject door in doors)
                {
                    if (door.transform.position.y > roomBounds.max.y)
                    {
                        System.Array.Resize(ref orderedGameObjects, orderedGameObjects.Length + 1);
                        orderedGameObjects[objArrayPos] = door;
                        objArrayPos++;
                    }
                }
            }

            System.Array.Resize(ref orderedGameObjects, orderedGameObjects.Length + 1);
            orderedGameObjects[objArrayPos] = topRightCorner;

            // Ordered from left to right
            orderedGameObjects = orderedGameObjects.OrderBy(go => go.transform.position.x).ToArray();

            if (debugWalls)
            {
                Debug.Log("Objects ordered from bottom to top");
                foreach (GameObject orderedObject in orderedGameObjects)
                    Debug.Log(orderedObject);
            }

            // Create walls in between doors and corners
            for (int i = 0; i < orderedGameObjects.Length - 1; i++)
            {
                float objAPosX = orderedGameObjects[i].GetComponent<Collider2D>().bounds.max.x;
                float objBPosX = orderedGameObjects[i + 1].GetComponent<Collider2D>().bounds.min.x;
//.........这里部分代码省略.........
开发者ID:NoManAlone,项目名称:No-Man-Alone-Vertical-Slice---Scripts,代码行数:101,代码来源:LevelBuilder.cs

示例3: BuildPlatformMidSections

    //Build Mid Sections
    void BuildPlatformMidSections(GameObject platformParent)
    {
        if (orientation == 1)
            platformParent.transform.Rotate(0, 0, 90);

        GameObject platformMidSections = new GameObject("Platform Mid Sections");
        platformMidSections.transform.SetParent(platformParent.transform);
        platformMidSections.transform.localPosition = new Vector3(0, 0, 0);

        // Create Ordered Array
        GameObject[] orderedObjects = new GameObject[0];
        int objArrayPos = 0;

        foreach(Transform child in platformParent.transform)
        {
            if (child.gameObject.tag == "Platform")
            {
                System.Array.Resize(ref orderedObjects, orderedObjects.Length + 1);
                orderedObjects[objArrayPos] = child.gameObject;
                objArrayPos++;
            }
        }

        if (platformParent.transform.FindChild("Doors"))
        {
            foreach (Transform child in platformParent.transform.FindChild("Doors"))
            {
                if (child.gameObject.tag == "Door")
                {
                    System.Array.Resize(ref orderedObjects, orderedObjects.Length + 1);
                    orderedObjects[objArrayPos] = child.gameObject;
                    objArrayPos++;
                }
            }
        }

        //Sort Array
        orderedObjects = orderedObjects.OrderBy(go => go.transform.position.x).ToArray();

        //Create platforms in between doors and ends
        for (int i = 0; i < orderedObjects.Length - 1; i++)
        {
            float objAPosX, objBPosX;

            if (orderedObjects[i].GetComponent<Collider2D>())
                objAPosX = orderedObjects[i].GetComponent<Collider2D>().bounds.max.x;

            else
                objAPosX = orderedObjects[i].transform.position.x;

            if (orderedObjects[i + 1].GetComponent<Collider2D>())
                objBPosX = orderedObjects[i + 1].GetComponent<Collider2D>().bounds.min.x;

            else
                objBPosX = orderedObjects[i + 1].transform.position.x;

            float distance = objBPosX - objAPosX;
            float midPoint = objAPosX + distance * 0.5f;

            //If there is space between doors or corners
            Object platformPrefab;

            if (distance > 0)
            {
                if(orientation == 0)
                    platformPrefab = Resources.Load("PlatformH");

                else
                    platformPrefab = Resources.Load("PlatformV");


                GameObject platform = (GameObject)PrefabUtility.InstantiatePrefab(platformPrefab);
                platform.name = "PlatformMid " + (i + 1);
                platform.transform.SetParent(platformMidSections.transform);
                platform.transform.position = new Vector2(midPoint, orderedObjects[i].transform.position.y);
                platform.transform.localScale = new Vector3(distance, 1, 1);
            }
        }

        if (orientation == 1)
            platformParent.transform.Rotate(0, 0, -90);
    }
开发者ID:NoManAlone,项目名称:No-Man-Alone-Vertical-Slice---Scripts,代码行数:83,代码来源:PlatformBuilder.cs

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