summaryrefslogtreecommitdiff
path: root/ROUNDS/Photon.Pun.Simple/AutoMountHitscan.cs
blob: 7b0c451059357bd5a789b8e8185aea5d093d2df2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System.Collections.Generic;
using UnityEngine;

namespace Photon.Pun.Simple;

public class AutoMountHitscan : HitscanComponent
{
	protected SyncState syncState;

	private Queue<Mount> foundMounts = new Queue<Mount>();

	public SyncState SyncState => syncState;

	public override void OnAwake()
	{
		base.OnAwake();
		if ((bool)netObj)
		{
			syncState = netObj.GetComponent<SyncState>();
		}
	}

	public override void OnAuthorityChanged(bool isMine, bool controllerChanged)
	{
		base.OnAuthorityChanged(isMine, controllerChanged);
		List<IOnPreSimulate> onPreSimulateCallbacks = netObj.onPreSimulateCallbacks;
		bool flag = onPreSimulateCallbacks.Contains(this);
		base.OnAuthorityChanged(isMine, controllerChanged);
		if (isMine)
		{
			if (!flag)
			{
				onPreSimulateCallbacks.Add(this);
			}
		}
		else if (flag)
		{
			onPreSimulateCallbacks.Remove(this);
		}
	}

	public override void OnPreSimulate(int frameId, int subFrameId)
	{
		if (subFrameId != TickEngineSettings.sendEveryXTick - 1)
		{
			return;
		}
		triggerQueued = true;
		base.OnPreSimulate(frameId, subFrameId);
		if (foundMounts.Count != 0)
		{
			do
			{
				Mount attachTo = foundMounts.Dequeue();
				syncState.SoftMount(attachTo);
			}
			while (foundMounts.Count != 0);
		}
		else
		{
			syncState.SoftMount(null);
		}
	}

	public override bool ProcessHit(Collider hit)
	{
		Mount nestedComponentInParents = hit.transform.GetNestedComponentInParents<Mount, NetObject>();
		if ((bool)nestedComponentInParents)
		{
			foundMounts.Enqueue(nestedComponentInParents);
		}
		return false;
	}
}