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


C# GameObject.SetParent方法代码示例

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


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

示例1: Awake

    void Awake()
    {
        lightMesh = new Mesh();
        lightMesh.name = string.Format("Light Mesh ({0})", name);
        lightMesh.MarkDynamic();

        meshFilter = GetComponent<MeshFilter>();
        meshFilter.mesh = lightMesh;

        meshRenderer = GetComponent<MeshRenderer>();
        meshRenderer.sharedMaterial = lightMaterial;

        var container = transform.Find("LightMesh");
        if (!container)
        {
            container = new GameObject("LightMesh").transform;
            container.SetParent(transform, true);
            container.localPosition = Vector3.zero;
            container.gameObject.layer = gameObject.layer;
        }

        lightMeshCollider = container.GetComponent<PolygonCollider2D>();
        if (lightMeshCollider == null)
        {
            lightMeshCollider = container.gameObject.AddComponent<PolygonCollider2D>();
        }

        lightMeshCollider.isTrigger = true;

        vertices = new List<Vertex>();

        UpdateLightFX();
    }
开发者ID:igm-capstone,项目名称:proto-03-lights,代码行数:33,代码来源:Light2D.cs

示例2: GetOrCreateChild

 static Transform GetOrCreateChild(Transform root, string name)
 {
     var child = root.Find(name);
     if (!child) {
         child = new GameObject(name).transform;
         child.SetParent(root, false);
     }
     return child;
 }
开发者ID:rcd229,项目名称:Crystallize2D,代码行数:9,代码来源:TransformPath.cs

示例3: LinkFolder

 Transform LinkFolder(NodeInstance node)
 {
     var linksFolder = node.transform.Find("Links");
     if (linksFolder == null) {
         linksFolder = new GameObject("Links").transform;
         linksFolder.SetParent(node.transform);
         linksFolder.transform.Reset();
     }
     return linksFolder;
 }
开发者ID:craus,项目名称:UnityTest,代码行数:10,代码来源:SpaceGraph+-+editor+features.cs

示例4: GetNested

    Transform GetNested(string name)
    {
        if (nestedViewContainers.ContainsKey(name))
        {
            return nestedViewContainers[name];
        }

        var nestedView = new GameObject(name).transform;
        nestedView.SetParent(viewContainer, false);
        nestedViewContainers[name] = nestedView;
        return nestedView;
    }
开发者ID:NotYours180,项目名称:entitas-2d-roguelike,代码行数:12,代码来源:AddViewSystem.cs

