本文整理汇总了C#中GameObject.SetActive方法的典型用法代码示例。如果您正苦于以下问题:C# GameObject.SetActive方法的具体用法?C# GameObject.SetActive怎么用?C# GameObject.SetActive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameObject
的用法示例。
在下文中一共展示了GameObject.SetActive方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
void Start()
{
this.playersNumber = (int) Mathf.Clamp((float)this.playersNumber, 1F, 4F);
for (int i = 0; i < this.playersNumber; i++) {
GameObject player = new GameObject("Player_" + (i + 1));
player.SetActive(false);
player.transform.localScale = new Vector3(2F, 2F, 1F);
InputHandler inputHandler = player.AddComponent<InputHandler>();
inputHandler.playerNumber = i + 1;
PlayerSelection selection = player.AddComponent<PlayerSelection>();
selection.character = this.character;
player.SetActive(true);
}
}
示例2: Start
void Start()
{
instance = this;
messageHandler = GameMessageHandler.Instance;
messageHandler.Register(this, "GmStats");
InvokeRepeating("SendRequest", 1f, 5f);
container = transform.Find("stats").gameObject;
template = transform.Find("template").gameObject;
template.SetActive(false);
canvas = gameObject.GetComponent<Canvas>() as Canvas;
canvas.enabled = false;
}
示例3: Start
void Start()
{
if (!GamePlayer.IsNetworked()) {
Destroy(this.gameObject);
return;
}
messageHandler = GameMessageHandler.instance;
messageHandler.Register(this, "GmStats");
InvokeRepeating("SendRequest", 1f, 5f);
container = transform.Find("stats").gameObject;
template = transform.Find("template").gameObject;
template.SetActive(false);
canvas = gameObject.GetComponent<Canvas>() as Canvas;
canvas.enabled = false;
}
示例4: OnLevelLoaded
private void OnLevelLoaded(GameScenes scene)
{
if (Settings.AllowEditors)
{
foreach (var editor in editorTypes.Where(e => e.Value.Contains(scene)))
{
try
{
GameObject obj = new GameObject (editor.Key.Name);
obj.AddComponent (editor.Key);
obj.SetActive (true);
Utils.Log ("IngameEditor " + editor.Key.Name + " created");
}
catch(Exception e)
{
Utils.LogError ("Failed to load editor: " + editor.Key.Name);
Debug.LogException (e);
}
}
}
}
示例5: AddMeshComponent
private CombinedMeshComponent AddMeshComponent()
{
GameObject gobj = new GameObject(
"LWF/" + data.name + "/Mesh/" + meshComponents.Count);
gobj.SetActive(false);
gobj.transform.parent = gameObject.transform;
gobj.transform.position = gameObject.transform.position;
CombinedMeshComponent meshComponent =
gobj.AddComponent<CombinedMeshComponent>();
meshComponent.Init(this);
meshComponents.Add(meshComponent);
return meshComponent;
}
示例6: AddMeshComponent
private CombinedMeshComponent AddMeshComponent()
{
GameObject gobj = new GameObject(
"LWF/" + data.name + "/Mesh/" + meshComponents.Count);
gobj.SetActive(false);
gobj.transform.parent = gameObject.transform;
gobj.transform.localPosition = Vector3.zero;
gobj.transform.localScale = Vector3.one;
gobj.transform.localRotation = Quaternion.identity;
CombinedMeshComponent meshComponent =
gobj.AddComponent<CombinedMeshComponent>();
meshComponent.Init(this);
meshComponents.Add(meshComponent);
return meshComponent;
}
示例7: Start
void Start()
{
gameObject.GetComponent<Canvas>().enabled = false;
template = transform.Find("panel").Find("character").gameObject;
template.SetActive(false);
}
示例8: SetupFootprintPrefab
private static void SetupFootprintPrefab()
{
footprintPrefab = new GameObject ("KerbalEVAFootprint");
footprintPrefab.layer = GameLayers.LocalSpace;
footprintPrefab.SetActive (false);
var mf = footprintPrefab.AddComponent<MeshFilter> ();
var mr = footprintPrefab.AddComponent<MeshRenderer> ();
mf.mesh = new Quad (0.15f, 0.3f, true);
var material = new Material (Shaders.Footprint);
var footprintMask = new Texture2D (4, 4);
footprintMask.LoadImage (Textures.KerbalEVAFootprintMask);
material.SetTexture ("_MainTex", footprintMask);
material.SetFloat ("_Opacity", 0.8f);
material.SetColor ("_Color", Color.black);
mr.material = material;
mr.castShadows = false;
footprintPrefab.AddComponent<KerbalEVAFootprint> ();
Utils.Log ("Footprint prefab created");
}
示例9: Initialize
private bool Initialize()
{
bool success = true;
try
{
_rectTransform = GetComponent<RectTransform>();
_inputRT = _rectTransform.FindChild("InputField").GetComponent<RectTransform>();
_mainInput = _inputRT.GetComponent<InputField>();
_overlayRT = _rectTransform.FindChild("Overlay").GetComponent<RectTransform>();
_overlayRT.gameObject.SetActive(false);
_scrollPanelRT = _overlayRT.FindChild("ScrollPanel").GetComponent<RectTransform>();
_scrollBarRT = _scrollPanelRT.FindChild("Scrollbar").GetComponent<RectTransform>();
_slidingAreaRT = _scrollBarRT.FindChild("SlidingArea").GetComponent<RectTransform>();
// scrollHandleRT = slidingAreaRT.FindChild("Handle").GetComponent<RectTransform>();
_itemsPanelRT = _scrollPanelRT.FindChild("Items").GetComponent<RectTransform>();
//itemPanelLayout = itemsPanelRT.gameObject.GetComponent<LayoutGroup>();
_canvas = GetComponentInParent<Canvas>();
_canvasRT = _canvas.GetComponent<RectTransform>();
_scrollRect = _scrollPanelRT.GetComponent<ScrollRect>();
_scrollRect.scrollSensitivity = _rectTransform.sizeDelta.y / 2;
_scrollRect.movementType = ScrollRect.MovementType.Clamped;
_scrollRect.content = _itemsPanelRT;
itemTemplate = _rectTransform.FindChild("ItemTemplate").gameObject;
itemTemplate.SetActive(false);
}
catch (System.NullReferenceException ex)
{
Debug.LogException(ex);
Debug.LogError("Something is setup incorrectly with the dropdownlist component causing a Null Refernece Exception");
success = false;
}
panelObjects = new Dictionary<string, GameObject>();
_prunedPanelItems = new List<string>();
_panelItems = AvailableOptions.ToList();
RebuildPanel();
//RedrawPanel(); - causes an initialisation failure in U5
return success;
}
示例10: Initialize
private bool Initialize()
{
bool success = true;
try
{
_rectTransform = GetComponent<RectTransform>();
_mainButton = new DropDownListButton(_rectTransform.FindChild("MainButton").gameObject);
_overlayRT = _rectTransform.FindChild("Overlay").GetComponent<RectTransform>();
_overlayRT.gameObject.SetActive(false);
_scrollPanelRT = _overlayRT.FindChild("ScrollPanel").GetComponent<RectTransform>();
_scrollBarRT = _scrollPanelRT.FindChild("Scrollbar").GetComponent<RectTransform>();
_slidingAreaRT = _scrollBarRT.FindChild("SlidingArea").GetComponent<RectTransform>();
// scrollHandleRT = slidingAreaRT.FindChild("Handle").GetComponent<RectTransform>();
_itemsPanelRT = _scrollPanelRT.FindChild("Items").GetComponent<RectTransform>();
//itemPanelLayout = itemsPanelRT.gameObject.GetComponent<LayoutGroup>();
_canvas = GetComponentInParent<Canvas>();
_canvasRT = _canvas.GetComponent<RectTransform>();
_scrollRect = _scrollPanelRT.GetComponent<ScrollRect>();
_scrollRect.scrollSensitivity = _rectTransform.sizeDelta.y / 2;
_scrollRect.movementType = ScrollRect.MovementType.Clamped;
_scrollRect.content = _itemsPanelRT;
_itemTemplate = _rectTransform.FindChild("ItemTemplate").gameObject;
_itemTemplate.SetActive(false);
}
catch (System.NullReferenceException ex)
{
Debug.LogException(ex);
Debug.LogError("Something is setup incorrectly with the dropdownlist component causing a Null Refernece Exception");
success = false;
}
_panelItems = new List<DropDownListButton>();
RebuildPanel();
RedrawPanel();
return success;
}
示例11: ReconnectPlayerForConnection
/// <summary>
/// <para>This re-establishes a player object with a client that is reconnected. It is similar to NetworkServer.AddPlayerForConnection(). The player game object will become the player object for the new connection.</para>
/// </summary>
/// <param name="newConnection">The connection of the new client.</param>
/// <param name="oldPlayer">The player object.</param>
/// <param name="oldConnectionId">This client's connectionId on the old host.</param>
/// <param name="playerControllerId">The playerControllerId of the player that is rejoining.</param>
/// <returns>
/// <para>True if able to re-add this player.</para>
/// </returns>
public bool ReconnectPlayerForConnection(NetworkConnection newConnection, GameObject oldPlayer, int oldConnectionId, short playerControllerId)
{
if (!NetworkServer.active)
{
if (LogFilter.logError)
Debug.LogError((object) "ReconnectPlayerForConnection must have active server");
return false;
}
if (LogFilter.logDebug)
Debug.Log((object) ("ReconnectPlayerForConnection: oldConnId=" + (object) oldConnectionId + " player=" + (object) oldPlayer + " conn:" + (object) newConnection));
if (!this.m_PendingPlayers.ContainsKey(oldConnectionId))
{
if (LogFilter.logError)
Debug.LogError((object) ("ReconnectPlayerForConnection oldConnId=" + (object) oldConnectionId + " not found."));
return false;
}
oldPlayer.SetActive(true);
NetworkServer.Spawn(oldPlayer);
if (!NetworkServer.AddPlayerForConnection(newConnection, oldPlayer, playerControllerId))
{
if (LogFilter.logError)
Debug.LogError((object) ("ReconnectPlayerForConnection oldConnId=" + (object) oldConnectionId + " AddPlayerForConnection failed."));
return false;
}
if (NetworkServer.localClientActive)
this.SendPeerInfo();
return true;
}
示例12: ReconnectObjectForConnection
/// <summary>
/// <para>This re-establishes a non-player object with client authority with a client that is reconnected. It is similar to NetworkServer.SpawnWithClientAuthority().</para>
/// </summary>
/// <param name="newConnection">The connection of the new client.</param>
/// <param name="oldObject">The object with client authority that is being reconnected.</param>
/// <param name="oldConnectionId">This client's connectionId on the old host.</param>
/// <returns>
/// <para>True if the object was reconnected.</para>
/// </returns>
public bool ReconnectObjectForConnection(NetworkConnection newConnection, GameObject oldObject, int oldConnectionId)
{
if (!NetworkServer.active)
{
if (LogFilter.logError)
Debug.LogError((object) "ReconnectObjectForConnection must have active server");
return false;
}
if (LogFilter.logDebug)
Debug.Log((object) ("ReconnectObjectForConnection: oldConnId=" + (object) oldConnectionId + " obj=" + (object) oldObject + " conn:" + (object) newConnection));
if (!this.m_PendingPlayers.ContainsKey(oldConnectionId))
{
if (LogFilter.logError)
Debug.LogError((object) ("ReconnectObjectForConnection oldConnId=" + (object) oldConnectionId + " not found."));
return false;
}
oldObject.SetActive(true);
oldObject.GetComponent<NetworkIdentity>().SetNetworkInstanceId(new NetworkInstanceId(0U));
if (NetworkServer.SpawnWithClientAuthority(oldObject, newConnection))
return true;
if (LogFilter.logError)
Debug.LogError((object) ("ReconnectObjectForConnection oldConnId=" + (object) oldConnectionId + " SpawnWithClientAuthority failed."));
return false;
}
示例13: ApplySpawnPayload
private static void ApplySpawnPayload(NetworkIdentity uv, Vector3 position, byte[] payload, NetworkInstanceId netId, GameObject newGameObject)
{
if (!uv.gameObject.activeSelf)
uv.gameObject.SetActive(true);
uv.transform.position = position;
if (payload != null && payload.Length > 0)
{
NetworkReader reader = new NetworkReader(payload);
uv.OnUpdateVars(reader, true);
}
if ((Object) newGameObject == (Object) null)
return;
newGameObject.SetActive(true);
uv.SetNetworkInstanceId(netId);
ClientScene.SetLocalObject(netId, newGameObject);
if (!ClientScene.s_IsSpawnFinished)
return;
uv.OnStartClient();
ClientScene.CheckForOwner(uv);
}
示例14: PushToPool
public void PushToPool( ref GameObject obj, bool retainObject = true, Transform parent = null)
{
if(obj == null) { return; }
if(retainObject == false)
{
Object.Destroy(obj);
obj = null;
return;
}
if(parent != null)
{
obj.transform.parent = parent;
}
Queue<GameObject> queue = FindInContainer(obj.name);
queue.Enqueue(obj);
obj.SetActive(false);
obj = null;
}