void Awake() { pm = (PerkManagerTB)target; LoadPerk(); InitLabel(); }
// Use this for initialization void Start() { PerkManagerTB perkManager = (PerkManagerTB)FindObjectOfType(typeof(PerkManagerTB)); perkManagerExist = perkManager == null ? false : true; #if glow //cache the color values c = GUI.color; //cache the color cc = GUI.contentColor; #endif }
public void OnUnlockPerkButton(PerkTB perk) { if (perk.cost > GetPlayerPoint()) { Debug.Log("Insufficient Points!"); //UINGUISetup.DisplayMessage("Insufficient Points!"); return; } if (PerkManagerTB.UnlockPerk(selectedID)) { Debug.Log(perk.name + " has been unlocked"); //UINGUISetup.DisplayMessage(selectedPerk.name+" has been unlocked"); } }
int GetPlayerPoint() { //~ if(UINGUISetup.IsSetupScene()){ //~ return UINGUISetup.playerPoint; //~ } //~ else{ if (!PerkManagerTB.UsePersistentData()) { return(PerkManagerTB.GetPoint()); } else { return(GlobalStatsTB.GetPlayerPoint()); } //~ } }
public int IsAvailable() { if (!PerkManagerTB.UsePersistentData()) { if (PerkManagerTB.GetPoint() < cost) { return(1); //return "insufficient point to unlock perk"; //return false; } } else { if (GlobalStatsTB.GetPlayerPoint() < cost) { return(1); //return "insufficient player point to unlock perk"; //return false; } } if (PerkManagerTB.GetPerkPoint() < pointReq) { return(2); //return "insufficient perk point to unlock perk"; //return false; } for (int i = 0; i < prereq.Count; i++) { if (!PerkManagerTB.GetPerk(prereq[i]).unlocked) { return(3); //return "pre-req perk needed to unlock perk"; //return false; } } //return true; //return ""; return(0); }
void Awake() { if (instance != null) { Destroy(gameObject); } if (dontDestroyOnLoad) { GameObject.DontDestroyOnLoad(gameObject); } instance = this; LoadPerk(); LoadUnit(); //if(!GlobalStatsTB.loaded){ // perkPoint=startingPerkPoint; //} //ResetPerk(); }
void Awake() { if(instance!=null) Destroy(gameObject); if(dontDestroyOnLoad){ GameObject.DontDestroyOnLoad(gameObject); } instance=this; LoadPerk(); LoadUnit(); //if(!GlobalStatsTB.loaded){ // perkPoint=startingPerkPoint; //} //ResetPerk(); }
public override void OnInspectorGUI() { pm = (PerkManagerTB)target; //DrawDefaultInspector(); EditorGUILayout.Space(); EditorGUILayout.Space(); cont=new GUIContent("Dont Destroy On Load:", "Check to use this component through out the game\nWhen checked, setting in other PerkManager wont take effect after this scene is loaded\nIntended for game where perk progress is persistant"); EditorGUILayout.BeginHorizontal(""); EditorGUILayout.LabelField(cont, GUILayout.MinWidth(230)); pm.dontDestroyOnLoad=EditorGUILayout.Toggle(pm.dontDestroyOnLoad); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); cont=new GUIContent("Use Persistent Data:", "Check to make any perk progression persistant. Otherwise any progression made will be reset upon leaving the level.\nAny persistant progression can be reset using PerkEditorWindow."); EditorGUILayout.BeginHorizontal(""); EditorGUILayout.LabelField(cont, GUILayout.MinWidth(230)); pm.usePersistentData=EditorGUILayout.Toggle(pm.usePersistentData); EditorGUILayout.EndHorizontal(); if(!pm.usePersistentData){ cont=new GUIContent("Starting Point:", "The point available for player to unlock perk in this level,\nor this play through if dontDestroyOnLoad is checked"); pm.point=EditorGUILayout.IntField(cont, pm.point); } EditorGUILayout.Space(); cont=new GUIContent("Set All To Default", "Set all perk starting state to default\n\nAll perk will be lock/unlocked state will be carried forward from previous play through"); if(GUILayout.Button(cont, GUILayout.MaxHeight(17))){ for(int i=0; i<pm.localPerkList.Count; i++){ pm.localPerkList[i].startingState=_StartingState.Default; } } cont=new GUIContent("Set All To Locked", "Set all perk starting state to locked\nAll perk will be locked from start, override any previous progress"); if(GUILayout.Button("Set All To Locked", GUILayout.MaxHeight(17))){ for(int i=0; i<pm.localPerkList.Count; i++){ pm.localPerkList[i].startingState=_StartingState.Locked; } } cont=new GUIContent("Set All To Unlocked", "Set all perk starting state to unlocked\nAll perk will be unlocked from start, override any previous progress"); if(GUILayout.Button("Set All To Unlocked", GUILayout.MaxHeight(17))){ for(int i=0; i<pm.localPerkList.Count; i++){ pm.localPerkList[i].startingState=_StartingState.Unlocked; } } EditorGUILayout.Space(); EditorGUILayout.Space(); for(int m=0; m<pm.localPerkList.Count; m++){ PerkTB perk=pm.localPerkList[m]; GUILayout.BeginHorizontal(); cont=new GUIContent(perk.icon, perk.desp); GUILayout.Box(cont, GUILayout.Width(35), GUILayout.Height(35), GUILayout.MaxHeight(35)); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); cont=new GUIContent(perk.name, "Check if perk is available in this scene"); GUILayout.Label(cont, GUILayout.ExpandWidth(true), GUILayout.MaxHeight(15)); perk.availableInScene=EditorGUILayout.Toggle(perk.availableInScene, GUILayout.MaxWidth(90), GUILayout.MaxHeight(15), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); if(perk.availableInScene){ int startingState=(int)perk.startingState; cont=new GUIContent("StartingState:", "The starting unlocked state of the perk"); contL=new GUIContent[startingStateLabel.Length]; for(int i=0; i<contL.Length; i++) contL[i]=new GUIContent(startingStateLabel[i], startingStateTooltip[i]); startingState = EditorGUILayout.IntPopup(cont, startingState, contL, intVal, GUILayout.MaxHeight(15)); perk.startingState=(_StartingState)startingState; } GUILayout.EndVertical(); GUILayout.EndHorizontal(); } if(GUI.changed){ EditorUtility.SetDirty(pm); } }
void Awake() { pm=(PerkManagerTB)target; LoadPerk(); InitLabel(); }
public override void OnInspectorGUI() { pm = (PerkManagerTB)target; //DrawDefaultInspector(); EditorGUILayout.Space(); EditorGUILayout.Space(); cont = new GUIContent("Dont Destroy On Load:", "Check to use this component through out the game\nWhen checked, setting in other PerkManager wont take effect after this scene is loaded\nIntended for game where perk progress is persistant"); EditorGUILayout.BeginHorizontal(""); EditorGUILayout.LabelField(cont, GUILayout.MinWidth(230)); pm.dontDestroyOnLoad = EditorGUILayout.Toggle(pm.dontDestroyOnLoad); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); cont = new GUIContent("Use Persistent Data:", "Check to make any perk progression persistant. Otherwise any progression made will be reset upon leaving the level.\nAny persistant progression can be reset using PerkEditorWindow."); EditorGUILayout.BeginHorizontal(""); EditorGUILayout.LabelField(cont, GUILayout.MinWidth(230)); pm.usePersistentData = EditorGUILayout.Toggle(pm.usePersistentData); EditorGUILayout.EndHorizontal(); if (!pm.usePersistentData) { cont = new GUIContent("Starting Point:", "The point available for player to unlock perk in this level,\nor this play through if dontDestroyOnLoad is checked"); pm.point = EditorGUILayout.IntField(cont, pm.point); } EditorGUILayout.Space(); cont = new GUIContent("Set All To Default", "Set all perk starting state to default\n\nAll perk will be lock/unlocked state will be carried forward from previous play through"); if (GUILayout.Button(cont, GUILayout.MaxHeight(17))) { for (int i = 0; i < pm.localPerkList.Count; i++) { pm.localPerkList[i].startingState = _StartingState.Default; } } cont = new GUIContent("Set All To Locked", "Set all perk starting state to locked\nAll perk will be locked from start, override any previous progress"); if (GUILayout.Button("Set All To Locked", GUILayout.MaxHeight(17))) { for (int i = 0; i < pm.localPerkList.Count; i++) { pm.localPerkList[i].startingState = _StartingState.Locked; } } cont = new GUIContent("Set All To Unlocked", "Set all perk starting state to unlocked\nAll perk will be unlocked from start, override any previous progress"); if (GUILayout.Button("Set All To Unlocked", GUILayout.MaxHeight(17))) { for (int i = 0; i < pm.localPerkList.Count; i++) { pm.localPerkList[i].startingState = _StartingState.Unlocked; } } EditorGUILayout.Space(); EditorGUILayout.Space(); for (int m = 0; m < pm.localPerkList.Count; m++) { PerkTB perk = pm.localPerkList[m]; GUILayout.BeginHorizontal(); cont = new GUIContent(perk.icon, perk.desp); GUILayout.Box(cont, GUILayout.Width(35), GUILayout.Height(35), GUILayout.MaxHeight(35)); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); cont = new GUIContent(perk.name, "Check if perk is available in this scene"); GUILayout.Label(cont, GUILayout.ExpandWidth(true), GUILayout.MaxHeight(15)); perk.availableInScene = EditorGUILayout.Toggle(perk.availableInScene, GUILayout.MaxWidth(90), GUILayout.MaxHeight(15), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); if (perk.availableInScene) { int startingState = (int)perk.startingState; cont = new GUIContent("StartingState:", "The starting unlocked state of the perk"); contL = new GUIContent[startingStateLabel.Length]; for (int i = 0; i < contL.Length; i++) { contL[i] = new GUIContent(startingStateLabel[i], startingStateTooltip[i]); } startingState = EditorGUILayout.IntPopup(cont, startingState, contL, intVal, GUILayout.MaxHeight(15)); perk.startingState = (_StartingState)startingState; } GUILayout.EndVertical(); GUILayout.EndHorizontal(); } if (GUI.changed) { EditorUtility.SetDirty(pm); } }
public void DrawPerkMenu(bool preBattle) { //GUI.depth = 0; GUIStyle style = new GUIStyle(); style.fontSize = 20; style.fontStyle = FontStyle.Bold; style.normal.textColor = UI.colorH; style.alignment = TextAnchor.UpperCenter; List <PerkTB> perkList = PerkManagerTB.GetAllPerks(); PerkTB perk = null; int winWidth = 595; int winHeight = 470; int startX = Screen.width / 2 - winWidth / 2; int startY = Screen.height / 2 - winHeight / 2; int rowLimit = 8; int row = 0; int column = 0; for (int i = 0; i < 3; i++) { GUI.Box(new Rect(startX, startY, winWidth, winHeight), ""); } GUI.Label(new Rect(startX, startY + 10, winWidth, winHeight), "Perk Menu", style); int point = 0; if (!PerkManagerTB.UsePersistentData()) { point = PerkManagerTB.GetPoint(); } else { point = GlobalStatsTB.GetPlayerPoint(); } style.fontSize = 14; style.fontStyle = FontStyle.Bold; style.normal.textColor = UI.colorH; style.alignment = TextAnchor.UpperLeft; if (!preBattle) { GUI.Label(new Rect(startX + 10, startY + 5, 150, 25), "Point: " + point, style); } GUI.Label(new Rect(startX + 10, startY + 20, 150, 25), "PerkPoint: " + PerkManagerTB.perkPoint, style); if (!preBattle) { if (GUI.Button(new Rect(startX + winWidth - 35, startY + 5, 30, 30), "X", UI.buttonStyle)) { OnPerkmenu(); } } startX += 10; startY += 40; int scrollLength = (int)(Mathf.Ceil(perkList.Count / 8 + 1) * 70); if (perkList.Count % rowLimit == 0) { scrollLength -= 70; } Rect viewRect = new Rect(startX, startY, winWidth - 20, 280); Rect scrollRect = new Rect(startX, startY, winWidth - 50, scrollLength); GUI.Box(viewRect, ""); scrollPosition = GUI.BeginScrollView(viewRect, scrollPosition, scrollRect); startX += 5; startY += 5; for (int ID = 0; ID < perkList.Count; ID++) { perk = perkList[ID]; Texture icon = null; if (perk.unlocked) { icon = perk.iconUnlocked; } else { if (perk.IsAvailable() == 0) { icon = perk.icon; } else { icon = perk.iconUnavailable; } } if (selectedID == ID) { if (GUI.Button(new Rect(startX + column * 70 - 3, startY + row * 70 - 3, 66, 66), icon)) { selectedID = ID; } } else { if (GUI.Button(new Rect(startX + column * 70, startY + row * 70, 60, 60), icon)) { selectedID = ID; } } column += 1; if (column == 8) { row += 1; column = 0; } } GUI.EndScrollView(); startY += 285; GUI.Box(new Rect(startX - 5, startY, winWidth - 20, 130), ""); perk = perkList[selectedID]; int perkAvai = perk.IsAvailable(); string status = ""; if (perk.unlocked) { status = " (Unlocked)"; } else if (perkAvai != 0) { status = " (Unavailable)"; } style.fontSize = 17; style.alignment = TextAnchor.UpperLeft; style.normal.textColor = UI.colorH; GUI.Label(new Rect(startX, startY += 5, winWidth - 30, 30), perk.name + status, style); style.fontSize = 17; style.alignment = TextAnchor.UpperRight; style.normal.textColor = UI.colorH; GUI.Label(new Rect(startX, startY += 5, winWidth - 30, 30), "Cost: " + perk.cost, style); style.alignment = TextAnchor.UpperLeft; style.normal.textColor = UI.colorN; style.wordWrap = true; GUI.Label(new Rect(startX, startY += 25, winWidth - 30, 30), perk.desp, style); string requireTxt = ""; //inssufficient points if (perkAvai == 1) { requireTxt = "Require " + perk.cost + "point"; } //min perk point not reach else if (perkAvai == 2) { requireTxt = "Require " + perk.pointReq + " perk points"; } //pre-req perk not unlocked else if (perkAvai == 3) { string text = "Require: "; List <int> list = perk.prereq; int i = 0; foreach (int ID in list) { if (i > 0) { text += ", "; } text += PerkManagerTB.GetAllPerks()[ID].name; i += 1; } requireTxt = text; } style.fontSize = 14; style.alignment = TextAnchor.UpperLeft; style.normal.textColor = Color.red; style.wordWrap = false; GUI.Label(new Rect(startX, startY + 75, winWidth - 30, 30), requireTxt, style); if (!perk.unlocked && perkAvai == 0) { if (GUI.Button(new Rect(startX + winWidth - 30 - 120, startY += 60, 120, 30), "Unlock", UI.buttonStyle)) { OnUnlockPerkButton(perk); } } }