示例#1
0
 private void OnDestroy()
 {
     CoroutineRunner.StopAllForOwner(this);
     UnityEngine.Object.Destroy(bubble);
     UnityEngine.Object.Destroy(bubbleMaterial);
     bubble = null;
     dispatcher.RemoveListener <InputEvents.ActionEvent>(OnAction);
     dispatcher.RemoveListener <DivingEvents.EnableLocalInfiniteAir>(onEnableLocalInfiniteAir);
     dispatcher.RemoveListener <DivingEvents.DisableLocalInfiniteAir>(onDisableLocalInfiniteAir);
     if (isLocalPlayer)
     {
         Service.Get <INetworkServicesManager>().PlayerStateService.RemoveAirBubble();
     }
     else
     {
         AvatarDataHandle component = GetComponent <AvatarDataHandle>();
         if (component != null && !component.Handle.IsNull)
         {
             AirBubbleData component2 = dataEntityCollection.GetComponent <AirBubbleData>(component.Handle);
             if (component2 != null)
             {
                 component2.AirBubbleChanged -= OnRemotePlayerAirBubbleChanged;
             }
         }
     }
     foreach (DivingGameController overlappingBubble in overlappingBubbles)
     {
         if (overlappingBubble != null)
         {
             overlappingBubble.RemotePlayerRemoved(this);
         }
     }
 }
示例#2
0
 private void Start()
 {
     dispatcher           = Service.Get <EventDispatcher>();
     dataEntityCollection = Service.Get <CPDataEntityCollection>();
     determineIfLocalPlayer();
     if (isLocalPlayer)
     {
         DataEntityHandle localPlayerHandle = dataEntityCollection.LocalPlayerHandle;
         if (dataEntityCollection.TryGetComponent <AirBubbleData>(localPlayerHandle, out localPlayerAirBubbleData))
         {
             AirSupply = localPlayerAirBubbleData.AirBubble.value;
         }
         else
         {
             localPlayerAirBubbleData = dataEntityCollection.AddComponent <AirBubbleData>(localPlayerHandle);
             AirBubble airBubble = new AirBubble();
             airBubble.value = 10f;
             localPlayerAirBubbleData.AirBubble = airBubble;
         }
         if (isLocalPenguinSpawned())
         {
             initializeDiving();
         }
         else
         {
             dispatcher.AddListener <PlayerSpawnedEvents.LocalPlayerSpawned>(onLocalPlayerSpawned);
         }
     }
     else
     {
         initializeDiving();
     }
 }
示例#3
0
        private IEnumerator InitializeBubbleCoroutine(string path, GameObject prefab)
        {
            bubble = UnityEngine.Object.Instantiate(prefab);
            bubble.SetActive(value: false);
            Transform jnt = null;

            while (jnt == null)
            {
                jnt = base.transform.Find("hips_jnt/backbone_jnt/chest_jnt/neck_jnt");
                yield return(new WaitForEndOfFrame());
            }
            CameraFacingController cameraFacingController = bubble.GetComponent <CameraFacingController>();

            if (cameraFacingController != null)
            {
                cameraFacingController.AttachPoint = jnt;
                bubble.transform.SetParent(base.gameObject.transform, worldPositionStays: false);
            }
            else
            {
                bubble.transform.SetParent(jnt.transform, worldPositionStays: false);
                bubble.transform.position = jnt.transform.position;
            }
            bubble.SetActive(value: true);
            swimController = GetComponent <SwimController>();
            bubbleMaterial = bubble.GetComponentInChildren <MeshRenderer>().material;
            float totalAirQuantity = 10f - AirThreshold;

            warningThreshold = AirThreshold + totalAirQuantity * 0.4f;
            dangerThreshold  = AirThreshold + totalAirQuantity * 0.2f;
            bubbleState      = getStartingBubbleState(AirSupply);
            updateBubbleState();
            if (isLocalPlayer)
            {
                CoroutineRunner.Start(UpdateLocalPlayerBubbleCoRoutine(), this, "UpdateLocalPlayerBubbleCoRoutine");
                CoroutineRunner.Start(SyncAirSupplyNetwork(), this, "SyncAirSupplyNetwork");
                yield break;
            }
            DataEntityHandle handle = GetComponent <AvatarDataHandle>().Handle;

            if (!handle.IsNull)
            {
                AirBubbleData component = dataEntityCollection.GetComponent <AirBubbleData>(handle);
                if (component != null)
                {
                    dataEntityCollection.GetComponent <AirBubbleData>(handle).AirBubbleChanged += OnRemotePlayerAirBubbleChanged;
                }
                else
                {
                    Log.LogError(this, "Failed to get the air bubble data for the remote player");
                }
            }
        }