Пример #1
0
    private static void AttachItem(GameObject character, AccessoryWearLogic accessoryWearLogic, ItemObject itemObject, ItemHoldLogic itemHoldLogic, CharacterItemAnimator.Hand hand, bool keepPrefabConnection)
    {
        if (itemObject != null)
        {
            if (itemObject.Item == null)
            {
                Debug.LogError("Null prefab in " + itemObject);
                return;
            }

            ItemLogic item = Instantiate(itemObject.Item, keepPrefabConnection);
            if (hand == CharacterItemAnimator.Hand.Left)
            {
                itemHoldLogic.m_itemInHandL = item;
            }
            else if (hand == CharacterItemAnimator.Hand.Right)
            {
                itemHoldLogic.m_itemInHandR = item;
            }

            if (itemObject.Item.AccessoryLogic)
            {
                item.transform.parent = character.transform;
                accessoryWearLogic.Attach(item.AccessoryLogic);
            }
            else
            {
                if (hand == CharacterItemAnimator.Hand.Left)
                {
                    item.transform.parent = itemHoldLogic.HandBoneL;
                }
                else if (hand == CharacterItemAnimator.Hand.Right)
                {
                    item.transform.parent = itemHoldLogic.HandBoneR;
                }

                item.transform.localPosition = Vector3.zero;
                item.transform.localRotation = Quaternion.identity;
            }
        }
    }
Пример #2
0
    private void OnWizardCreate()
    {
        GameObject character = Instantiate(m_appearanceObject.Model);

        CapsuleCollider collider = character.AddComponent <CapsuleCollider>();

        collider.radius    = 0.1f;
        collider.direction = 1;
        collider.center    = new Vector3(0.0f, 0.5f, 0.0f);

        Rigidbody rigidbody = character.AddComponent <Rigidbody>();

        rigidbody.angularDrag = 5.0f;
        rigidbody.constraints = RigidbodyConstraints.FreezeRotation;

        m_behaviorObject.InitializeBehaviour(character);

        character.transform.position = Vector3.zero;

        ItemHoldLogic      itemHoldLogic      = character.GetComponent <ItemHoldLogic>();
        AccessoryWearLogic accessoryWearLogic = character.GetComponent <AccessoryWearLogic>();
        bool hasItems = m_itemLeftHand || m_itemRightHand;

        if ((itemHoldLogic == null) &&
            (m_itemLeftHand || m_itemRightHand))
        {
            itemHoldLogic = character.AddComponent <ItemHoldLogic>();
            hasItems      = true;
        }
        if (accessoryWearLogic == null)
        {
            if (m_itemLeftHand != null && m_itemLeftHand.Item.AccessoryLogic != null)
            {
                accessoryWearLogic = character.AddComponent <AccessoryWearLogic>();
            }
            else if (m_itemRightHand != null && m_itemRightHand.Item.AccessoryLogic != null)
            {
                accessoryWearLogic = character.AddComponent <AccessoryWearLogic>();
            }
            else if (m_accessories.Length > 0)
            {
                accessoryWearLogic = character.AddComponent <AccessoryWearLogic>();
            }
        }

        // Attach items
        if (hasItems)
        {
            CharacterItemAnimator itemAnimator;
            itemAnimator          = itemHoldLogic.gameObject.AddComponent <CharacterItemAnimator>();
            itemAnimator.ThisHand = CharacterItemAnimator.Hand.Left;

            itemAnimator          = itemHoldLogic.gameObject.AddComponent <CharacterItemAnimator>();
            itemAnimator.ThisHand = CharacterItemAnimator.Hand.Right;
        }

        if (m_itemLeftHand)
        {
            ItemLogic item = Instantiate(m_itemLeftHand.Item);
            itemHoldLogic.m_itemInHandL = item;

            if (m_itemLeftHand.Item.AccessoryLogic)
            {
                item.transform.parent = character.transform;
                accessoryWearLogic.Attach(item.AccessoryLogic);
            }
            else
            {
                item.transform.parent        = itemHoldLogic.HandBoneL;
                item.transform.localPosition = Vector3.zero;
                item.transform.localRotation = Quaternion.identity;
            }
        }

        if (m_itemRightHand)
        {
            ItemLogic item = Instantiate(m_itemRightHand.Item);
            itemHoldLogic.m_itemInHandR = item;

            if (m_itemRightHand.Item.AccessoryLogic)
            {
                item.transform.parent = character.transform;
                accessoryWearLogic.Attach(item.AccessoryLogic);
            }
            else
            {
                item.transform.parent        = itemHoldLogic.HandBoneR;
                item.transform.localPosition = Vector3.zero;
                item.transform.localRotation = Quaternion.identity;
            }
        }

        // Attach accessories
        foreach (AccessoryObject a in m_accessories)
        {
            AccessoryLogic accessory = Instantiate(a.Accessory);
            accessory.transform.parent = character.transform;
            accessoryWearLogic.Attach(accessory);
        }
    }
