private void CopyToDestLightMap(SceneItemJson srcItemJson, SceneItemJson destItemJson) { destItemJson.lightMapName = srcItemJson.lightMapName; for (int i = 0; i < srcItemJson.items.Count; i++) { for (int j = 0; j < destItemJson.items.Count; j++) { if (srcItemJson.items[i].itemID == destItemJson.items[j].itemID) { for (int k = 0; k < destItemJson.items[j].itemPos.Count; k++) { if (srcItemJson.items.Count > k) { ItemPosInfoJson srcJson = srcItemJson.items[i].itemPos[k]; ItemPosInfoJson destJson = destItemJson.items[i].itemPos[k]; destJson.lightIndex = srcJson.lightIndex; destJson.offsetX = srcJson.offsetX; destJson.offsetY = srcJson.offsetY; destJson.tilingX = srcJson.tilingX; destJson.tilingY = srcJson.tilingY; } } break; } } } }
private void LoadModel(long id, ItemPosInfoJson posInfo, int posIndex, int itemIndex, string groupFileName) { BaseItem baseItem = m_data.GetExhibitByID(id); if (baseItem == null) { Debug.LogError("exhibit id is not exist:" + id); return; } ExhibitObjData exhibitObjData = m_data.CheckExhibit(id, posInfo); if (exhibitObjData != null) { ExhibitObjData objdataTemp = new ExhibitObjData(groupFileName, id, posIndex, itemIndex, exhibitObjData.gameObject); m_data.AddExhibitObj(objdataTemp); return; } GameObject obj = LoadGameObject(baseItem.model, posInfo); obj.name = groupFileName + "/" + id + "/" + posIndex; ExhibitObjData objdata = new ExhibitObjData(groupFileName, id, posIndex, itemIndex, obj); m_data.AddExhibitObj(objdata); }
public void SetData(SceneItemJson json) { m_lightMapName = json.lightMapName; m_data = new List <LightMapData>(); for (int i = 0; i < json.items.Count; i++) { LightMapData mapdata = new LightMapData(); mapdata.m_data = new List <SingleLightMapData>(); ItemInfoJson itemjson = json.items[i]; mapdata.itemID = itemjson.itemID; mapdata.itemName = itemjson.itemName; for (int j = 0; j < itemjson.itemPos.Count; j++) { SingleLightMapData singleData = new SingleLightMapData(); ItemPosInfoJson posJson = itemjson.itemPos[j]; singleData.lightIndex = posJson.lightIndex; singleData.offsetX = posJson.offsetX; singleData.offsetY = posJson.offsetY; singleData.tilingX = posJson.tilingX; singleData.tilingY = posJson.tilingY; mapdata.m_data.Add(singleData); } m_data.Add(mapdata); } }
void Check() { if (tex == null) { return; } for (int i = 0; i < sceneItem.items.Count; i++) { if (itemState[i]) { ItemInfoJson itemInfo = sceneItem.items[i]; BaseItem baseItem = getBaseItemByID(itemInfo.itemID); for (int j = 0; j < itemInfo.itemPos.Count; j++) { ItemPosInfoJson posInfo = itemInfo.itemPos[j]; Object obj = AssetDatabase.LoadAssetAtPath("Assets/" + baseItem.model + ".prefab", typeof(Object)); GameObject gameObj = Instantiate(obj) as GameObject; gameObj.transform.position = new Vector3(posInfo.pos.x, posInfo.pos.y, posInfo.pos.z); gameObj.transform.eulerAngles = new Vector3(posInfo.rotate.x, posInfo.rotate.y, posInfo.rotate.z); gameObj.name = itemInfo.itemName; ObjLightMapData mapdata = objLightData.groups[i].objLightDatas[j]; MeshRenderer render = gameObj.GetComponent <MeshRenderer>(); render.lightmapIndex = (int)mapdata.lightIndex; render.lightmapScaleOffset = new Vector4(mapdata.tilingX, mapdata.tilingY, mapdata.offsetX, mapdata.offsetY); //MColor[] mc = mapdata.color; //creatNewLightMap(mapdata,tex); } } } }
protected override void OnLoadedRes(string assetName, Object resObject) { this.m_entityObject = this.m_entityObject ?? new SceneItemEntityObject(this, resObject as GameObject); if (EntityData.itemPos.Count == 0) { Debug.LogError($"SceneItem no position data, ItemName:{EntityData.itemName} , ItemID:{EntityData.itemID}"); } //客户端自己随机放一个位置,mmp int randamLocationIndex = Random.Range(0, EntityData.itemPos.Count); ItemPosInfoJson itemLocationInfo = EntityData.itemPos[randamLocationIndex]; EntityData.itemPos.RemoveAt(randamLocationIndex); Confexhibit sceneItemConfig = Confexhibit.Get(EntityData.itemID); if (sceneItemConfig == null) { Debug.LogError($"no item :{EntityData.itemID}in exhibit "); } EntityPosition = new Vector3(itemLocationInfo.pos.x, itemLocationInfo.pos.y, itemLocationInfo.pos.z); EntityScale = new Vector3(itemLocationInfo.scale.x, itemLocationInfo.scale.y, itemLocationInfo.scale.z); EntityEulerRotation = new Vector3(itemLocationInfo.rotate.x, itemLocationInfo.rotate.y, itemLocationInfo.rotate.z); EntityLightInfo = new Vector4(itemLocationInfo.offsetX, itemLocationInfo.offsetY, itemLocationInfo.tilingX, itemLocationInfo.tilingY); EntityObject.SetColliderScale(sceneItemConfig.colliderScale); Vector3 finalPos = EntityObject.EntityTransform.rotation * EntityObject.entityCollider.center; centerPostion = EntityPosition + new Vector3(finalPos.x * EntityScale.x, finalPos.y * EntityScale.y, finalPos.z * EntityScale.z); CameraName = itemLocationInfo.cameraNode; }
protected override GameObject LoadGameObject(string modelPath, ItemPosInfoJson posInfo) { GameObject obj = UnityEditor.AssetDatabase.LoadAssetAtPath <GameObject>("Assets/" + modelPath + ".prefab"); obj = GameObject.Instantiate(obj) as GameObject; MeshRenderer render = obj.GetComponent <MeshRenderer>(); if (render != null) { render.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; render.receiveShadows = false; render.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off; render.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off; string shaderName = render.sharedMaterial.shader.name; if (shaderName.Contains("Mobile/Diffuse")) { render.sharedMaterial.shader = Shader.Find("Seeker/Diffuse"); } render.sharedMaterial.SetTextureOffset("_LightTex", new Vector2(posInfo.offsetX, posInfo.offsetY)); render.sharedMaterial.SetTextureScale("_LightTex", new Vector2(posInfo.tilingX, posInfo.tilingY)); } obj.transform.position = new Vector3(posInfo.pos.x, posInfo.pos.y, posInfo.pos.z); obj.transform.eulerAngles = new Vector3(posInfo.rotate.x, posInfo.rotate.y, posInfo.rotate.z); obj.transform.localScale = new Vector3(posInfo.scale.x, posInfo.scale.y, posInfo.scale.z); return(obj); }
protected override void OnLoadedRes(string assetName, Object resObject) { this.m_entityObject = this.m_entityObject ?? new EntityObjectBase(this, resObject as GameObject); int randamLocationIndex = GetRandomIndex(EntityData.itemPos);//Random.Range(0, EntityData.itemPos.Count); ItemPosInfoJson itemLocationInfo = EntityData.itemPos[randamLocationIndex]; EntityPosition = new Vector3(itemLocationInfo.pos.x, itemLocationInfo.pos.y, itemLocationInfo.pos.z); EntityScale = new Vector3(itemLocationInfo.scale.x, itemLocationInfo.scale.y, itemLocationInfo.scale.z); EntityEulerRotation = new Vector3(itemLocationInfo.rotate.x, itemLocationInfo.rotate.y, itemLocationInfo.rotate.z); EntityLightInfo = new Vector4(itemLocationInfo.offsetX, itemLocationInfo.offsetY, itemLocationInfo.tilingX, itemLocationInfo.tilingY); }
private void GetLightMapForGameObject(ItemPosInfoJson infoJson, GameObject obj) { MeshRenderer render = obj.GetComponent <MeshRenderer>(); if (render == null) { return; } infoJson.lightIndex = render.lightmapIndex; infoJson.tilingX = render.lightmapScaleOffset.x; infoJson.tilingY = render.lightmapScaleOffset.y; infoJson.offsetX = render.lightmapScaleOffset.z; infoJson.offsetY = render.lightmapScaleOffset.w; }
protected virtual GameObject LoadGameObject(string modelPath, ItemPosInfoJson posInfo) { GameObject obj = UnityEditor.AssetDatabase.LoadAssetAtPath <GameObject>("Assets/" + modelPath + ".prefab"); obj = GameObject.Instantiate(obj) as GameObject; MeshRenderer render = obj.GetComponent <MeshRenderer>(); if (render != null) { obj.isStatic = true; render.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; render.receiveShadows = false; render.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off; render.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off; } obj.transform.position = new Vector3(posInfo.pos.x, posInfo.pos.y, posInfo.pos.z); obj.transform.eulerAngles = new Vector3(posInfo.rotate.x, posInfo.rotate.y, posInfo.rotate.z); obj.transform.localScale = new Vector3(posInfo.scale.x, posInfo.scale.y, posInfo.scale.z); return(obj); }
public ExhibitObjData CheckExhibit(long propId, ItemPosInfoJson posInfo) { for (int i = 0; i < m_allExhibitObj.Count; i++) { if (m_allExhibitObj[i].m_propId == propId) { UnityEngine.GameObject mObj = m_allExhibitObj[i].gameObject; if (Mathf.Abs(mObj.transform.position.x - posInfo.pos.x) < LightingData.ErrorNumber && Mathf.Abs(mObj.transform.position.y - posInfo.pos.y) < LightingData.ErrorNumber && Mathf.Abs(mObj.transform.position.z - posInfo.pos.z) < LightingData.ErrorNumber) { if (Mathf.Abs(mObj.transform.eulerAngles.x - posInfo.rotate.x) < LightingData.ErrorNumber && Mathf.Abs(mObj.transform.eulerAngles.y - posInfo.rotate.y) < LightingData.ErrorNumber && Mathf.Abs(mObj.transform.eulerAngles.z - posInfo.rotate.z) < LightingData.ErrorNumber) { if (Mathf.Abs(mObj.transform.localScale.x - posInfo.scale.x) < LightingData.ErrorNumber && Mathf.Abs(mObj.transform.localScale.y - posInfo.scale.y) < LightingData.ErrorNumber && Mathf.Abs(mObj.transform.localScale.z - posInfo.scale.z) < LightingData.ErrorNumber) { return(m_allExhibitObj[i]); } } } } } return(null); }
public void CopySceneItemInfo(SceneItemInfo sceneItemInfo) { if (sceneItemInfo == null) { return; } items = new List <ItemInfoJson>(); for (int i = 0; i < sceneItemInfo.items.Count; i++) { ItemInfo itemInfo = sceneItemInfo.items[i]; ItemInfoJson infoJson = new ItemInfoJson(); infoJson.itemPos = new List <ItemPosInfoJson>(); infoJson.itemID = itemInfo.itemID; infoJson.itemName = itemInfo.itemName; for (int j = 0; j < itemInfo.itemPos.Count; j++) { ItemPosInfoJson posJson = new ItemPosInfoJson(itemInfo.itemPos[j]); infoJson.itemPos.Add(posJson); } items.Add(infoJson); } }
GameObject LoadModel(long id, ItemPosInfoJson posInfo) { for (int i = 0; i < baseItemsData.Count; i++) { if (id == baseItemsData[i].id) { GameObject parentObj = GameObject.Find(id.ToString() + "_parent"); if (parentObj == null) { parentObj = new GameObject(id.ToString() + "_parent"); parentObj.transform.position = Vector3.zero; } GameObject obj = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/" + baseItemsData[i].model + ".prefab"); obj = Instantiate(obj) as GameObject; obj.name = id.ToString(); obj.transform.SetParent(parentObj.transform); obj.isStatic = true; obj.transform.position = new Vector3(posInfo.pos.x, posInfo.pos.y, posInfo.pos.z); obj.transform.eulerAngles = new Vector3(posInfo.rotate.x, posInfo.rotate.y, posInfo.rotate.z); obj.transform.localScale = new Vector3(posInfo.scale.x, posInfo.scale.y, posInfo.scale.z); if (itemObjs.ContainsKey(id)) { itemObjs[id].Add(obj); } else { itemObjs.Add(id, new List <GameObject>() { obj }); } return(obj); } } return(null); }
GameObject LoadModel(long id, ItemPosInfoJson posInfo, string fileName, int index) { for (int i = 0; i < baseItemsData.Count; i++) { if (id == baseItemsData[i].id) { GameObject parentObj = GameObject.Find(id.ToString() + "_parent"); if (parentObj == null) { parentObj = new GameObject(id.ToString() + "_parent"); parentObj.transform.position = Vector3.zero; } if (itemObjs.ContainsKey(id)) { for (int j = 0; j < itemObjs[id].Count; j++) { GameObject mObj = itemObjs[id][j]; if (Mathf.Abs(mObj.transform.position.x - posInfo.pos.x) < errorNumber && Mathf.Abs(mObj.transform.position.y - posInfo.pos.y) < errorNumber && Mathf.Abs(mObj.transform.position.z - posInfo.pos.z) < errorNumber) { if (Mathf.Abs(mObj.transform.eulerAngles.x - posInfo.rotate.x) < errorNumber && Mathf.Abs(mObj.transform.eulerAngles.y - posInfo.rotate.y) < errorNumber && Mathf.Abs(mObj.transform.eulerAngles.z - posInfo.rotate.z) < errorNumber) { if (Mathf.Abs(mObj.transform.localScale.x - posInfo.scale.x) < errorNumber && Mathf.Abs(mObj.transform.localScale.y - posInfo.scale.y) < errorNumber && Mathf.Abs(mObj.transform.localScale.z - posInfo.scale.z) < errorNumber) { return(mObj); } } } } } GameObject obj = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/" + baseItemsData[i].model + ".prefab"); obj = Instantiate(obj) as GameObject; obj.name = id.ToString() + "/" + index + "/" + fileName; obj.transform.SetParent(parentObj.transform); obj.isStatic = true; MeshRenderer render = obj.GetComponent <MeshRenderer>(); if (render != null) { render.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; render.receiveShadows = false; render.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off; render.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off; } obj.transform.position = new Vector3(posInfo.pos.x, posInfo.pos.y, posInfo.pos.z); obj.transform.eulerAngles = new Vector3(posInfo.rotate.x, posInfo.rotate.y, posInfo.rotate.z); obj.transform.localScale = new Vector3(posInfo.scale.x, posInfo.scale.y, posInfo.scale.z); if (itemObjs.ContainsKey(id)) { itemObjs[id].Add(obj); } else { itemObjs.Add(id, new List <GameObject>() { obj }); } return(obj); } } return(null); }