Skip to content

Commit

Permalink
Minor performance improvement, discription changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TamakiRuri committed Dec 9, 2024
1 parent 43fa721 commit 6520ec3
Show file tree
Hide file tree
Showing 11 changed files with 293 additions and 137 deletions.
13 changes: 8 additions & 5 deletions EditorOnly/ItemLockDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@
public class ItemLockDatabase : MonoBehaviour
{
[SerializeField] private String[] usernames;

[Header("必ずプレハブをUnpackしてからお使いください")]
[Header("Please UNPACK this prefab before using.")]
[Header(" ")]
[Header("Action Mode[0]アイテムが消える、[1]アイテムが触れなくなる")]
[Header("予め[0]オブジェクト[1]コライダーを無効にするとよりセキュアになります")]
[Header("全ての操作がJoin時に終わるため")]
[Header("スイッチでオブジェクト(コライダー)を強制的に有効にすると、このスクリプトが無効になります。")]
[Header("スイッチでオブジェクト(コライダー)を有効にするとロックが解除されます")]
[Header("Wall Modeでは、動作が逆になります(壁などを一部の人だけがぬけるようにするなど)")]
[Header("導入が成功したあと、下のスクリプトにデータが表示されます")]
[Header("導入したあと、下のスクリプトにデータが表示されます")]
[Header(" ")]
[Header("Action Mode 0 will make the item disappear, 1 will make the item not touchable")]
[Header("Deactivating[0]objects[1]colliders before uploading is recommanded for better security")]
[Header("However, this script could be overidden by a switch enabling the object(collider) directly")]
[Header("In Wall Mode the function of the script become reversed (for creating walls that can only be go through by whitelisted users).")]
[Header("However, the item will be unlocked if a switch enables the object(collider) directly")]
[Header("In Wall Mode the function of the script become reversed.")]
[Header("(for creating walls that can only be go through by whitelisted users)")]
[Header("If the data is correctly imported, The script below will show the imported data")]
[Header(" ")]

Expand Down
2 changes: 1 addition & 1 deletion EditorOnly/ItemLockDatabaseEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override void OnInspectorGUI()
}
else if (targetLock.GetComponent<ItemLockUsername>()!= null)
targetLock.GetComponent<ItemLockUsername>().ImportUsernames(managedScript.ExportUserData());
else Debug.LogError("ItemLockDatabase: Cannot find ItemLock script in target lock.");
else throw new ArgumentException("ItemLockDatabase: Cannot find ItemLock script in target lock.");
}
catch (Exception e){
throw e;
Expand Down
30 changes: 20 additions & 10 deletions ItemLockCenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ public class ItemLockCenter : UdonSharpBehaviour
[Header("Action Mode[0]アイテムが消える、[1]アイテムが触れなくなる")]
[Header("予め[0]オブジェクト[1]コライダーを無効にするとよりセキュアになります")]
[Header("全ての操作がJoin時に終わるため")]
[Header("スイッチでオブジェクト(コライダー)を強制的に有効にすると、このスクリプトが無効になります。")]
[Header("スイッチでオブジェクト(コライダー)を強制的に有効にするとロックが解除されます。")]


[Header("Action Mode 0 will make the item disappear, 1 will make the item not touchable")]
[Header("Deactivating[0]objects[1]colliders before uploading is recommanded for better security")]
[Header("However, this script could be overidden by a switch enabling the object(collider) directly")]
[Header("However, the item will be unlocked if a switch enables the object(collider) directly")]

[Header(" ")]


Expand All @@ -30,21 +31,30 @@ public class ItemLockCenter : UdonSharpBehaviour
[Header("In Wall Mode the function of the script become reversed (for creating walls that can only be go through by whitelisted users).")]
[Header(" ")]
[SerializeField]private bool wallMode = false;
private bool shouldOn = false;
void Start()
{
ScriptAction(actionMode, false);
EnableItemorCollider(actionMode);
shouldOn = UserCheck();
ScriptAction(actionMode, shouldOn);
}
private void EnableItemorCollider(int actionMode){
private bool UserCheck()
{
String localPlayer = Networking.LocalPlayer.displayName;
if(Networking.LocalPlayer.isInstanceOwner && allowInstanceOwner){
ScriptAction(actionMode,true);
if (Networking.LocalPlayer.isInstanceOwner && allowInstanceOwner)
{
return true;
}
for (int i =0; i < userName.Length; i++){
if (localPlayer == userName[i]){
ScriptAction(actionMode,true);
else
{
for (int i = 0; i < userName.Length; i++)
{
if (localPlayer == userName[i])
{
return true;
}
}
}
return false;
}
private void ScriptAction(int mode, bool targetState){
switch (mode) {
Expand Down
107 changes: 66 additions & 41 deletions ItemLockCenterAdvanced.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,91 +10,116 @@ public class ItemLockCenterAdvanced : UdonSharpBehaviour
[Header("このScriptのデータは自動生成されます")]
[Header("アイテムを動かしたりすることは、エラーを引き起こす恐れがあります。")]
[Header("全ての操作がJoin時に終わるため")]
[Header("スイッチでオブジェクト(コライダー)を強制的に有効にすると、このスクリプトが無効になります。")]
[Header("スイッチでオブジェクト(コライダー)を有効にするとロックが解除されます。")]

[Header("The data in this script is auto generated")]
[Header("Adding or moving objects could potentially break the program")]
[Header("However, this script could be overidden by a switch enabling the object(collider) directly")]
[Header("However, the item will be unlocked if a switch enables the object(collider) directly")]
[Header(" ")]
[SerializeField]private String[] userName;
[SerializeField]private GameObject[] targetObjects;
[SerializeField]private int[] actionMode;
[SerializeField]private bool[] allowInstanceOwner;
[SerializeField]private bool[] wallModes;
[SerializeField] private String[] userName;
[SerializeField] private GameObject[] targetObjects;
[SerializeField] private int[] actionMode;
[SerializeField] private bool[] allowInstanceOwner;
[SerializeField] private bool[] wallModes;

// allow InstanceOwner is different for each object this only applies to list members
private bool userInList = false;

void Start()
{
userInList = UserListCheck();
if (wallModes.Length == 0) wallModes = new bool[targetObjects.Length];
for (int i=0; i< targetObjects.Length; i++){
ScriptAction(targetObjects[i],actionMode[i], false, wallModes[i]);
EnableItemorCollider(targetObjects[i], actionMode[i],allowInstanceOwner[i], wallModes[i]);
for (int i = 0; i < targetObjects.Length; i++)
{
EnableItemorCollider(targetObjects[i], actionMode[i], allowInstanceOwner[i], wallModes[i]);
}
}
private void EnableItemorCollider(GameObject targetObject, int actionMode,bool allowInstanceOwner, bool wallMode){
// UserCheck. Different funcion name to prevent misunderstandings. THIS DOES NOT CHECK INSTANCE OWNER.
private bool UserListCheck()
{
String localPlayer = Networking.LocalPlayer.displayName;
if(Networking.LocalPlayer.isInstanceOwner && allowInstanceOwner){
ScriptAction(targetObject, actionMode,true, wallMode);
}
for (int i =0; i < userName.Length; i++){
if (localPlayer == userName[i]){
ScriptAction(targetObject, actionMode,true, wallMode);
for (int i = 0; i < userName.Length; i++)
{
if (localPlayer == userName[i])
{
return true;
}
}
return false;
}
private void EnableItemorCollider(GameObject targetObject, int actionMode, bool allowInstanceOwner, bool wallMode)
{
if (Networking.LocalPlayer.isInstanceOwner && allowInstanceOwner)
{
ScriptAction(targetObject, actionMode, true, wallMode);
}
else{
ScriptAction(targetObject, actionMode, userInList, wallMode);
}
}

private void ScriptAction(GameObject targetObject, int mode, bool targetState, bool wallMode = false){
switch (mode) {
private void ScriptAction(GameObject targetObject, int mode, bool targetState, bool wallMode = false)
{
switch (mode)
{
case 0:
if (!wallMode)targetObject.SetActive(targetState);
if (!wallMode) targetObject.SetActive(targetState);
else targetObject.SetActive(!targetState);
break;
break;
case 1:
if (!wallMode)targetObject.GetComponent<Collider>().enabled = targetState;
if (!wallMode) targetObject.GetComponent<Collider>().enabled = targetState;
else targetObject.GetComponent<Collider>().enabled = !targetState;
break;

break;
default:
Debug.LogError("Item Lock: Action Mode Index Out Of Bound.");
Debug.LogError("Item Lock: Action Modeの入力にエラーを検出しました。");
break;
Debug.LogError("Item Lock: Action Mode Index Out Of Bound.");
Debug.LogError("Item Lock: Action Modeの入力にエラーを検出しました。");
break;
}

}


#if UNITY_EDITOR && !COMPILER_UDONSHARP
public void ImportUsernames(String[] importedUsernames){
userName=importedUsernames;

#if UNITY_EDITOR && !COMPILER_UDONSHARP
public void ImportUsernames(String[] importedUsernames)
{
userName = importedUsernames;
Debug.Log("Username Imported");
}

public void ImportLockData(GameObject[] l_gameObject, int[] l_modes, bool[] l_allowOwner, bool[] l_wallModes){
public void ImportLockData(GameObject[] l_gameObject, int[] l_modes, bool[] l_allowOwner, bool[] l_wallModes)
{
targetObjects = l_gameObject;
actionMode = l_modes;
allowInstanceOwner = l_allowOwner;
wallModes = l_wallModes;
}
public void ImportTargets(GameObject[] importedGameObjects){
public void ImportTargets(GameObject[] importedGameObjects)
{
targetObjects = importedGameObjects;
Debug.Log("Target GameObjects Imported");
}
public void ImportModes(int[] importedModes){
public void ImportModes(int[] importedModes)
{
actionMode = importedModes;
Debug.Log("Action Modes Imported");
}
public void ImportAllowOwner(bool[] importedAllowOwner){
public void ImportAllowOwner(bool[] importedAllowOwner)
{
allowInstanceOwner = importedAllowOwner;
Debug.Log("Allow Instance Owner Settings Imported");
}
public void ImportWallModes(bool[] importedWallModes){
public void ImportWallModes(bool[] importedWallModes)
{
wallModes = importedWallModes;
Debug.Log("Wall Mode Settings Imported");
}
// Export Functions (not in use)
public String[] ExportUsernames(){
public String[] ExportUsernames()
{
return userName;
}
#endif

#endif

}
63 changes: 25 additions & 38 deletions ItemLockUsername.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@
public class ItemLockUsername : UdonSharpBehaviour
{
[Header("何も入れない場合、現在のオブジェクトが設定されます。")]
[Header("If no object is here, current object will be automatically set up")]
[Header("If no object is attached, current object will be automatically set up")]
[Header(" ")]
[SerializeField] private GameObject targetObject;
[SerializeField] private String[] userName;

[Header("Action Mode[0]アイテムが消える、[1]アイテムが触れなくなる")]
[Header("[1]予めコライダーを無効にするとよりセキュアになります")]
[Header("スイッチでオブジェクト(コライダー)を強制的に有効にすると、このスクリプトが無効になります。")]
[Header("[0]このスクリプトがオブジェクトにアタッチしたまま無効にしないでください")]
[Header("スイッチでオブジェクト(コライダー)を強制的に有効にするとロックが解除されます。")]


[Header("Action Mode 0 will make the item disappear, 1 will make the item not touchable")]
[Header("[1]Deactivating colliders before uploading is recommanded for better security")]
[Header("However, this script could be overidden by a switch enabling the object(collider) directly")]
[Header("[0]Don't deactivate the game object if this script is attacted to it.")]
[Header("The item will be unlocked if a switch enables the object(collider) directly")]

[Header(" ")]


Expand All @@ -41,15 +44,17 @@ void Start()
{
if (targetObject == null) targetObject = gameObject;
shouldOn = UserCheck();
if (actionMode == 1) {
if (actionMode == 1)
{
targetCollider = targetObject.GetComponent<Collider>();
if (targetCollider == null) {
if (targetCollider == null)
{
Debug.LogError("Item Lock: This object is in Action Mode 1 but the Collider can't be detected");
Debug.LogError("Item Lock: このオブジェクトの動作モードがAction Mode 1ですがコライダーを取得できません");
return;
}
}
EnableItemorCollider();
ScriptAction(actionMode, shouldOn);
}

private bool UserCheck()
Expand All @@ -72,52 +77,34 @@ private bool UserCheck()
return false;
}

private void ObjectMode()
{
if (!wallMode) targetObject.SetActive(false);
else targetObject.SetActive(true);
if (shouldOn)
{
if (!wallMode) targetObject.SetActive(true);
else targetObject.SetActive(false);
}
}
private void ColliderMode()
private void ScriptAction(int mode, bool targetState)
{
if (!wallMode) targetObject.GetComponent<Collider>().enabled = false;
else targetObject.GetComponent<Collider>().enabled = true;

if (shouldOn)
{
if (!wallMode) targetObject.GetComponent<Collider>().enabled = true;
else targetObject.GetComponent<Collider>().enabled = false;
}
}

private void EnableItemorCollider()
{
switch (actionMode)
switch (mode)
{
case 0:
ObjectMode();
if (!wallMode) targetObject.SetActive(targetState);
else targetObject.SetActive(!targetState);
break;
case 1:
ColliderMode();
if (!wallMode) targetObject.GetComponent<Collider>().enabled = targetState;
else targetObject.GetComponent<Collider>().enabled = !targetState;
break;
default:
Debug.LogError("Item Lock: Action Mode Index Out Of Bound.");
Debug.LogError("Item Lock: Action Modeを0か1にしてください。");
Debug.LogError("Item Lock: Action Modeの入力にエラーを検出しました。");
break;
}
}
#if UNITY_EDITOR && !COMPILER_UDONSHARP
public void ImportUsernames(String[] importedUsernames){
userName=importedUsernames;
#if UNITY_EDITOR && !COMPILER_UDONSHARP
public void ImportUsernames(String[] importedUsernames)
{
userName = importedUsernames;
Debug.Log("Username Imported");
}
#endif
#endif

public String[] ExportUsernames(){
public String[] ExportUsernames()
{
return userName;
}

Expand Down
Loading

0 comments on commit 6520ec3

Please sign in to comment.