GetColor









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

Featured Snippets


File name: DemoOwnershipGui.cs Copy
23     public void OnGUI()
24     {
25         GUI.skin = this.Skin;
26         GUILayout.BeginArea(new Rect(Screen.width - 200, 0, 200, Screen.height));
27         {
28             string label = TransferOwnershipOnRequest ? "passing objects" : "rejecting to pass";
29             if (GUILayout.Button(label))
30             {
31                 this.TransferOwnershipOnRequest = !this.TransferOwnershipOnRequest;
32             }
33         }
34         GUILayout.EndArea();
35
36
37
38         if (PhotonNetwork.inRoom)
39         {
40             int playerNr = PhotonNetwork.player.ID;
41             string playerIsMaster = PhotonNetwork.player.isMasterClient ? "(master) " : "";
42             string playerColor = PlayerVariables.GetColorName(PhotonNetwork.player.ID);
43             GUILayout.Label(string.Format("player {0}, {1} {2}(you)", playerNr, playerColor, playerIsMaster));
44
45             foreach (PhotonPlayer otherPlayer in PhotonNetwork.otherPlayers)
46             {
47                 playerNr = otherPlayer.ID;
48                 playerIsMaster = otherPlayer.isMasterClient ? "(master)" : "";
49                 playerColor = PlayerVariables.GetColorName(otherPlayer.ID);
50                 GUILayout.Label(string.Format("player {0}, {1} {2}", playerNr, playerColor, playerIsMaster));
51             }
52
53             if (PhotonNetwork.inRoom && PhotonNetwork.otherPlayers.Length == 0)
54             {
55                 GUILayout.Label("Join more clients to switch object-control.");
56             }
57         }
58         else
59         {
60             GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
61         }
62     }
File name: PlayerVariables.cs Copy
9     public static Color GetColor(int playerId)
10     {
11         if (playerId <= 0)
12         {
13             return Color.white;
14         }
15         return playerColors[playerId%playerColors.Length];
16     }
File name: PlayerVariables.cs Copy
18     public static string GetColorName(int playerId)
19     {
20         if (playerId <= 0)
21         {
22             return "none";
23         }
24         return playerColorNames[playerId%playerColors.Length];
25     }
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: 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: BlockScript.cs Copy
94  public void setBlockNumber(int blockNumber) {
95   this.blockNumber = blockNumber;
96   TextMesh textMesh = this.GetComponentInChildren();
97   Material blockTextMaterial = gameObject.transform.Find ("BlockText").gameObject.GetComponent().material;
98   MeshRenderer cube = gameObject.GetComponentInChildren();
99   Color cubeColor = cube.GetComponent().material.color;
100
101   //block doesn't exits
102   if(blockNumber == -2) {
103    cube.GetComponent().enabled = false;
104    textMesh.text = "";
105   }
106   //block is empty
107   else if (blockNumber == -1 ) {
108    cube.GetComponent().enabled = false;
109    cube.GetComponent().material.color = new Color(1, 1, 1, 0.2f);
110    textMesh.text = "";
111   }
112   //block has a value
113   else {
114    cube.GetComponent().enabled = true;
115    cube.material.color = this.getColor (blockNumber);
116    blockTextMaterial.SetColor ("_Color", new Color(1,1,1));
117    if(blockNumber == 0) blockTextMaterial.SetColor ("_Color", new Color(0.8f,0.8f,1));
118    textMesh.text = blockNumber.ToString();
119    transform.position = this.originalPosition;
120   }
121
122  }
File name: BlockScript.cs Copy
124  private Color getColor(int num) {
125   if (num == -2) return HexToColor ("000000");
126   if (num == 0) return HexToColor ("000055");
127   if (num == 2) return HexToColor ("3333cc");
128   if (num == 4) return HexToColor ("0099aa");
129   if (num == 8) return HexToColor ("00ff99");
130   if (num == 16) return HexToColor ("00ff00");
131   if (num == 32) return HexToColor ("99ff00");
132   if (num == 64) return HexToColor ("bbff55");
133   if (num == 128) return HexToColor ("ffff00");
134   if (num == 256) return HexToColor ("ff9933");
135   if (num == 512) return HexToColor ("ff6600");
136   if (num == 1024) return HexToColor ("ff5050");
137   if (num == 2048) return HexToColor ("ff0000");
138   if (num == 4096) return HexToColor ("cc0066");
139   if (num == 8192) return HexToColor ("990099");
140   if (num == 16284) return HexToColor ("9999ff");
141   if (num == 32568) return HexToColor ("ffffff");
142   return new Color (0.5f, 0.5f, 0.5f);
143
144
145  }

GetColor 132 lượt xem

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