protected void btnNieuwItem_Click(object sender, EventArgs e) { try { Controller c = (Controller)Session["Controller"]; string soort = soortDrager.SelectedValue; DragerType drager = soort == "boek" ? DragerType.Boek : DragerType.CD; string strTitel = this.titel.Text; ItemBuilder.BuildItem(strTitel, drager); //this.titel.Text = ""; boodschap.Text = "item toegevoegd"; this.titel.AutoPostBack = true; } catch (Exception exception) { boodschap.Text = exception.Message; } }
public void OneTimeSetUp() { _itemBuilder = new ItemBuilder(); _item = _itemBuilder.BuildItem("1245"); }
/// <summary> /// Draws the UI for new item. /// </summary> private void DrawNewItem() { var canBuild = true; m_Name = EditorGUILayout.TextField("Name", m_Name); if (string.IsNullOrEmpty(m_Name)) { canBuild = false; EditorGUILayout.HelpBox("The item must have a name.", MessageType.Error); } m_ItemType = EditorGUILayout.ObjectField("Item Type", m_ItemType, typeof(ItemType), false) as ItemType; if (canBuild && m_ItemType == null) { canBuild = false; EditorGUILayout.HelpBox("The item must specify an ItemType.", MessageType.Error); } var character = EditorGUILayout.ObjectField("Character", m_Character, typeof(GameObject), true) as GameObject; var characterUpdate = false; if (character != m_Character) { m_Character = character; characterUpdate = true; #if FIRST_PERSON_CONTROLLER // Try to assign the first person objects if they exist. if (m_Character != null) { var firstPersonObjects = m_Character.GetComponentInChildren <FirstPersonController.Character.FirstPersonObjects>(); if (firstPersonObjects != null) { var firstPersonBaseObject = firstPersonObjects.GetComponentInChildren <FirstPersonController.Character.Identifiers.FirstPersonBaseObject>(); if (firstPersonBaseObject != null) { m_FirstPersonObject = firstPersonBaseObject.gameObject; } } m_AddThirdPersonPerspective = m_Character.GetComponent <Animator>() != null; } #endif } if (m_Character == null) { m_SlotID = EditorGUILayout.IntField("Slot ID", m_SlotID); } else { if (EditorUtility.IsPersistent(m_Character)) { if (canBuild) { EditorGUILayout.HelpBox("The character must be located within the scene.", MessageType.Error); canBuild = false; } } else { // The attach to object must be a character already created. if (m_Character.GetComponentInChildren <ItemPlacement>() == null) { if (canBuild) { EditorGUILayout.HelpBox("The character must be an already created character.", MessageType.Error); canBuild = false; } } else { if (m_ItemType != null & m_Character.GetComponent <InventoryBase>() != null) { // The item can automatically be added to the default loadout if the inventory component exists. EditorGUI.indentLevel++; m_AddToDefaultLoadout = EditorGUILayout.Toggle("Add to Default Loadout", m_AddToDefaultLoadout); EditorGUI.indentLevel--; } else { m_AddToDefaultLoadout = false; } } } } m_AnimatorItemID = EditorGUILayout.IntField("Animator Item ID", m_AnimatorItemID); #if FIRST_PERSON_CONTROLLER GUILayout.Space(5); GUILayout.Label("First Person", InspectorStyles.BoldLabel); GUI.enabled = m_FirstPersonObject == null && m_FirstPersonVisibleItem == null; m_AddFirstPersonPerspective = EditorGUILayout.Toggle("Add First Person Item", m_AddFirstPersonPerspective); GUI.enabled = m_AddFirstPersonPerspective; var firstPersonSuccess = DrawFirstPersonObject(m_Character, ref m_FirstPersonObject, ref m_FirstPersonObjectAnimatorController, ref m_FirstPersonVisibleItem, ref m_FirstPersonParent, ref m_FirstPersonItemSlot, ref m_FirstPersonVisibleItemAnimatorController, m_ThirdPersonItemSlot != null ? m_ThirdPersonItemSlot.ID : 0, characterUpdate, canBuild && m_AddFirstPersonPerspective); GUI.enabled = true; if (m_AddFirstPersonPerspective && !firstPersonSuccess) { canBuild = false; } #endif if (m_Character == null || (m_Character != null && m_Character.GetComponent <Animator>() != null)) { GUILayout.Space(10); GUILayout.Label("Third Person (including AI and multiplayer)", InspectorStyles.BoldLabel); GUI.enabled = m_ThirdPersonObject == null; m_AddThirdPersonPerspective = EditorGUILayout.Toggle("Add Third Person Item", m_AddThirdPersonPerspective); GUI.enabled = m_AddThirdPersonPerspective; var thirdPersonSuccess = DrawThirdPersonObject(m_Character, ref m_ThirdPersonObject, ref m_ThirdHumanoidParentHand, ref m_ThirdPersonParent, ref m_ThirdPersonItemSlot, ref m_ThirdPersonObjectAnimatorController, m_FirstPersonItemSlot != null ? m_FirstPersonItemSlot.ID : 0, characterUpdate, canBuild && m_AddThirdPersonPerspective); GUI.enabled = true; if (m_AddThirdPersonPerspective && !thirdPersonSuccess) { canBuild = false; } } if (!m_AddFirstPersonPerspective && !m_AddThirdPersonPerspective) { if (canBuild) { EditorGUILayout.HelpBox("At least one perspective must be added.", MessageType.Error); canBuild = false; } } GUILayout.Space(15); m_ActionType = (ItemBuilder.ActionType)EditorGUILayout.EnumPopup("Action Type", m_ActionType); #if !ULTIMATE_CHARACTER_CONTROLLER_SHOOTER if (m_ActionType == ItemBuilder.ActionType.ShootableWeapon && canBuild) { EditorGUILayout.HelpBox("The shooter controller is necessary in order to create shootable weapons.", MessageType.Error); canBuild = false; } #endif #if !ULTIMATE_CHARACTER_CONTROLLER_MELEE if (m_ActionType == ItemBuilder.ActionType.MeleeWeapon && canBuild) { EditorGUILayout.HelpBox("The melee controller is necessary in order to create melee weapons.", MessageType.Error); canBuild = false; } #endif #if FIRST_PERSON_CONTROLLER // The slot IDs must match. if (m_FirstPersonItemSlot != null && m_ThirdPersonItemSlot != null && m_FirstPersonItemSlot.ID != m_ThirdPersonItemSlot.ID && canBuild) { canBuild = false; EditorGUILayout.HelpBox("The first and third person ItemSlots must use the same ID.", MessageType.Error); } #endif if (canBuild && (m_ActionType != ItemBuilder.ActionType.Shield)) { EditorGUI.indentLevel++; m_ActionItemType = EditorGUILayout.ObjectField("Consumable Item Type", m_ActionItemType, typeof(ItemType), false) as ItemType; EditorGUI.indentLevel--; } // Setup profiles. GUILayout.Space(5); var updatedStateConfiguration = EditorGUILayout.ObjectField("State Configuration", m_AddStateConfiguration, typeof(StateConfiguration), false) as StateConfiguration; if (updatedStateConfiguration != m_AddStateConfiguration) { if (updatedStateConfiguration != null) { EditorPrefs.SetString(ManagerUtility.LastStateConfigurationGUIDString, AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(updatedStateConfiguration))); } else { EditorPrefs.SetString(ManagerUtility.LastStateConfigurationGUIDString, string.Empty); } m_AddStateConfiguration = updatedStateConfiguration; } if (m_AddStateConfiguration != null) { EditorGUI.indentLevel++; var profiles = m_AddStateConfiguration.GetProfilesForGameObject(null, StateConfiguration.Profile.ProfileType.Item); if (profiles.Count > 0) { // The item can be added without any profiles. profiles.Insert(0, "(None)"); m_AddProfileIndex = EditorGUILayout.Popup("Profile", m_AddProfileIndex, profiles.ToArray()); m_AddProfileName = profiles[m_AddProfileIndex]; } EditorGUI.indentLevel--; } GUILayout.Space(5); GUI.enabled = canBuild; if (GUILayout.Button("Build Item")) { var item = ItemBuilder.BuildItem(m_Name, m_ItemType, m_AnimatorItemID, m_Character, m_SlotID, m_AddToDefaultLoadout, m_AddFirstPersonPerspective, m_FirstPersonObject, m_FirstPersonObjectAnimatorController, m_FirstPersonVisibleItem, m_FirstPersonItemSlot, m_FirstPersonVisibleItemAnimatorController, m_AddThirdPersonPerspective, m_ThirdPersonObject, m_ThirdPersonItemSlot, m_ThirdPersonObjectAnimatorController, m_InvisibleShadowCaster, m_ActionType, m_ActionItemType); // Setup any profiles on the item. if (m_AddStateConfiguration != null) { if (m_AddProfileIndex > 0) { m_AddStateConfiguration.AddStatesToGameObject(m_AddProfileName, item.gameObject); InspectorUtility.SetDirty(item.gameObject); } } // If the character is null then a prefab will be created. if (m_Character == null) { var path = EditorUtility.SaveFilePanel("Save Item", "Assets", m_Name + ".prefab", "prefab"); if (path.Length != 0 && Application.dataPath.Length < path.Length) { var relativePath = path.Replace(Application.dataPath, ""); #if UNITY_2018_3_OR_NEWER PrefabUtility.SaveAsPrefabAsset(item, "Assets" + relativePath); #else PrefabUtility.CreatePrefab("Assets" + relativePath, item); #endif Object.DestroyImmediate(item, true); } } // Remove the original objects if they are in the scene - this will prevent duplicate objects from existing. if (m_FirstPersonVisibleItem != null && !EditorUtility.IsPersistent(m_FirstPersonVisibleItem) && (m_Character == null || !m_FirstPersonVisibleItem.transform.IsChildOf(m_Character.transform))) { Object.DestroyImmediate(m_FirstPersonVisibleItem, true); m_FirstPersonVisibleItem = null; } if (m_FirstPersonObject != null && !EditorUtility.IsPersistent(m_FirstPersonObject) && (m_Character == null || !m_FirstPersonObject.transform.IsChildOf(m_Character.transform))) { Object.DestroyImmediate(m_FirstPersonObject, true); m_FirstPersonObject = null; #if FIRST_PERSON_CONTROLLER // The base object should be updated to the new instance. var firstPersonObjects = m_Character.GetComponentInChildren <FirstPersonController.Character.FirstPersonObjects>(); if (firstPersonObjects != null) { var firstPersonBaseObject = firstPersonObjects.GetComponentInChildren <FirstPersonController.Character.Identifiers.FirstPersonBaseObject>(); if (firstPersonBaseObject != null) { m_FirstPersonObject = firstPersonBaseObject.gameObject; } } #endif } if (m_ThirdPersonObject != null && !EditorUtility.IsPersistent(m_ThirdPersonObject) && (m_Character == null || !m_ThirdPersonObject.transform.IsChildOf(m_Character.transform))) { Object.DestroyImmediate(m_ThirdPersonObject, true); m_ThirdPersonObject = null; } // Select the newly added item. Selection.activeGameObject = item.gameObject; } GUI.enabled = true; }
protected override IEnumerator ItemBuilder_BuildItem() { yield return(new WaitForSeconds(0f)); if (SerializedAddableItem == null) { Debug.LogError("No SerializedAddableItem on character"); yield return(new WaitForSeconds(0f)); } //Base Method Functionality var characterAnimator = spawnedGameObject.GetComponent <Animator>(); for (int i = 0; i < AddableItemsList.Count; ++i) { var item = GameObject.Instantiate(AddableItemsList[i].Base) as GameObject; item.name = AddableItemsList[i].Base.name; var handTransform = characterAnimator.GetBoneTransform(AddableItemsList[i].HandAssignment == ItemBuilder.HandAssignment.Left ? HumanBodyBones.LeftHand : HumanBodyBones.RightHand); item.transform.parent = handTransform.GetComponentInChildren <ItemPlacement>().transform; Vector3 _position = Vector3.zero; Vector3 _rotation = Vector3.zero; //Set Specific Position and Rotation Only If ItemType Has //Been Assigned in the Inspector if (AddableItemHasSpecificPosition(AddableItemsList[i].ItemType, out _position, out _rotation)) { item.transform.localPosition = _position; item.transform.localEulerAngles = _rotation; } else { item.transform.localPosition = AddableItemsList[i].LocalPosition; item.transform.localEulerAngles = AddableItemsList[i].LocalRotation; } ItemBuilder.BuildItem(item, AddableItemsList[i].ItemType, AddableItemsList[i].ItemName, AddableItemsList[i].Type, AddableItemsList[i].HandAssignment); //Additional Method Functionality Transform itemTransform = item.transform; //Set Weapon Volume var _audioSource = item.GetComponent <AudioSource>(); if (_audioSource != null) { _audioSource.volume = AddableItemsList[i].WeaponVolume; } //Set Up Shootable Weapon var _shootable = item.GetComponent <ShootableWeapon>(); if (_shootable != null) { //Set up Muzzle Location if (AddableItemsList[i].m_MuzzleFlash != null) { AddableItemsList[i].m_MuzzleFlashLocation = CreateChildObject(itemTransform, "Muzzle Flash Location", AddableItemsList[i].m_MuzzleFlashPosition, AddableItemsList[i].m_MuzzleFlashRotation); } //Set up Smoke Location if (AddableItemsList[i].m_Smoke != null) { AddableItemsList[i].m_SmokeLocation = CreateChildObject(itemTransform, "Smoke Location", AddableItemsList[i].m_SmokePosition, AddableItemsList[i].m_SmokeRotation); _shootable.ModifyRTSShooterProperties(AddableItemsList[i]); } } else { //Set up Melee Weapon var _melee = item.GetComponent <MeleeWeapon>(); if (_melee != null) { _melee.ModifyRTSMeleeProperties(AddableItemsList[i]); } } } }