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


C# GameObject.Translate方法代码示例

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


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

示例1: BoardHolderInit

 void BoardHolderInit()
 {
     Transform board_holder = holders[(int)(holderID.BOARD)];
     if (board_holder == null)
     {
         board_holder = new GameObject(holderNames[(int)(holderID.BOARD)]).transform;
         board_holder.localScale += new Vector3(1.0f / SQUARESIZE_PER_UNIT - 1.0f,
             1.0f / SQUARESIZE_PER_UNIT - 1.0f,
             0.0f);
         board_holder.Translate(new Vector3(
             (-rows / 2.0f + 0.5f) * SQUARESIZE_PER_UNIT,
             (-columns / 2.0f + 0.5f) * SQUARESIZE_PER_UNIT,
             0
         ));
         holders[(int)(holderID.BOARD)] = board_holder;
     }
     for (int i = (int)holderID.START; i <= (int)holderID.END; i++)
     {
         // do not add new board holder into the board holder
         if (i == (int)holderID.BOARD)
             continue;
         
         if (holders[i] == null)
         {
             holders[i] = new GameObject(holderNames[i]).transform;
             holders[i].SetParent(board_holder);
         }
     }
 }
开发者ID:sysexits,项目名称:2DRoguelike,代码行数:29,代码来源:BoardManager.cs

示例2: generateMapAndPlayer


//.........这里部分代码省略.........
                }
                else if (y == eastGate - 1)
                {
                    instantiateAndAdd(cliffTiles[14], columns, y, holders[(int)(holderID.CLIFF)]);
                    instantiateAndAdd(cliffTiles[Random.Range(0, 2)], columns + 1, y, holders[(int)(holderID.CLIFF)]);
                }
                else if (Mathf.Abs(y - (eastGate + 1)) >= 3)
                {
                    instantiateAndAdd(cliffTiles[12 + Random.Range(0, 2)], columns, y, holders[(int)(holderID.CLIFF)]);
                    rockTilePositions.Add(new Vector3(columns + 1, y, 0));
                }
            }

            // random generation of rock tiles
            foreach (Vector3 pos in rockTilePositions)
            {
                instantiateAndAdd(
                    rockFloorTiles[Random.Range(0, rockFloorTiles.Length)],
                    Mathf.FloorToInt(pos.x),
                    Mathf.FloorToInt(pos.y),
                    holders[(int)(holderID.CLIFF)]
                );
            }

            // box colliders for the borders
            for (int x = 0; x < columns; x++)
            {
                for (int y = 0; y < rows; y++)
                {
                    if (arrayMap[x + (rows - 1 - y) * columns] == "#")
                    {
                        Transform border = new GameObject("collider").transform;
                        border.SetParent(holders[(int)(holderID.BOARD_COLLIDER)]);
                        border.Translate(x, y, 0);
                        border.gameObject.layer = LayerMask.NameToLayer("Object");

                        border.gameObject.AddComponent<BoxCollider2D>();
                    }
                }
            }
            if (northGate >= 1 && northGate < columns - 1)
            {
                for (int x = northGate-1; x <= northGate+1; x += 2)
                {
                    Transform border = new GameObject("collider").transform;
                    border.SetParent(holders[(int)(holderID.BOARD_COLLIDER)]);
                    border.Translate(x, rows + 1f, 0);
                    border.localScale += new Vector3(0, 2.0f, 0);
                    border.gameObject.layer = LayerMask.NameToLayer("Object");

                    border.gameObject.AddComponent<BoxCollider2D>();
                }
            }
            if (southGate >= 1 && southGate < columns - 1)
            {
                for (int x = southGate - 1; x <= southGate + 1; x += 2)
                {
                    Transform border = new GameObject("collider").transform;
                    border.SetParent(holders[(int)(holderID.BOARD_COLLIDER)]);
                    border.Translate(x, -2f, 0);
                    border.localScale += new Vector3(0, 2.0f, 0);
                    border.gameObject.layer = LayerMask.NameToLayer("Object");

                    border.gameObject.AddComponent<BoxCollider2D>();
                }
            }
