回答編集履歴

3

CustomEditorを使うまでも無かったためOnValidateを使用するよう修正

2021/07/01 17:00

投稿

hokuto37
hokuto37

スコア14

test CHANGED
@@ -1,8 +1,8 @@
1
1
  回答いただいたMonoScript型を参考にして作成してみました。
2
2
 
3
- ComponentDisabler の targetScriptに無効化したいスクリプトを設定します。
3
+ targetScriptに無効化したいスクリプトを設定します。
4
4
 
5
- すると ComponentDisablerEditor が、targetAssemblyQualifiedName に無効化したいスクリプトのAssemblyQualifiedName自動で設定ます。
5
+ すると OnValidateの中で、targetAssemblyQualifiedName に無効化したいスクリプトのAssemblyQualifiedName自動で設定されます。
6
6
 
7
7
  このAssemblyQualifiedNameを比較して、同じスクリプトを無効化します。
8
8
 
@@ -13,12 +13,6 @@
13
13
 
14
14
 
15
15
  ```ここに言語を入力
16
-
17
- using System;
18
-
19
- using System.Collections;
20
-
21
- using System.Collections.Generic;
22
16
 
23
17
  using UnityEngine;
24
18
 
@@ -43,6 +37,8 @@
43
37
  #endif
44
38
 
45
39
 
40
+
41
+ [HideInInspector]
46
42
 
47
43
  public string targetAssemblyQualifiedName;
48
44
 
@@ -78,33 +74,11 @@
78
74
 
79
75
  #if UNITY_EDITOR
80
76
 
81
- [CustomEditor(typeof(ComponentDisabler))]
77
+ private void OnValidate()
82
-
83
- public class ComponentDisablerEditor : Editor
84
78
 
85
79
  {
86
80
 
87
- public override void OnInspectorGUI()
88
-
89
- {
90
-
91
- base.OnInspectorGUI ();
92
-
93
-
94
-
95
- ComponentDisabler componentDisabler = base.target as ComponentDisabler;
96
-
97
-
98
-
99
- if(componentDisabler.targetScript != null)
100
-
101
- {
102
-
103
- componentDisabler.targetAssemblyQualifiedName = componentDisabler.targetScript.GetClass().AssemblyQualifiedName;
81
+ this.targetAssemblyQualifiedName = this.targetScript.GetClass().AssemblyQualifiedName;
104
-
105
- }
106
-
107
- }
108
82
 
109
83
  }
110
84
 

2

変数名を修正

2021/07/01 17:00

投稿

hokuto37
hokuto37

スコア14

test CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  ComponentDisabler の targetScriptに無効化したいスクリプトを設定します。
4
4
 
5
- すると ComponentDisablerEditor が、targetAssemblyAualifiedName に無効化したいスクリプトのAssemblyAualifiedNameを自動で設定します。
5
+ すると ComponentDisablerEditor が、targetAssemblyQualifiedName に無効化したいスクリプトのAssemblyQualifiedNameを自動で設定します。
6
6
 
7
- このAssemblyAualifiedNameを比較して、同じスクリプトを無効化します。
7
+ このAssemblyQualifiedNameを比較して、同じスクリプトを無効化します。
8
8
 
9
- AssemblyAualifiedNameではなくてType型で比較できればよかったのですが、TypeはSerialize出来なかったのでAssemblyAualifiedNameで代替しました。
9
+ AssemblyQualifiedNameではなくてType型で比較できればよかったのですが、TypeはSerialize出来なかったのでAssemblyQualifiedNameで代替しました。
10
10
 
11
- AssemblyAualifiedNameも使ったことが無いのでこれで完全に問題無いのかよく分かってないですけども、簡易的なテストを行って動作確認済みです。
11
+ AssemblyQualifiedNameも使ったことが無いのでこれで完全に問題無いのかよく分かってないですけども、簡易的なテストを行って動作確認済みです。
12
12
 
13
13
 
14
14
 

1

変数名を修正

2021/07/01 01:39

投稿

hokuto37
hokuto37

スコア14

test CHANGED
@@ -44,7 +44,7 @@
44
44
 
45
45
 
46
46
 
47
- public string targetAssemblyAualifiedName;
47
+ public string targetAssemblyQualifiedName;
48
48
 
49
49
 
50
50
 
@@ -60,7 +60,7 @@
60
60
 
61
61
  {
62
62
 
63
- if(monoBehaviour.GetType().AssemblyQualifiedName == targetAssemblyAualifiedName)
63
+ if(monoBehaviour.GetType().AssemblyQualifiedName == targetAssemblyQualifiedName)
64
64
 
65
65
  {
66
66
 
@@ -100,7 +100,7 @@
100
100
 
101
101
  {
102
102
 
103
- componentDisabler.targetAssemblyAualifiedName = componentDisabler.targetScript.GetClass().AssemblyQualifiedName;
103
+ componentDisabler.targetAssemblyQualifiedName = componentDisabler.targetScript.GetClass().AssemblyQualifiedName;
104
104
 
105
105
  }
106
106
 
@@ -112,8 +112,4 @@
112
112
 
113
113
  }
114
114
 
115
-
116
-
117
-
118
-
119
115
  ```