示例5: Start

	// BIG TODO: change the hierarchy to a messaging system
	void Start() {
		// TODO: make this read from a file instead of hardcoded ofc lol
		foodWeb = new RungeEcosystem();
		foodWeb.AddSpecies("grass",       -0.03f,  1.0f,  0f);
		foodWeb.AddSpecies("oak tree",    -0.03f,  0.8f, 10f);
		foodWeb.AddSpecies("berries",     -0.03f,  0.6f, 10f);
		foodWeb.AddSpecies("rabbit",      -0.01f, -0.1f,  0f);
		foodWeb.AddSpecies("caterpillar", -0.01f, -0.2f, 10f);
		foodWeb.AddSpecies("squirrel",    -0.01f, -0.2f, 10f);
		foodWeb.AddSpecies("fox",         -0.01f, -0.2f,  0f);
		
		foodWeb.AddInteraction("rabbit",      "grass",       0.05f, 0.8f);
		foodWeb.AddInteraction("rabbit",      "berries",     0.02f, 0.8f);
		foodWeb.AddInteraction("squirrel",    "berries",     0.02f, 0.8f);
		foodWeb.AddInteraction("squirrel",    "oak tree",    0.04f, 0.8f);
		foodWeb.AddInteraction("caterpillar", "oak tree",    0.04f, 0.8f);
		foodWeb.AddInteraction("fox",         "berries",     0.02f, 0.5f);
		foodWeb.AddInteraction("fox",         "squirrel",    0.02f, 0.6f);
		foodWeb.AddInteraction("fox",         "rabbit",      0.05f, 0.6f);
		foodWeb.AddInteraction("fox",         "caterpillar", 0.01f, 0.5f);
		// TODO: add humans hunting as the interesting bit of this ecosystem

		Transform iconTransform = new GameObject("Icon Manager").transform; // for organisation
		iconTransform.SetParent(transform);
		iconWeb = new IconManager(iconTransform, transferPrefab, interactionPrefab);
		iconWeb.AddSpecies("grass",       'p',    0f,  0f,  100f, 1f, iconPrefab, pictures[0], Color.green);
		iconWeb.AddSpecies("oak tree",    'p',    0f, 10f,  100f, 1f, iconPrefab, pictures[1], Color.black);
		iconWeb.AddSpecies("berries",     'p',    0f, 10f,  100f, 1f, iconPrefab, pictures[2], Color.magenta);
		iconWeb.AddSpecies("rabbit",      'h',    1f,  0f,  100f, 1f, iconPrefab, pictures[3], Color.grey);
		iconWeb.AddSpecies("caterpillar", 'h', 0.03f, 10f,  100f, 1f, iconPrefab, pictures[4], Color.yellow);
		iconWeb.AddSpecies("squirrel",    'h',  0.5f, 10f,  100f, 1f, iconPrefab, pictures[5], Color.white);
		iconWeb.AddSpecies("fox",         'o',    5f,  0f,  100f, 1f, iconPrefab, pictures[6], Color.red);

		speciesNames = new List<string>();
		speciesNames.Add("grass");
		speciesNames.Add("oak tree");
		speciesNames.Add("berries");
		speciesNames.Add("rabbit");
		speciesNames.Add("caterpillar");
		speciesNames.Add("squirrel");
		speciesNames.Add("fox");
		foreach (string species in speciesNames) SetIconInteractionSprings(species);
		
		CreateGraph();
		InvokeRepeating("UpdateIconPopulations", 0.7f, 2f);

		screenWidth = 2f * Camera.main.orthographicSize * Screen.width / Screen.height;
		screenHeight = screenWidth / Screen.width * Screen.height;

		gui = transform.Find("GUI").GetComponent<GUI>();
		gui.Init(screenWidth, screenHeight);
	}
开发者ID:jxz12,项目名称:ecosystems_game,代码行数:53,代码来源:GameManager.cs

示例6: CreateSpawner

    void CreateSpawner(int index) {
        Transform rotater = new GameObject("Rotater").transform;
        rotater.SetParent(transform, false);
        rotater.localRotation =
            Quaternion.Euler(0f, index * (360f / numberOfSpawners), 0f);

        StuffSpawner spawner = Instantiate<StuffSpawner>(spawnerPrefab);
        spawner.transform.SetParent(rotater, false);
        spawner.transform.localPosition = new Vector3(0f, 0f, radius);
        spawner.transform.localRotation = Quaternion.Euler(tiltAngle, 0f, 0f);

        spawner.stuffMaterial = stuffMaterials[index % stuffMaterials.Length];
    }
开发者ID:jtuttle,项目名称:tutorials,代码行数:13,代码来源:StuffSpawnerRing.cs

示例7: GetNested

    static Transform GetNested(string name,
                               Transform viewContainer,
                               IDictionary<string, Transform> nestedViewContainer)
    {
        if (nestedViewContainer.ContainsKey(name))
        {
            return nestedViewContainer[name];
        }

        var nestedView = new GameObject(name).transform;
        nestedView.SetParent(viewContainer, false);
        nestedViewContainer[name] = nestedView;
        return nestedView;
    }
开发者ID:JamesMcMahon,项目名称:entitas-2d-roguelike,代码行数:14,代码来源:AddViewSystem.cs

示例8: CreateJoystick

 public static void CreateJoystick()
 {
     GameObject joystick = new GameObject("Joystick", typeof(Image), typeof(EasyJoystick) , typeof(CanvasGroup));
     joystick.GetComponent<Image>().sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(kKnobPath);
     joystick.GetComponent<RectTransform> ().sizeDelta = Vector2.one * 150;
     joystick.layer = LayerMask.NameToLayer(kUILayerName);
     RectTransform stick = new GameObject("Stick", typeof(Image)).GetComponent<RectTransform>();
     stick.gameObject.GetComponent<Image>().sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(kKnobPath);
     stick.sizeDelta = Vector2.one * 60;
     stick.SetParent (joystick.transform, false);
     stick.gameObject.layer = LayerMask.NameToLayer(kUILayerName);
     joystick.GetComponent<EasyJoystick> ().stick = stick;
     SetCanvas (joystick.transform);
     Debug.Log("Joystick has been created");
     Selection.activeGameObject = joystick;
 }
