//===================================================== public static Object GetPrefab(eSwitchType type = eSwitchType.FLOOR_LEVER) { Init(); Object prefab = null; switch (type) { default: prefab = Resources.Load("Prefabs/Switches/pfbSwitch"); break; case eSwitchType.PRESSURE: prefab = Resources.Load("Prefabs/Switches/pfbPressureSwitch"); break; } if (prefab != null) { return(prefab); } Debug.Log("Switch prefab not found in resources"); return(null); }
//===================================================== private static void AddSwitchOfType(eSwitchType type) { Object pfb = null; switch (type) { default: pfb = ResourcesSwitches.GetPrefab(); break; case eSwitchType.PRESSURE: pfb = ResourcesSwitches.GetPrefab(eSwitchType.PRESSURE); break; } if (pfb == null) { return; } var mdl = ResourcesSwitches.GetModel(type, 0); var prefab = PrefabUtility.InstantiatePrefab(pfb) as GameObject; if (prefab == null) { return; } var script = prefab.GetComponent <Switch>(); switch (type) { case eSwitchType.FLOOR_LEVER: prefab.name = "Switch-Floor-0"; break; case eSwitchType.WALL_SWITCH: prefab.name = "Switch-Wall-0"; break; case eSwitchType.PRESSURE: prefab.name = "Switch-Pressure-0"; break; } if (script != null) { script.Type = type; if (mdl != null) { var model = PrefabUtility.InstantiatePrefab(mdl) as GameObject; script.Init(model); } } PositionObjectAndSelect(prefab); }
//===================================================== public static Object GetModel(eSwitchType type, int index) { Init(); var path = GetModelPath(type, index); if (string.IsNullOrEmpty(path) == false) { var model = Resources.Load(path); if (model != null) { return(model); } } Debug.Log("Switch not found in resources: " + type + " [" + index + "]"); return(null); }
//===================================================== private static string GetModelPath(eSwitchType type, int index) { var path = new StringBuilder(); path.Append("Prefabs/Switches/"); switch (type) { case eSwitchType.FLOOR_LEVER: SetModelPathLocation(ref path, _floorSwitches, "Floor", index); break; case eSwitchType.WALL_SWITCH: SetModelPathLocation(ref path, _wallSwitches, "Wall", index); break; case eSwitchType.PRESSURE: SetModelPathLocation(ref path, _pressureSwitches, "Pressure", index); break; } return(string.IsNullOrEmpty(path.ToString()) == false ? path.ToString() : string.Empty); }