Пример #3
0
    public static void CreateCharacter(CharacterAppearanceObject appearance, CharacterBehaviorObject behaviour, ItemObject leftHandItem, ItemObject rightHandItem, AccessoryObject[] accessories, Vector3 offset, bool keepCharacterPrefabConnection = false, bool keepItemPrefabConnection = true)
    {
        if (EditorApplication.isPlaying)
        {
            if (keepCharacterPrefabConnection)
            {
                keepCharacterPrefabConnection = false;
                Debug.LogError("Character Maker: keepCharacterPrefabConnection is not supported in playmode");
            }

            if (keepItemPrefabConnection)
            {
                keepItemPrefabConnection = false;
                Debug.LogError("Character Maker: keepItemPrefabConnection is not supported in playmode");
            }
        }

        GameObject character = Instantiate(appearance.Model, offset, Quaternion.identity, keepCharacterPrefabConnection);

        CapsuleCollider collider = character.AddComponent <CapsuleCollider>();

        collider.radius    = 0.1f;
        collider.direction = 1;
        collider.center    = new Vector3(0.0f, 0.5f, 0.0f);

        Rigidbody rigidbody = character.AddComponent <Rigidbody>();

        rigidbody.angularDrag = 5.0f;
        rigidbody.constraints = RigidbodyConstraints.FreezeRotation;

        if (behaviour != null)
        {
            behaviour.InitializeBehaviour(character);
        }

        ItemHoldLogic      itemHoldLogic      = character.GetComponent <ItemHoldLogic>();
        AccessoryWearLogic accessoryWearLogic = character.GetComponent <AccessoryWearLogic>();
        bool hasItems = leftHandItem || rightHandItem;

        if ((itemHoldLogic == null) && (leftHandItem || rightHandItem))
        {
            itemHoldLogic = character.AddComponent <ItemHoldLogic>();
            hasItems      = true;
        }

        if (itemHoldLogic != null)
        {
            itemHoldLogic.Initialize(character);
        }

        if (accessoryWearLogic == null)
        {
            if ((leftHandItem != null && leftHandItem.Item != null && leftHandItem.Item.AccessoryLogic != null) ||
                (rightHandItem != null && rightHandItem.Item != null && rightHandItem.Item.AccessoryLogic != null) ||
                (accessories != null && accessories.Length > 0))
            {
                accessoryWearLogic = character.AddComponent <AccessoryWearLogic>();
            }
        }

        // Attach items
        if (hasItems)
        {
            CharacterItemAnimator itemAnimator;
            itemAnimator          = itemHoldLogic.gameObject.AddComponent <CharacterItemAnimator>();
            itemAnimator.ThisHand = CharacterItemAnimator.Hand.Left;

            itemAnimator          = itemHoldLogic.gameObject.AddComponent <CharacterItemAnimator>();
            itemAnimator.ThisHand = CharacterItemAnimator.Hand.Right;
        }

        AttachItem(character, accessoryWearLogic, leftHandItem, itemHoldLogic, CharacterItemAnimator.Hand.Left, keepItemPrefabConnection);
        AttachItem(character, accessoryWearLogic, rightHandItem, itemHoldLogic, CharacterItemAnimator.Hand.Right, keepItemPrefabConnection);

        if (accessories != null)
        {
            // Attach accessories
            foreach (AccessoryObject a in accessories)
            {
                if (a == null)
                {
                    continue;
                }
                AccessoryLogic accessory = Instantiate(a.Accessory, keepItemPrefabConnection);
                accessory.transform.parent = character.transform;
                accessoryWearLogic.Attach(accessory);
            }
        }
    }