Material









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

Featured Snippets


File name: MaterialPerOwner.cs Copy
18     private void Update()
19     {
20         if( this.photonView.ownerId != assignedColorForUserId )
21         {
22             m_Renderer.material = PlayerVariables.GetMaterial( m_Renderer.material, this.photonView.ownerId );
23             this.assignedColorForUserId = this.photonView.ownerId;
24             //Debug.Log("Switched Material to: " + this.assignedColorForUserId + " " + this.renderer.material.GetInstanceID());
25         }
26     }
File name: OnClickRequestOwnership.cs Copy
28     public void ColorRpc( Vector3 col )
29     {
30         Color color = new Color( col.x, col.y, col.z );
31         this.gameObject.GetComponent().material.color = color;
32     }
File name: PlayerVariables.cs Copy
27     public static Material GetMaterial(Material original, int playerId)
28     {
29         Material result = playerMaterials[playerId%playerMaterials.Length];
30
31         if (result == null)
32         {
33             result = new Material(original);
34             result.color = GetColor(playerId);
35             playerMaterials[playerId%playerMaterials.Length] = result;
36         }
37
38         return result;
39     }
File name: ShowInfoOfPlayer.cs Copy
20     void Start()
21     {
22         if (font == null)
23         {
24             #if UNITY_3_5
25             font = (Font)FindObjectsOfTypeIncludingAssets(typeof(Font))[0];
26             #else
27             font = (Font)Resources.FindObjectsOfTypeAll(typeof(Font))[0];
28             #endif
29             Debug.LogWarning("No font defined. Found font: " + font);
30         }
31
32         if (tm == null)
33         {
34             textGo = new GameObject("3d text");
35             //textGo.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
36             textGo.transform.parent = this.gameObject.transform;
37             textGo.transform.localPosition = Vector3.zero;
38
39             MeshRenderer mr = textGo.AddComponent();
40             mr.material = font.material;
41             tm = textGo.AddComponent();
42             tm.font = font;
43             tm.anchor = TextAnchor.MiddleCenter;
44             if (this.CharacterSize > 0)
45             {
46                 tm.characterSize = this.CharacterSize;
47             }
48         }
49     }
File name: Scalable.cs Copy
14  protected virtual void Start() {
15   renderer = GetComponent();
16   origMaterial = GetComponent().material;
17   origColor = origMaterial.GetColor("_Color");
18   origEmission = origMaterial.GetColor("_EmissionColor");
19  }
File name: Scalable.cs Copy
31  public void SetMaterialOriginal() {
32   SetMaterial(origMaterial);
33  }
File name: Scalable.cs Copy
43  public void SetMaterial(Material material) {
44   renderer.material = material;
45  }
File name: Scalable.cs Copy
47  public void SetEmission(Color color) {
48   renderer.material.SetColor("_EmissionColor", color);
49   //DynamicGI.UpdateMaterials(r);
50         //DynamicGI.UpdateEnvironment();
51  }
File name: Scalable.cs Copy
53  public void SetColor(Color color) {
54   renderer.material.SetColor("_Color", color);
55  }
File name: Grid.cs Copy
206  public void SpawnPiece(GridCoords coords, GameObject piece, float yRotation, PlayerType playerType) {
207   Node pieceNode = GetNodeAt(coords.row, coords.col);
208
209   Vector3 pRotation = piece.transform.rotation.eulerAngles;
210   Quaternion newPRotation = Quaternion.Euler(pRotation.x, yRotation, pRotation.z);
211
212   GameObject pieceObject = Instantiate(piece, pieceNode.transform.position + Vector3.up * 1.2f, newPRotation) as GameObject;
213   pieceObject.transform.localScale = Vector3.zero; //for scaling in start from zero
214   Piece pieceScript = pieceObject.GetComponent(typeof(Piece)) as Piece;
215
216   //assign mat and player type
217   Material mat = null;
218   GCPlayer player = null;
219   switch (playerType) {
220    case PlayerType.P1:
221     mat = GameManager.Instance.PieceP1;
222     player = GameManager.Instance.P1;
223     break;
224    case PlayerType.P2:
225     mat = GameManager.Instance.PieceP2;
226     player = GameManager.Instance.P2;
227     break;
228   }
229   pieceObject.GetComponent().material = mat;
230   player.AddPieces(pieceScript);
231   pieceScript.PieceMovement = Creator.CreatePieceMovement(pieceScript.MovementType, player, pieceScript);
232
233   if(pieceScript) //if exists type then scale
234    pieceScript.ScaleIn(Random.Range(0f,1f),Random.Range(1f,2f),piece.transform.localScale);
235
236
237   pieceScript.UpdateNode(pieceNode);
238  }

Download file with original file name:Material

Material 122 lượt xem

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