Creates









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

Featured Snippets


File name: HubGui.cs Copy
28     void OnGUI()
29     {
30         GUI.skin = this.Skin;
31         GUILayout.Space(10);
32
33         GUILayout.BeginHorizontal();
34         GUILayout.Space(10);
35         scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Width(320));
36
37         GUILayout.Label("Basics", m_Headline);
38         if (GUILayout.Button("Demo Boxes", GUILayout.Width(280)))
39         {
40             demoDescription = "Demo Boxes\n\nUses ConnectAndJoinRandom script.\n(joins a random room or creates one)\n\nInstantiates simple prefab.\nSynchronizes positions without smoothing.";
41             demoBtn = new DemoBtn() { Text = "Start", Link = "DemoBoxes-Scene" };
42         }
43         if (GUILayout.Button("Demo Worker", GUILayout.Width(280)))
44         {
45             demoDescription = "Demo Worker\n\nJoins the default lobby and shows existing rooms.\nLets you create or join a room.\nInstantiates an animated character.\nSynchronizes position and animation state of character with smoothing.\nImplements simple in-room Chat via RPC calls.";
46             demoBtn = new DemoBtn() { Text = "Start", Link = "DemoWorker-Scene" };
47         }
48         if (GUILayout.Button("Movement Smoothing", GUILayout.Width(280)))
49         {
50             demoDescription = "Movement Smoothing\n\nUses ConnectAndJoinRandom script.\nShows several basic ways to update positions of remote objects.";
51             demoBtn = new DemoBtn() { Text = "Start", Link = "DemoSynchronization-Scene" };
52         }
53
54         GUILayout.Label("Advanced", m_Headline);
55         if (GUILayout.Button("Ownership Transfer", GUILayout.Width(280)))
56         {
57             demoDescription = "Ownership Transfer\n\nShows how to transfer the ownership of a PhotonView.\nThe owner will send position updates of the GameObject.\nTransfer can be edited per PhotonView and set to Fixed (no transfer), Request (owner has to agree) or Takeover (owner can't object).";
58             this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoChangeOwner-Scene" };
59             this.webLink = new DemoBtn();
60         }
61         if (GUILayout.Button("Pickup, Teams, Scores", GUILayout.Width(280)))
62         {
63             demoDescription = "Pickup, Teams, Scores\n\nUses ConnectAndJoinRandom script.\nImplements item pickup with RPCs.\nUses Custom Properties for Teams.\nCounts score per player and team.\nUses PhotonPlayer extension methods for easy Custom Property access.";
64             this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoPickup-Scene" };
65             this.webLink = new DemoBtn();
66         }
67
68         GUILayout.Label("Feature Demos", m_Headline);
69         if (GUILayout.Button("Chat", GUILayout.Width(280)))
70         {
71             demoDescription = "Chat\n\nUses the Chat API (now part of PUN).\nSimple UI.\nYou can enter any User ID.\nAutomatically subscribes some channels.\nAllows simple commands via text.\n\nRequires configuration of Chat App ID in scene.";
72             this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoChat-Scene" };
73             this.webLink = new DemoBtn();
74         }
75         if (GUILayout.Button("RPG Movement", GUILayout.Width(280)))
76         {
77             demoDescription = "RPG Movement\n\nDemonstrates how to use the PhotonTransformView component to synchronize position updates smoothly using inter- and extrapolation.\n\nThis demo also shows how to setup a Mecanim Animator to update animations automatically based on received position updates (without sending explicit animation updates).";
78             this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoRPGMovement-Scene" };
79             this.webLink = new DemoBtn();
80         }
81         if (GUILayout.Button("Mecanim Animations", GUILayout.Width(280)))
82         {
83             demoDescription = "Mecanim Animations\n\nThis demo shows how to use the PhotonAnimatorView component to easily synchronize Mecanim animations.\n\nIt also demonstrates another feature of the PhotonTransformView component which gives you more control how position updates are inter-/extrapolated by telling the component how fast the object moves and turns using SetSynchronizedValues().";
84             this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoMecanim-Scene" };
85             this.webLink = new DemoBtn();
86         }
87         if (GUILayout.Button("2D Game", GUILayout.Width(280)))
88         {
89             demoDescription = "2D Game Demo\n\nSynchronizes animations, positions and physics in a 2D scene.";
90             this.demoBtn = new DemoBtn() { Text = "Start", Link = "Demo2DJumpAndRunWithPhysics-Scene" };
91             this.webLink = new DemoBtn();
92         }
93         if (GUILayout.Button("Friends & Authentication", GUILayout.Width(280)))
94         {
95             demoDescription = "Friends & Authentication\n\nShows connect with or without (server-side) authentication.\n\nAuthentication requires minor server-side setup (in Dashboard).\n\nOnce connected, you can find (made up) friends.\nJoin a room just to see how that gets visible in friends list.";
96             this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoFriends-Scene" };
97             this.webLink = new DemoBtn();
98         }
99
100         GUILayout.Label("Tutorial", m_Headline);
101         if (GUILayout.Button("Marco Polo Tutorial", GUILayout.Width(280)))
102         {
103             demoDescription = "Marco Polo Tutorial\n\nFinal result you could get when you do the Marco Polo Tutorial.\nSlightly modified to be more compatible with this package.";
104             this.demoBtn = new DemoBtn() { Text = "Start", Link = "MarcoPolo-Scene" };
105             this.webLink = new DemoBtn() { Text = "Open Tutorial (www)", Link = "http://tinyurl.com/nmylf44" };
106         }
107         GUILayout.EndScrollView();
108
109         GUILayout.BeginVertical(GUILayout.Width(Screen.width - 345));
110         GUILayout.Label(demoDescription);
111         GUILayout.Space(10);
112         if (!string.IsNullOrEmpty(this.demoBtn.Text))
113         {
114             if (GUILayout.Button(this.demoBtn.Text))
115             {
116                 Application.LoadLevel(this.demoBtn.Link);
117             }
118         }
119         if (!string.IsNullOrEmpty(this.webLink.Text))
120         {
121             if (GUILayout.Button(this.webLink.Text))
122             {
123                 Application.OpenURL(this.webLink.Link);
124             }
125         }
126         GUILayout.EndVertical();
127
128
129         GUILayout.EndHorizontal();
130     }
File name: ResultLayer.cs Copy
79         private void createGUI()
80         {
81             for (int i = 0; i < 3; i++)
82             {
83                 if (i < star)
84                 {
85                     // stars[i].GetComponent().sprite = starSprite;
86                     int temp = i;
87                     stars[temp].GetComponent().addAction(new ActionSequence(
88                         new ActionDelay(0.4f + 0.6f * temp),
89                         new ActionRunnable(delegate()
90                     {
91                         stars[temp].GetComponent().sprite = starSprite;
92
93                         createStars(stars[temp].transform.localPosition, temp);
94                         if (temp == star - 1)
95                         {
96                             showButtons(true);
97                         }
98                     })
99                         ));
100                 }
101                 else
102                 {
103                     showButtons(false);
104                 }
105             }
106         }
File name: ResultLayer.cs Copy
129         private void createStars(Vector3 position, int starIndex)
130         {
131             for (int i = 0; i < 20; i++)
132             {
133                 GameObject starObject = new GameObject("StarFly");
134                 starObject.layer = LayerMask.NameToLayer("GUI");
135                 starObject.transform.parent = gameObject.transform;
136                 starObject.transform.localPosition = new Vector3(position.x, position.y, -3);
137                 starObject.AddComponent().sprite = starSprite;
138                 starObject.GetComponent().sortingLayerName = "GUI";
139                 starObject.transform.localScale = new Vector3(0.5f, 0.5f, starObject.transform.localScale.z);
140
141                 starObject.AddComponent().addAction(new ActionParallel(
142                     new ActionRotateBy(720, 2),
143                     new ActionScaleTo(0, 0, 1.5f)
144                     ));
145
146                 if (starIndex == 0)
147                 {
148                     starObject.AddComponent().setBezier(-1,
149                         new Vector2(position.x, position.y),
150                         new Vector2(position.x, Random.Range(1f, 2f)),
151                         new Vector2(position.x - Random.Range(2f, 3f), Random.Range(1f, 2f)),
152                         new Vector2(position.x - Random.Range(2f, 5.5f), Random.Range(-2f, -1f))
153                         );
154                 }
155                 else if (starIndex == 1)
156                 {
157                     starObject.AddComponent().setBezier(-1,
158                         new Vector2(position.x, position.y),
159                         new Vector2(position.x, Random.Range(1f, 2f)),
160                         new Vector2(Random.Range(-1f, 1f), Random.Range(1f, 2f)),
161                         new Vector2(Random.Range(-2f, 2f), Random.Range(-4f, -2f))
162                         );
163                 }
164                 else if (starIndex == 2)
165                 {
166                     starObject.AddComponent().setBezier(-1,
167                         new Vector2(position.x, position.y),
168                         new Vector2(position.x, Random.Range(1f, 2f)),
169                         new Vector2(position.x + Random.Range(2f, 3f), Random.Range(1f, 2f)),
170                         new Vector2(position.x + Random.Range(2f, 5.5f), Random.Range(-4f, -2f))
171                         );
172                 }
173                 Destroy(starObject, 2);
174             }
175         }
File name: Animal.cs Copy
82         private void createShadow()
83         {
84             if (animalIndex != 0) return;
85             shadowCreateTime += Time.deltaTime;
86             if (shadowCreateTime >= 0.05f)
87             {
88                 shadowCreateTime = 0;
89                 GameObject shadowObject = new GameObject("Shadow");
90                 shadowObject.transform.parent = gameScreen.shadowLayer.transform;
91                 shadowObject.layer = LayerMask.NameToLayer("AnimalStand");
92                 shadowObject.transform.localPosition = transform.localPosition + new Vector3(0, 0.3f, 0);
93                 shadowObject.AddComponent().sprite = shadowSprite;
94                 shadowObject.GetComponent().sortingLayerName = "MapObject";
95                 shadowObject.GetComponent().color = new Color(1, 1, 1, 0.8f);
96                 shadowObject.AddComponent().addAction(new ActionSequence(
97                     new ActionColorTo(0, 0, 0, 0, 0.5f),
98                     new ActionRunnable(delegate ()
99                 {
100                     Destroy(shadowObject);
101                 })
102                 ));
103             }
104         }
File name: Animal.cs Copy
261         private void UpdateAnimal()
262         {
263             SetVelocity(state);
264             switch (state)
265             {
266                 case RUN:
267                 //GetComponent().velocity = new Vector2(speedX, speedY);
268                 //break;
269                 case JUMP:
270                     animalBody.velocity = new Vector2(speedX, speedY);
271                     state = JUMPING;
272                     break;
273                 case JUMPING:
274                     break;
275             }
276             if (isBooster)
277             {
278                 boosterTime -= Time.deltaTime;
279                 if (boosterTime <= 0)
280                 {
281                     isBooster = false;
282                 }
283                 createShadow();
284             }
285             else if (isSprings)
286             {
287                 createShadow();
288             }
289
290             if (isRevival)
291             {
292                 revivalTime -= Time.deltaTime;
293                 if (revivalTime <= 0)
294                 {
295                     revival();
296                 }
297             }
298         }
File name: GameScreen.cs Copy
150         private void setupMap(GameObject mObject)
151         {
152             GameObject markGounds = new GameObject("MarkGrounds");
153             markGounds.transform.parent = mObject.transform;
154             markGounds.transform.localScale = new Vector3(1, 1, 1);
155             markGounds.transform.localPosition = new Vector3(0, 0, 0);
156
157             for (int i = 0; i < mObject.transform.childCount; i++)
158             {
159                 Transform childTransform = mObject.transform.GetChild(i);
160                 string childname = childTransform.gameObject.name;
161                 if (childname == MapObjectNames.MarkObject)
162                 {
163                     createMarkObjects(childTransform);
164                 }
165                 else if (childname == MapObjectNames.BoostObject)
166                 {
167                     createBoosterObjects(childTransform);
168                 }
169                 else if (childname == MapObjectNames.SpringsObject)
170                 {
171                     createSpringsObjects(childTransform);
172                 }
173                 else if (childname == MapObjectNames.HoleObject)
174                 {
175                     createHoles(childTransform);
176                 }
177                 else if (childname == MapObjectNames.Coin)
178                 {
179                     createCoins(childTransform);
180                 }
181                 else if (childname == MapObjectNames.SkillObject)
182                 {
183                     createSkillRandoms(childTransform);
184                 }
185                 else if (childname == MapObjectNames.RevivalObject)
186                 {
187                     createRevivalObjects(childTransform);
188                 }
189                 else if (childname == MapObjectNames.GroundObject)
190                 {
191                     createGrounds(childTransform, markGounds.transform);
192                 }
193                 else if (childname == MapObjectNames.FinishObject)
194                 {
195                     createFinishObject(childTransform);
196                 }
197             }
198
199             createDeadLine();
200         }
File name: GameScreen.cs Copy
235         private void createSpringsObjects(Transform parentTransform)
236         {
237             for (int i = 0; i < parentTransform.childCount; i++)
238             {
239                 GameObject springsObject = (GameObject)Instantiate(Resources.Load("Springs"));
240                 GameObject c = parentTransform.GetChild(i).gameObject;
241                 springsObject.transform.position = c.transform.position;
242                 springsObject.transform.parent = springsLayer.transform;
243                 springsObject.transform.position -= new Vector3(-0.2f, 0.3f, 0);
244                 springsObject.name = MapObjectNames.SpringsObject;
245                 Destroy(c);
246             }
247         }
File name: GameScreen.cs Copy
277         private void createSkillRandoms(Transform parentTransform)
278         {
279             for (int i = 0; i < parentTransform.childCount; i++)
280             {
281                 GameObject skillObject = (GameObject)Instantiate(Resources.Load("SkillRandom"));
282                 skillObject.name = MapObjectNames.SkillObject;
283                 GameObject c = parentTransform.GetChild(i).gameObject;
284                 skillObject.transform.position = c.transform.position;
285                 skillObject.transform.parent = skillRandomLayer.transform;
286                 skillObject.transform.position -= new Vector3(-0.2f, 0.2f, 0);
287
288                 skillObject.AddComponent().skillType = SkillRandom.getSkillType(skills[Random.Range(0, skills.Length)]);
289                // Debug.Log(skillObject.GetComponent().skillType.ToString());
290
291                 Destroy(c);
292             }
293         }

Creates 142 lượt xem

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