예제 #1
0
 public Texture GetTexture(string textureName)
 {
     textureName = textureName.ToLower();
     if (textureName.Contains("_rt_camera"))
     {
         if (!Textures.ContainsKey(textureName))
         {
             Textures.Add(textureName, Test.Inst.cameraTexture);
         }
         return(Textures [textureName]);
     }
     else
     {
         if (!Textures.ContainsKey(textureName))
         {
             Textures.Add(textureName, VTFLoader.LoadFile(textureName));
         }
         return(Textures [textureName]);
     }
 }
예제 #2
0
 public Texture GetTexture(string textureName, string appendedOutName, bool asNormalMap)
 {
     textureName = textureName.ToLower();
     if (textureName.Contains("_rt_camera"))
     {
         if (!Textures.ContainsKey(textureName))
         {
             Textures.Add(textureName, Test.Inst.cameraTexture);
         }
         return(Textures [textureName]);
     }
     else
     {
         if (!Textures.ContainsKey(appendedOutName))
         {
             Texture2D texture      = VTFLoader.LoadFile(textureName, asNormalMap);
             Texture   finalTexture = SerializeTexture(textureName, texture);
             Textures.Add(appendedOutName, finalTexture);
         }
         return(Textures[appendedOutName]);
     }
 }
예제 #3
0
		void LoadEntity (int index)
		{
			List<string> data = new List<string> ();
			string pattern = "\"[^\"]*\"";

			foreach (Match match in Regex.Matches (entities[index], pattern, RegexOptions.IgnoreCase))
				data.Add (match.Value.Trim ('"'));

			int classNameIndex = data.FindIndex (n => n == "classname");
			string className = data[classNameIndex + 1];

			if (className == "worldspawn")
			{
			    if(data.Contains("skyname")) // Skybox loading
			    {
			       string sky = data[data.FindIndex(n => n == "skyname") + 1];
			       Material SkyMaterial = new Material(Shader.Find("Skybox/6 Sided"));
			       
			       Texture FrontTex = VTFLoader.LoadFile("skybox/" + sky + "ft");
                               FrontTex.wrapMode = TextureWrapMode.Repeat;
			       
			       Texture BackTex = VTFLoader.LoadFile("skybox/" + sky + "bk");
                    	       BackTex.wrapMode = TextureWrapMode.Repeat;
			       
			       Texture LeftTex = VTFLoader.LoadFile("skybox/" + sky + "lf");
                    	       LeftTex.wrapMode = TextureWrapMode.Repeat;
			       
			       Texture RightTex = VTFLoader.LoadFile("skybox/" + sky + "rt");
                               RightTex.wrapMode = TextureWrapMode.Repeat;
			       
			       Texture DownTex = VTFLoader.LoadFile("skybox/" + sky + "dn");
                    	       DownTex.wrapMode = TextureWrapMode.Repeat;
			       
			       Texture UpTex = VTFLoader.LoadFile("skybox/" + sky + "up");
                               UpTex.wrapMode = TextureWrapMode.Repeat;
			       
			       //if any of you can code it so that the up texture of the skybox
			       //gets rotated by 90 that would be perfect -Jhrino
			       
			      SkyMaterial.SetTexture("_FrontTex", FrontTex);
                   	      SkyMaterial.SetTexture("_BackTex", BackTex);
                              SkyMaterial.SetTexture("_LeftTex", LeftTex);
                              SkyMaterial.SetTexture("_RightTex", RightTex);
                              SkyMaterial.SetTexture("_DownTex", DownTex);
                              SkyMaterial.SetTexture("_UpTex", UpTex);
			      
			      RenderSettings.skybox = SkyMaterial;	       
			    }
				return;
			}

			Vector3 angles = new Vector3 (0, 0, 0);
			if (data[0] == "model")
			{
				int modelIndex = int.Parse (data[data.FindIndex (n => n == "model") + 1].Substring (1));
				GameObject obj = models[modelIndex];

				if (data.Contains ("origin"))
				{
					if (data.FindIndex (n => n == "origin") % 2 == 0)
						obj.transform.position = ConvertUtils.StringToVector (data[data.FindIndex (n => n == "origin") + 1]);
				}

				if (data.Contains ("angles"))
				{
					string[] t = data[data.FindIndex (n => n == "angles") + 1].Split (' ');
					angles = new Vector3 (-ConvertUtils.floatParse(t[2]), ConvertUtils.floatParse(t[1]), ConvertUtils.floatParse(t[0]));
					obj.transform.eulerAngles = angles;
				}

				if (className == "func_illusionary")
				{
					MeshRenderer[] renderers = obj.GetComponentsInChildren<MeshRenderer> ();
					for (int i = 0; i < renderers.Length; i++)
					{
						renderers[i].shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
					}
				}

				return;
			}
			string[] testEnts = new string[]
			{
				"info_player_start",
				"sky_camera",
				"point_camera",
				"light_environment",
				"prop_dynamic",
				"prop_dynamic_override" /*,"point_viewcontrol"*/ ,
				"info_target",
				"light_spot",
				"light",
				"info_survivor_position",
				"env_projectedtexture",
				"func_illusionary",
				"prop_button",
				"prop_floor_button",
				"prop_weighted_cube",
				"prop_physics"
			};

			if (testEnts.Contains (className))
			{
				string targetname = null;

				if (data.Contains ("targetname"))
					targetname = data[data.FindIndex (n => n == "targetname") + 1];

				if (data.Contains ("angles"))
				{
					string[] t = data[data.FindIndex (n => n == "angles") + 1].Split (' ');
					angles = new Vector3 (-ConvertUtils.floatParse(t[2]), ConvertUtils.floatParse(t[1]), ConvertUtils.floatParse(t[0]));
				}

				if (data.Contains ("pitch"))
					angles.x = -ConvertUtils.floatParse(data[data.FindIndex (n => n == "pitch") + 1]);

				GameObject obj = new GameObject (targetname ?? className);
				//if(className.Contains("light"))
				obj.transform.parent = entObject.transform;
				obj.transform.position = ConvertUtils.StringToVector (data[data.FindIndex (n => n == "origin") + 1]);
				obj.transform.eulerAngles = angles;

				/*if(className=="light")
				{
					Light l = obj.AddComponent<Light>();
					l.color = ConvertUtils.stringToColor(data[data.FindIndex (n=>n=="_light")+1],255);
				}
				if(className=="light_spot")
				{
					Light l = obj.AddComponent<Light>();
					l.type=LightType.Spot;
					l.color = ConvertUtils.stringToColor(data[data.FindIndex (n=>n=="_light")+1],255);
					//float pitch = 0;
					//if(data.Contains ("pitch"))
					//	pitch = float.Parse (data[data.FindIndex (n=>n=="pitch")+1]);
					if(data.Contains ("_cone"))
					{
						l.spotAngle = int.Parse (data[data.FindIndex (n=>n=="_cone")+1]);
					}
					//angles.y = pitch;
					angles.y+=90;
					//obj.transform.eulerAngles = angles; 
				}*/

				if (className == "light_environment" & Test.Inst.light_environment != null)
				{
					Light l = Test.Inst.light_environment;
					l.color = ConvertUtils.stringToColor (data[data.FindIndex (n => n == "_light") + 1], 255);
					//float pitch = 0;
					//if(data.Contains ("pitch"))
					//	pitch = float.Parse (data[data.FindIndex (n=>n=="pitch")+1]);
					//angles.y = pitch;
					angles.y += 90;
					l.transform.eulerAngles = angles;
				}

				if (className == "sky_camera")
				{
					Test.Inst.skyCameraOrigin = obj.transform.position;
					if (Test.Inst.skyCamera != null)
					{
						//Test.Inst.skyCamera.transform.SetParent(obj.transform);
						//Test.Inst.skyCamera.transform.localPosition=Vector3.zero;
						Test.Inst.skyCamera.transform.localPosition = (Test.Inst.playerCamera.transform.position / 16) + Test.Inst.skyCameraOrigin;
						Test.Inst.skyCamera.transform.rotation = Test.Inst.playerCamera.transform.rotation;
					}
				}

				if (!Test.Inst.isL4D2)
				{
					if (className == "info_player_start")
					{
						Test.Inst.startPos = obj.transform.position;
					}
				}
				else
				{
					if (className == "info_survivor_position")
					{
						Test.Inst.startPos = obj.transform.position;
					}
				}
				if ((className == "prop_dynamic" | className == "prop_dynamic_override" | className == "prop_weighted_cube" | className == "prop_floor_button" | className == "prop_button" | className == "prop_physics") && uSrcSettings.Inst.propsDynamic)
				{
					string modelName = "";

					if (data.Contains ("model"))
						modelName = data[data.FindIndex (n => n == "model") + 1];
					else if (className == "prop_weighted_cube")
						modelName = "models/props/metal_box.mdl";
					else if (className == "prop_floor_button")
						modelName = "models/props/portal_button.mdl";
					else if (className == "prop_button")
						modelName = "models/props/switch001.mdl";

					//angles.y-=90;
					//Kostyl
					//if(modelName.Contains("signage_num0"))
					//	angles.y+=90;
					//======
					obj.transform.eulerAngles = angles;

					SourceStudioModel tempModel = ResourceManager.Inst.GetModel (modelName);
					if (tempModel == null || !tempModel.loaded)
					{
						//Debug.LogWarning("Error loading: "+modelName);
						GameObject prim = GameObject.CreatePrimitive (PrimitiveType.Cube);
						prim.name = modelName;
						prim.transform.parent = obj.transform;
						prim.transform.localPosition = Vector3.zero;
					}
					else
					{
						tempModel.GetInstance (obj, true, 0);
					}
					if(className == "prop_physics")
					{
						obj.GetComponent<MeshCollider>().convex = true;
						obj.AddComponent<Rigidbody>();
					}

				}

				/*if(className=="prop_floor_button")
				{
					string modelname="models/props/button_base_reference.mdl";
					SourceStudioModel baseModel = ResourceManager.Inst.GetModel(modelName);
					if(baseModel==null||!baseModel.loaded)
					{
						Debug.LogWarning("Error loading: "+modelName);
					}
					else
					{
						GameObject baseObj=new GameObject("button_base");
						baseObj.transform.SetParent(go.transform);
						baseModel.GetInstance(baseObj, true,0);
					}
					
					modelname="models/props/button_top_reference.mdl";
					SourceStudioModel topModel = ResourceManager.Inst.GetModel(modelName);
					if(topModel==null||!topModel.loaded)
					{
						Debug.LogWarning("Error loading: "+modelName);
					}
					else
					{
						GameObject topObj=new GameObject("button_base");
						topObj.transform.SetParent(go.transform);
						topModel.GetInstance(topObj, true,0);
					}
						
					obj.transform.eulerAngles = angles;
				}*/
			}
		}