Unity game framework to build 2019 (XIX) GameObject show, hide, simplified & Chapter Summary and Quick Review

We are doing the project, often write the code below.

gameObject.SetActive(true);
gameObject.SetActive(false);

active activation means is, in fact, is more appropriate.

But it was transferred over from other platforms, initially wanted to find the Hide / Show GameObject time a little less suited.

Like Cocos2d display is Visible (visible), while the iOS is Hidden (hidden), Quick-Cocos2d-x is a Show / Hide and so on, with the exception of Unity is called active, speaking for the author new to Unity, In fact, very difficult to understand.

So naturally start to gameObject.active, the method of packaging a bit Show and Hide.

Named using the Show and Hide.

code show as below:

#if UNITY_EDITOR
using UnityEditor;
#endif

using UnityEngine;

namespace QFramework
{
	public class GameObejctActiveImprovements 
	{
#if UNITY_EDITOR
		[MenuItem("QFramework/13.GameObejct 的显示、隐藏简化")]
#endif
		private static void MenuClicked()
		{
			var gameObject = new GameObject();

			Hide(gameObject);
		}

		public static void Show(GameObject gameObj)
		{
			gameObj.SetActive(true);
		}

		public static void Hide(GameObject gameObj)
		{
			gameObj.SetActive(false);
		}
	}
}

After executing this code, you create a hidden GameObject in the scene, as shown in FIG.
006tNc79gy1fzdi32usd7j30i00860t6.jpg
OK, today's content on these.

summary

Today's sample code, it seems very simple, in fact, to build a library of more advanced in terms of content, and why do you say it?

In fact, today is for us to do a little coding experience optimization, coding and this experience is the author's own experience, but that it is very sensitive to the code or coding experience a lot of people would notice such a little subtle problem. But because the code itself is relatively simple, so the initial library or build a framework more suitable for everyone practice.

Chapter Summary and Quick Review

006tNc79gy1fzdi3hfk9tj311l0e378a.jpg

Address reprint please specify: sandals notes: liangxiegame.com

more content

  • QFramework Address: https://github.com/liangxiegame/QFramework

  • QQ exchange group: 623 597 263

  • Unity advanced small class :

    • The main training content:
      • Framework set up training (first year)
      • Case study along with Shader (first year)
      • Sideline incubation (second year, third year)
    • Specific details of equity, in the form of lectures, etc. Please see the "small class Product Manual" : HTTPS: //liangxiegame.com/master/intro
  • No public concern: liangxiegame obtaining a first time update notifications, and more free content.

Published 62 original articles · won praise 101 · views 50000 +

Guess you like

Origin blog.csdn.net/u010125551/article/details/105332114