private float DrawAddWeapon(float startX, float startY, Perk perk) { startY += 35; int weaponIdx = perk.newWeaponID >= 0 ? TDSEditor.GetWeaponIndex(perk.newWeaponID) : 0; TDSEditorUtility.DrawSprite(new Rect(startX + spaceX + width - 40, startY + spaceY - 45, 40, 40), weaponIdx > 0 ? weaponDB.weaponList[weaponIdx - 1].icon : null); if (GUI.Button(new Rect(startX + spaceX, startY - 2, 40, height - 2), "Edit ")) { WeaponEditorWindow.Init(); } cont = new GUIContent("New Weapon:", "New weapon to be made available to player"); EditorGUI.LabelField(new Rect(startX, startY += spaceY - 5, width, height), cont, headerStyle); weaponIdx = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), weaponIdx, weaponLabel); if (weaponIdx > 0) { perk.newWeaponID = weaponDB.weaponList[weaponIdx - 1].ID; } else { perk.newWeaponID = -1; } cont = new GUIContent("Replace Existing:", "Check if the new weapon is to replace player's current weapon"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); perk.replaceExisting = EditorGUI.Toggle(new Rect(startX + spaceX, startY, widthS, height), perk.replaceExisting); if (!perk.replaceExisting) { weaponIdx = perk.replaceWeaponID >= 0 ? TDSEditor.GetWeaponIndex(perk.replaceWeaponID) : 0; cont = new GUIContent("Replacing:", "If the new weapon is to replace a existing player's weapon\n\nIf no matching weapon is found during runtime, the new weapon will simply be added"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); weaponIdx = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), weaponIdx, weaponLabel); if (weaponIdx > 0) { perk.replaceWeaponID = weaponDB.weaponList[weaponIdx - 1].ID; } else { perk.replaceWeaponID = -1; } } else { cont = new GUIContent("Replacing:", "If the new weapon is to replace a existing player's ability\n\nIf no matching weapon is found during runtime, the new weapon will simply be added"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); EditorGUI.LabelField(new Rect(startX + spaceX, startY, width, height), "-"); } return(startY); }
public static void Init(int prefabID=-1) { // Get existing open window or if none, make a new one: window = (WeaponEditorWindow)EditorWindow.GetWindow(typeof (WeaponEditorWindow), false, "Weapon Editor"); window.minSize=new Vector2(400, 300); //~ window.maxSize=new Vector2(375, 800); LoadDB(); if(prefabID>=0) window.selectID=TDSEditor.GetWeaponIndex(prefabID)-1; window.SetupCallback(); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); if (instance == null) { Awake(); } GUI.changed = false; Undo.RecordObject(instance, "Weapon"); EditorGUILayout.Space(); EditorGUILayout.HelpBox("Editing Weapon component using Inspector is not recommended.\nPlease use the editor window instead", MessageType.Info); if (GUILayout.Button("Weapon Editor Window")) { WeaponEditorWindow.Init(); } if (TDSEditor.IsPrefab(instance.gameObject)) { if (!TDSEditor.ExistInDB(instance)) { EditorGUILayout.Space(); EditorGUILayout.HelpBox("This prefab hasn't been added to database hence it won't be accessible by other editor.", MessageType.Warning); GUI.color = new Color(1f, 0.7f, .2f, 1f); if (GUILayout.Button("Add Prefab to Database")) { WeaponEditorWindow.Init(); WeaponEditorWindow.NewItem(instance); WeaponEditorWindow.Init(); //call again to select the instance in editor window } GUI.color = Color.white; } } EditorGUILayout.Space(); DefaultInspector(); if (GUI.changed) { EditorUtility.SetDirty(instance); } }
public static void Init(int prefabID = -1) { // Get existing open window or if none, make a new one: window = (WeaponEditorWindow)EditorWindow.GetWindow(typeof(WeaponEditorWindow), false, "Weapon Editor"); window.minSize = new Vector2(400, 300); //~ window.maxSize=new Vector2(375, 800); LoadDB(); if (prefabID >= 0) { window.selectID = TDSEditor.GetWeaponIndex(prefabID) - 1; } window.SetupCallback(); }
Vector2 DrawUnitConfigurator(float startX, float startY, UnitPlayer unit) { Vector2 v2 = DrawUnitBaseStats(startX, startY, unit, true); startY = v2.y; startY += 10; int objID = GetObjectIDFromHList(unit.turretObj, objHList); cont = new GUIContent("Turret Object:", "The pivot transform on the unit to track the shoot direction"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); objID = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), objID, objHLabelList); unit.turretObj = (objHList[objID] == null) ? null : objHList[objID].transform; objID = GetObjectIDFromHList(unit.weaponMountPoint, objHList); cont = new GUIContent("WeaponMount:", "The transform where the weapon object to be anchored to as child object"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); objID = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), objID, objHLabelList); unit.weaponMountPoint = (objHList[objID] == null) ? null : objHList[objID].transform; startY += 10; EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), "Weapons", headerStyle); cont = new GUIContent("Enable All - ", "Check to enable all weapons"); EditorGUI.LabelField(new Rect(startX + spaceX + 50, startY, width, height), cont); unit.enableAllWeapons = EditorGUI.Toggle(new Rect(startX + spaceX + width - 15, startY, width, height), unit.enableAllWeapons); if (!unit.enableAllWeapons) { int enabledCount = 0; for (int i = 0; i < weaponDB.weaponList.Count; i++) { Weapon weapon = weaponDB.weaponList[i]; bool enabled = unit.weaponList.Contains(weapon); bool enabledCached = enabled; TDSEditorUtility.DrawSprite(new Rect(startX + 20, startY += spaceY, 30, 30), weapon.icon, weapon.desp); cont = new GUIContent(weapon.weaponName, weapon.desp); EditorGUI.LabelField(new Rect(startX + 65, startY + 15, width, height), cont); enabled = EditorGUI.Toggle(new Rect(startX + spaceX + width - 15, startY + 15, width, height), enabled); startY += 14; if (enabled != enabledCached) { if (enabled) { unit.weaponList.Insert(enabledCount, weapon); } else { unit.weaponList.Remove(weapon); } } if (enabled) { enabledCount += 1; } } startY += 10; } if (GUI.Button(new Rect(startX + spaceX + width - 100, startY += spaceY, 100, height - 2), "Weapon Editor")) { WeaponEditorWindow.Init(); } startY += 20; unit.enableAbility = EditorGUI.Toggle(new Rect(startX, startY += spaceY, width, height), unit.enableAbility); EditorGUI.LabelField(new Rect(startX + 20, startY, width, height), "Abilities", headerStyle); if (unit.enableAbility) { cont = new GUIContent("Enable All - ", "Check to enable all abilities"); EditorGUI.LabelField(new Rect(startX + spaceX + 50, startY, width, height), cont); unit.enableAllAbilities = EditorGUI.Toggle(new Rect(startX + spaceX + width - 15, startY, width, height), unit.enableAllAbilities); if (!unit.enableAllAbilities) { int enabledCount = 0; for (int i = 0; i < abilityDB.abilityList.Count; i++) { Ability ability = abilityDB.abilityList[i]; bool enabled = unit.abilityIDList.Contains(ability.ID); bool enabledCached = enabled; TDSEditorUtility.DrawSprite(new Rect(startX + 20, startY += spaceY, 30, 30), ability.icon); cont = new GUIContent(ability.name, ability.desp); EditorGUI.LabelField(new Rect(startX + 65, startY + 15, width, height), cont); enabled = EditorGUI.Toggle(new Rect(startX + spaceX + width - 15, startY + 15, width, height), enabled); startY += 14; if (enabled != enabledCached) { if (enabled) { unit.abilityIDList.Insert(enabledCount, ability.ID); } else { unit.abilityIDList.Remove(ability.ID); } } if (enabled) { enabledCount += 1; } } startY += 10; } if (GUI.Button(new Rect(startX + spaceX + width - 100, startY += spaceY, 100, height - 2), "Ability Editor")) { AbilityEditorWindow.Init(); } } startY += 10; EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), "Movement & Control", headerStyle); cont = new GUIContent("EnableTurretAiming:", "Check to allow turret object to rotate and aim towards cursor position"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); unit.enableTurretRotate = EditorGUI.Toggle(new Rect(startX + spaceX, startY, width, height), unit.enableTurretRotate); cont = new GUIContent("Turret Aim Mode:", "The way in which the turret aim direction will be calculated"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); if (unit.enableTurretRotate) { int aimMode = (int)unit.turretAimMode; contL = new GUIContent[turretAimModeLabel.Length]; for (int i = 0; i < contL.Length; i++) { contL[i] = new GUIContent(turretAimModeLabel[i], turretAimModeTooltip[i]); } aimMode = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, 15), new GUIContent(""), aimMode, contL); unit.turretAimMode = (_TurretAimMode)aimMode; } else { EditorGUI.LabelField(new Rect(startX + spaceX, startY, width, height), "-"); } cont = new GUIContent("Aim At Move Dir.:", "Check to have the unit's aim locked with it's move direction"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); if (unit.enableTurretRotate) { EditorGUI.LabelField(new Rect(startX + spaceX, startY, width, height), "-"); } else { unit.aimAtTravelDirection = EditorGUI.Toggle(new Rect(startX + spaceX, startY, width, height), unit.aimAtTravelDirection); } startY += 10; cont = new GUIContent("FaceTravelDirection:", "Enable to have the unit's transform rotates to face its travel direction"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); unit.faceTravelDirection = EditorGUI.Toggle(new Rect(startX + spaceX, startY, width, height), unit.faceTravelDirection); cont = new GUIContent("x-axis movement:", "Check to enabled unit movement in x-axis"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); unit.enabledMovementX = EditorGUI.Toggle(new Rect(startX + spaceX, startY, width, height), unit.enabledMovementX); cont = new GUIContent("z-axis movement:", "Check to enabled unit movement in z-axis"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); unit.enabledMovementZ = EditorGUI.Toggle(new Rect(startX + spaceX, startY, width, height), unit.enabledMovementZ); startY += 10; int mode = (int)unit.movementMode; cont = new GUIContent("Movement Mode:", "The way in which the movement of the unit is handled with regard to the input"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); contL = new GUIContent[movementModeLabel.Length]; for (int i = 0; i < contL.Length; i++) { contL[i] = new GUIContent(movementModeLabel[i], movementModeTooltip[i]); } mode = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, 15), new GUIContent(""), mode, contL); unit.movementMode = (_MovementMode)mode; cont = new GUIContent("Move Speed:", "The move speed of the unit"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); unit.moveSpeed = EditorGUI.DelayedFloatField(new Rect(startX + spaceX, startY, 40, height), unit.moveSpeed); cont = new GUIContent("Boost Speed Mul:", "Speed-Multiplier(rigid mode)/Acceleration-Multiplier(free-form mode) when using boost (left-shift by default)"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); unit.boostMultiplier = EditorGUI.DelayedFloatField(new Rect(startX + spaceX, startY, 40, height), unit.boostMultiplier); cont = new GUIContent("Boost Energy Rate:", "Energy consumption rate (per second) when using boost (left-shift by default)\n0.3 being 30% of total energy per second"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); unit.boostEnergyRate = EditorGUI.DelayedFloatField(new Rect(startX + spaceX, startY, 40, height), unit.boostEnergyRate); if (unit.movementMode == _MovementMode.FreeForm) { cont = new GUIContent("Acceleration:", "The acceleration of the unit"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); unit.acceleration = EditorGUI.DelayedFloatField(new Rect(startX + spaceX, startY, 40, height), unit.acceleration); cont = new GUIContent("Decceleration:", "The rate of the unit losing it's speed"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); unit.decceleration = EditorGUI.DelayedFloatField(new Rect(startX + spaceX, startY, 40, height), unit.decceleration); cont = new GUIContent("Active Braking:", "Stopping power when using active braking (space by default)"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); unit.activeBrakingRate = EditorGUI.DelayedFloatField(new Rect(startX + spaceX, startY, 40, height), unit.activeBrakingRate); } startY += 10; cont = new GUIContent("Enable Limit ", "Check to limit player movement to a defined area"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); unit.useLimit = EditorGUI.Toggle(new Rect(startX + spaceX, startY, 30, height), unit.useLimit); if (unit.useLimit) { cont = new GUIContent("Show", ""); limitFoldout = EditorGUI.Foldout(new Rect(startX + spaceX + 40, startY, spaceX, height), limitFoldout, cont); if (limitFoldout) { cont = new GUIContent("x-axis (min/max):", "Stopping power when using active braking (space by default)"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); unit.minPosX = EditorGUI.DelayedFloatField(new Rect(startX + spaceX, startY, 70, height), unit.minPosX); unit.maxPosX = EditorGUI.DelayedFloatField(new Rect(startX + spaceX + 75, startY, 70, height), unit.maxPosX); cont = new GUIContent("z-axis (min/max):", "Stopping power when using active braking (space by default)"); EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont); unit.minPosZ = EditorGUI.DelayedFloatField(new Rect(startX + spaceX, startY, 70, height), unit.minPosZ); unit.maxPosZ = EditorGUI.DelayedFloatField(new Rect(startX + spaceX + 75, startY, 70, height), unit.maxPosZ); } } startY += 10; Vector2 v3 = DrawDestroyEffectObj(startX, startY + spaceY, unit); startY = v3.y + 20; GUIStyle style = new GUIStyle("TextArea"); style.wordWrap = true; cont = new GUIContent("Unit description (to be used in runtime): ", ""); EditorGUI.LabelField(new Rect(startX, startY += spaceY, 400, 20), cont); unit.desp = EditorGUI.DelayedTextField(new Rect(startX, startY + spaceY - 3, 270, 150), unit.desp, style); return(new Vector2(startX, startY + 200)); }
static void OpenWeaponEditor() { WeaponEditorWindow.Init(); }