OnEnable









How do I use On Enable
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: PickupCamera.cs Copy
41     void OnEnable()
42     {
43         if( this.photonView != null && !this.photonView.isMine )
44         {
45             this.enabled = false;
46             return;
47         }
48
49         if( !cameraTransform && Camera.main )
50             cameraTransform = Camera.main.transform;
51         if( !cameraTransform )
52         {
53             Debug.Log( "Please assign a camera to the ThirdPersonCamera script." );
54             enabled = false;
55         }
56
57         m_CameraTransformCamera = cameraTransform.GetComponent();
58
59
60         _target = transform;
61         if( _target )
62         {
63             controller = _target.GetComponent();
64         }
65
66         if( controller )
67         {
68             CharacterController characterController = (CharacterController)_target.GetComponent();
69             centerOffset = characterController.bounds.center - _target.position;
70             headOffset = centerOffset;
71             headOffset.y = characterController.bounds.max.y - _target.position.y;
72         }
73         else
74             Debug.Log( "Please assign a target to the camera that has a ThirdPersonController script attached." );
75
76
77         Cut( _target, centerOffset );
78     }
File name: ThirdPersonCamera.cs Copy
40     void OnEnable()
41     {
42         if( !cameraTransform && Camera.main )
43             cameraTransform = Camera.main.transform;
44         if( !cameraTransform )
45         {
46             Debug.Log( "Please assign a camera to the ThirdPersonCamera script." );
47             enabled = false;
48         }
49
50         m_CameraTransformCamera = cameraTransform.GetComponent();
51
52         _target = transform;
53         if( _target )
54         {
55             controller = _target.GetComponent();
56         }
57
58         if( controller )
59         {
60             CharacterController characterController = (CharacterController)_target.GetComponent();
61             centerOffset = characterController.bounds.center - _target.position;
62             headOffset = centerOffset;
63             headOffset.y = characterController.bounds.max.y - _target.position.y;
64         }
65         else
66             Debug.Log( "Please assign a target to the camera that has a ThirdPersonController script attached." );
67
68
69         Cut( _target, centerOffset );
70     }
File name: PhotonAnimatorViewEditor.cs Copy
54     private void OnEnable()
55     {
56         this.m_Target = (PhotonAnimatorView) target;
57         this.m_Animator = this.m_Target.GetComponent();
58
59#if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6
60         this.m_Controller = AnimatorController.GetEffectiveAnimatorController(this.m_Animator);
61#endif
62
63         CheckIfStoredParametersExist();
64     }
File name: PhotonTransformViewEditor.cs Copy
42     public void OnEnable()
43     {
44         SetupSerializedProperties();
45     }
File name: PhotonLagSimulationGui.cs Copy
57     private void NetSimWindow(int windowId)
58     {
59         GUILayout.Label(string.Format("Rtt:{0,4} +/-{1,3}", this.Peer.RoundTripTime, this.Peer.RoundTripTimeVariance));
60
61         bool simEnabled = this.Peer.IsSimulationEnabled;
62         bool newSimEnabled = GUILayout.Toggle(simEnabled, "Simulate");
63         if (newSimEnabled != simEnabled)
64         {
65             this.Peer.IsSimulationEnabled = newSimEnabled;
66         }
67
68         float inOutLag = this.Peer.NetworkSimulationSettings.IncomingLag;
69         GUILayout.Label("Lag " + inOutLag);
70         inOutLag = GUILayout.HorizontalSlider(inOutLag, 0, 500);
71
72         this.Peer.NetworkSimulationSettings.IncomingLag = (int)inOutLag;
73         this.Peer.NetworkSimulationSettings.OutgoingLag = (int)inOutLag;
74
75         float inOutJitter = this.Peer.NetworkSimulationSettings.IncomingJitter;
76         GUILayout.Label("Jit " + inOutJitter);
77         inOutJitter = GUILayout.HorizontalSlider(inOutJitter, 0, 100);
78
79         this.Peer.NetworkSimulationSettings.IncomingJitter = (int)inOutJitter;
80         this.Peer.NetworkSimulationSettings.OutgoingJitter = (int)inOutJitter;
81
82         float loss = this.Peer.NetworkSimulationSettings.IncomingLossPercentage;
83         GUILayout.Label("Loss " + loss);
84         loss = GUILayout.HorizontalSlider(loss, 0, 10);
85
86         this.Peer.NetworkSimulationSettings.IncomingLossPercentage = (int)loss;
87         this.Peer.NetworkSimulationSettings.OutgoingLossPercentage = (int)loss;
88
89         // if anything was clicked, the height of this window is likely changed. reduce it to be layouted again next frame
90         if (GUI.changed)
91         {
92             this.WindowRect.height = 100;
93         }
94
95         GUI.DragWindow();
96     }
File name: CurvedLayout.cs Copy
30         protected override void OnEnable() { base.OnEnable(); CalculateRadial(); }
File name: RadialLayout.cs Copy
34         protected override void OnEnable() { base.OnEnable(); CalculateRadial(); }
File name: TutorialInfoEditor.cs Copy
8  void OnEnable()
9  {
10   if (PlayerPrefs.HasKey(TutorialInfo.showAtStartPrefsKey))
11   {
12    ((TutorialInfo)target).showAtStart = PlayerPrefs.GetInt(TutorialInfo.showAtStartPrefsKey) == 1;
13   }
14  }

OnEnable 130 lượt xem

Gõ tìm kiếm nhanh...