コード例 #1
0
        public void EquipItem(EquipmentItem item)
        {
            foreach (ObjectProperty property in item.GetProperties())
            {
                if (property.SerializedType == typeof(int) || property.SerializedType == typeof(float))
                {
                    float value = System.Convert.ToSingle(property.GetValue());
                    SendMessage("AddModifier", new object[] { property.Name, value, (value <= 1f && value >= -1f) ? 1 : 0, item }, SendMessageOptions.DontRequireReceiver);
                }
            }

            for (int i = 0; i < this.m_VisibleItems.Count; i++)
            {
                VisibleItem visibleItem = this.m_VisibleItems[i];
                if (visibleItem.item.Id == item.Id)
                {
                    visibleItem.OnItemEquip(item);
                    return;
                }
            }

            StaticItem staticItem = gameObject.AddComponent <StaticItem>();

            staticItem.item = InventoryManager.Database.items.Find(x => x.Id == item.Id);
            VisibleItem.Attachment attachment = new VisibleItem.Attachment();
            attachment.prefab      = item.EquipPrefab;
            attachment.region      = item.Region[0];
            staticItem.attachments = new VisibleItem.Attachment[1] {
                attachment
            };
            staticItem.OnItemEquip(item);
        }
コード例 #2
0
        private void OnEnable()
        {
            this.m_Script     = serializedObject.FindProperty("m_Script");
            this.m_WindowName = serializedObject.FindProperty("m_WindowName");
            EquipmentHandler handler = target as EquipmentHandler;

            gameObject = handler.gameObject;

            VisibleItem[] visibleItems = gameObject.GetComponents <VisibleItem>();
            for (int i = 0; i < visibleItems.Length; i++)
            {
                visibleItems[i].hideFlags = EditorPrefs.GetBool("InventorySystem.showAllComponents") ? HideFlags.None : HideFlags.HideInInspector;
            }

            if (!EditorApplication.isPlaying)
            {
                for (int i = 0; i < handler.VisibleItems.Count; i++)
                {
                    if (handler.VisibleItems[i].gameObject != gameObject)
                    {
                        if (ComponentUtility.CopyComponent(handler.VisibleItems[i]))
                        {
                            VisibleItem compoent = gameObject.AddComponent(handler.VisibleItems[i].GetType()) as VisibleItem;
                            ComponentUtility.PasteComponentValues(compoent);
                            handler.VisibleItems[i] = compoent;
                        }
                    }
                }
            }
            EditorApplication.playModeStateChanged += PlayModeState;
        }
コード例 #3
0
 public void UpdateEquipment()
 {
     for (int i = 0; i < this.m_VisibleItems.Count; i++)
     {
         VisibleItem visibleItem = this.m_VisibleItems[i];
         visibleItem.OnItemUnEquip(visibleItem.item);
     }
     EquipmentItem[] containerItems = this.m_EquipmentContainer.GetItems <EquipmentItem>();
     foreach (EquipmentItem item in containerItems)
     {
         EquipItem(item);
     }
 }
コード例 #4
0
 public void UnEquipItem(EquipmentItem item)
 {
     foreach (ObjectProperty property in item.GetProperties())
     {
         if (property.SerializedType == typeof(int) || property.SerializedType == typeof(float))
         {
             SendMessage("RemoveModifiersFromSource", new object[] { property.Name, item }, SendMessageOptions.DontRequireReceiver);
         }
     }
     for (int i = 0; i < this.m_VisibleItems.Count; i++)
     {
         VisibleItem visibleItem = this.m_VisibleItems[i];
         if (visibleItem.item.Id == item.Id)
         {
             visibleItem.OnItemUnEquip(item);
             break;
         }
     }
 }
コード例 #5
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.PropertyField(position, property, label, true);
            if (property.isExpanded)
            {
                SerializedProperty region     = property.FindPropertyRelative("region");
                SerializedProperty prefab     = property.FindPropertyRelative("prefab");
                SerializedProperty pos        = property.FindPropertyRelative("position");
                SerializedProperty rotation   = property.FindPropertyRelative("rotation");
                SerializedProperty scale      = property.FindPropertyRelative("scale");
                SerializedProperty gameObject = property.FindPropertyRelative("gameObject");
                EditorGUI.BeginDisabledGroup(region.objectReferenceValue == null || prefab.objectReferenceValue == null);

                if (GUI.Button(new Rect(position.xMin + 30f, position.yMax - 20f, position.width - 30f, 20f), gameObject.objectReferenceValue != null?"Remove Prefab Handle":"Attach Prefab Handle"))
                {
                    if (gameObject.objectReferenceValue != null)
                    {
                        GameObject.DestroyImmediate(gameObject.objectReferenceValue);
                        return;
                    }
                    VisibleItem      visibleItem        = (VisibleItem)property.serializedObject.targetObject;
                    EquipmentHandler handler            = visibleItem.GetComponent <EquipmentHandler>();
                    EquipmentHandler.EquipmentBone bone = handler.Bones.Find(x => x.region == region.objectReferenceValue);
                    if (bone != null)
                    {
                        GameObject go = (GameObject)GameObject.Instantiate(prefab.objectReferenceValue, bone.bone.transform);
                        go.transform.localPosition      = pos.vector3Value;
                        go.transform.localEulerAngles   = rotation.vector3Value;
                        go.transform.localScale         = scale.vector3Value;
                        gameObject.objectReferenceValue = go;
                    }
                }
                EditorGUI.EndDisabledGroup();

                if (gameObject.objectReferenceValue != null)
                {
                    Transform transform = (gameObject.objectReferenceValue as GameObject).transform;
                    pos.vector3Value      = transform.localPosition;
                    rotation.vector3Value = transform.localEulerAngles;
                    scale.vector3Value    = transform.localScale;
                }
            }
        }
コード例 #6
0
 public void EquipItem(EquipmentItem item)
 {
     foreach (ObjectProperty property in item.GetProperties())
     {
         if (property.SerializedType == typeof(int) || property.SerializedType == typeof(float))
         {
             float value = System.Convert.ToSingle(property.GetValue());
             SendMessage("AddModifier", new object[] { property.Name, value, (value <= 1f && value >= -1f) ? 1 : 0, item }, SendMessageOptions.DontRequireReceiver);
         }
     }
     for (int i = 0; i < this.m_VisibleItems.Count; i++)
     {
         VisibleItem visibleItem = this.m_VisibleItems[i];
         if (visibleItem.item.Id == item.Id)
         {
             visibleItem.OnItemEquip(item);
             break;
         }
     }
 }