Starting









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

Featured Snippets


File name: PhotonConverter.cs Copy
18     public static void RunConversion()
19     {
20         //Ask if user has made a backup.
21         int option = EditorUtility.DisplayDialogComplex("Conversion", "Attempt automatic conversion from Unity Networking to Photon Unity Networking \"PUN\"?", "Yes", "No!", "Pick Script Folder");
22         switch (option)
23         {
24             case 0:
25                 break;
26             case 1:
27                 return;
28             case 2:
29                 PickFolderAndConvertScripts();
30                 return;
31             default:
32                 return;
33         }
34
35         //REAAAALY?
36         bool result = EditorUtility.DisplayDialog("Conversion", "Disclaimer: The code conversion feature is quite crude, but should do it's job well (see the sourcecode). A backup is therefore strongly recommended!", "Yes, I've made a backup: GO", "Abort");
37         if (!result)
38         {
39             return;
40         }
41         Output(EditorApplication.timeSinceStartup + " Started conversion of Unity networking -> Photon");
42
43         //Ask to save current scene (optional)
44         EditorApplication.SaveCurrentSceneIfUserWantsTo();
45
46         EditorUtility.DisplayProgressBar("Converting..", "Starting.", 0);
47
48         //Convert NetworkViews to PhotonViews in Project prefabs
49         //Ask the user if we can move all prefabs to a resources folder
50         bool movePrefabs = EditorUtility.DisplayDialog("Conversion", "Can all prefabs that use a PhotonView be moved to a Resources/ folder? You need this if you use Network.Instantiate.", "Yes", "No");
51
52
53         string[] prefabs = Directory.GetFiles("Assets/", "*.prefab", SearchOption.AllDirectories);
54         foreach (string prefab in prefabs)
55         {
56             EditorUtility.DisplayProgressBar("Converting..", "Object:" + prefab, 0.6f);
57
58             Object[] objs = (Object[])AssetDatabase.LoadAllAssetsAtPath(prefab);
59             int converted = 0;
60             foreach (Object obj in objs)
61             {
62                 if (obj != null && obj.GetType() == typeof(GameObject))
63                     converted += ConvertNetworkView(((GameObject)obj).GetComponents(), false);
64             }
65             if (movePrefabs && converted > 0)
66             {
67                 //This prefab needs to be under the root of a Resources folder!
68                 string path = prefab.Replace("\\", "/");
69                 int lastSlash = path.LastIndexOf("/");
70                 int resourcesIndex = path.LastIndexOf("/Resources/");
71                 if (resourcesIndex != lastSlash - 10)
72                 {
73                     if (path.Contains("/Resources/"))
74                     {
75                         Debug.LogWarning("Warning, prefab [" + prefab + "] was already in a resources folder. But has been placed in the root of another one!");
76                     }
77                     //This prefab NEEDS to be placed under a resources folder
78                     string resourcesFolder = path.Substring(0, lastSlash) + "/Resources/";
79                     EnsureFolder(resourcesFolder);
80                     string newPath = resourcesFolder + path.Substring(lastSlash + 1);
81                     string error = AssetDatabase.MoveAsset(prefab, newPath);
82                     if (error != "")
83                         Debug.LogError(error);
84                     Output("Fixed prefab [" + prefab + "] by moving it into a resources folder.");
85                 }
86             }
87         }
88
89         //Convert NetworkViews to PhotonViews in scenes
90         string[] sceneFiles = Directory.GetFiles("Assets/", "*.unity", SearchOption.AllDirectories);
91         foreach (string sceneName in sceneFiles)
92         {
93             EditorApplication.OpenScene(sceneName);
94             EditorUtility.DisplayProgressBar("Converting..", "Scene:" + sceneName, 0.2f);
95
96             int converted2 = ConvertNetworkView((NetworkView[])GameObject.FindObjectsOfType(typeof(NetworkView)), true);
97             if (converted2 > 0)
98             {
99                 //This will correct all prefabs: The prefabs have gotten new components, but the correct ID's were lost in this case
100                 PhotonViewHandler.HierarchyChange(); //TODO: most likely this is triggered on change or on save
101
102                 Output("Replaced " + converted2 + " NetworkViews with PhotonViews in scene: " + sceneName);
103                 EditorApplication.SaveScene(EditorApplication.currentScene);
104             }
105
106         }
107
108         //Convert C#/JS scripts (API stuff)
109         List scripts = GetScriptsInFolder("Assets");
110
111         EditorUtility.DisplayProgressBar("Converting..", "Scripts..", 0.9f);
112         ConvertScripts(scripts);
113
114         Output(EditorApplication.timeSinceStartup + " Completed conversion!");
115         EditorUtility.ClearProgressBar();
116
117         EditorUtility.DisplayDialog("Completed the conversion", "Don't forget to add \"PhotonNetwork.ConnectWithDefaultSettings();\" to connect to the Photon server before using any multiplayer functionality.", "OK");
118     }
File name: HorizontalScrollSnap.cs Copy
14         void Start()
15         {
16             _isVertical = false;
17             _childAnchorPoint = new Vector2(0, 0.5f);
18             _currentPage = StartingScreen;
19             UpdateLayout();
20         }
File name: HorizontalScrollSnap.cs Copy
61         private bool IsRectMovingSlowerThanThreshold(float startingSpeed)
62         {
63             return (_scroll_rect.velocity.x > startingSpeed && _scroll_rect.velocity.x < SwipeVelocityThreshold) ||
64                                 (_scroll_rect.velocity.x < startingSpeed && _scroll_rect.velocity.x > -SwipeVelocityThreshold);
65         }
File name: ScrollSnap.cs Copy
207         public void UpdateListItemPositions()
208         {
209             if (!listContainerRectTransform.rect.size.Equals(listContainerCachedSize))
210             {
211                 // checking how many children of list are active
212                 int activeCount = 0;
213
214                 foreach (var tr in listContainerTransform)
215                 {
216                     if (((Transform)tr).gameObject.activeInHierarchy)
217                     {
218                         activeCount++;
219                     }
220                 }
221
222                 // if anything changed since last check reinitialize anchors list
223                 itemsCount = 0;
224                 Array.Resize(ref pageAnchorPositions, activeCount);
225
226                 if (activeCount > 0)
227                 {
228                     pages = Mathf.Max(activeCount - itemsVisibleAtOnce + 1, 1);
229
230                     if (direction == ScrollDirection.Horizontal)
231                     {
232                         // looking for list spanning range min/max
233                         scrollRect.horizontalNormalizedPosition = 0;
234                         listContainerMaxPosition = listContainerTransform.localPosition.x;
235                         scrollRect.horizontalNormalizedPosition = 1;
236                         listContainerMinPosition = listContainerTransform.localPosition.x;
237
238                         listContainerSize = listContainerMaxPosition - listContainerMinPosition;
239
240                         for (var i = 0; i < pages; i++)
241                         {
242                             pageAnchorPositions[i] = new Vector3(
243                                 listContainerMaxPosition - itemSize * i,
244                                 listContainerTransform.localPosition.y,
245                                 listContainerTransform.localPosition.z
246                             );
247                         }
248                     }
249                     else
250                     {
251                         //Debug.Log ("-------------looking for list spanning range----------------");
252                         // looking for list spanning range
253                         scrollRect.verticalNormalizedPosition = 1;
254                         listContainerMinPosition = listContainerTransform.localPosition.y;
255                         scrollRect.verticalNormalizedPosition = 0;
256                         listContainerMaxPosition = listContainerTransform.localPosition.y;
257
258                         listContainerSize = listContainerMaxPosition - listContainerMinPosition;
259
260                         for (var i = 0; i < pages; i++)
261                         {
262                             pageAnchorPositions[i] = new Vector3(
263                                 listContainerTransform.localPosition.x,
264                                 listContainerMinPosition + itemSize * i,
265                                 listContainerTransform.localPosition.z
266                             );
267                         }
268                     }
269
270                     UpdateScrollbar(linkScrolbarSteps);
271                     startingPage = Mathf.Min(startingPage, pages);
272                     ResetPage();
273                 }
274
275                 if (itemsCount != activeCount)
276                 {
277                     PageChanged(CurrentPage());
278                 }
279
280                 itemsCount = activeCount;
281                 listContainerCachedSize.Set(listContainerRectTransform.rect.size.x, listContainerRectTransform.rect.size.y);
282             }
283
284         }
File name: ScrollSnap.cs Copy
286         public void ResetPage()
287         {
288             if (direction == ScrollDirection.Horizontal)
289             {
290                 scrollRect.horizontalNormalizedPosition = pages > 1 ? (float)startingPage / (float)(pages - 1) : 0;
291             }
292             else
293             {
294                 scrollRect.verticalNormalizedPosition = pages > 1 ? (float)(pages - startingPage - 1) / (float)(pages - 1) : 0;
295             }
296         }
File name: ScrollSnap.cs Copy
462         private void PageChanged(int currentPage)
463         {
464             startingPage = currentPage;
465
466             if (nextButton)
467             {
468                 nextButton.interactable = currentPage < pages - 1;
469             }
470
471             if (prevButton)
472             {
473                 prevButton.interactable = currentPage > 0;
474             }
475
476             if (onPageChange != null)
477             {
478                 onPageChange(currentPage);
479             }
480         }
File name: ScrollSnapBase.cs Copy
115         void Awake()
116   {
117    _scroll_rect = gameObject.GetComponent();
118
119    if (_scroll_rect.horizontalScrollbar || _scroll_rect.verticalScrollbar)
120    {
121     Debug.LogWarning("Warning, using scrollbars with the Scroll Snap controls is not advised as it causes unpredictable results");
122    }
123
124    if (StartingScreen < 0)
125    {
126     StartingScreen = 0;
127    }
128
129    _screensContainer = _scroll_rect.content;
130    if (ChildObjects != null && ChildObjects.Length > 0)
131    {
132     if (_screensContainer.transform.childCount > 0)
133     {
134      Debug.LogError("ScrollRect Content has children, this is not supported when using managed Child Objects\n Either remove the ScrollRect Content children or clear the ChildObjects array");
135      return;
136     }
137
138     InitialiseChildObjectsFromArray();
139    }
140    else
141    {
142     InitialiseChildObjectsFromScene();
143    }
144
145    if (NextButton)
146     NextButton.GetComponent
File name: ScrollSnapBase.cs Copy
373  private void OnValidate()
374  {
375   var children = gameObject.GetComponent().content.childCount;
376   if (children != 0 || ChildObjects != null)
377   {
378    var childCount = ChildObjects == null || ChildObjects.Length == 0 ? children : ChildObjects.Length;
379    if (StartingScreen > childCount - 1)
380    {
381     StartingScreen = childCount - 1;
382    }
383
384    if (StartingScreen < 0)
385    {
386     StartingScreen = 0;
387    }
388   }
389
390   if (MaskBuffer <= 0)
391   {
392    MaskBuffer = 1;
393   }
394
395   if (PageStep < 0)
396   {
397    PageStep = 0;
398   }
399
400   if (PageStep > 8)
401   {
402    PageStep = 9;
403   }
404  }
File name: UIVerticalScroller.cs Copy
73         public void Start()
74         {
75             if (_arrayOfElements.Length < 1)
76             {
77                 Debug.Log("No child content found, exiting..");
78                 return;
79             }
80
81             elementLength = _arrayOfElements.Length;
82             distance = new float[elementLength];
83             distReposition = new float[elementLength];
84
85             //get distance between buttons
86             //elementsDistance = (int)Mathf.Abs(_arrayOfElements[1].GetComponent().anchoredPosition.y - _arrayOfElements[0].GetComponent().anchoredPosition.y);
87             deltaY = _arrayOfElements[0].GetComponent().rect.height * elementLength / 3 * 2;
88             Vector2 startPosition = new Vector2(_scrollingPanel.anchoredPosition.x, -deltaY);
89             _scrollingPanel.anchoredPosition = startPosition;
90
91             for (var i = 0; i < _arrayOfElements.Length; i++)
92             {
93                 AddListener(_arrayOfElements[i], i);
94             }
95
96             if (ScrollUpButton)
97                 ScrollUpButton.GetComponent
File name: VerticalScrollSnap.cs Copy
14         void Start()
15         {
16             _isVertical = true;
17             _childAnchorPoint = new Vector2(0.5f,0);
18             _currentPage = StartingScreen;
19             UpdateLayout();
20         }

Starting 123 lượt xem

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