Project









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

Featured Snippets


File name: PhotonEditor.cs Copy
215     static PhotonEditor()
216     {
217         EditorApplication.projectWindowChanged += EditorUpdate;
218         EditorApplication.hierarchyWindowChanged += EditorUpdate;
219         EditorApplication.playmodeStateChanged += PlaymodeStateChanged;
220         EditorApplication.update += OnUpdate;
221
222         WizardIcon = AssetDatabase.LoadAssetAtPath("Assets/Photon Unity Networking/photoncloud-icon.png", typeof(Texture2D)) as Texture2D;
223
224         // to be used in toolbar, the enum needs conversion to string[] being done here, once.
225         Array enumValues = Enum.GetValues(typeof(CloudRegionCode));
226         CloudServerRegionNames = new string[enumValues.Length];
227         for (int i = 0; i < CloudServerRegionNames.Length; i++)
228         {
229             CloudServerRegionNames[i] = enumValues.GetValue(i).ToString();
230             if (CloudServerRegionNames[i].Equals("none"))
231             {
232                 CloudServerRegionNames[i] = PhotonEditor.CurrentLang.BestRegionLabel;
233             }
234         }
235
236         // detect optional packages
237         PhotonEditor.CheckPunPlus();
238
239     }
File name: PhotonViewInspector.cs Copy
21     public override void OnInspectorGUI()
22     {
23         #if UNITY_3_5
24         EditorGUIUtility.LookLikeInspector();
25         #endif
26         //EditorGUI.indentLevel = 1;
27
28         m_Target = (PhotonView)this.target;
29         bool isProjectPrefab = EditorUtility.IsPersistent(m_Target.gameObject);
30
31         if( m_Target.ObservedComponents == null )
32         {
33             m_Target.ObservedComponents = new System.Collections.Generic.List();
34         }
35
36         if( m_Target.ObservedComponents.Count == 0 )
37         {
38             m_Target.ObservedComponents.Add( null );
39         }
40
41         EditorGUILayout.BeginHorizontal();
42         // Owner
43         if (isProjectPrefab)
44         {
45             EditorGUILayout.LabelField("Owner:", "Set at runtime");
46         }
47         else if (m_Target.isSceneView)
48         {
49             EditorGUILayout.LabelField("Owner", "Scene");
50         }
51         else
52         {
53             PhotonPlayer owner = m_Target.owner;
54             string ownerInfo = (owner != null) ? owner.name : "";
55
56             if (string.IsNullOrEmpty(ownerInfo))
57             {
58                 ownerInfo = "";
59             }
60
61             EditorGUILayout.LabelField("Owner", "[" + m_Target.ownerId + "] " + ownerInfo);
62         }
63
64         // ownership requests
65         EditorGUI.BeginDisabledGroup(Application.isPlaying);
66         m_Target.ownershipTransfer = (OwnershipOption)EditorGUILayout.EnumPopup(m_Target.ownershipTransfer, GUILayout.Width(100));
67         EditorGUI.EndDisabledGroup();
68
69         EditorGUILayout.EndHorizontal();
70
71
72         // View ID
73         if (isProjectPrefab)
74         {
75             EditorGUILayout.LabelField("View ID", "Set at runtime");
76         }
77         else if (EditorApplication.isPlaying)
78         {
79             EditorGUILayout.LabelField("View ID", m_Target.viewID.ToString());
80         }
81         else
82         {
83             int idValue = EditorGUILayout.IntField("View ID [1.."+(PhotonNetwork.MAX_VIEW_IDS-1)+"]", m_Target.viewID);
84             m_Target.viewID = idValue;
85         }
86
87
88
89         // Locally Controlled
90         if (EditorApplication.isPlaying)
91         {
92             string masterClientHint = PhotonNetwork.isMasterClient ? "(master)" : "";
93             EditorGUILayout.Toggle("Controlled locally: " + masterClientHint, m_Target.isMine);
94         }
95
96
97
98         //DrawOldObservedItem();
99         ConvertOldObservedItemToObservedList();
100
101
102         // ViewSynchronization (reliability)
103         if (m_Target.synchronization == ViewSynchronization.Off)
104         {
105             GUI.color = Color.grey;
106         }
107
108         EditorGUILayout.PropertyField( serializedObject.FindProperty( "synchronization" ), new GUIContent( "Observe option:" ) );
109
110         if( m_Target.synchronization != ViewSynchronization.Off &&
111             m_Target.ObservedComponents.FindAll( item => item != null ).Count == 0 )
112         {
113             GUILayout.BeginVertical( GUI.skin.box );
114             GUILayout.Label( "Warning", EditorStyles.boldLabel );
115             GUILayout.Label( "Setting the synchronization option only makes sense if you observe something." );
116             GUILayout.EndVertical();
117         }
118
119         /*ViewSynchronization vsValue = (ViewSynchronization)EditorGUILayout.EnumPopup("Observe option:", m_Target.synchronization);
120         if (vsValue != m_Target.synchronization)
121         {
122             m_Target.synchronization = vsValue;
123             if (m_Target.synchronization != ViewSynchronization.Off && m_Target.observed == null)
124             {
125                 EditorUtility.DisplayDialog("Warning", "Setting the synchronization option only makes sense if you observe something.", "OK, I will fix it.");
126             }
127         }*/
128
129         DrawSpecificTypeSerializationOptions();
130
131         GUI.color = Color.white;
132         DrawObservedComponentsList();
133
134         // Cleanup: save and fix look
135         if (GUI.changed)
136         {
137             EditorUtility.SetDirty(m_Target);
138             PhotonViewHandler.HierarchyChange(); // TODO: check if needed
139         }
140
141         GUI.color = Color.white;
142         EditorGUIUtility.LookLikeControls();
143     }
File name: VSCode.cs Copy
106         {
107             get
108             {
109                 return EditorPrefs.GetBool("VSCode_Enabled", false);
110             }
111             set
112             {
113                 // When turning the plugin on, we should remove all the previous project files
114                 if (!Enabled && value)
115                 {
116                     ClearProjectFiles();
117                 }
118                 EditorPrefs.SetBool("VSCode_Enabled", value);
119             }
120         }
File name: VSCode.cs Copy
271         {
272             get
273             {
274                 return ProjectPath + System.IO.Path.DirectorySeparatorChar + ".vscode";
275             }
276         }
File name: VSCode.cs Copy
357         public static void UpdateSolution()
358         {
359             // No need to process if we are not enabled
360             if (!VSCode.Enabled)
361             {
362                 return;
363             }
364
365             if (VSCode.Debug)
366             {
367                 UnityEngine.Debug.Log("[VSCode] Updating Solution & Project Files");
368             }
369
370             var currentDirectory = Directory.GetCurrentDirectory();
371             var solutionFiles = Directory.GetFiles(currentDirectory, "*.sln");
372             var projectFiles = Directory.GetFiles(currentDirectory, "*.csproj");
373
374             foreach (var filePath in solutionFiles)
375             {
376                 string content = File.ReadAllText(filePath);
377                 content = ScrubSolutionContent(content);
378
379                 File.WriteAllText(filePath, content);
380
381                 ScrubFile(filePath);
382             }
383
384             foreach (var filePath in projectFiles)
385             {
386                 string content = File.ReadAllText(filePath);
387                 content = ScrubProjectContent(content);
388
389                 File.WriteAllText(filePath, content);
390
391                 ScrubFile(filePath);
392             }
393
394         }
File name: VSCode.cs Copy
1248         static void WriteWorkspaceSettings()
1249         {
1250             if (Debug)
1251             {
1252                 UnityEngine.Debug.Log("[VSCode] Workspace Settings Written");
1253             }
1254
1255             if (!Directory.Exists(VSCode.SettingsFolder))
1256             {
1257                 System.IO.Directory.CreateDirectory(VSCode.SettingsFolder);
1258             }
1259
1260             string exclusions =
1261                 // Associations
1262                 "{\n" +
1263                 "\t\"files.associations\":\n" +
1264                 "\t{\n" +
1265                 "\t\t\"*.bjs\":\"javascript\",\n" +
1266                 "\t\t\"*.javascript\":\"javascript\"\n" +
1267                 "\t},\n" +
1268                 "\t\"files.exclude\":\n" +
1269                 "\t{\n" +
1270                 // Hidden Files
1271                 "\t\t\"**/.DS_Store\":true,\n" +
1272                 "\t\t\"**/.git\":true,\n" +
1273                 "\t\t\"**/.gitignore\":true,\n" +
1274                 "\t\t\"**/.gitattributes\":true,\n" +
1275                 "\t\t\"**/.gitmodules\":true,\n" +
1276                 "\t\t\"**/.svn\":true,\n" +
1277
1278
1279                 // Project Files
1280                 "\t\t\"**/*.booproj\":true,\n" +
1281                 "\t\t\"**/*.pidb\":true,\n" +
1282                 "\t\t\"**/*.suo\":true,\n" +
1283                 "\t\t\"**/*.user\":true,\n" +
1284                 "\t\t\"**/*.userprefs\":true,\n" +
1285                 "\t\t\"**/*.unityproj\":true,\n" +
1286                 "\t\t\"**/*.dll\":true,\n" +
1287                 "\t\t\"**/*.exe\":true,\n" +
1288
1289                 // Media Files
1290                 "\t\t\"**/*.pdf\":true,\n" +
1291
1292                 // Video
1293                 "\t\t\"**/*.mp4\":true,\n" +
1294
1295                 // Audio
1296                 "\t\t\"**/*.mid\":true,\n" +
1297                 "\t\t\"**/*.midi\":true,\n" +
1298                 "\t\t\"**/*.wav\":true,\n" +
1299                 "\t\t\"**/*.mp3\":true,\n" +
1300                 "\t\t\"**/*.ogg\":true,\n" +
1301
1302                 // Textures
1303                 "\t\t\"**/*.gif\":true,\n" +
1304                 "\t\t\"**/*.ico\":true,\n" +
1305                 "\t\t\"**/*.jpg\":true,\n" +
1306                 "\t\t\"**/*.jpeg\":true,\n" +
1307                 "\t\t\"**/*.png\":true,\n" +
1308                 "\t\t\"**/*.psd\":true,\n" +
1309                 "\t\t\"**/*.tga\":true,\n" +
1310                 "\t\t\"**/*.tif\":true,\n" +
1311                 "\t\t\"**/*.tiff\":true,\n" +
1312                 "\t\t\"**/*.hdr\":true,\n" +
1313                 "\t\t\"**/*.exr\":true,\n" +
1314
1315                 // Models
1316                 "\t\t\"**/*.3ds\":true,\n" +
1317                 "\t\t\"**/*.3DS\":true,\n" +
1318                 "\t\t\"**/*.fbx\":true,\n" +
1319                 "\t\t\"**/*.FBX\":true,\n" +
1320                 "\t\t\"**/*.lxo\":true,\n" +
1321                 "\t\t\"**/*.LXO\":true,\n" +
1322                 "\t\t\"**/*.ma\":true,\n" +
1323                 "\t\t\"**/*.MA\":true,\n" +
1324                 "\t\t\"**/*.obj\":true,\n" +
1325                 "\t\t\"**/*.OBJ\":true,\n" +
1326
1327                 // Unity File Types
1328                 "\t\t\"**/*.asset\":true,\n" +
1329                 "\t\t\"**/*.cubemap\":true,\n" +
1330                 "\t\t\"**/*.flare\":true,\n" +
1331                 "\t\t\"**/*.mat\":true,\n" +
1332                 "\t\t\"**/*.meta\":true,\n" +
1333                 "\t\t\"**/*.prefab\":true,\n" +
1334                 "\t\t\"**/*.unity\":true,\n" +
1335
1336                 // Folders
1337                 "\t\t\"build/\":true,\n" +
1338                 "\t\t\"Build/\":true,\n" +
1339                 "\t\t\"Library/\":true,\n" +
1340                 "\t\t\"library/\":true,\n" +
1341                 "\t\t\"obj/\":true,\n" +
1342                 "\t\t\"Obj/\":true,\n" +
1343                 "\t\t\"ProjectSettings/\":true,\r" +
1344                 "\t\t\"temp/\":true,\n" +
1345                 "\t\t\"Temp/\":true\n" +
1346                 "\t}\n" +
1347                 "}";
1348
1349             // Dont like the replace but it fixes the issue with the JSON
1350             File.WriteAllText(VSCode.SettingsPath, exclusions);
1351         }
File name: VSCode.cs Copy
1366         private static void OnGeneratedCSProjectFiles()
1367         {
1368             // Force execution of VSCode update
1369             VSCode.UpdateSolution();
1370         }
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: MenuScript.cs Copy
21  void OnGUI() {
22   if (this.gameScript.gameView == "menu") {
23    this.gameScript.mainCamera.transform.eulerAngles = new Vector3 (180, 23, 0);
24    this.gameScript.gameLight.intensity = 0;
25
26    //set the sizes appropriately
27    GUI.skin = this.gameScript.currentGUISkin;
28
29    GUIStyle playButtonStyle = new GUIStyle(currentGUISkin.GetStyle("Button"));
30    playButtonStyle.fontSize = Mathf.CeilToInt(Screen.height * 0.10F);
31    playButtonStyle.fontStyle = FontStyle.Italic;
32
33
34    GUIStyle menuButtonStyle = new GUIStyle(currentGUISkin.GetStyle("Button"));
35    menuButtonStyle.fontSize = Mathf.CeilToInt(Screen.height * 0.06F);
36
37
38    GUIStyle titleLabelStyle = new GUIStyle(currentGUISkin.GetStyle("TitleLabel"));
39    titleLabelStyle.fontSize = Mathf.CeilToInt(Screen.height * 0.13F);
40
41    GUI.Label (new Rect (0, 0, Screen.width, Screen.height * 0.06F), "2048 - 3D", titleLabelStyle);
42
43
44    GUI.Label (new Rect (0, Screen.height * 0.15F, Screen.width, Screen.height * 0.06F), "");
45
46
47    if (GUI.Button(new Rect(Screen.width * 0.20f, Screen.height * 0.25f, Screen.width * 0.60F, Screen.height * 0.10F),"Options", menuButtonStyle)) {
48     this.gameScript.gameView = "options";
49    }
50    if (GUI.Button(new Rect(Screen.width * 0.20f, Screen.height * 0.40f, Screen.width * 0.60F, Screen.height * 0.10F),"Instructions", menuButtonStyle)) {
51     this.gameScript.gameView = "instructions";
52    }
53    if (GUI.Button(new Rect(Screen.width * 0.20f, Screen.height * 0.55F, Screen.width * 0.60F, Screen.height * 0.10F),"Exit", menuButtonStyle)) {
54     Application.Quit();
55    }
56
57    if (GUI.Button(new Rect(Screen.width * .20f, Screen.height * 0.70F, Screen.width * 0.60F, Screen.height * 0.15F),"Play!",playButtonStyle)) {
58     this.gameScript.gameView = "game";
59    }
60
61    GUI.Label (new Rect (0, Screen.height * 0.94F, Screen.width, Screen.height * 0.06F), " 2018 - Brought To You By code-projects.org");
62
63   }
64  }
File name: ScmlPostProcessor.cs Copy
44             string[] movedFromAssetPaths)
45         {
46             //Reimport everything if the importer itself has been modified or added
47             //.Union(deletedAssets).Union(movedAssets).Union(movedFromAssetPaths)
48             bool shouldReimportAll = importedAssets.Where(s => s.EndsWith(ASSET_PATH)).FirstOrDefault() != null;
49
50             //If we should reimport all SCML files, replace the passed in array with ALL scml project files
51             if(shouldReimportAll)
52             {
53                 Debug.Log("Reimporting all SCML files in project...");
54                 importedAssets = AssetDatabase.GetAllAssetPaths().Where(assetPath => assetPath.EndsWith(".scml")).ToArray();
55             }
56
57             foreach (var path in importedAssets)
58             {
59                 if (!path.EndsWith(".scml"))
60                     continue;
61
62                 ImportScml(path);
63             }
64         }

Download file with original file name:Project

Project 103 lượt xem

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