Had
How do I use Had
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: NetworkingPeer.cs
Copy
2663 public PhotonView GetPhotonView(int viewID)
2664 {
2665 PhotonView result = null;
2666 this.photonViewList.TryGetValue(viewID, out result);
2667
2668 if (result == null)
2669 {
2670 PhotonView[] views = GameObject.FindObjectsOfType(typeof(PhotonView)) as PhotonView[];
2671
2672 foreach (PhotonView view in views)
2673 {
2674 if (view.viewID == viewID)
2675 {
2676 if (view.didAwake)
2677 {
2678 Debug.LogWarning("Had to lookup view that wasn't in photonViewList: " + view);
2679 }
2680 return view;
2681 }
2682 }
2683 }
2684
2685 return result;
2686 }
File name: Animal.cs
Copy
77 public void setAnimalName(string animalName)
78 {
79 shadowSprite = Resources.Load
80 }
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
94 shadowObject.GetComponent
95 shadowObject.GetComponent
96 shadowObject.AddComponent
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
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
573 private void setAnimationRunning(bool isRunning)
574 {
575 for (int i = 0; i < coinLayer.transform.childCount; i++)
576 {
577 coinLayer.transform.GetChild(i).gameObject.GetComponent
578 }
579 for (int i = 0; i < goldLayer.transform.childCount; i++)
580 {
581 goldLayer.transform.GetChild(i).gameObject.GetComponent
582 goldLayer.transform.GetChild(i).gameObject.GetComponent
583 }
584 for (int i = 0; i < boosterLayer.transform.childCount; i++)
585 {
586 boosterLayer.transform.GetChild(i).gameObject.GetComponent
587 }
588 for (int i = 0; i < shadowLayer.transform.childCount; i++)
589 {
590 if (shadowLayer.transform.GetChild(i).gameObject.GetComponent
591 shadowLayer.transform.GetChild(i).gameObject.GetComponent
592 }
593 }
File name: ImportTiled2Unity.Xml.cs
Copy
42 private void ImportTexturesFromXml(XDocument xml)
43 {
44 var texData = xml.Root.Elements("ImportTexture");
45 foreach (var tex in texData)
46 {
47 string name = tex.Attribute("filename").Value;
48 string data = tex.Value;
49
50 // The data is gzip compressed base64 string. We need the raw bytes.
51 //byte[] bytes = ImportUtils.GzipBase64ToBytes(data);
52 byte[] bytes = ImportUtils.Base64ToBytes(data);
53
54 // Save and import the texture asset
55 {
56 string pathToSave = ImportUtils.GetTexturePath(name);
57 ImportUtils.ReadyToWrite(pathToSave);
58 File.WriteAllBytes(pathToSave, bytes);
59 AssetDatabase.ImportAsset(pathToSave, ImportAssetOptions.ForceSynchronousImport);
60 }
61
62 // Create a material if needed in prepartion for the texture being successfully imported
63 {
64 string materialPath = ImportUtils.GetMaterialPath(name);
65 Material material = AssetDatabase.LoadAssetAtPath(materialPath, typeof(Material)) as Material;
66 if (material == null)
67 {
68 // We need to create the material afterall
69 // Use our custom shader
70 material = new Material(Shader.Find("Tiled/TextureTintSnap"));
71 ImportUtils.ReadyToWrite(materialPath);
72 AssetDatabase.CreateAsset(material, materialPath);
73 }
74 }
75 }
76 }
File name: ImportTiled2Unity.Xml.cs
Copy
78 private void CreateMaterialsFromInternalTextures(XDocument xml)
79 {
80 var texData = xml.Root.Elements("InternalTexture");
81 foreach (var tex in texData)
82 {
83 string texAssetPath = tex.Attribute("assetPath").Value;
84 string materialPath = ImportUtils.GetMaterialPath(texAssetPath);
85
86 Material material = AssetDatabase.LoadAssetAtPath(materialPath, typeof(Material)) as Material;
87 if (material == null)
88 {
89 // Create our material
90 material = new Material(Shader.Find("Tiled/TextureTintSnap"));
91
92 // Assign to it the texture that is already internal to our Unity project
93 Texture2D texture2d = AssetDatabase.LoadAssetAtPath(texAssetPath, typeof(Texture2D)) as Texture2D;
94 material.SetTexture("_MainTex", texture2d);
95
96 // Write the material to our asset database
97 ImportUtils.ReadyToWrite(materialPath);
98 AssetDatabase.CreateAsset(material, materialPath);
99 }
100 }
101 }
File name: Tiled2UnityMenuItems.cs
Copy
17 static void ExportLibrary()
18 {
19 string name = String.Format("Tiled2Unity.{0}.unitypackage", ImportTiled2Unity.ThisVersion);
20 var path = EditorUtility.SaveFilePanel("Save texture as PNG", "", name, "unitypackage");
21 if (path.Length != 0)
22 {
23 List
24 packageFiles.AddRange(EnumerateAssetFilesAt("Assets/Tiled2Unity", ".cs", ".shader", ".txt"));
25 AssetDatabase.ExportPackage(packageFiles.ToArray(), path);
26 }
27 }
File name: TiledAssetPostProcessor.cs
Copy
111 private void OnPostprocessModel(GameObject gameObject)
112 {
113 if (!UseThisImporter())
114 return;
115
116 // Each mesh renderer has the ability to set the a sort layer but it takes some work with Unity to expose it.
117 foreach (MeshRenderer mr in gameObject.GetComponentsInChildren
118 {
119 mr.gameObject.AddComponent
120
121 // Also, no shadows
122 mr.receiveShadows = false;
123 mr.castShadows = false;
124 }
125 }
Download file with original file name:Had
Had 161 lượt xem
Gõ tìm kiếm nhanh...