开发者ID:youti174,项目名称:Island-Village,代码行数:16,代码来源:CreateJoystick.cs

示例9: InstantiateBlock

	/// <summary>
	/// Spawn the GameObject of the blocks prefab
	/// </summary>
	/// <param name="parent">Parent of GameObject</param>
	/// <param name="pos">Local position to spawn at</param>
	public override void InstantiateBlock(Transform parent, Vector3 pos, int x, int y, int z, Block[,,] blocks) {
		//Create parent gameobject to store position of block
		Transform posOffset = new GameObject(GetName()).transform;
		posOffset.SetParent(parent);
		posOffset.localPosition = pos + new Vector3(0f, -0.5f, 0f);

		//Instantiate block
		gameObject = Object.Instantiate(GetPrefab()) as GameObject;
		transform = gameObject.transform;

		//Set parent
		transform.SetParent(posOffset);
		transform.localPosition = Vector3.zero;

		//Create spawnable controller
		SpawnableController controller = gameObject.AddComponent<SpawnableController>();
		controller.SetBlock(this);

		Spawn();
	}
开发者ID:platformed,项目名称:Platformed-Game,代码行数:25,代码来源:SpawnableBlock.cs

示例10: Start

 // Use this for initialization
 void Start () {
     m_animator = GetComponent<Animator>();
     GameObject baggage_obj = null;
     if (m_Baggages.Length > 0) {
         var i = Random.Range(0, m_Baggages.Length + 1);
         if (i < m_Baggages.Length) {
             baggage_obj = GameObject.Instantiate(m_Baggages[i]);
             var baggage = baggage_obj.transform;
             var seat = transform.Find(m_BaggageOriginName);
             var joint = new GameObject("Joint").transform;
             joint.localPosition = new Vector3(
                 m_BaggageOrigin.x / seat.localScale.x,
                 m_BaggageOrigin.z / seat.localScale.z,
                 m_BaggageOrigin.y / seat.localScale.y);
             joint.localScale = new Vector3(
                 1.0f / seat.localScale.x,
                 1.0f / seat.localScale.z,
                 1.0f / seat.localScale.y);
             joint.SetParent(seat, false);
             baggage.SetParent(joint, false);
         }
     }
 }
开发者ID:kazusanto,项目名称:unity3d-vietnam-traffic-game,代码行数:24,代码来源:CabController.cs

示例11: BuildActionProjectile

        public static GameObject BuildActionProjectile(
            Game1 game,
            GameObject parent,
            ActionInfo actInfo,
            Vector2 position,
            Vector2 velocity,
            int lifetime,
            List<Shape> boundingBoxes)
        {
            GameObject entity = new GameObject(game);
            entity.SetParent(parent);

            Transform2DComponent transformComponent = new Transform2DComponent(
                entity,
                position,
                0.0f,
                Vector2.One);

            BoundingBoxComponent bbComponent = new BoundingBoxComponent(entity, boundingBoxes, true);
            CurrentActionComponent caComponent = new CurrentActionComponent(
                entity,
                new ActionComponent(DirectionalAction.Left, SecondaryAction.Stand, PrimaryAction.None),
                new Dictionary<ActionDefinition, ActionInfo>());
            LifetimeComponent lifetimeComponent = new LifetimeComponent(entity, lifetime);
            IsActionComponent isActionComponent = new IsActionComponent(entity, actInfo);
            MotionPropertiesComponent motionComponent = new MotionPropertiesComponent(entity, 1.0f);
            motionComponent.SetVelocity(velocity);

            entity.AddComponent(transformComponent);
            entity.AddComponent(bbComponent);
            entity.AddComponent(caComponent);
            entity.AddComponent(motionComponent);
            entity.AddComponent(lifetimeComponent);
            entity.AddComponent(isActionComponent);

            return entity;
        }
开发者ID:patpaquette,项目名称:SSB-clone,代码行数:37,代码来源:DynamicEntityFactory.cs

