Exemplo n.º 1
0
        // Event hooks
        public void EventHooks()
        {
            // Generic vehicle FSMs.
            throttleFsm = Utils.GetPlaymakerScriptByName(parentGameObject, "Throttle");
            EventHook.SyncAllEvents(throttleFsm, new Func <bool>(() => {
                if (syncComponent.Owner != steamID && syncComponent.Owner != 0 || syncComponent.Owner == 0 && !Network.NetManager.Instance.IsHost)
                {
                    return(true);
                }
                return(false);
            }));

            // Traffic FSMs.
            EventHook.AddWithSync(directionFsm, "CW", new Func <bool>(() => {
                isClockwise = 1;
                return(false);
            }));
            EventHook.AddWithSync(directionFsm, "CCW", new Func <bool>(() => {
                isClockwise = 0;
                return(false);
            }));

            // Bus specific FSMs.
            if (type == VehicleTypes.Bus)
            {
                PlayMakerFSM doorFsm  = Utils.GetPlaymakerScriptByName(parentGameObject.transform.FindChild("Route").gameObject, "Door");
                PlayMakerFSM startFsm = Utils.GetPlaymakerScriptByName(parentGameObject.transform.FindChild("Route").gameObject, "Start");

                EventHook.SyncAllEvents(doorFsm, new Func <bool>(() => {
                    if (syncComponent.Owner != steamID && syncComponent.Owner != 0 || syncComponent.Owner == 0 && !Network.NetManager.Instance.IsHost)
                    {
                        return(true);
                    }
                    return(false);
                }));

                EventHook.SyncAllEvents(startFsm, new Func <bool>(() => {
                    if (syncComponent.Owner != steamID && syncComponent.Owner != 0 || syncComponent.Owner == 0 && !Network.NetManager.Instance.IsHost)
                    {
                        return(true);
                    }
                    return(false);
                }));
            }

            // None traffic cars specific FSMs.
            if (type == VehicleTypes.Amis || type == VehicleTypes.Fitan)
            {
                PlayMakerFSM crashFsm = Utils.GetPlaymakerScriptByName(parentGameObject.transform.FindChild("CrashEvent").gameObject, "Crash");

                EventHook.SyncAllEvents(crashFsm, new Func <bool>(() => {
                    if (syncComponent.Owner != steamID && syncComponent.Owner != 0 || syncComponent.Owner == 0 && !Network.NetManager.Instance.IsHost)
                    {
                        return(true);
                    }
                    return(false);
                }));
            }

            // Sync vehicle data with the host on spawn.
            if (Network.NetManager.Instance.IsOnline && !Network.NetManager.Instance.IsHost)
            {
                syncComponent.RequestObjectSync();
            }
        }