Free
How do I use Free
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: PhotonEditor.cs
Copy
727 protected virtual void OnGuiSetupSelfhosting()
728 {
729 GUILayout.Label(CurrentLang.YourPhotonServerLabel);
730
731 this.photonAddress = EditorGUILayout.TextField(CurrentLang.AddressIPLabel, this.photonAddress);
732 this.photonPort = EditorGUILayout.IntField(CurrentLang.PortLabel, this.photonPort);
733 this.photonProtocol = (ConnectionProtocol)EditorGUILayout.EnumPopup("Protocol", this.photonProtocol);
734 EditorGUILayout.Separator();
735
736 GUILayout.BeginHorizontal();
737 if (GUILayout.Button(CurrentLang.CancelButton))
738 {
739 GUIUtility.keyboardControl = 0;
740 this.ReApplySettingsToWindow();
741 }
742
743 if (GUILayout.Button(CurrentLang.SaveButton))
744 {
745 GUIUtility.keyboardControl = 0;
746
747 PhotonEditor.Current.UseMyServer(this.photonAddress, this.photonPort, null);
748 PhotonEditor.Current.Protocol = this.photonProtocol;
749 PhotonEditor.Save();
750
751 Inspect();
752 EditorUtility.DisplayDialog(CurrentLang.SettingsSavedTitle, CurrentLang.SettingsSavedMessage, CurrentLang.OkButton);
753 }
754
755 GUILayout.EndHorizontal();
756
757
758 GUILayout.Space(20);
759
760
761 // license
762 GUILayout.BeginHorizontal();
763 GUILayout.Label(CurrentLang.LicensesLabel, EditorStyles.boldLabel, GUILayout.Width(100));
764
765 if (GUILayout.Button(new GUIContent(CurrentLang.LicenseDownloadText, CurrentLang.LicenseDownloadTooltip)))
766 {
767 EditorUtility.OpenWithDefaultApp(UrlFreeLicense);
768 }
769
770 GUILayout.EndHorizontal();
771
772
773 GUILayout.Space(20);
774
775
776 GUILayout.Label(CurrentLang.TryPhotonAppLabel);
777
778 if (GUILayout.Button(CurrentLang.GetCloudAppButton))
779 {
780 this.cloudAppId = string.Empty;
781 this.photonSetupState = PhotonSetupStates.RegisterForPhotonCloud;
782 }
783
784 EditorGUILayout.Separator();
785 GUILayout.Label(CurrentLang.OwnHostCloudCompareLabel);
786 if (GUILayout.Button(CurrentLang.ComparisonPageButton))
787 {
788 Application.OpenURL(UrlCompare);
789 }
790 }
File name: PhotonNetwork.cs
Copy
2150 public static GameObject InstantiateSceneObject(string prefabName, Vector3 position, Quaternion rotation, int group, object[] data)
2151 {
2152 if (!connected || (InstantiateInRoomOnly && !inRoom))
2153 {
2154 Debug.LogError("Failed to InstantiateSceneObject prefab: " + prefabName + ". Client should be in a room. Current connectionStateDetailed: " + PhotonNetwork.connectionStateDetailed);
2155 return null;
2156 }
2157
2158 if (!isMasterClient)
2159 {
2160 Debug.LogError("Failed to InstantiateSceneObject prefab: " + prefabName + ". Client is not the MasterClient in this room.");
2161 return null;
2162 }
2163
2164 GameObject prefabGo;
2165 if (!UsePrefabCache || !PrefabCache.TryGetValue(prefabName, out prefabGo))
2166 {
2167 prefabGo = (GameObject)Resources.Load(prefabName, typeof(GameObject));
2168 if (UsePrefabCache)
2169 {
2170 PrefabCache.Add(prefabName, prefabGo);
2171 }
2172 }
2173
2174 if (prefabGo == null)
2175 {
2176 Debug.LogError("Failed to InstantiateSceneObject prefab: " + prefabName + ". Verify the Prefab is in a Resources folder (and not in a subfolder)");
2177 return null;
2178 }
2179
2180 // a scene object instantiated with network visibility has to contain a PhotonView
2181 if (prefabGo.GetComponent
2182 {
2183 Debug.LogError("Failed to InstantiateSceneObject prefab:" + prefabName + ". Prefab must have a PhotonView component.");
2184 return null;
2185 }
2186
2187 Component[] views = (Component[])prefabGo.GetPhotonViewsInChildren();
2188 int[] viewIDs = AllocateSceneViewIDs(views.Length);
2189
2190 if (viewIDs == null)
2191 {
2192 Debug.LogError("Failed to InstantiateSceneObject prefab: " + prefabName + ". No ViewIDs are free to use. Max is: " + MAX_VIEW_IDS);
2193 return null;
2194 }
2195
2196 // Send to others, create info
2197 Hashtable instantiateEvent = networkingPeer.SendInstantiate(prefabName, position, rotation, group, viewIDs, data, true);
2198
2199 // Instantiate the GO locally (but the same way as if it was done via event). This will also cache the instantiationId
2200 return networkingPeer.DoInstantiate(instantiateEvent, networkingPeer.mLocalActor, prefabGo);
2201 }
File name: KingMovement.cs
Copy
25 public override void ComputeBound() {
26 Node currNode = piece.Node;
27 int origRow = currNode.row;
28 int origCol = currNode.col;
29
30 for (int row = -1; row <= 1; row++) {
31 for (int col = -1; col <= 1; col++) {
32 if (row == 0 && col == 0) continue;
33
34 int newRow = origRow + row;
35 int newCol = origCol + col;
36 ComputeMoveOrEatPiece(grid.GetNodeAt(newRow, newCol));
37 }
38 }
39
40 if (!moved && !didCastling && !player.IsChecked) {
41 //check left
42 int left = 1;
43 bool freeLeft = true;
44 int sign = GetSign();
45 while (true) {
46 int newCol = origCol - left * sign;
47 if (newCol < 0 || newCol >= grid.Cols) break;
48 Node toCheckNode = grid.GetNodeAt(origRow, newCol);
49
50 if (toCheckNode.EmptySpace) {
51 if (Rules.IsGuardedMove(player,piece,toCheckNode)) {
52 freeLeft = false;
53 break;
54 }
55 } else {
56 Piece cPiece = toCheckNode.Piece;
57 if (Rules.IsAlly(cPiece, piece) && cPiece.PieceType == PieceType.SQUARE) {
58 rooks[0] = cPiece;
59 } else {
60 freeLeft = false;
61 }
62 break;
63 }
64
65
66 left++;
67 }
68 if (freeLeft && !rooks[0].IsMoved) {
69 specialNodes[0,0] = grid.GetNodeAt(origRow, origCol - 1 * sign); //for rook
70 specialNodes[0,1] = grid.GetNodeAt(origRow, origCol - 2 * sign); //for king
71 ComputeMovePiece(specialNodes[0,1]);
72 }
73
74 //check right
75 int right = 1;
76 bool freeRight = true;
77 while (true) {
78 int newCol = origCol + right * sign;
79 if (newCol < 0 || newCol >= grid.Cols) break;
80 Node toCheckNode = grid.GetNodeAt(origRow, newCol);
81
82 if (toCheckNode.EmptySpace) {
83 if (Rules.IsGuardedMove(player,piece,toCheckNode)) {
84 freeRight = false;
85 break;
86 }
87 } else {
88 Piece cPiece = toCheckNode.Piece;
89 if (Rules.IsAlly(cPiece, piece) && cPiece.PieceType == PieceType.SQUARE) {
90 rooks[1] = cPiece;
91 } else {
92 freeRight = false;
93 }
94 break;
95 }
96
97
98 right++;
99 }
100 if (freeRight && !rooks[1].IsMoved) {
101 specialNodes[1,0] = grid.GetNodeAt(origRow, origCol + 1 * sign); //for rook
102 specialNodes[1,1] = grid.GetNodeAt(origRow, origCol + 2 * sign); //for king
103 ComputeMovePiece(specialNodes[1,1]);
104 }
105
106 }
107 }
File name: InstructionsScript.cs
Copy
27 void OnGUI() {
28 if (this.gameScript.gameView == "instructions") {
29 GUI.skin = currentGUISkin;
30
31 this.gameScript.mainCamera.transform.eulerAngles = new Vector3 (120, 23, 0);
32
33 GUIStyle labelStyle = new GUIStyle(currentGUISkin.label);
34 labelStyle.alignment = TextAnchor.UpperLeft;
35 GUILayout.Label ("Instructions", "BigLabel");
36
37
38 scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(Screen.width), GUILayout.Height(Mathf.Ceil(Screen.height * .80f)));
39
40 GUILayout.Label ("Object", "Subheader");
41
42 GUILayout.Label (@"The object of 2048-3D is to"
43 + " slide numbered blocks in such a way"
44 + " so that blocks with the same numbers collide"
45 + " and combine into a new block that is twice"
46 + " as much as the originals until"
47 + " the number 2048 is reached.", labelStyle);
48
49 GUILayout.Label ("Moving the Blocks", "Subheader");
50
51 GUILayout.Label (@"You cannot move blocks individually, but must"
52 + " move all blocks simultaneously in the same direction."
53 + " Blocks can move forward, backward, up, down, left"
54 + " and right along the green connectors."
55 + " Simply swipe any part of the screen to move up,"
56 + " down, left or right (keyboard: arrow keys). To move the"
57 + " blocks forward and backward use the"
58 + " big red arrow keys at the bottom of the screen (keyboard: a and z keys)."
59 + " When moving, all blocks that can slide in the chosen direction will move."
60 + " Any block moving toward another block with the same number will collide "
61 + " and form a single block with twice the number as the originals", labelStyle);
62
63
64 GUILayout.Label ("New Blocks", "Subheader");
65
66 GUILayout.Label (@"After each move is"
67 + " made a new block will appear randomly in an empty position."
68 + " This block will have a number of either 2 or 4."
69 + " For an extra challenge, there is a game option you can"
70 + " set so that zeros can also be assinged to a new block."
71 + " Zeros act like any other number in that they can"
72 + " collide with other zeros to make a block twice as much "
73 + " (which is still zero).", labelStyle);
74
75
76
77 GUILayout.Label ("Scoring and Finishing", "Subheader");
78
79 GUILayout.Label(@"For every block collision that occurs you receive"
80 + " the number of points of the newly"
81 + " created block. If after making a move"
82 + " all positions are filled and no new"
83 + " moves are possible, the game ends."
84 + " A separate high score / highest block is kept for each"
85 + " distinct combination of game options", labelStyle);
86
87
88 GUILayout.Label ("Game Layout Options", "Subheader");
89
90 GUILayout.Label (@"When I first made this game there"
91 + " was only one game layout, a 3x3x3 cube."
92 + " After testing it a bit, it was way to easy"
93 + " so the zero option was added."
94 + " It was still way to easy "
95 + " (e.g. you could swipe without even looking and get pretty far)."
96 + " Therefore there are now several diffent game layouts that"
97 + " make the game more challenging and fun.", labelStyle);
98
99 GUILayout.Label ("Game Timer Option", "Subheader");
100
101 GUILayout.Label (@"To give yourself even more of a challenge"
102 + " you can set game options to include a timer."
103 + " If a timer is chosen you have a specific"
104 + " amount of time to combined blocks to make the 64 block."
105 + " If you run out of time the game is over."
106 + " If you reach your target before the timer runs down you will"
107 + " receive additional time to reach the next target."
108 + " The time you received is as follows: \n"
109 + " 64: option time + 5 seconds (because the first one is the hardest!)\n"
110 + " 128: option time\n"
111 + " 256: 2X option time\n"
112 + " 512: 4X option time \n"
113 + " 1024: 8X option time \n"
114 + " you get the idea.", labelStyle);
115
116
117 GUILayout.Label ("Acknowledgements \nand Confessions", "Subheader");
118
119 GUILayout.Label (@"2048-3D is based upon the original" +
120 " 2048 game designed by Gabriele Cirulli " +
121 " \n\n" +
122 " Sound effects by freeSFX http://www.freesfx.co.uk.\n\n" +
123 " This game was designed using the Unity3D game engine.\n\n" +
124 " FOR MORE PROJECTS VISIT:" +
125 " https://code-projects.org/", labelStyle);
126
127
128 foreach (Touch touch in Input.touches) {
129 if (touch.phase == TouchPhase.Moved)
130 {
131 // dragging
132 this.scrollPosition.y += touch.deltaPosition.y;
133 }
134 }
135 GUILayout.EndScrollView();
136
137 if (GUILayout.Button ("Return to Menu")) {
138 this.gameScript.gameView = "menu";
139 }
140 }
141 }
File name: Animal.cs
Copy
52 void Start()
53 {
54 CircleCollider2D animalCollider = gameObject.AddComponent
55 animalCollider.radius = 0.3f;
56 animalCollider.offset = new Vector2(0, 0.27f);
57 animalCollider.sharedMaterial = Resources.Load
58 animalBody = gameObject.AddComponent
59 //animalBody.fixedAngle = true;
60 animalBody.constraints = RigidbodyConstraints2D.FreezeRotation;
61 state = JUMPING;
62 //gameObject.name = "Animal";
63
64 //test
65 //if (animalIndex != 0) gameObject.SetActive(false);
66
67 stepJump = 2;
68 isRunning = true;
69 }
File name: SkillDescription.cs
Copy
8 public SkillDescription(){
9 names = new string[]{"Fire", "Ice", "Shock", "Thunder", "Bomb", "Swap", "Shield", "Speed Up", "Health"};
10 descriptions = new string[,]{
11 {"Attack enemy by fire ball",""},
12 {"Freeze enemy by ice",""},
13 {"Stun enemy by flash",""},
14 {"Attack and stun enemies ", "whom got hit by skill"},
15 {"Attack enemy in character's ", "behind by bomb"},
16 {"Swap position with enemy ", "who got hit by skill"},
17 {"Make a shield to block ", "one attack"},
18 {"Increase character's move ", "speed by 50%"},
19 {"Increase character's", "health by 50%"}
20 };
21 }
Download file with original file name:Free
Free 119 lượt xem
Gõ tìm kiếm nhanh...