public override void OnStart() { this.m_ItemCollection = gameObject.GetComponent <ItemCollection>(); }
private void SetupPrefab(SerializedProperty prefabProperty) { if (prefabProperty.objectReferenceValue != null) { GameObject mPrefab = prefabProperty.objectReferenceValue as GameObject; if (mPrefab.GetComponent <Trigger>() == null || mPrefab.GetComponent <Collider>() == null || mPrefab.GetComponent <Rigidbody>() == null) { Color color = GUI.backgroundColor; GUI.backgroundColor = Color.red; if (GUILayout.Button("Setup", GUILayout.Width(70))) { GameObject prefab = (GameObject)Instantiate(mPrefab); if (prefab.GetComponent <Trigger>() == null) { Trigger trigger = prefab.AddComponent <Trigger>(); //trigger.actions.Add(prefab.AddComponent<CanPickup>()); /*SetEnabled setEnabled = prefab.AddComponent<SetEnabled>(); * SerializedObject setEnabledObject = new SerializedObject(setEnabled); * setEnabledObject.Update(); * setEnabledObject.FindProperty("m_ComponentName").stringValue = "ThirdPersonController"; * setEnabledObject.FindProperty("m_Enable").boolValue = false; * setEnabledObject.ApplyModifiedProperties(); * trigger.actions.Add(setEnabled); * trigger.actions.Add(prefab.AddComponent<LookAtTrigger>()); * trigger.actions.Add(prefab.AddComponent<CrossFade>()); * trigger.actions.Add(prefab.AddComponent<Wait>()); * trigger.actions.Add(prefab.AddComponent<Pickup>()); * setEnabled = prefab.AddComponent<SetEnabled>(); * setEnabledObject = new SerializedObject(setEnabled); * setEnabledObject.Update(); * setEnabledObject.FindProperty("m_ComponentName").stringValue = "ThirdPersonController"; * setEnabledObject.FindProperty("m_Enable").boolValue = true; * setEnabledObject.ApplyModifiedProperties(); * trigger.actions.Add(setEnabled);*/ } if (prefab.GetComponent <ItemCollection>() == null) { ItemCollection collection = prefab.AddComponent <ItemCollection>(); collection.Add((Item)target); } if (prefab.GetComponent <Collider>() == null) { MeshCollider collider = prefab.AddComponent <MeshCollider>(); collider.convex = true; } if (prefab.GetComponent <Rigidbody>() == null) { prefab.AddComponent <Rigidbody>(); } #if PUN if (prefab.GetComponent <PhotonView> () == null) { prefab.AddComponent <PhotonView> (); } #endif string mPath = EditorUtility.SaveFilePanelInProject( "Create Prefab" + prefab.name, "New " + prefab.name + ".prefab", "prefab", ""); if (!string.IsNullOrEmpty(mPath)) { GameObject mGameObject = PrefabUtility.SaveAsPrefabAsset(prefab, mPath); AssetDatabase.SaveAssets(); prefabProperty.objectReferenceValue = mGameObject; } DestroyImmediate(prefab); } GUI.backgroundColor = color; } } }
private void Start() { ItemCollection collection = GetComponent <ItemCollection>(); collection.Add(GenerateItems().ToArray()); }
private void DrawInspector() { EditorGUILayout.PropertyField(this.m_UseButton); EditorGUILayout.PropertyField(this.m_DynamicContainer); this.m_ShowDynamicContainer.target = this.m_DynamicContainer.boolValue; if (EditorGUILayout.BeginFadeGroup(this.m_ShowDynamicContainer.faded)) { EditorGUI.indentLevel = EditorGUI.indentLevel + 1; EditorGUILayout.PropertyField(this.m_SlotParent); EditorGUILayout.PropertyField(this.m_SlotPrefab); EditorGUI.indentLevel = EditorGUI.indentLevel - 1; } EditorGUILayout.EndFadeGroup(); ItemCollection collection = (target as ItemContainer).GetComponent <ItemCollection>(); EditorGUI.BeginDisabledGroup(collection != null); if (collection != null) { EditorGUILayout.HelpBox("You can't use references with an ItemCollection component.", MessageType.Warning); this.m_UseReferences.boolValue = false; } EditorGUILayout.PropertyField(this.m_UseReferences); EditorGUI.EndDisabledGroup(); DrawTypePropertiesExcluding(typeof(ItemContainer), this.m_PropertiesToExcludeForDefaultInspector); EditorGUILayout.PropertyField(this.m_UseContextMenu); this.m_ShowContextMenu.target = this.m_UseContextMenu.boolValue; if (EditorGUILayout.BeginFadeGroup(this.m_ShowContextMenu.faded)) { EditorGUI.indentLevel = EditorGUI.indentLevel + 1; EditorGUILayout.PropertyField(this.m_ContextMenuButton); EditorGUILayout.HelpBox("Here you can define custom context menu functions. The script should be attached to this game object and have the form of MyFunction(Item item).", MessageType.Info); EditorGUI.indentLevel = EditorGUI.indentLevel - 1; GUILayout.BeginHorizontal(); GUILayout.Space(16f); GUILayout.BeginVertical(); this.m_ContextMenuFunctionList.DoLayoutList(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); } EditorGUILayout.EndFadeGroup(); EditorGUILayout.PropertyField(this.m_MoveUsedItems); this.m_ShowMoveUsedItems.target = this.m_MoveUsedItems.boolValue; if (EditorGUILayout.BeginFadeGroup(this.m_ShowMoveUsedItems.faded)) { GUILayout.BeginHorizontal(); GUILayout.Space(16f); GUILayout.BeginVertical(); this.m_MoveItemConditionList.DoLayoutList(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); } EditorGUILayout.EndFadeGroup(); if (EditorTools.RightArrowButton(new GUIContent("Restrictions", "Container Restrictions"))) { AssetWindow.ShowWindow("Container Restrictions", this.m_Restrictions); } }
public static void Load(string key, bool includePersistent = true) { key += "InventorySystem"; key += " [" + UnityEngine.SceneManagement.SceneManager.GetActiveScene().name + "]"; string data = PlayerPrefs.GetString(key); if (string.IsNullOrEmpty(data)) { return; } ItemCollection[] itemCollections = FindObjectsOfType <ItemCollection>(); for (int i = 0; i < itemCollections.Length; i++) { if (InventoryManager.GetPrefab(itemCollections[i].name.Replace("(Clone)", "")) == null) { continue; } Destroy(itemCollections[i].gameObject); } List <object> list = MiniJSON.Deserialize(data) as List <object>; for (int i = 0; i < list.Count; i++) { Dictionary <string, object> mData = list[i] as Dictionary <string, object>; string prefab = (string)mData["Prefab"]; List <object> positionData = mData["Position"] as List <object>; List <object> rotationData = mData["Rotation"] as List <object>; string type = (string)mData["Type"]; Vector3 position = new Vector3(System.Convert.ToSingle(positionData[0]), System.Convert.ToSingle(positionData[1]), System.Convert.ToSingle(positionData[2])); Quaternion rotation = Quaternion.Euler(new Vector3(System.Convert.ToSingle(rotationData[0]), System.Convert.ToSingle(rotationData[1]), System.Convert.ToSingle(rotationData[2]))); ItemCollection itemCollection = null; if (type == "UI") { UIWidget container = WidgetUtility.Find <UIWidget>(prefab); if (container != null && (includePersistent || container.gameObject.scene == UnityEngine.SceneManagement.SceneManager.GetActiveScene())) { itemCollection = container.GetComponent <ItemCollection>(); } } else { GameObject collectionGameObject = CreateCollection(prefab, position, rotation); if (collectionGameObject != null) { IGenerator[] generators = collectionGameObject.GetComponents <IGenerator>(); for (int j = 0; j < generators.Length; j++) { generators[j].enabled = false; } itemCollection = collectionGameObject.GetComponent <ItemCollection>(); } } if (itemCollection != null) { itemCollection.SetObjectData(mData); } } if (InventoryManager.current != null && InventoryManager.current.onSceneLoaded != null) { InventoryManager.current.onSceneLoaded.Invoke(); } if (InventoryManager.DefaultSettings.debugMessages) { Debug.Log("[Inventory System] Data loaded: " + data); } }