开发者ID:sysexits,项目名称:2DRoguelike,代码行数:67,代码来源:BoardManager.cs

示例3: Start

        /// <summary>
        /// Start everything up and get it configured.
        /// </summary>
        public void Start()
        {
            try
            {
                rpmComp = RasterPropMonitorComputer.Instantiate(internalProp, true);

                Transform textObjTransform = internalProp.FindModelTransform(transformName);
                Vector3 localScale = internalProp.transform.localScale;

                Transform offsetTransform = new GameObject().transform;
                offsetTransform.gameObject.name = "JSILabel-" + this.internalProp.propID + "-" + this.GetHashCode().ToString();
                offsetTransform.gameObject.layer = textObjTransform.gameObject.layer;
                offsetTransform.SetParent(textObjTransform, false);
                offsetTransform.Translate(transformOffset.x * localScale.x, transformOffset.y * localScale.y, 0.0f);

                textObj = offsetTransform.gameObject.AddComponent<JSITextMesh>();

                font = JUtil.LoadFont(fontName, fontQuality);

                textObj.font = font;
                //textObj.fontSize = fontQuality; // This doesn't work with Unity-embedded fonts
                textObj.fontSize = font.fontSize;

                if (!string.IsNullOrEmpty(anchor))
                {
                    if (anchor == TextAnchor.LowerCenter.ToString())
                    {
                        textObj.anchor = TextAnchor.LowerCenter;
                    }
                    else if (anchor == TextAnchor.LowerLeft.ToString())
                    {
                        textObj.anchor = TextAnchor.LowerLeft;
                    }
                    else if (anchor == TextAnchor.LowerRight.ToString())
                    {
                        textObj.anchor = TextAnchor.LowerRight;
                    }
                    else if (anchor == TextAnchor.MiddleCenter.ToString())
                    {
                        textObj.anchor = TextAnchor.MiddleCenter;
                    }
                    else if (anchor == TextAnchor.MiddleLeft.ToString())
                    {
                        textObj.anchor = TextAnchor.MiddleLeft;
                    }
                    else if (anchor == TextAnchor.MiddleRight.ToString())
                    {
                        textObj.anchor = TextAnchor.MiddleRight;
                    }
                    else if (anchor == TextAnchor.UpperCenter.ToString())
                    {
                        textObj.anchor = TextAnchor.UpperCenter;
                    }
                    else if (anchor == TextAnchor.UpperLeft.ToString())
                    {
                        textObj.anchor = TextAnchor.UpperLeft;
                    }
                    else if (anchor == TextAnchor.UpperRight.ToString())
                    {
                        textObj.anchor = TextAnchor.UpperRight;
                    }
                    else
                    {
                        JUtil.LogErrorMessage(this, "Unrecognized anchor '{0}' in config for {1} ({2})", anchor, internalProp.propID, internalProp.propName);
                    }
                }

                if (!string.IsNullOrEmpty(alignment))
                {
                    if (alignment == TextAlignment.Center.ToString())
                    {
                        textObj.alignment = TextAlignment.Center;
                    }
                    else if (alignment == TextAlignment.Left.ToString())
                    {
                        textObj.alignment = TextAlignment.Left;
                    }
                    else if (alignment == TextAlignment.Right.ToString())
                    {
                        textObj.alignment = TextAlignment.Right;
                    }
                    else
                    {
                        JUtil.LogErrorMessage(this, "Unrecognized alignment '{0}' in config for {1} ({2})", alignment, internalProp.propID, internalProp.propName);
                    }
                }

                float sizeScalar = 32.0f / (float)font.fontSize;
                textObj.characterSize = fontSize * 0.00005f * sizeScalar;
                textObj.lineSpacing = textObj.lineSpacing * lineSpacing;

                // "Normal" mode
                if (string.IsNullOrEmpty(switchTransform))
                {
                    // Force oneshot if there's no variables:
                    oneshot |= !labelText.Contains("$&$");
                    string sourceString = labelText.UnMangleConfigText();
//.........这里部分代码省略.........
开发者ID:Kerbas-ad-astra,项目名称:RasterPropMonitor,代码行数:101,代码来源:JSILabel.cs


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