Ended
How do I use Ended
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
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
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: InputToEvent.cs
Copy
32 void Update()
33 {
34 if( DetectPointedAtGameObject )
35 {
36 goPointedAt = RaycastObject( Input.mousePosition );
37 }
38
39 if( Input.touchCount > 0 )
40 {
41 Touch touch = Input.GetTouch( 0 );
42 this.currentPos = touch.position;
43
44 if( touch.phase == TouchPhase.Began )
45 {
46 Press( touch.position );
47 }
48 else if( touch.phase == TouchPhase.Ended )
49 {
50 Release( touch.position );
51 }
52
53 return;
54 }
55
56 currentPos = Input.mousePosition;
57 if( Input.GetMouseButtonDown( 0 ) )
58 {
59 Press( Input.mousePosition );
60 }
61 if( Input.GetMouseButtonUp( 0 ) )
62 {
63 Release( Input.mousePosition );
64 }
65
66 if( Input.GetMouseButtonDown( 1 ) )
67 {
68 pressedPosition = Input.mousePosition;
69 lastGo = RaycastObject( pressedPosition );
70 if( lastGo != null )
71 {
72 lastGo.SendMessage( "OnPressRight", SendMessageOptions.DontRequireReceiver );
73 }
74 }
75 }
File name: SwipeListenerScript.cs
Copy
10 void Update () {
11 //transform.guiText.text = "my text";
12 int fingerCount = 0;
13 foreach (Touch touch in Input.touches) {
14 if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
15 fingerCount++;
16
17 if (touch.phase == TouchPhase.Began)
18 {
19 startPosition = touch.position;
20 lastPosition = touch.position;
21 }
22
23 if (touch.phase == TouchPhase.Moved )
24 {
25 lastPosition = touch.position;
26 }
27 if(touch.phase == TouchPhase.Ended)
28 {
29
30 if((startPosition.x - lastPosition.x) > 80) // left swipe
31 {
32 this.Swipe ("x", -1);
33 }
34 else if((startPosition.x - lastPosition.x) < -80) // right swipe
35 {
36 this.Swipe ("x", 1);
37 }
38 else if((startPosition.y - lastPosition.y) < -80 ) // up swipe
39 {
40 this.Swipe ("y", 1);
41 }
42 else if((startPosition.y - lastPosition.y) > 80 ) // down swipe
43 {
44 this.Swipe ("y", -1);
45 }
46
47 }
48 }
49 }
File name: Cannon.cs
Copy
63 void TouchCannonShoot(){
64 if(Input.touchCount > 0){
65 Touch touch = Input.GetTouch (0);
66
67 touchPos = Camera.main.ScreenToWorldPoint (touch.position);
68
69 Vector2 touchRayHit = new Vector2 (touchPos.x, touchPos.y);
70
71 RaycastHit2D hit = Physics2D.Raycast (touchRayHit , Vector2.zero);
72
73 if(hit.collider != null){
74 if(hit.collider.CompareTag("Player")){
75 if(touch.phase == TouchPhase.Stationary){
76 if (shot != 0) {
77 UpdatePowerLevel ();
78 isCharging = true;
79 }
80 }else if(touch.phase == TouchPhase.Ended){
81 if (shot != 0) {
82 GameObject newCannonBullet = Instantiate (cannonBullet, cannonTip.position, Quaternion.identity) as GameObject;
83 newCannonBullet.transform.GetComponent
84 if (GameController.instance != null && MusicController.instance != null) {
85 if (GameController.instance.isMusicOn) {
86 audioSource.PlayOneShot (cannonShot);
87 }
88 }
89 shot--;
90 powerLevel.value = 0;
91 readyToShoot = false;
92 isCharging = false;
93 }
94 }
95 }
96 }
97
98 /*if(touch.phase == TouchPhase.Stationary){
99 if (shot != 0) {
100 UpdatePowerLevel ();
101 }
102 }else if(touch.phase == TouchPhase.Ended){
103 if (shot != 0) {
104 GameObject newCannonBullet = Instantiate (cannonBullet, cannonTip.position, Quaternion.identity) as GameObject;
105 newCannonBullet.transform.GetComponent
106 if (GameController.instance != null && MusicController.instance != null) {
107 if (GameController.instance.isMusicOn) {
108 audioSource.PlayOneShot (cannonShot);
109 }
110 }
111 shot--;
112 powerLevel.value = 0;
113 readyToShoot = false;
114 }
115 }*/
116
117 }
118 }
File name: Player.cs
Copy
56 private void Update ()
57 {
58 //If it's not the player's turn, exit the function.
59 if(!GameManager.instance.playersTurn) return;
60
61 int horizontal = 0; //Used to store the horizontal move direction.
62 int vertical = 0; //Used to store the vertical move direction.
63
64 //Check if we are running either in the Unity editor or in a standalone build.
65#if UNITY_STANDALONE || UNITY_WEBPLAYER
66
67 //Get input from the input manager, round it to an integer and store in horizontal to set x axis move direction
68 horizontal = (int) (Input.GetAxisRaw ("Horizontal"));
69
70 //Get input from the input manager, round it to an integer and store in vertical to set y axis move direction
71 vertical = (int) (Input.GetAxisRaw ("Vertical"));
72
73 //Check if moving horizontally, if so set vertical to zero.
74 if(horizontal != 0)
75 {
76 vertical = 0;
77 }
78 //Check if we are running on iOS, Android, Windows Phone 8 or Unity iPhone
79#elif UNITY_IOS || UNITY_ANDROID || UNITY_WP8 || UNITY_IPHONE
80
81 //Check if Input has registered more than zero touches
82 if (Input.touchCount > 0)
83 {
84 //Store the first touch detected.
85 Touch myTouch = Input.touches[0];
86
87 //Check if the phase of that touch equals Began
88 if (myTouch.phase == TouchPhase.Began)
89 {
90 //If so, set touchOrigin to the position of that touch
91 touchOrigin = myTouch.position;
92 }
93
94 //If the touch phase is not Began, and instead is equal to Ended and the x of touchOrigin is greater or equal to zero:
95 else if (myTouch.phase == TouchPhase.Ended && touchOrigin.x >= 0)
96 {
97 //Set touchEnd to equal the position of this touch
98 Vector2 touchEnd = myTouch.position;
99
100 //Calculate the difference between the beginning and end of the touch on the x axis.
101 float x = touchEnd.x - touchOrigin.x;
102
103 //Calculate the difference between the beginning and end of the touch on the y axis.
104 float y = touchEnd.y - touchOrigin.y;
105
106 //Set touchOrigin.x to -1 so that our else if statement will evaluate false and not repeat immediately.
107 touchOrigin.x = -1;
108
109 //Check if the difference along the x axis is greater than the difference along the y axis.
110 if (Mathf.Abs(x) > Mathf.Abs(y))
111 //If x is greater than zero, set horizontal to 1, otherwise set it to -1
112 horizontal = x > 0 ? 1 : -1;
113 else
114 //If y is greater than zero, set horizontal to 1, otherwise set it to -1
115 vertical = y > 0 ? 1 : -1;
116 }
117 }
118
119#endif //End of mobile platform dependendent compilation section started above with #elif
120 //Check if we have a non-zero value for horizontal or vertical
121 if(horizontal != 0 || vertical != 0)
122 {
123 //Call AttemptMove passing in the generic parameter Wall, since that is what Player may interact with if they encounter one (by attacking it)
124 //Pass in horizontal and vertical as parameters to specify the direction to move Player in.
125 AttemptMove
126 }
127 }
File name: frmReturn.cs
Copy
83 private void dtCus_addedlist_CellEndEdit(object sender, DataGridViewCellEventArgs e)
84 {
85 double total;
86 if (dtCus_addedlist.CurrentCell.ColumnIndex == 4)
87 {
88 foreach (DataGridViewRow row in dtCus_addedlist.Rows)
89 {
90 total = double.Parse(row.Cells[4].Value.ToString()) * double.Parse(row.Cells[3].Value.ToString());
91 row.Cells[5].Value = total;
92 }
93 }
94 }
File name: frmStockOut.cs
Copy
117 private void dtCus_addedlist_CellEndEdit(object sender, DataGridViewCellEventArgs e)
118 {
119 double total;
120 if (dtCus_addedlist.CurrentCell.ColumnIndex == 4)
121 {
122 foreach (DataGridViewRow row in dtCus_addedlist.Rows)
123 {
124 total = double.Parse(row.Cells[4].Value.ToString()) * double.Parse(row.Cells[3].Value.ToString());
125 row.Cells[5].Value = total;
126 }
127 }
128 }
Ended 166 lượt xem
Gõ tìm kiếm nhanh...