public void AddModel() { var modelProperties = GetGameProperties(); ArcadeType arcadeType = ArcadeManager.activeMenuType == ArcadeType.None ? ArcadeManager.activeArcadeType : ArcadeManager.activeMenuType; var myObj = ArcadeManager.loadSaveArcadeConfiguration.AddModelToArcade(ModelType.Game, modelProperties, arcadeType, true); myObj.transform.position = Camera.main.transform.position + Camera.main.transform.forward * 2f; myObj.transform.LookAt(Camera.main.transform.parent.transform); myObj.transform.rotation = Quaternion.Euler(0, myObj.transform.eulerAngles.y, myObj.transform.eulerAngles.z); myObj.transform.localScale = new Vector3(1, 1, 1); }
public void ReplaceModel(GameObject obj) { var tranformPosition = obj.transform.parent.transform.position; var tranformRotation = obj.transform.parent.transform.rotation; var tranformScale = obj.transform.parent.transform.localScale; Destroy(obj.transform.parent.gameObject); var modelProperties = GetGameProperties(); ArcadeType arcadeType = ArcadeManager.activeMenuType == ArcadeType.None ? ArcadeManager.activeArcadeType : ArcadeManager.activeMenuType; var myObj = ArcadeManager.loadSaveArcadeConfiguration.AddModelToArcade(ModelType.Game, modelProperties, arcadeType, true); myObj.transform.position = tranformPosition; myObj.transform.position = myObj.transform.position + new Vector3(0, 0.5f, 0); myObj.transform.rotation = tranformRotation; myObj.transform.localScale = tranformScale; }
public static void Setup(ArcadeType arcadeType) { string type = arcadeType == ArcadeType.FpsArcade || arcadeType == ArcadeType.CylArcade || arcadeType == ArcadeType.None ? "Arcade/" : "Menu/"; List <ModelSetup> tempModelSetups = new List <ModelSetup>(); GameObject obj = GameObject.Find(type + "ArcadeModels"); if (obj != null) { AddFromParent(obj); } obj = GameObject.Find(type + "GameModels"); if (obj != null) { AddFromParent(obj); } obj = GameObject.Find(type + "PropModels"); if (obj != null) { AddFromParent(obj); } foreach (ModelSetup modelSetup in tempModelSetups) { Add(modelSetup, arcadeType); } modelSetups.AddRange(tempModelSetups); modelSetups.RemoveAll(x => x == null); void AddFromParent(GameObject objParent) { var transform = objParent.transform; for (int i = transform.childCount - 1; i >= 0; --i) { ModelSetup modelSetup = objParent.transform.GetChild(i).gameObject.GetComponent <ModelSetup>(); if (modelSetup != null) { tempModelSetups.Add(modelSetup); } } } }
public GameObject AddModelToArcade(ModelType modelType, ModelProperties modelProperties, ArcadeType arcadeType, bool addTrigger) { AssetBundle tAsset; GameObject tObj; tAsset = GetExternalModel(modelProperties.model); if (tAsset != null) { return(addExternalModel(tAsset)); } tObj = GetInternalModel(modelProperties.model); if (tObj != null) { return(AddInternalModel(tObj)); } tAsset = GetExternalModel(modelProperties.id); if (tAsset != null) { return(addExternalModel(tAsset)); } tObj = GetInternalModel(modelProperties.id); if (tObj != null) { return(AddInternalModel(tObj)); } tAsset = GetExternalModel(modelProperties.idParent); if (tAsset != null) { return(addExternalModel(tAsset)); } tObj = GetInternalModel(modelProperties.idParent); if (tObj != null) { return(AddInternalModel(tObj)); } // Now check for defaultmodels // First defaultmodel filters in the emulator List <EmulatorConfiguration> emulatorConfiguration = ArcadeManager.emulatorsConfigurationList.Where(x => x.emulator.id == modelProperties.emulator).ToList(); if (emulatorConfiguration.Count > 1) { List <DefaultModelFilter> defaultModelFilters = emulatorConfiguration[0].emulator.defaultModelFilters; foreach (DefaultModelFilter defaultModel in defaultModelFilters) { bool success = true; foreach (ModelFilter filter in defaultModel.modelFilters) { success &= FilterModel(filter, modelProperties); } if (success) { tAsset = GetExternalModel(defaultModel.model); if (tAsset != null) { return(addExternalModel(tAsset)); } tObj = GetInternalModel(defaultModel.model); if (tObj != null) { return(AddInternalModel(tObj)); } } } } // Generic defaultmodel filters if (arcadeManager.generalConfiguration != null) { List <DefaultModelFilter> defaultModelFilters = arcadeManager.generalConfiguration.defaultModelFilters; foreach (DefaultModelFilter defaultModel in defaultModelFilters) { bool success = true; foreach (ModelFilter filter in defaultModel.modelFilters) { success &= FilterModel(filter, modelProperties); } if (success) { tAsset = GetExternalModel(defaultModel.model); if (tAsset != null) { return(addExternalModel(tAsset)); } tObj = GetInternalModel(defaultModel.model); if (tObj != null) { return(AddInternalModel(tObj)); } } } } // defaultmodel string[] defaultModels = { "default70hor", "default70vert", "default80hor", "default80vert", "default90hor", "default90vert" }; System.Random rnd = new System.Random(); tObj = GetInternalModel(defaultModels[rnd.Next(defaultModels.Length)]); if (tObj != null) { return(AddInternalModel(tObj)); } return(null); AssetBundle GetExternalModel(string modelName) { List <AssetBundle> prefab = ArcadeManager.modelAssets.Where(x => x.name == modelName).ToList(); if (prefab.Count < 1) { var file = FileManager.FileExists(ArcadeManager.applicationPath + "/3darcade~/Configuration/Assets/" + ArcadeManager.currentOS.ToString() + "/" + modelType.ToString() + "s/", modelName + ".unity3d"); if (file != null) { var asset = AssetBundle.LoadFromFile(file); if (asset != null && asset.name != null && asset.name != "") { ArcadeManager.modelAssets.Add(asset); prefab.Add(asset); return(asset); } } } return(prefab.Count == 1 ? prefab[0] : null); } GameObject addExternalModel(AssetBundle asset) { GameObject me = asset.LoadAsset(asset.name) as GameObject; GameObject child = UnityEngine.Object.Instantiate(me); return(AddModel(child, modelProperties)); } GameObject GetInternalModel(string modelName) { GameObject obj = (UnityEngine.GameObject)Resources.Load(modelType.ToString() + "s/" + modelName, typeof(GameObject)); // TODO: NBNB remove this hack to be able to use gamelist models as prop models if (obj == null) { obj = (UnityEngine.GameObject)Resources.Load(ModelType.Game.ToString() + "s/" + modelName, typeof(GameObject)); } return(obj == null ? null : obj); } GameObject AddInternalModel(GameObject obj) { GameObject child = UnityEngine.Object.Instantiate(obj); return(AddModel(child, modelProperties)); } GameObject AddModel(GameObject obj, ModelProperties model) { GameObject dummyNode; if (Application.isPlaying) { dummyNode = new GameObject("dummy"); obj.transform.SetParent(dummyNode.transform); } else { dummyNode = obj; } var modelSetup = dummyNode.GetComponent <ModelSetup>(); if (modelSetup == null) { dummyNode.AddComponent <ModelSetup>(); modelSetup = dummyNode.GetComponent <ModelSetup>(); } //Rigidbody rigidbody = obj.GetComponent<Rigidbody>(); //if (rigidbody != null) //{ // rigidbody.isKinematic = true; //} dummyNode.transform.position = model.position; // model is redundant you aleady have access to modelProperties dummyNode.transform.rotation = model.rotation; dummyNode.transform.localScale = model.scale; if (modelType == ModelType.Arcade) { dummyNode.tag = "arcademodel"; } if (modelType == ModelType.Game) { dummyNode.tag = "gamemodel"; } if (modelType == ModelType.Prop) { dummyNode.tag = "propmodel"; } bool isArcadeLayer = arcadeType == ArcadeType.FpsArcade || arcadeType == ArcadeType.CylArcade || arcadeType == ArcadeType.None ? true : false; string layer = (isArcadeLayer ? "Arcade/" : "Menu/") + modelType.ToString() + "Models"; dummyNode.layer = LayerMask.NameToLayer(layer); dummyNode.RunOnChildrenRecursive(tChild => tChild.layer = LayerMask.NameToLayer(layer)); GameObject node = null; if (isArcadeLayer) { node = GameObject.Find("Arcade/" + modelType.ToString() + "Models"); } else { node = GameObject.Find("Menu/" + modelType.ToString() + "Models"); } if (node != null) { dummyNode.transform.SetParent(node.transform); } else { Debug.Log("Error: Could not find the models parent node..."); } // Zoning if (arcadeType == ArcadeType.FpsArcade || arcadeType == ArcadeType.FpsMenu) { if (!ArcadeManager.visibleZones[arcadeType].ContainsKey(modelProperties.zone)) { ArcadeManager.visibleZones[arcadeType][modelProperties.zone] = new List <GameObject>(); } if (modelProperties.zone != 0) { ArcadeManager.visibleZones[arcadeType][modelProperties.zone].Add(dummyNode); } else { if (Physics.Raycast(dummyNode.transform.position, -dummyNode.transform.up, out RaycastHit vision, 100.0f)) { GameObject objectHit = vision.transform.gameObject; if (objectHit != null) { ModelSetup hitModelSetup = objectHit.transform.parent.gameObject.GetComponent <ModelSetup>(); if (hitModelSetup != null) { //Debug.Log("zonemodel " + modelSetup.descriptiveName); ArcadeManager.visibleZones[arcadeType][hitModelSetup.zone].Add(dummyNode); } } } } } ArcadeConfiguration arcadeConfiguration = isArcadeLayer ? ArcadeManager.arcadeConfiguration : ArcadeManager.menuConfiguration; modelSetup.Setup(model, arcadeConfiguration.modelSharedProperties); if (addTrigger && modelSetup.triggers.Count > 0 && Application.isPlaying) { TriggerManager.Add(modelSetup, arcadeType); } return(dummyNode); } }
public bool LoadArcade(ArcadeConfiguration arcadeConfiguration) { if (arcadeManager == null) { Debug.Log("No ArcadeManager reference found, create one..."); return(false); } if (arcadeConfiguration == null) { return(false); } if (arcadeConfiguration.arcadeType == ArcadeType.FpsArcade.ToString() || arcadeConfiguration.arcadeType == ArcadeType.CylArcade.ToString() || !Application.isPlaying) { arcadeManager.SetArcadeConfiguration(arcadeConfiguration); } else { ArcadeManager.menuConfiguration = arcadeConfiguration; } System.Enum.TryParse(arcadeConfiguration.arcadeType, true, out ArcadeType arcadeType); if (arcadeType == ArcadeType.FpsArcade || arcadeType == ArcadeType.FpsMenu) { ArcadeManager.allZones[arcadeType] = new Dictionary <int, List <int> >(); ArcadeManager.visibleZones[arcadeType] = new Dictionary <int, List <GameObject> >(); foreach (Zone zone in arcadeConfiguration.zones) { ArcadeManager.allZones[arcadeType][zone.zone] = zone.visibleZones; } } SetListOfModelProperties(ModelType.Arcade, arcadeConfiguration.arcadeModelList, "Arcades"); if (arcadeConfiguration.arcadeType == ArcadeType.FpsArcade.ToString() || !Application.isPlaying) { SetListOfModelProperties(ModelType.Game, arcadeConfiguration.gameModelList, "Games"); } SetListOfModelProperties(ModelType.Prop, arcadeConfiguration.propModelList, "Props"); if (!Application.isPlaying) { return(true); } // TODO: Why true? if (arcadeConfiguration.arcadeType == ArcadeType.CylArcade.ToString()) { ArcadeManager.activeArcadeType = ArcadeType.CylArcade; ArcadeManager.arcadeHistory.Add(arcadeConfiguration.id); CylController cylController = ArcadeManager.arcadeControls[ArcadeType.CylArcade].GetComponentInChildren <CylController>(); cylController.SetupCylArcade(arcadeConfiguration); } if (arcadeConfiguration.arcadeType == ArcadeType.FpsArcade.ToString()) { ArcadeManager.activeArcadeType = ArcadeType.FpsArcade; ArcadeManager.arcadeHistory.Add(arcadeConfiguration.id); } if (arcadeConfiguration.arcadeType == ArcadeType.CylMenu.ToString()) { ArcadeManager.activeMenuType = ArcadeType.CylMenu; CylController cylController = ArcadeManager.arcadeControls[ArcadeType.CylMenu].GetComponentInChildren <CylController>(); cylController.SetupCylArcade(arcadeConfiguration); } if (arcadeConfiguration.arcadeType == ArcadeType.FpsMenu.ToString()) { ArcadeManager.activeMenuType = ArcadeType.FpsMenu; } TriggerManager.Setup(arcadeType); return(true); void SetListOfModelProperties(ModelType modelType, List <ModelProperties> list, string resourceFolder) { ArcadeType tempArcadeType = !Application.isPlaying ? ArcadeType.None : arcadeType; int count = list.Count; for (int i = 0; i < count; i++) { ModelProperties modelProperties = list[i]; AddModelToArcade(modelType, modelProperties, tempArcadeType, false); } } }
public static bool Add(ModelSetup modelSetup, ArcadeType arcadeType) { Dictionary <Event, List <TriggerWrapper> > triggerEvents = new Dictionary <Event, List <TriggerWrapper> >(); ModelTriggerSetup modelTriggerSetup = null; GameObject obj = modelSetup.gameObject.transform.GetChild(0).gameObject; // Get the model from its dummy parent if (obj == null) { return(false); } if (modelSetup.triggers.Count > 0) { modelTriggerSetup = obj.GetComponent <ModelTriggerSetup>(); if (modelTriggerSetup == null) { modelTriggerSetup = obj.AddComponent <ModelTriggerSetup>(); } else { // We already setup the triggers for this model! return(true); } foreach (Trigger trigger in modelSetup.triggers) { TriggerWrapper triggerWrapper = new TriggerWrapper(); triggerWrapper.triggerSourceGameObjects = new List <GameObject>(); triggerWrapper.triggerTargetGameObjects = new List <GameObject>(); triggerWrapper.trigger = trigger; foreach (string source in trigger.triggerSource) { if (source.Trim().ToLower() == "self") { triggerWrapper.triggerSourceGameObjects.Add(obj); } else if (source.Trim().ToLower() == "camera") { triggerWrapper.triggerSourceGameObjects.Add(ArcadeManager.arcadeControls[arcadeType]); } else { List <ModelSetup> modelSetupsWithTriggerSources = modelSetups.Where(x => x.triggerIDs.Contains(source)).ToList(); if (modelSetupsWithTriggerSources.Count > 0) { foreach (ModelSetup modelSetupWithTriggerSource in modelSetupsWithTriggerSources) { if (modelSetupWithTriggerSource == null) { continue; } triggerWrapper.triggerSourceGameObjects.Add(modelSetupWithTriggerSource.gameObject.transform.GetChild(0).gameObject); } } else { triggerWrapper.triggerSourceGameObjects.Add(obj); } } } if (triggerWrapper.triggerSourceGameObjects.Count < 1) { triggerWrapper.triggerSourceGameObjects.Add(ArcadeManager.arcadeControls[arcadeType]); } foreach (string target in trigger.triggerTarget) { if (target.Trim().ToLower() == "self") { triggerWrapper.triggerTargetGameObjects.Add(obj); } else if (target.Trim().ToLower() == "camera") { triggerWrapper.triggerTargetGameObjects.Add(ArcadeManager.arcadeControls[arcadeType]); } else { List <ModelSetup> modelSetupsWithTriggerTargets = modelSetups.Where(x => x.triggerIDs.Contains(target)).ToList(); if (modelSetupsWithTriggerTargets.Count > 0) { foreach (ModelSetup modelSetupWithTriggerTarget in modelSetupsWithTriggerTargets) { if (modelSetupWithTriggerTarget == null) { continue; } triggerWrapper.triggerTargetGameObjects.Add(modelSetupWithTriggerTarget.gameObject.transform.GetChild(0).gameObject); } } else { triggerWrapper.triggerTargetGameObjects.Add(obj); } } } if (triggerWrapper.triggerTargetGameObjects.Count < 1) { triggerWrapper.triggerTargetGameObjects.Add(obj); } Event triggerEvent; if (System.Enum.TryParse(trigger.triggerEvent, true, out triggerEvent)) { if (!triggerEvents.ContainsKey(triggerEvent)) { triggerEvents[triggerEvent] = new List <TriggerWrapper>(); } if (!triggersActive.ContainsKey(triggerEvent)) { triggersActive[triggerEvent] = new List <ModelTriggerSetup>(); } triggerEvents[triggerEvent].Add(triggerWrapper); if (modelTriggerSetup != null && !triggersActive[triggerEvent].Contains(modelTriggerSetup)) { triggersActive[triggerEvent].Add(modelTriggerSetup); } } } modelTriggerSetup.Setup(triggerEvents); } return(true); }