12
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

unity > show/hide line on Panelの実装

Last updated at Posted at 2015-09-07
動作確認
Unity 5.1.2-f1 on MacOS X 10.8.5

前置き

http://qiita.com/7of9/items/60bffb5a0810d9aabd1f
にてPanel上にグラフを描画できるところまでできた。

そこで、気になるのが
http://qiita.com/7of9/items/95813013d0e18eb54a95
で実装した、Panelごとshow / hideする実装が有効かどうか。

やってみた

以下のような実装を準備。

Main_unity_-150907-2dHideLineOnPanel-PC__Mac___Linux_Standalone__Personal.jpg

Hide Panelsボタンを押したところ以下となった。
InputFieldとToggleは隠れているが、グラフは隠れていない。

Main_unity_-150907-2dHideLineOnPanel-PC__Mac___Linux_Standalone__Personal.jpg

理由としてはlinerendererは UIのコンポーネントでないため、Maskが効かない。

結果として、Panelを隠した時にグラフが描画されたままという、ショボーンな実装が完成する。

修正版

graphDrawControl.csにおいて、以下のように isHide(panel)を追加して、PanelがHide状態にある場合は、drawGraphをスキップするようにした。

v0.5 @ github

graphDrawControl.cs
...
	bool isHide(GameObject panel) {
		RectTransform rect = panel.GetComponent (typeof(RectTransform)) as RectTransform;
		Vector2 scale = rect.localScale;
		if (scale.x < 0.1) {
			return true;
		}
		return false;
	}

	void drawGraph(List<Vector2> my2DVec, GameObject panel) {
		if (isHide (panel)) {
			return;
		}

		lineGroup = new GameObject ("LineGroup");

		for (int idx=0; idx < my2DVec.Count - 1; idx++) {
			DrawLine (my2DVec, /* startPos=*/idx);
		}

		lineGroup.transform.parent = panel.transform; // to belong to panel
	}
...

結果

Hideボタンを押した結果。

描画を更新しているCosineの方は隠すことができた。
描画を更新しない左側のSineのグラフは隠れていない。こちらは別の考慮が必要であるが、とりあえずUpdate()時に再描画しているグラフのHideのみの対応としておく。

Main_unity_-150907-2dHideLineOnPanel-PC__Mac___Linux_Standalone__Personal.jpg

12
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?