Пример #1
0
    public FXController PlayFX(string fxName, GameObject parent, bool attachedToParent, bool autoDestroy, bool isResetLocalPos, bool startImmediately, bool setLayerAsParent = true)
    {
        //	string fxPath = PathUtility.Combine(baseFxPath, fxName);
        FXController fx = CreateFxNonStart(fxName);

        //	AssertHelper.Check(fx != null, fxName + " not exist!");

        if (fx == null)
        {
            return(null);
        }

        // Attach to parent
        if (attachedToParent)
        {
            if (isResetLocalPos)
            {
                ObjectUtility.AttachToParentAndResetLocalPosAndRotation(parent.transform, fx.Root);
            }
            else
            {
                ObjectUtility.AttachToParentAndKeepLocalTrans(parent.transform, fx.Root);
            }
        }
        else
        {
            if (isResetLocalPos)
            {
                ObjectUtility.UnifyWorldTrans(parent.transform, fx.Root);
            }
        }

        // Set layer
        if (setLayerAsParent)
        {
            ObjectUtility.SetObjectLayer(fx.gameObject, parent.layer);
        }

        if (autoDestroy)
        {
            // Set auto destroy flag to FX script.
            FXController pfxScp = fx.GetComponentInChildren <FXController>();

            if (pfxScp != null)
            {
                pfxScp.autoDestroy = true;
                pfxScp.loop        = false;
            }
        }

        if (startImmediately)
        {
            fx.Start();
        }

        return(fx);
    }
Пример #2
0
    // Attach style mesh, return the new game object.
    private GameObject AttachSkinComponent(GameObject attachingObject)
    {
        // Create one new object for this mesh renderer.
        GameObject attachingRoot = new GameObject(attachingObject.name);

        // Attach to avatar object.
        Vector3 oldScale = avatar.gameObject.transform.localScale;

        avatar.gameObject.transform.localScale = new Vector3(1, 1, 1);
        ObjectUtility.AttachToParentAndResetLocalPosAndRotation(avatar.AvatarObject, attachingRoot);

        // Copy SkinnedMeshRenderer.
        foreach (SkinnedMeshRenderer renderer in attachingObject.GetComponentsInChildren <SkinnedMeshRenderer>(true))
        {
            // Create one new object for this mesh renderer.
            GameObject newSubMsh = new GameObject(renderer.sharedMesh.name);
            ObjectUtility.AttachToParentAndResetLocalPosAndRotation(attachingRoot, newSubMsh);

            // Copy renderer.
            SkinnedMeshRenderer newRenderer = newSubMsh.AddComponent <SkinnedMeshRenderer>();
            newRenderer.sharedMesh          = renderer.sharedMesh;
            newRenderer.sharedMaterials     = renderer.sharedMaterials;
            newRenderer.quality             = renderer.quality;
            newRenderer.updateWhenOffscreen = renderer.updateWhenOffscreen;

            Transform[] bones = new Transform[renderer.bones.Length];
            for (int i = 0; i < renderer.bones.Length; i++)
            {
                var bone = ObjectUtility.FindChildObject(avatar.AvatarObject, renderer.bones[i].name);
                if (bone == null)
                {
                    Debug.LogError(string.Format("Bone {0} is missing", renderer.bones[i].name));
                    continue;
                }

                bones[i] = bone;
            }

            newRenderer.bones = bones;
        }

        // Reset local scale.
        avatar.gameObject.transform.localScale = oldScale;

        // Set to current layer.
        ObjectUtility.SetObjectLayer(attachingRoot, avatar.gameObject.layer);

        return(attachingRoot);
    }
Пример #3
0
    // Mount style mesh.
    private GameObject MountComponent(Transform mountingObject, string mountBoneName, string mountingMakerName)
    {
        // Find mount mountBone.
        var mountBone = ObjectUtility.FindChildObject(avatar.AvatarObject, mountBoneName);

        if (mountBone == null)
        {
#if ENABLE_AVATAR_COMPONENT_LOG
            Debug.LogWarning("Not found the mount bone on base object : " + mountBoneName);
#endif
            return(null);
        }

        // Find mount mountBone in first depth children.
        var mountingBone = ObjectUtility.FindChildObject(mountingObject, mountingMakerName, true);
        if (mountingBone == null)
        {
#if ENABLE_AVATAR_COMPONENT_LOG
            Debug.LogWarning("Not found the mount mountBone in usedComponent model: " + mountingObject.name + " " + mountingMakerName);
#endif
            return(null);
        }

        // Create one new object for this usedComponent.
        Transform mountingRoot = new GameObject(mountingObject.gameObject.name).transform;
        ObjectUtility.UnifyWorldTrans(mountingBone, mountingRoot);

        // Attach to mounting root
        ObjectUtility.AttachToParentAndKeepWorldTrans(mountingRoot, mountingObject);

        // Set to layer.
        ObjectUtility.SetObjectLayer(mountingRoot.gameObject, avatar.gameObject.layer);

        // Attach to mount bone.
        Transform avatarTrans = avatar.gameObject.transform;
        Vector3   oldScale    = avatarTrans.localScale;
        avatarTrans.localScale = Vector3.one;
        ObjectUtility.AttachToParentAndResetLocalPosAndRotation(mountBone, mountingRoot);
        avatarTrans.localScale = oldScale;

        return(mountingRoot.gameObject);
    }