Exemplo n.º 1
0
        /// <summary>
        /// パーティクルの有効フラグ設定
        /// </summary>
        /// <param name="c"></param>
        /// <param name="sw"></param>
        public void SetEnable(
            ChunkData c,
            bool sw,
            System.Func <int, Transform> funcTarget,
            System.Func <int, float3> funcLpos,
            System.Func <int, quaternion> funcLrot
            )
        {
            for (int i = 0; i < c.dataLength; i++)
            {
                int index = c.startIndex + i;

                var flag = flagList[index];
                flag.SetEnable(sw);
                if (sw)
                {
                    // 有効化
                    // 位置リセットフラグも立てる
                    flag.SetFlag(Flag_Reset_Position, true);

                    // ボーン登録
                    if (funcTarget != null)
                    {
                        var target = funcTarget(i);
                        if (target != null)
                        {
                            // 復元トランスフォーム
                            if (flag.IsRestoreTransform() && restoreTransformIndexList[index] == -1)
                            {
                                float3 lpos = funcLpos != null?funcLpos(i) : 0;

                                quaternion lrot = funcLrot != null?funcLrot(i) : quaternion.identity;

                                restoreTransformIndexList[index] = Bone.AddRestoreBone(target, lpos, lrot);
                            }

                            // 読み込みトランスフォーム
                            if (flag.IsReadTransform() && transformIndexList[index] == -1)
                            {
                                // パーティクル書き戻し判定
                                int windex = flag.IsWriteTransform() ? index : -1;

                                // 親トランスフォームの参照の有無
                                bool parent = flag.IsParentTransform();

                                transformIndexList[index] = Bone.AddBone(target, windex, parent);
                            }
                        }
                    }
                }
                else
                {
                    // 無効化
                    // ボーン登録解除
                    // 復元トランスフォーム
                    if (flag.IsRestoreTransform())
                    {
                        var restoreTransformIndex = restoreTransformIndexList[index];
                        if (restoreTransformIndex >= 0)
                        {
                            Bone.RemoveRestoreBone(restoreTransformIndex);
                            restoreTransformIndexList[index] = -1;
                        }
                    }

                    // 読み込み/書き込みトランスフォーム
                    if (flag.IsReadTransform())
                    {
                        var transformIndex = transformIndexList[index];
                        if (transformIndex >= 0)
                        {
                            int windex = flag.IsWriteTransform() ? index : -1;
                            Bone.RemoveBone(transformIndex, windex);
                            transformIndexList[index] = -1;
                        }
                    }
                }

                flagList[index] = flag;
            }
        }