示例12: CreatePoolContainers

 /// <summary>
 /// This method creates the containers for the pooling system to use.
 /// </summary>
 private void CreatePoolContainers()
 {
     SoundsPool = new GameObject().transform;
     SoundsPool.name = "SoundsPool";
     SoundsPool.SetParent(transform);
     SoundsPlaying = new GameObject().transform;
     SoundsPlaying.name = "SoundsPlaying";
     SoundsPlaying.SetParent(transform);
 }
开发者ID:gcoope,项目名称:HeroesAndVillains,代码行数:12,代码来源:SoundManager.cs

示例13: Reset

    private void Reset()
    {
        if (_waveContainer == null)
        {
            _waveContainer = new GameObject("WaveContainer").transform;
            _waveContainer.SetParent(transform);
            _waveContainer.localPosition = Vector3.zero;

            // Add an initial wave
            var wave = new GameObject("Wave").transform;
            wave.SetParent(_waveContainer);
            wave.localPosition = Vector3.zero;
            wave.gameObject.AddComponent<WaveProperty>();
        }
    }
开发者ID:Barabicus,项目名称:ATOMFIACHRA,代码行数:15,代码来源:EntityWaveObjective.cs

示例14: SetUpSpawners

    private void SetUpSpawners(Level level)
    {
        Debug.Log("Set Up Spawners");
        Transform levelSpawnersTransform = new GameObject("Level " + level.levelName + " Spawners").transform;
        levelSpawnersTransform.SetParent(spawnerParent);

        for (int i = 0; i < level.spawners.Count; i++)
        {
            Spawner spawner = Instantiate(level.spawners[i]) as Spawner;
            Debug.Log(spawner + " created");

            spawner.transform.SetParent(levelSpawnersTransform);

            createdSpawners.Add(spawner);
        }

        SpawnManager.Instance.SetUpLevel(level.initialSpawnDirection);
    }
开发者ID:VCRhythm,项目名称:hotfrog,代码行数:18,代码来源:LevelManager.cs

示例15: LocateBackLink

 void LocateBackLink(LinkScript link, bool allowCreate = false)
 {
     NodeInstance from = link.GetComponentInParent<NodeInstance>();
     NodeInstance to = link.to;
     link.backLink = to.GetComponentsInChildren<LinkScript>().ToList().FirstOrDefault(other => {
         if (other.to != from) {
             return false;
         }
         var testObject = new GameObject("TestObject").transform;
         var otherParent = other.transform.parent;
         testObject.SetParent(to.transform, worldPositionStays: false);
         other.transform.SetParent(testObject, worldPositionStays: true);
         testObject.SetParent(link.transform, worldPositionStays: false);
         var result = Extensions.Close(other.transform, from.transform);
         other.transform.SetParent(otherParent, worldPositionStays: false);
         DestroyImmediate(testObject.gameObject);
         return result;
     });
     if (link.backLink == null) {
         if (!allowCreate) {
             Debug.LogError(string.Format("No backlink detected: {0} {1}", from.name, link.name));
         } else {
             Debug.LogFormat(string.Format("No backlink detected: {0} {1}", from.name, link.name));
             var backlinkObject = new GameObject(GenerateLinkName(link.to, from) + " (backlink)");
             var backlink = backlinkObject.AddComponent<LinkScript>();
             backlink.to = from;
             backlinkObject.transform.SetParent(from.transform);
             backlinkObject.transform.Reset();
             backlinkObject.transform.SetParent(link.transform, worldPositionStays: true);
             var linkFolder = LinkFolder(link.to);
             backlinkObject.transform.SetParent(linkFolder, worldPositionStays: false);
             link.backLink = backlink;
             Debug.LogFormat("Backlink created: {0} {1} - {2} {3}", from.name, link.name, to.name, link.backLink.name);
             backlink.backLink = link;
             Debug.LogFormat("Backlink set: {0} {1} - {2} {3}", to.name, link.backLink.name, from.name, link.name);
         }
     } else {
         Debug.LogFormat("Backlink set: {0} {1} - {2} {3}", from.name, link.name, to.name, link.backLink.name);
     }
 }
开发者ID:craus,项目名称:UnityTest,代码行数:40,代码来源:SpaceGraph+-+editor+features.cs


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