Beispiel #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);
    }
Beispiel #2
0
    public bool Load(int avatarAssetId, bool playDefaultAnim, bool useShadow)
    {
        this.avatarAssetId = avatarAssetId;

        // Save the avatar id.
        this.avatarTypeId = AvatarAssetConfig.ComponentIdToAvatarTypeId(avatarAssetId);

        // Check avatar id.
        if (ConfigDatabase.DefaultCfg.AvatarAssetConfig.GetAvatarById(avatarTypeId) == null)
        {
            Debug.LogError(System.String.Format("Invalid avatar id: {0:X}", avatarTypeId));
            return(false);
        }

        // Save old scale.
        Vector3 oldScale = gameObject.transform.localScale;

        gameObject.transform.localScale = new Vector3(1, 1, 1);

        // Create avatar object.
        if (avatarComponent.UseComponent(avatarAssetId, ""))
        {
            // Create avatar animation
            avatarAnimation.CreateAnimation();

            // Play the default animation.
            if (playDefaultAnim)
            {
                avatarAnimation.PlayDefaultAnim(avatarTypeId);
            }
        }

        // Create shadow.
        if (useShadow)
        {
            GameObject shadowGO = ResourceManager.Instance.InstantiateAsset <GameObject>(GameDefines.avtShadow);
            if (shadowGO != null)
            {
                shadow = shadowGO.transform;
                ObjectUtility.AttachToParentAndKeepLocalTrans(gameObject, shadow.gameObject);
                shadow.gameObject.name = "shadow";
            }
        }

        // Finished loading recover old scale
        gameObject.transform.localScale = oldScale;

        // Process delay used styles.
        avatarComponent.ReuseDelayStyles();

        return(true);
    }
Beispiel #3
0
    public void CreateRoot()
    {
        if (root == null)
        {
            root = new GameObject(this.gameObject.name).transform;
            ObjectUtility.AttachToParentAndKeepLocalTrans(root, this.transform);

            // Reset root transform
            root.localPosition = Vector3.zero;
            root.localRotation = Quaternion.identity;
            root.localScale    = Vector3.one;
        }
    }
Beispiel #4
0
    public FxPool(Transform root, GameObject template)
    {
        // Get FxController
        var fx = template.GetComponent <FXController>();

        if (fx == null)
        {
            fx             = template.AddComponent <FXController>();
            fx.loop        = true;
            fx.autoDestroy = true;
        }

        // Inactive template
        template.SetActive(false);

        // Attach template to root
        ObjectUtility.AttachToParentAndKeepLocalTrans(root, template.transform);

        this.root     = root;
        this.template = fx;
        this.released = false;
    }