예제 #1
0
	/// <summary>
	/// Generate a new photo plane
	/// </summary>
	/// <returns></returns>
	private GameObject GeneratePhotoPlane(KGFPhotoData thePhotoData)
	{
//		GameObject aMiniMapPlaneRoot = new GameObject("minimap_photo_plane");
//		aMiniMapPlaneRoot.transform.parent = transform;
//		aMiniMapPlaneRoot.transform.localPosition = Vector3.zero;
//		aMiniMapPlaneRoot.transform.localRotation = Quaternion.identity;
//		aMiniMapPlaneRoot.transform.localScale = Vector3.one;
		
		GameObject aGameObject = new GameObject("photo_plane");
		aGameObject.layer = itsLayerMinimap;
		aGameObject.transform.parent = transform;
		MeshFilter aMiniMapPlane = aGameObject.AddComponent<MeshFilter>();
		aMiniMapPlane.transform.eulerAngles = Vector3.zero;
		aMiniMapPlane.transform.position = Vector3.zero;
		aMiniMapPlane.mesh = GeneratePlaneMeshXZ();
		
		MeshRenderer aMeshRenderer = aMiniMapPlane.gameObject.AddComponent<MeshRenderer>();
		aMeshRenderer.castShadows = false;
		aMeshRenderer.receiveShadows = false;
		
		Material aMaterial = new Material(itsDataModuleMinimap.itsShaders.itsShaderPhotoPlane);
		aMaterial.mainTexture = thePhotoData.itsTexture;
//		aMaterial.SetColor("_Color",Color.black);
		aMeshRenderer.material = aMaterial;
//		aMeshRenderer.material.mainTexture = thePhotoData.itsTexture;
		thePhotoData.itsPhotoPlaneMaterial = aMaterial;
		return aGameObject;
	}
예제 #2
0
	void AutoCreatePhoto()
	{
		// try to find photo parent
		if (itsGameObjectPhotoParent == null)
		{
			Transform aTransform = transform.Find("photo");
			if (aTransform != null)
			{
				itsGameObjectPhotoParent = aTransform.gameObject;
			}
		}
		
		if(itsTempCameraGameObject != null)
		{
			if(Application.isPlaying)
				Destroy(itsTempCameraGameObject);
			else
				DestroyImmediate(itsTempCameraGameObject);
		}
		
		if (itsGameObjectPhotoParent != null)
		{
			if (Application.isPlaying)
				GameObject.Destroy(itsGameObjectPhotoParent);
			else
				GameObject.DestroyImmediate(itsGameObjectPhotoParent);
		}
		itsGameObjectPhotoParent = new GameObject("photo");
		itsGameObjectPhotoParent.transform.parent = transform;
		
		Vector2 aTerrainBoundsMin = GetVector3Plane(itsTerrainBoundsPhoto.min);
		Vector2 aTerrainBoundsMax = GetVector3Plane(itsTerrainBoundsPhoto.max);
		
		{
			float aTextureSize = GetHighestNPOTSizeSmallerThanScreen();
			float aMeters = aTextureSize / itsDataModuleMinimap.itsPhoto.itsPixelPerMeter;
			float aMetersBorder = aTextureSize / itsDataModuleMinimap.itsPhoto.itsPixelPerMeter;
			
			int i = 0;
			int j = 0;
			
			ClearPhotoData();
			while (true)
			{
				KGFPhotoData aPhotoData = new KGFPhotoData();
				aPhotoData.itsMeters = aMeters;
				Vector3 aDirection = itsTerrainBoundsPhoto.max - itsTerrainBoundsPhoto.min;
				aDirection = ChangeVectorHeight(aDirection,0); // aDirection.y = 0;
				
				
				switch (itsDataModuleMinimap.itsGlobalSettings.itsOrientation)
				{
					case KGFMapSystemOrientation.XYSideScroller:
						aPhotoData.itsPosition = CreateVector(aTerrainBoundsMin.x + aMeters * i,
						                                      aTerrainBoundsMin.y + aMeters * j,
						                                      itsTerrainBoundsPhoto.max.z + 1);
						break;
					case KGFMapSystemOrientation.XZDefault:
						aPhotoData.itsPosition = CreateVector(aTerrainBoundsMin.x + aMeters * i,
						                                      aTerrainBoundsMin.y + aMeters * j,
						                                      itsTerrainBoundsPhoto.min.y - 1);
						break;
				}
				
				// render to texture
				aPhotoData.itsTexture = new Texture2D((int)aTextureSize,(int)aTextureSize,TextureFormat.ARGB32,false);
				{
					aPhotoData.itsTextureSize = aTextureSize;
//					aPhotoData.itsTexture.wrapMode = TextureWrapMode.Clamp;
				}
				
				// show photo in plane under terrain
				{
					// create plane
					// create material with photo
					// assign material to plane
					GameObject aPhotoPlane = GeneratePhotoPlane(aPhotoData);
					KGFSetChildrenActiveRecursively(aPhotoPlane,false);
					aPhotoPlane.transform.parent = itsGameObjectPhotoParent.transform;
					aPhotoPlane.name = aPhotoPlane.name+"_"+i+"_"+j;
					
					// use minimap layer
					SetLayerRecursively(aPhotoPlane.gameObject,itsLayerMinimap);
					
					// rescale plane
					Vector3 aPhotoPlanePosition = aPhotoData.itsPosition;// - Vector3.one * aMeters;
//					aPhotoPlanePosition = ChangeVectorHeight(aPhotoPlanePosition,GetHeightPhoto());//aPhotoPlanePosition.y = itsFixedHeightPhoto;
					aPhotoPlane.transform.position = aPhotoPlanePosition;
					aPhotoPlane.transform.localScale = new Vector3(aMeters,1,aMeters); // CreateVector(aMeters,aMeters,1);
					switch (itsDataModuleMinimap.itsGlobalSettings.itsOrientation)
					{
						case KGFMapSystemOrientation.XYSideScroller:
							aPhotoPlane.transform.localEulerAngles = new Vector3(270,0,0);
							break;
						case KGFMapSystemOrientation.XZDefault:
							aPhotoPlane.transform.localEulerAngles = Vector3.zero;
							break;
//						case KGFMapSystemOrientation.YZ:
//							aPhotoPlane.transform.localEulerAngles = new Vector3(0,0,270);
//							break;
					}
//					KGFSetChildrenActiveRecursively(aPhotoPlane,true);
					
					aPhotoData.itsPhotoPlane = aPhotoPlane;
				}
				itsListOfPhotoData.Add(aPhotoData);
				
				i++;
				if (aTerrainBoundsMin.x + (i)*aMeters > aTerrainBoundsMax.x)
				{
					i = 0;
					j++;
				}
				if (aTerrainBoundsMin.y + (j)*aMeters > aTerrainBoundsMax.y)
				{
					break;
				}
			}
			itsArrayOfPhotoData = itsListOfPhotoData.ToArray();
			SetColors();
			//everything prepared for photo session. Create the camera. It will destroy itself after the photosession.
			CreatePhotoCamera(aMetersBorder,aTextureSize);
		}
	}