Mine









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

Featured Snippets


File name: JumpAndRunMovement.cs Copy
29     void FixedUpdate()
30     {
31         if( m_PhotonView.isMine == false )
32         {
33             return;
34         }
35
36         UpdateMovement();
37         UpdateJumping();
38     }
File name: OnAwakePhysicsSettings.cs Copy
10     public void Awake()
11     {
12         if (!photonView.isMine)
13         {
14             Rigidbody attachedRigidbody = GetComponent();
15             if (attachedRigidbody != null)
16             {
17                 attachedRigidbody.isKinematic = true;
18             }
19             else
20             {
21                 Rigidbody2D attachedRigidbody2d = GetComponent();
22                 if (attachedRigidbody2d != null)
23                 {
24                     attachedRigidbody2d.isKinematic = true;
25                 }
26             }
27         }
28     }
File name: ClickAndDrag.cs Copy
11  void Update ()
12  {
13         if (!photonView.isMine)
14         {
15             return;
16         }
17
18      InputToEvent input = Camera.main.GetComponent();
19      if (input == null) return;
20         if (!following)
21         {
22             if (input.Dragging)
23             {
24                 camOnPress = this.transform.position;
25                 following = true;
26             }
27             else
28             {
29                 return;
30             }
31         }
32         else
33         {
34             if (input.Dragging)
35             {
36                 Vector3 target = camOnPress - (new Vector3(input.DragVector.x, 0, input.DragVector.y) * factor);
37                 this.transform.position = Vector3.Lerp(this.transform.position, target, Time.deltaTime*.5f);
38             }
39             else
40             {
41                 camOnPress = Vector3.zero;
42                 following = false;
43             }
44         }
45  }
File name: OnClickRequestOwnership.cs Copy
8     public void OnClick()
9     {
10         if( Input.GetKey( KeyCode.LeftShift ) || Input.GetKey( KeyCode.RightShift ) )
11         {
12             Vector3 colVector = new Vector3( Random.Range( 0.0f, 1.0f ), Random.Range( 0.0f, 1.0f ), Random.Range( 0.0f, 1.0f ) );
13             this.photonView.RPC( "ColorRpc", PhotonTargets.AllBufferedViaServer, colVector );
14         }
15         else
16         {
17             if( this.photonView.ownerId == PhotonNetwork.player.ID )
18             {
19                 Debug.Log( "Not requesting ownership. Already mine." );
20                 return;
21             }
22
23             this.photonView.RequestOwnership();
24         }
25     }
File name: DemoMecanimGUI.cs Copy
42     public void FindRemoteAnimator()
43     {
44         if( m_RemoteAnimator != null )
45         {
46             return;
47         }
48
49         // the prefab has to be tagged as Player
50         GameObject[] gos = GameObject.FindGameObjectsWithTag( "Player" );
51         for( int i = 0; i < gos.Length; ++i )
52         {
53             PhotonView view = gos[ i ].GetComponent();
54             if( view != null && view.isMine == false )
55             {
56                 m_RemoteAnimator = gos[ i ].GetComponent();
57             }
58         }
59     }
File name: OnCollideSwitchTeam.cs Copy
9     public void OnTriggerEnter(Collider other)
10     {
11         // it's ridiculously easy to switch teams. you only have to make sure you do it for your own characters
12         // (this trigger is called on all clients, when a user's character enters the trigger...)
13
14         // find a PhotonView and check if the character "isMine". Only then, set this client's player-team.
15         PhotonView otherPv = other.GetComponent();
16         if (otherPv != null && otherPv.isMine)
17         {
18             PhotonNetwork.player.SetTeam(this.TeamToSwitchTo);
19         }
20     }
File name: OnPickedUpScript.cs Copy
6  public void OnPickedUp(PickupItem item)
7  {
8      if (item.PickupIsMine)
9      {
10          Debug.Log("I picked up something. That's a score!");
11          PhotonNetwork.player.AddScore(1);
12      }
13      else
14      {
15             Debug.Log("Someone else picked up something. Lucky!");
16      }
17  }
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: PickupController.cs Copy
73     // Are we jumping? (Initiated with jump button and not grounded yet)
77     // Are we moving backwards (This locks the camera to not do a 180 degree spin)
81     // When did the user start walking (Used for going into trot after a while)
87     // the height we jumped from (Used to determine for how long to apply extra jump power after jumping.)
101     void Awake()
102     {
103         // PUN: automatically determine isControllable, if this GO has a PhotonView
104         PhotonView pv = this.gameObject.GetComponent();
105         if (pv != null)
106         {
107             isControllable = pv.isMine;
108
109             // The pickup demo assigns this GameObject as the PhotonPlayer.TagObject. This way, we can access this character (controller, position, etc) easily
110             if (this.AssignAsTagObject)
111             {
112                 pv.owner.TagObject = this.gameObject;
113             }
114
115             // please note: we change this setting on ANY PickupController if "DoRotate" is off. not only locally when it's "our" GameObject!
116             if (pv.observed is Transform && !DoRotate)
117             {
118                 pv.onSerializeTransformOption = OnSerializeTransform.OnlyPosition;
119             }
120         }
121
122
123         moveDirection = transform.TransformDirection(Vector3.forward);
124
125         _animation = GetComponent();
126         if (!_animation)
127             Debug.Log("The character you would like to control doesn't have animations. Moving her might look weird.");
128
129         if (!idleAnimation)
130         {
131             _animation = null;
132             Debug.Log("No idle animation found. Turning off animations.");
133         }
134         if (!walkAnimation)
135         {
136             _animation = null;
137             Debug.Log("No walk animation found. Turning off animations.");
138         }
139         if (!runAnimation)
140         {
141             _animation = null;
142             Debug.Log("No run animation found. Turning off animations.");
143         }
144         if (!jumpPoseAnimation && canJump)
145         {
146             _animation = null;
147             Debug.Log("No jump animation found and the character has canJump enabled. Turning off animations.");
148         }
149     }
File name: PickupDemoGui.cs Copy
15     public void OnGUI()
16     {
17         if (!PhotonNetwork.inRoom)
18         {
19             return;
20         }
21
22
23         if (this.ShowScores)
24         {
25             GUILayout.Label("Your Score: " + PhotonNetwork.player.GetScore());
26         }
27
28
29         if (this.ShowDropButton)
30         {
31             foreach (PickupItem item in PickupItem.DisabledPickupItems)
32             {
33                 if (item.PickupIsMine && item.SecondsBeforeRespawn <= 0)
34                 {
35                     if (GUILayout.Button("Drop " + item.name))
36                     {
37                         item.Drop(); // drops the item at the place where it originates
38                     }
39
40                     GameObject playerCharGo = PhotonNetwork.player.TagObject as GameObject;
41                     if (playerCharGo != null && GUILayout.Button("Drop here " + item.name))
42                     {
43                         // drop the item at some other place. next to the user's character would be fine...
44                         Vector3 random = Random.insideUnitSphere;
45                         random.y = 0;
46                         random = random.normalized;
47                         Vector3 itempos = playerCharGo.transform.position + this.DropOffset * random;
48
49                         item.Drop(itempos);
50                     }
51                 }
52             }
53         }
54
55
56         if (this.ShowTeams)
57         {
58             foreach (var teamName in PunTeams.PlayersPerTeam.Keys)
59             {
60                 GUILayout.Label("Team: " + teamName.ToString());
61                 List teamPlayers = PunTeams.PlayersPerTeam[teamName];
62                 foreach (PhotonPlayer player in teamPlayers)
63                 {
64                     GUILayout.Label(" " + player.ToStringFull() + " Score: " + player.GetScore());
65                 }
66             }
67
68             if (GUILayout.Button("to red"))
69             {
70                 PhotonNetwork.player.SetTeam(PunTeams.Team.red);
71             }
72             if (GUILayout.Button("to blue"))
73             {
74                 PhotonNetwork.player.SetTeam(PunTeams.Team.blue);
75             }
76         }
77     }

Download file with original file name:Mine

Mine 283 lượt xem

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