private void UpdateSectors() { if (!displayInactiveSectors) { for (int i = 0; i < sectors.Count; i++) { SectorComponent sc = sectors[i]; if (sc.Loaded) { sc.SetGameObjectActive(true); } else { sc.SetGameObjectActive(false); } } } else { for (int i = 0; i < sectors.Count; i++) { sectors[i].SetGameObjectActive(true); } } }
public void UpdateSectorLoading(Vector3 camPos) { if (Settings.s.engineVersion < Settings.EngineVersion.R2 || Settings.s.game == Settings.Game.LargoWinch) { activeSector = GetActiveSectorOld(camPos, activeSector); } else { activeSector = GetActiveSector(camPos, blockVirtual: true); } for (int i = 0; i < sectors.Count; i++) { SectorComponent s = sectors[i]; s.Loaded = false; s.Active = false; } if (activeSector == null) { for (int i = 0; i < sectors.Count; i++) { sectors[i].Loaded = true; } } else { activeSector.Loaded = true; for (int j = 0; j < activeSector.neighbors.Length; j++) { activeSector.neighbors[j].Loaded = true; } } }
public GameObject GetGameObject() { GameObject gao = new GameObject("SO @ " + Offset + " - " + type); if (data.Value != null) { if (data.Value is PhysicalObject) { PhysicalObjectComponent poc = ((PhysicalObject)data.Value).GetGameObject(gao); } else if (data.Value is Sector) { SectorComponent sc = ((Sector)data.Value).GetGameObject(gao); } } if (children.Value != null) { foreach (Reference <SuperObject> so in children.Value.superObjects) { if (so.Value != null) { GameObject soGao = so.Value.GetGameObject(); if (soGao != null) { soGao.transform.SetParent(gao.transform); ROMTransform.Apply(so.Value.transform, soGao); } } } } return(gao); }
public SectorComponent GetGameObject(GameObject gao) { gao.name += " - Sector @ " + Offset; // + " - " + isSectorVirtual + " - " + byte2D + " - " + sectorPriority + " - " + byte31 + " - " + byte1E + " - " + byte1F; SectorComponent sc = gao.AddComponent <SectorComponent>(); sc.sectorPS1 = this; sc.sectorManager = MapLoader.Loader.controller.sectorManager; MapLoader.Loader.controller.sectorManager.AddSector(sc); //sc.Init(); return(sc); }
public void Init() { lights = new List <LightBehaviour>(); if (MapLoader.Loader is OpenSpace.Loader.R2ROMLoader) { for (int i = 0; i < sectorManager.sectors.Count; i++) { SectorComponent sc = sectorManager.sectors[i]; if (sc.sectorROM.lights.Value != null) { sc.lights = new LightBehaviour[sc.sectorROM.lights.Value.lights.Length]; for (int j = 0; j < sc.lights.Length; j++) { sc.lights[j] = Register(sc.sectorROM.lights.Value.lights[j]); } } } } else if (MapLoader.Loader is OpenSpace.Loader.R2PS1Loader) { for (int i = 0; i < sectorManager.sectors.Count; i++) { SectorComponent sc = sectorManager.sectors[i]; /*if (sc.sectorPS1.lights.Value != null) { * sc.lights = new LightBehaviour[sc.sectorPS1.lights.Value.lights.Length]; * for (int j = 0; j < sc.lights.Length; j++) { * sc.lights[j] = Register(sc.sectorPS1.lights.Value.lights[j]); * } * }*/ } } else { for (int i = 0; i < sectorManager.sectors.Count; i++) { SectorComponent sc = sectorManager.sectors[i]; if (sc.sector.staticLights != null) { sc.lights = new LightBehaviour[sc.sector.staticLights.Count]; for (int j = 0; j < sc.lights.Length; j++) { sc.lights[j] = Register(sc.sector.staticLights[j]); } } } } if (useDefaultSettings) { luminosity = Settings.s.luminosity; saturate = Settings.s.saturate; } loaded = true; }
private SectorComponent GetActiveSector(Vector3 point, bool blockVirtual = false) { float smallestDistanceToSector = float.MaxValue; float smallestDistanceToSectorVirtual = float.MaxValue; byte activeSectorPriority = 0; byte activeSectorPriorityVirtual = 0; SectorComponent activeSectorVirtual = null; SectorComponent activeSector = null; foreach (SectorComponent s in sectors) { if (s.SectorBorder != null ? s.SectorBorder.ContainsPoint(point) : false) { float dist = Vector3.Distance(s.SectorBorder.Center, point); if (s.IsSectorVirtual) { if (s.SectorPriority > activeSectorPriorityVirtual || (s.SectorPriority == activeSectorPriorityVirtual && dist < smallestDistanceToSectorVirtual)) { smallestDistanceToSectorVirtual = dist; activeSectorVirtual = s; activeSectorPriorityVirtual = s.SectorPriority; } } else { if (s.SectorPriority > activeSectorPriority || (s.SectorPriority == activeSectorPriority && dist < smallestDistanceToSector)) { smallestDistanceToSector = dist; activeSector = s; activeSectorPriority = s.SectorPriority; } } } } if (activeSector != null) { return(activeSector); } else if (activeSectorVirtual != null && !blockVirtual) { return(activeSectorVirtual); } else { return(sectors.Last()); // Univers } }
private SectorComponent GetActiveSectorOld(Vector3 point, SectorComponent currentActiveSector = null, bool allowVirtual = false) { if (currentActiveSector != null && currentActiveSector.sectorTransitions != null && currentActiveSector.sectorTransitions.Length > 0) { // We shouldn't really test the sector transitions here, but a lot of "absorbing" sectors have no transitions if (currentActiveSector.SectorBorder != null ? currentActiveSector.SectorBorder.ContainsPoint(point) : false) { return(currentActiveSector); } } SectorComponent activeSector = null; for (int i = 0; i < sectors.Count; i++) { SectorComponent s = sectors[i]; s.Loaded = false; s.Active = false; } if (currentActiveSector != null && currentActiveSector.sectorTransitions != null) { for (int i = 0; i < currentActiveSector.sectorTransitions.Length; i++) { SectorComponent s = currentActiveSector.sectorTransitions[i]; bool active = (allowVirtual || !s.IsSectorVirtual) && (s.SectorBorder != null ? s.SectorBorder.ContainsPoint(point) : false); if (active) { activeSector = s; break; } } } if (activeSector == null) { for (int i = 0; i < sectors.Count; i++) { SectorComponent s = sectors[i]; bool active = (allowVirtual || !s.IsSectorVirtual) && (s.SectorBorder != null ? s.SectorBorder.ContainsPoint(point) : false); if (active) { activeSector = s; break; } } } return(activeSector); }
public void Init() { /*sectors = MapLoader.Loader.sectors; * sectorComponents = sectors.Select(s => s.Gao.AddComponent<SectorComponent>()).ToList(); * if (MapLoader.Loader is OpenSpace.Loader.R2ROMLoader) { * SectorsROM = new List<SectorComponent>(); * OpenSpace.Loader.R2ROMLoader l = (OpenSpace.Loader.R2ROMLoader)MapLoader.Loader; * OpenSpace.ROM.LevelHeader lh = l.level; * }*/ for (int i = 0; i < sectors.Count; i++) { SectorComponent sc = sectors[i]; sc.Init(); /*if (sc.sector != null) { * ApplySectorLighting(sc, sc.Gao, LightInfo.ObjectLightedFlag.Environment); * }*/ } }
public GameObject GetGameObject() { GameObject gao = new GameObject("SO @ " + Offset + " - " + type); SuperObjectComponent soc = gao.AddComponent <SuperObjectComponent>(); gao.layer = LayerMask.NameToLayer("SuperObject"); soc.soROM = this; MapLoader.Loader.controller.superObjects.Add(soc); if (data.Value != null) { if (data.Value is PhysicalObject) { PhysicalObjectComponent poc = ((PhysicalObject)data.Value).GetGameObject(gao); } else if (data.Value is Sector) { SectorComponent sc = ((Sector)data.Value).GetGameObject(gao); } } if (children.Value != null) { foreach (Reference <SuperObject> so in children.Value.superObjects) { if (so.Value != null) { GameObject soGao = so.Value.GetGameObject(); if (soGao != null) { soc.Children.Add(soGao.GetComponent <SuperObjectComponent>()); soGao.transform.SetParent(gao.transform); ROMTransform.Apply(so.Value.transform, soGao); } } } } return(gao); }
async Task InitPersos() { if (loader != null) { for (int i = 0; i < loader.persos.Count; i++) { detailedState = "Initializing persos: " + i + "/" + loader.persos.Count; await WaitIfNecessary(); Perso p = loader.persos[i]; PersoBehaviour unityBehaviour = p.Gao.AddComponent <PersoBehaviour>(); unityBehaviour.controller = this; if (loader.globals != null && loader.globals.spawnablePersos != null) { if (loader.globals.spawnablePersos.IndexOf(p) > -1) { unityBehaviour.IsAlways = true; unityBehaviour.transform.position = new Vector3(i * 10, -1000, 0); } } if (!unityBehaviour.IsAlways) { if (p.sectInfo != null && p.sectInfo.off_sector != null) { unityBehaviour.sector = sectorManager.sectors.FirstOrDefault(s => s.sector != null && s.sector.SuperObject.offset == p.sectInfo.off_sector); } else { SectorComponent sc = sectorManager.GetActiveSectorWrapper(p.Gao.transform.position); unityBehaviour.sector = sc; } } else { unityBehaviour.sector = null; } unityBehaviour.perso = p; unityBehaviour.Init(); // Scripts if (p.Gao) { if (p.brain != null && p.brain.mind != null && p.brain.mind.AI_model != null) { if (p.brain.mind.AI_model.behaviors_normal != null) { GameObject intelParent = new GameObject("Rule behaviours"); intelParent.transform.parent = p.Gao.transform; Behavior[] normalBehaviors = p.brain.mind.AI_model.behaviors_normal; int iter = 0; foreach (Behavior behavior in normalBehaviors) { string shortName = behavior.GetShortName(p.brain.mind.AI_model, Behavior.BehaviorType.Intelligence, iter); GameObject behaviorGao = new GameObject(shortName); behaviorGao.transform.parent = intelParent.transform; foreach (Script script in behavior.scripts) { GameObject scriptGao = new GameObject("Script"); scriptGao.transform.parent = behaviorGao.transform; ScriptComponent scriptComponent = scriptGao.AddComponent <ScriptComponent>(); scriptComponent.SetScript(script, p); } if (behavior.firstScript != null) { ScriptComponent scriptComponent = behaviorGao.AddComponent <ScriptComponent>(); scriptComponent.SetScript(behavior.firstScript, p); } if (iter == 0) { behaviorGao.name += " (Init)"; } if ((behavior.scripts == null || behavior.scripts.Length == 0) && behavior.firstScript == null) { behaviorGao.name += " (Empty)"; } iter++; } } if (p.brain.mind.AI_model.behaviors_reflex != null) { GameObject reflexParent = new GameObject("Reflex behaviours"); reflexParent.transform.parent = p.Gao.transform; Behavior[] reflexBehaviors = p.brain.mind.AI_model.behaviors_reflex; int iter = 0; foreach (Behavior behavior in reflexBehaviors) { string shortName = behavior.GetShortName(p.brain.mind.AI_model, Behavior.BehaviorType.Reflex, iter); GameObject behaviorGao = new GameObject(shortName); behaviorGao.transform.parent = reflexParent.transform; foreach (Script script in behavior.scripts) { GameObject scriptGao = new GameObject("Script"); scriptGao.transform.parent = behaviorGao.transform; ScriptComponent scriptComponent = scriptGao.AddComponent <ScriptComponent>(); scriptComponent.SetScript(script, p); } if (behavior.firstScript != null) { ScriptComponent scriptComponent = behaviorGao.AddComponent <ScriptComponent>(); scriptComponent.SetScript(behavior.firstScript, p); } if ((behavior.scripts == null || behavior.scripts.Length == 0) && behavior.firstScript == null) { behaviorGao.name += " (Empty)"; } iter++; } } if (p.brain.mind.AI_model.macros != null) { GameObject macroParent = new GameObject("Macros"); macroParent.transform.parent = p.Gao.transform; Macro[] macros = p.brain.mind.AI_model.macros; int iter = 0; foreach (Macro macro in macros) { GameObject behaviorGao = new GameObject(macro.GetShortName(p.brain.mind.AI_model, iter)); behaviorGao.transform.parent = macroParent.transform; ScriptComponent scriptComponent = behaviorGao.AddComponent <ScriptComponent>(); scriptComponent.SetScript(macro.script, p); iter++; } } } } } // Initialize DSGVars after all persos have their perso behaviours for (int i = 0; i < loader.persos.Count; i++) { Perso p = loader.persos[i]; Moddable mod = null; if (p.SuperObject != null && p.SuperObject.Gao != null) { mod = p.SuperObject.Gao.GetComponent <Moddable>(); if (mod != null) { mod.persoBehaviour = p.Gao.GetComponent <PersoBehaviour>(); } } if (p.Gao && p.brain != null && p.brain.mind != null && p.brain.mind.AI_model != null) { // DsgVars if (p.brain.mind.dsgMem != null || p.brain.mind.AI_model.dsgVar != null) { DsgVarComponent dsgVarComponent = p.Gao.AddComponent <DsgVarComponent>(); dsgVarComponent.SetPerso(p); if (mod != null) { mod.dsgVarComponent = dsgVarComponent; } } // Dynam if (p.dynam != null && p.dynam.dynamics != null) { DynamicsMechanicsComponent dynamicsBehaviour = p.Gao.AddComponent <DynamicsMechanicsComponent>(); dynamicsBehaviour.SetDynamics(p.dynam.dynamics); } // Mind if (p.brain != null && p.brain.mind != null) { MindComponent mindComponent = p.Gao.AddComponent <MindComponent>(); mindComponent.Init(p, p.brain.mind); if (mod != null) { mod.mindComponent = mindComponent; } } // Custom Bits if (p.stdGame != null) { CustomBitsComponent c = p.Gao.AddComponent <CustomBitsComponent>(); c.stdGame = p.stdGame; if (Settings.s.engineVersion == Settings.EngineVersion.R3) { c.hasAiCustomBits = true; } c.Init(); } } } } if (loader is OpenSpace.Loader.R2ROMLoader) { OpenSpace.Loader.R2ROMLoader romLoader = loader as OpenSpace.Loader.R2ROMLoader; if (romPersos.Count > 0) { for (int i = 0; i < romPersos.Count; i++) { detailedState = "Initializing persos: " + i + "/" + romPersos.Count; await WaitIfNecessary(); ROMPersoBehaviour unityBehaviour = romPersos[i]; unityBehaviour.controller = this; /*if (loader.globals != null && loader.globals.spawnablePersos != null) { * if (loader.globals.spawnablePersos.IndexOf(p) > -1) { * unityBehaviour.IsAlways = true; * unityBehaviour.transform.position = new Vector3(i * 10, -1000, 0); * } * }*/ if (!unityBehaviour.IsAlways) { SectorComponent sc = sectorManager.GetActiveSectorWrapper(unityBehaviour.transform.position); unityBehaviour.sector = sc; } else { unityBehaviour.sector = null; } /*Moddable mod = null; * if (p.SuperObject != null && p.SuperObject.Gao != null) { * mod = p.SuperObject.Gao.GetComponent<Moddable>(); * if (mod != null) { * mod.persoBehaviour = unityBehaviour; * } * }*/ unityBehaviour.Init(); var iteratorPerso = unityBehaviour.perso; // Of sound brain and AI model? if (iteratorPerso.brain?.Value?.aiModel?.Value != null) { var aiModel = iteratorPerso.brain.Value.aiModel.Value; // DsgVars if (iteratorPerso.brain?.Value?.dsgMem?.Value != null || aiModel.dsgVar?.Value != null) { DsgVarComponent dsgVarComponent = unityBehaviour.gameObject.AddComponent <DsgVarComponent>(); dsgVarComponent.SetPerso(iteratorPerso); } // Comports if (aiModel.comportsIntelligence.Value != null) { aiModel.comportsIntelligence.Value.CreateGameObjects("Rule", unityBehaviour.gameObject, iteratorPerso); } if (aiModel.comportsReflex.Value != null) { aiModel.comportsReflex.Value.CreateGameObjects("Reflex", unityBehaviour.gameObject, iteratorPerso); } } } } if (romLoader.level != null && romLoader.level.spawnablePersos.Value != null && romLoader.level.num_spawnablepersos > 0) { GameObject spawnableParent = new GameObject("Spawnable persos"); for (int i = 0; i < romLoader.level.num_spawnablepersos; i++) { detailedState = "Initializing spawnable persos: " + i + "/" + romLoader.level.num_spawnablepersos; await WaitIfNecessary(); OpenSpace.ROM.SuperObjectDynamic sod = romLoader.level.spawnablePersos.Value.superObjects[i]; GameObject sodGao = sod.GetGameObject(); if (sodGao != null) { ROMPersoBehaviour unityBehaviour = sodGao.GetComponent <ROMPersoBehaviour>(); unityBehaviour.controller = this; unityBehaviour.IsAlways = true; unityBehaviour.transform.SetParent(spawnableParent.transform); unityBehaviour.transform.position = new Vector3(i * 10, -1000, 0); unityBehaviour.transform.rotation = Quaternion.identity; unityBehaviour.transform.localScale = Vector3.one; if (!unityBehaviour.IsAlways) { SectorComponent sc = sectorManager.GetActiveSectorWrapper(unityBehaviour.transform.position); unityBehaviour.sector = sc; } else { unityBehaviour.sector = null; } unityBehaviour.Init(); var iteratorPerso = unityBehaviour.perso; // Of sound brain and AI model? if (iteratorPerso.brain?.Value?.aiModel?.Value != null) { var aiModel = iteratorPerso.brain.Value.aiModel.Value; // DsgVars if (iteratorPerso.brain?.Value?.dsgMem?.Value != null || aiModel.dsgVar?.Value != null) { DsgVarComponent dsgVarComponent = unityBehaviour.gameObject.AddComponent <DsgVarComponent>(); dsgVarComponent.SetPerso(iteratorPerso); } // Comports if (aiModel.comportsIntelligence.Value != null) { aiModel.comportsIntelligence.Value.CreateGameObjects("Rule", unityBehaviour.gameObject, iteratorPerso); } if (aiModel.comportsReflex.Value != null) { aiModel.comportsReflex.Value.CreateGameObjects("Reflex", unityBehaviour.gameObject, iteratorPerso); } } } } } } }
private void UpdateBackgroundROM() { // Update background color or material Color?backgroundColor = null; OpenSpace.ROM.VisualMaterial skyMaterial = null; OpenSpace.ROM.VisualMaterial[] skyMaterialsDD = null; SectorComponent activeBackgroundSector = null; OpenSpace.Loader.R2ROMLoader l = MapLoader.Loader as OpenSpace.Loader.R2ROMLoader; OpenSpace.ROM.LevelHeader lh = l.level; if (lh != null && lh.backgroundUpLeft != null && lh.backgroundUpLeft.Value != null && lh.backgroundUpRight != null && lh.backgroundUpRight.Value != null && lh.backgroundDownLeft != null && lh.backgroundDownLeft.Value != null && lh.backgroundDownRight != null && lh.backgroundDownRight.Value != null) { skyMaterial = null; skyMaterialsDD = new OpenSpace.ROM.VisualMaterial[4]; skyMaterialsDD[0] = lh.backgroundUpLeft.Value; skyMaterialsDD[1] = lh.backgroundUpRight.Value; skyMaterialsDD[2] = lh.backgroundDownLeft.Value; skyMaterialsDD[3] = lh.backgroundDownRight.Value; } else { if (sectorManager != null && sectorManager.sectors != null && sectorManager.sectors.Count > 0) { foreach (SectorComponent s in sectorManager.sectors) { if (!s.Loaded) { continue; } if (s.sectorROM == null) { continue; } if (s.sectorROM.background != null && s.sectorROM.background.Value != null && s.sectorROM.background.Value.num_textures > 0 && s.sectorROM.background.Value.textures.Value != null && s.sectorROM.background.Value.textures.Value.vmTex[0].texRef.Value != null && s.sectorROM.background.Value.textures.Value.vmTex[0].texRef.Value.texInfo.Value != null) { skyMaterial = s.sectorROM.background; //print(skyMaterial.Offset); activeBackgroundSector = s; break; } else { /*foreach (LightInfo li in s.sector.staticLights) { * if (li.type == 6) { * backgroundColor = li.background_color; * break; * } * }*/ } } } } if (!controller.viewCollision) { if (skyMaterial != null) { backgroundPanel.gameObject.SetActive(true); if (backgroundMaterialROM != skyMaterial) { backgroundMaterialROM = skyMaterial; Material skyboxMat = skyMaterial.GetMaterial(OpenSpace.ROM.VisualMaterial.Hint.None); /*Texture tex = skyboxMat.GetTexture("_Tex0"); * tex.filterMode = FilterMode.Point; * tex.wrapMode = TextureWrapMode.Clamp; * skyboxMat.SetTexture("_Tex0", tex);*/ backgroundPanel.sharedMaterial = skyboxMat; } //skyboxMat.SetFloat("_DisableLighting", 1f); backgroundPanel.sharedMaterial.SetFloat("_DisableLightingLocal", 1f); if (activeBackgroundSector != null) { if (activeBackgroundSector != previousActiveBackgroundSector) { //backgroundPanel.material.SetFloat("_DisableLightingLocal", 0f); sectorManager.ApplySectorLighting(activeBackgroundSector, backgroundPanel.gameObject, LightInfo.ObjectLightedFlag.Environment); previousActiveBackgroundSector = activeBackgroundSector; } } else { //backgroundPanel.material.SetFloat("_DisableLighting", 1f); } //RenderSettings.skybox = skyboxMat; //Camera.main.clearFlags = CameraClearFlags.Skybox; } else { backgroundPanel.gameObject.SetActive(false); } if (skyMaterialsDD != null) { for (int i = 0; i < 4; i++) { backgroundPanelsROM[i].gameObject.SetActive(true); } if (backgroundMaterialsDDROM == null) { backgroundMaterialsDDROM = skyMaterialsDD; for (int i = 0; i < 4; i++) { Material skyboxMat = skyMaterialsDD[i].GetMaterial(OpenSpace.ROM.VisualMaterial.Hint.None); backgroundPanelsROM[i].sharedMaterial = skyboxMat; backgroundPanelsROM[i].sharedMaterial.SetFloat("_DisableLightingLocal", 1f); } } if (activeBackgroundSector != null) { if (activeBackgroundSector != previousActiveBackgroundSector) { //backgroundPanel.material.SetFloat("_DisableLightingLocal", 0f); //sectorManager.ApplySectorLighting(activeBackgroundSector, backgroundPanel.gameObject, LightInfo.ObjectLightedFlag.Environment); previousActiveBackgroundSector = activeBackgroundSector; } } else { //backgroundPanel.material.SetFloat("_DisableLighting", 1f); } //RenderSettings.skybox = skyboxMat; //Camera.main.clearFlags = CameraClearFlags.Skybox; } else { for (int i = 0; i < 4; i++) { backgroundPanelsROM[i].gameObject.SetActive(false); } } } else { backgroundPanel.gameObject.SetActive(false); for (int i = 0; i < 4; i++) { backgroundPanelsROM[i].gameObject.SetActive(false); } //RenderSettings.skybox = null; //Camera.main.clearFlags = CameraClearFlags.SolidColor; } if (backgroundColor.HasValue && !controller.viewCollision) { Camera.main.backgroundColor = backgroundColor.Value; //Camera.main.backgroundColor = Color.Lerp(Camera.main.backgroundColor, backgroundColor.Value, 0.5f * Time.deltaTime); } else { Camera.main.backgroundColor = Color.black; //Camera.main.backgroundColor = Color.Lerp(Camera.main.backgroundColor, Color.black, 0.5f * Time.deltaTime); } }
private void UpdateBackground() { // Update background color or material Color? backgroundColor = null; VisualMaterial skyMaterial = null; SectorComponent activeBackgroundSector = null; if (MapLoader.Loader.globals != null && MapLoader.Loader.globals.backgroundGameMaterial != null && MapLoader.Loader.globals.backgroundGameMaterial.visualMaterial != null) { skyMaterial = MapLoader.Loader.globals.backgroundGameMaterial.visualMaterial; } else { if (sectorManager != null && sectorManager.sectors != null && sectorManager.sectors.Count > 0) { foreach (SectorComponent s in sectorManager.sectors) { if (!s.Loaded) { continue; } if (s.sector == null) { continue; } if (s.sector.skyMaterial != null && s.sector.skyMaterial.textures.Count > 0 && s.sector.skyMaterial.textures.Where(t => t.texture != null).Count() > 0) { skyMaterial = s.sector.skyMaterial; activeBackgroundSector = s; break; } else { if (!s.Active) { continue; } foreach (LightInfo li in s.sector.staticLights) { if (li.type == 6) { backgroundColor = li.background_color; break; } } } } } } if (skyMaterial != null && !controller.viewCollision) { backgroundPanel.gameObject.SetActive(true); if (backgroundMaterial != skyMaterial) { backgroundMaterial = skyMaterial; Material skyboxMat = skyMaterial.GetMaterial(); backgroundPanel.sharedMaterial = skyboxMat; } //skyboxMat.SetFloat("_DisableLighting", 1f); backgroundPanel.sharedMaterial.SetFloat("_DisableLightingLocal", 1f); if (activeBackgroundSector != null) { if (activeBackgroundSector != previousActiveBackgroundSector) { //backgroundPanel.material.SetFloat("_DisableLightingLocal", 0f); sectorManager.ApplySectorLighting(activeBackgroundSector, backgroundPanel.gameObject, LightInfo.ObjectLightedFlag.Environment); previousActiveBackgroundSector = activeBackgroundSector; } } else { //backgroundPanel.material.SetFloat("_DisableLighting", 1f); } //RenderSettings.skybox = skyboxMat; //Camera.main.clearFlags = CameraClearFlags.Skybox; } else { backgroundPanel.gameObject.SetActive(false); //RenderSettings.skybox = null; //Camera.main.clearFlags = CameraClearFlags.SolidColor; } if (backgroundColor.HasValue && !controller.viewCollision) { Camera.main.backgroundColor = backgroundColor.Value; //Camera.main.backgroundColor = Color.Lerp(Camera.main.backgroundColor, backgroundColor.Value, 0.5f * Time.deltaTime); } else { Camera.main.backgroundColor = Color.black; //Camera.main.backgroundColor = Color.Lerp(Camera.main.backgroundColor, Color.black, 0.5f * Time.deltaTime); } }
public void ApplySectorLighting(SectorComponent sector, GameObject gao, LightInfo.ObjectLightedFlag objectType) { if (objectType == LightInfo.ObjectLightedFlag.None) { if (gao) { List <Renderer> rs = gao.GetComponents <Renderer>().ToList(); foreach (Renderer r in rs) { if (r.sharedMaterial.shader.name.Contains("Gouraud") || r.sharedMaterial.shader.name.Contains("Texture Blend")) { r.material.SetFloat("_DisableLightingLocal", 1); } } rs = gao.GetComponentsInChildren <Renderer>(true).ToList(); foreach (Renderer r in rs) { if (r.sharedMaterial.shader.name.Contains("Gouraud") || r.sharedMaterial.shader.name.Contains("Texture Blend")) { r.material.SetFloat("_DisableLightingLocal", 1); } } } } else { if (sector == null) { return; } /*Sector s = sector.sector; * if (s == null) return;*/ if (sector.lights != null) { Vector4? fogColor = null; Vector4? fogParams = null; Vector4 ambientLight = Vector4.zero; List <Vector4> staticLightPos = new List <Vector4>(); List <Vector4> staticLightDir = new List <Vector4>(); List <Vector4> staticLightCol = new List <Vector4>(); List <Vector4> staticLightParams = new List <Vector4>(); for (int i = 0; i < sector.lights.Length; i++) { LightBehaviour lb = sector.lights[i]; //LightInfo li = lb.li; //if (li == null) continue; //if (!li.IsObjectLighted(objectType)) continue; //if (li.turnedOn == 0x0) continue; switch (lb.Type) { case 4: ambientLight += lb.Color; staticLightPos.Add(new Vector4(lb.transform.position.x, lb.transform.position.y, lb.transform.position.z, lb.Type)); staticLightDir.Add(lb.transform.TransformVector(Vector3.back)); staticLightCol.Add(lb.Color); staticLightParams.Add(new Vector4(lb.Near, lb.Far, lb.PaintingLightFlag, lb.AlphaLightFlag)); break; case 6: if (!fogColor.HasValue) { fogColor = lb.Color; fogParams = new Vector4(lb.FogBlendNear / 255f, lb.FogBlendFar / 255f, lb.Near, lb.Far); } break; default: staticLightPos.Add(new Vector4(lb.transform.position.x, lb.transform.position.y, lb.transform.position.z, lb.Type)); staticLightDir.Add(lb.transform.TransformVector(Vector3.back)); staticLightCol.Add(lb.Color); Vector3 scale = lb.transform.localScale; float maxScale = Mathf.Max(scale.x, scale.y, scale.z); staticLightParams.Add(new Vector4(lb.Near * maxScale, lb.Far * maxScale, lb.PaintingLightFlag, lb.AlphaLightFlag)); break; } } Vector4[] staticLightPosArray = staticLightPos.ToArray(); Vector4[] staticLightDirArray = staticLightDir.ToArray(); Vector4[] staticLightColArray = staticLightCol.ToArray(); Vector4[] staticLightParamsArray = staticLightParams.ToArray(); //print(staticLightPosArray.Length + " - " + objectType); if (gao) { List <Renderer> rs = gao.GetComponents <Renderer>().ToList(); foreach (Renderer r in rs) { if (r.sharedMaterial.shader.name.Contains("Gouraud") || r.sharedMaterial.shader.name.Contains("Texture Blend")) { MaterialPropertyBlock props = new MaterialPropertyBlock(); r.GetPropertyBlock(props); if (fogColor.HasValue) { props.SetVector("_SectorFog", fogColor.Value); } if (fogParams.HasValue) { props.SetVector("_SectorFogParams", fogParams.Value); } //r.material.SetVector("_SectorAmbient", ambientLight); props.SetFloat("_StaticLightCount", staticLightPosArray.Length); if (staticLightPosArray.Length > 0) { props.SetVectorArray("_StaticLightPos", staticLightPosArray); props.SetVectorArray("_StaticLightDir", staticLightDirArray); props.SetVectorArray("_StaticLightCol", staticLightColArray); props.SetVectorArray("_StaticLightParams", staticLightParamsArray); } r.SetPropertyBlock(props); } } rs = gao.GetComponentsInChildren <Renderer>(true).ToList(); foreach (Renderer r in rs) { if (r.sharedMaterial != null && (r.sharedMaterial.shader.name.Contains("Gouraud") || r.sharedMaterial.shader.name.Contains("Texture Blend"))) { MaterialPropertyBlock props = new MaterialPropertyBlock(); r.GetPropertyBlock(props); if (fogColor.HasValue) { props.SetVector("_SectorFog", fogColor.Value); } if (fogParams.HasValue) { props.SetVector("_SectorFogParams", fogParams.Value); } //r.material.SetVector("_SectorAmbient", ambientLight); props.SetFloat("_StaticLightCount", staticLightPosArray.Length); if (staticLightPosArray.Length > 0) { props.SetVectorArray("_StaticLightPos", staticLightPosArray); props.SetVectorArray("_StaticLightDir", staticLightDirArray); props.SetVectorArray("_StaticLightCol", staticLightColArray); props.SetVectorArray("_StaticLightParams", staticLightParamsArray); } r.SetPropertyBlock(props); } } } } } }
public void AddSector(SectorComponent sc) { sectors.Add(sc); }
public GameObject GetGameObject() { GameObject gao = new GameObject(type + " @ " + Offset); if (FileSystem.mode == FileSystem.Mode.Web) { gao.name = type.ToString(); } SuperObjectComponent soc = gao.AddComponent <SuperObjectComponent>(); gao.layer = LayerMask.NameToLayer("SuperObject"); soc.soPS1 = this; MapLoader.Loader.controller.superObjects.Add(soc); if (type != Type.IPO) { matrix1?.Apply(gao); } /*if (.Value != null) { * if (data.Value is PhysicalObject) { * PhysicalObjectComponent poc = ((PhysicalObject)data.Value).GetGameObject(gao); * } else if (data.Value is Sector) { * SectorComponent sc = ((Sector)data.Value).GetGameObject(gao); * } * }*/ if (type == Type.IPO) { PhysicalObjectComponent poc = gao.AddComponent <PhysicalObjectComponent>(); LevelHeader h = (Load as R2PS1Loader).levelHeader; int ind = (dataIndex >> 1); if (ind >= h.geometricObjectsStatic.entries.Length) { throw new Exception("IPO SO data index was too high! " + h.geometricObjectsStatic.entries.Length + " - " + dataIndex); } gao.name = gao.name + " - " + ind; GameObject g = h.geometricObjectsStatic.GetGameObject(ind, null, out _); if (g != null) { poc.visual = g; g.transform.SetParent(gao.transform); g.transform.localPosition = Vector3.zero; g.transform.localRotation = Quaternion.identity; } if (h.ipoCollision != null && h.ipoCollision.Length > ind) { GameObject c = h.ipoCollision[ind].GetGameObject(); if (c != null) { poc.collide = c; c.transform.SetParent(gao.transform); c.transform.localPosition = Vector3.zero; c.transform.localRotation = Quaternion.identity; } } poc.Init(MapLoader.Loader.controller); } else if (type == Type.Perso) { LevelHeader h = (Load as R2PS1Loader).levelHeader; if (dataIndex >= h.persos.Length) { throw new Exception("Perso SO data index was too high! " + h.persos.Length + " - " + dataIndex); } gao.name = gao.name + " - " + dataIndex; PS1PersoBehaviour ps1Perso = h.persos[dataIndex].GetGameObject(gao); ps1Perso.superObject = this; } else if (type == Type.Sector) { LevelHeader h = (Load as R2PS1Loader).levelHeader; if (dataIndex >= h.sectors.Length) { throw new Exception("Sector SO data index was too high! " + h.sectors.Length + " - " + dataIndex); } gao.name = gao.name + " - " + dataIndex; SectorComponent sect = h.sectors[dataIndex].GetGameObject(gao); } if (children != null) { foreach (SuperObject so in children) { if (so != null) { GameObject soGao = so.GetGameObject(); if (soGao != null) { soc.Children.Add(soGao.GetComponent <SuperObjectComponent>()); soGao.transform.SetParent(gao.transform); if (so.type != Type.IPO) { so.matrix1?.Apply(soGao); } else { soGao.transform.localPosition = Vector3.zero; soGao.transform.localRotation = Quaternion.identity; } } } } } return(gao); }