Example #1
0
        /// <summary>
        /// 播放音效
        /// </summary>
        /// <param name="effectPath"></param>
        /// <param name="pos"></param>
        /// <returns></returns>
        public IEnumerator PlayAudio(string resPath, EmitInfo emitInfo, uint emitId)
        {
            var ar = new AssetResource();

            yield return(ResourceLoader.Instance.StartCoroutine(ResourceLoader.Instance.load_asset(resPath, typeof(Object), ar)));

            if (ar.asset_ == null)
            {
                GameDebug.LogError(string.Format("the res {0} does not exist", resPath));
                yield break;
            }

            // 如果当前ID发生变化,说明之前的特效播放已经被终止
            if (emitId != mCurEmitId)
            {
                ar.destroy();
                yield break;
            }

            emitInfo.SetAuido(ar);
            var audio_clip = ar.asset_ as AudioClip;

            if (audio_clip != null)
            {
                AudioManager.Instance.PlayAudio(audio_clip, false);
            }
        }
Example #2
0
        void ConvertToEmitInfo()
        {
            var self = target as EnemyEmitter;

            self._formations = new List <Formation>();

            foreach (var source in self._formationSouces)
            {
                if (source.formationRoot == null)
                {
                    continue;
                }

                var formation = new Formation();
                formation.name = source.name;
                foreach (Transform elem in source.formationRoot.transform)
                {
                    var info = new EmitInfo();
                    info.position = elem.position;
                    info.prefab   = (GameObject)PrefabUtility.GetPrefabParent(elem.gameObject);
                    formation.infos.Add(info);
                }
                self._formations.Add(formation);

                Debug.LogFormat("Converted fleet:name->{0}", formation.name);
            }
        }
Example #3
0
        public virtual void CompleteType()
        {
            if (emit_info == null)
            {
                return;
            }

            foreach (var baseClass in base_classes)
            {
                baseClass.CompleteType();
            }

            // Update the offsets for virtual base classes
            if (this.IsFinalClass)
            {
                // TODO: This GCHandleOffset stuff probably needs a bit of work
                // I think the GCHandleOffset is typically only used on the final class
                // and for non primary base classes in which case the offsets should be right
                // However, I wouldn't trust the values for any other types

                int offset   = 0;
                var virtDict = new Dictionary <Type, int>();
                foreach (var virt in this.GetVirtualBases().Reverse())
                {
                    // If we've already seen this type then use the offset from before
                    if (virtDict.ContainsKey(virt.WrapperType))
                    {
                        virt.gchandle_offset_delta = virtDict[virt.WrapperType];
                        continue;
                    }

                    virtDict.Add(virt.WrapperType, offset);
                    virt.gchandle_offset_delta = offset;
                    offset += virt.NativeSize;
                    this.field_offset_padding_without_vtptr += virt.native_size_without_padding +
                                                               virt.FieldOffsetPadding;
                }

                // If we have any virtual bases then we need to offset by their sizes
                if (virtDict.Count > 0)
                {
                    EachBase((b) =>
                    {
                        // Don't offset any of our virtual bases because they're already done
                        if (virtDict.ContainsKey(b.WrapperType))
                        {
                            return;
                        }

                        b.gchandle_offset_delta += offset;
                    });
                }
            }

            emit_info = null;

            RemoveVTableDuplicates();
        }
Example #4
0
        /// <summary>
        /// 在uuid的玩家身上播放物品gid对应的烟火特效资源
        /// </summary>
        /// <param name="uuid"></param>
        /// <param name="gid"></param>
        public void Ignite(uint uuid, uint gid)
        {
            var info = DBMarryFirework.Instance.GetInfo(gid);

            if (info == null)
            {
                GameDebug.LogError("[Ignite]get firework info failed, id:" + gid);
                return;
            }

            /*var actor = ActorManager.Instance.GetActor(uuid);
             * if (actor == null || actor.IsDestroy)
             * {
             *  GameDebug.LogError("[Ignite]get actor info failed, id:" + uuid);
             *  return;
             * }*/

            var isLocalPlayer = uuid == LocalPlayerManager.Instance.LocalActorAttribute.UnitId.obj_idx;

            if (isLocalPlayer)
            {
                // 停止之前正在播放的特效
                if (mEmitInfo != null && !mEmitInfo.IsFinish)
                {
                    mEmitInfo.Stop();
                }
            }
            else
            {
                // 如果当前有正在播放的特效,则直接返回
                if (mEmitInfo != null && !mEmitInfo.IsFinish)
                {
                    return;
                }
            }

            if (mEmitId == 0)
            {
                mEmitId++;
            }
            mCurEmitId = mEmitId;

            if (mEmitInfo == null)
            {
                mEmitInfo = new EmitInfo(mCurEmitId, info.Time, info.AssetPath);
            }
            else
            {
                mEmitInfo.Reset(mCurEmitId, info.Time, info.AssetPath);
            }

            MainGame.HeartBehavior.StartCoroutine(PlayEffect(info.AssetPath, mEmitInfo, mCurEmitId));
            MainGame.HeartBehavior.StartCoroutine(PlayAudio("Assets/Res/" + info.AudioPath, mEmitInfo, mCurEmitId));
            mEmitId++;
        }
Example #5
0
        protected CppTypeInfo()
        {
            base_classes = new List <CppTypeInfo> ();
            BaseClasses  = new ReadOnlyCollection <CppTypeInfo> (base_classes);

            field_offset_padding_without_vtptr = 0;
            gchandle_offset_delta = 0;
            IsPrimaryBase         = true;
            BaseVTableSlots       = 0;
            lazy_vtable           = null;

            emit_info = new EmitInfo();
        }
Example #6
0
        static void BuildMap <TFrom, TTo>(ILGenerator il, MappingInfo <TFrom, TTo> mappingInfo, int firstArgIndex, Action emitBeforeMapLoadDelegate, Action emitAfterMapLoadDelegate, Dictionary <MetaMemberPair <TFrom, TTo>, FieldBuilder> convertActionDictionary)
        {
            var fromType = typeof(TFrom);
            var toType   = typeof(TTo);

            var argFrom     = new ArgumentField(il, firstArgIndex, fromType);
            var argResolver = new ArgumentField(il, firstArgIndex + 1);

            // call beforeMap
            if (mappingInfo.BeforeMap != null)
            {
                emitBeforeMapLoadDelegate();
                argFrom.EmitLdarg();
                il.EmitCall(EmitInfo.GetActionInvoke <TFrom>());
            }

            // if(from == null) return null
            if (!fromType.IsValueType)
            {
                var gotoNextLabel = il.DefineLabel();
                argFrom.EmitLoad();
                il.Emit(OpCodes.Brtrue_S, gotoNextLabel);
                il.Emit(OpCodes.Ldnull);
                il.Emit(OpCodes.Ret);
                il.MarkLabel(gotoNextLabel);
            }

            // construct totype
            var result = EmitNewObject <TFrom, TTo>(il, argFrom, mappingInfo.TargetConstructor);

            // map from -> to.

            foreach (var item in mappingInfo.TargetMembers)
            {
                EmitMapMember(il, item, argFrom, argResolver, result, convertActionDictionary);
            }

            // call afterMap
            if (mappingInfo.AfterMap != null)
            {
                emitAfterMapLoadDelegate();
                il.EmitLdloc(result);
                il.EmitCall(EmitInfo.GetActionInvoke <TTo>());
            }

            // end.
            il.EmitLdloc(result);
            il.Emit(OpCodes.Ret);
        }
Example #7
0
        /// <summary>
        /// 在指定位置播放特效
        /// </summary>
        /// <param name="effectPath"></param>
        /// <param name="pos"></param>
        /// <returns></returns>
        public IEnumerator PlayEffect(string effectPath, EmitInfo emitInfo, uint emitId)
        {
            var objectWrapper = new ObjectWrapper();

            yield return(MainGame.HeartBehavior.StartCoroutine(ObjCachePoolMgr.Instance.LoadPrefab(effectPath, ObjCachePoolType.SFX, effectPath, objectWrapper)));

            if (objectWrapper.obj == null)
            {
                yield break;
            }

            var effectObject = objectWrapper.obj as GameObject;

            if (effectObject == null)
            {
                yield break;
            }

            GameDebug.Log("emit:" + emitInfo.EmitID + "," + emitId);

            // 如果当前ID发生变化,说明之前的特效播放已经被终止
            if (emitId != mCurEmitId)
            {
                ObjCachePoolMgr.Instance.RecyclePrefab(effectObject, ObjCachePoolType.SFX, effectPath);
                yield break;
            }

            emitInfo.SetObject(effectObject);

            // 如果找不到当前主相机,则停止特效的播放
            Camera mainCam = Camera.main;

            if (mainCam == null)
            {
                if (!emitInfo.IsFinish)
                {
                    emitInfo.Stop();
                }
                yield break;
            }

            var effectTrans = effectObject.transform;

            effectTrans.parent        = mainCam.transform;
            effectTrans.localPosition = Vector3.zero;
            effectTrans.localScale    = Vector3.one;
            effectTrans.localRotation = Quaternion.identity;
        }
Example #8
0
        public virtual void CompleteType()
        {
            if (emit_info == null)
            {
                return;
            }

            foreach (var baseClass in base_classes)
            {
                baseClass.CompleteType();
            }

            emit_info = null;

            RemoveVTableDuplicates();
        }
Example #9
0
        static void EmitMapMember <TFrom, TTo>(ILGenerator il, MetaMemberPair <TFrom, TTo> pair, ArgumentField argFrom, ArgumentField argResolver, LocalBuilder toLocal, Dictionary <MetaMemberPair <TFrom, TTo>, FieldBuilder> convertFields)
        {
            if (pair.From == null)
            {
                // To and conversion pattern(Func<TFrom, TFromMember>).
                if (toLocal.LocalType.IsValueType)
                {
                    il.EmitLdloca(toLocal);
                }
                else
                {
                    il.EmitLdloc(toLocal);
                }

                // note: if use DynamicMethod, should change field to argument.

                // Func[TFrom, TToMember]
                var convertField = convertFields[pair];
                il.EmitLoadThis();
                il.EmitLdfld(convertField);
                il.Emit(OpCodes.Castclass, typeof(Func <,>).MakeGenericType(typeof(TFrom), pair.To.Type));
                argFrom.EmitLdarg();
                il.EmitCall(EmitInfo.GetFuncInvokeDynamic(typeof(TFrom), pair.To.Type));
                pair.To.EmitStoreValue(il);
            }
            else
            {
                // optimize for primitive to primitive
                if (pair.From.Type == pair.To.Type)
                {
                    if (optimizeInliningType.Contains(pair.To.Type))
                    {
                        if (toLocal.LocalType.IsValueType)
                        {
                            il.EmitLdloca(toLocal);
                        }
                        else
                        {
                            il.EmitLdloc(toLocal);
                        }

                        if (convertFields.TryGetValue(pair, out var convertField))
                        {
                            il.EmitLoadThis();
                            il.EmitLdfld(convertField);
                            il.Emit(OpCodes.Castclass, typeof(Func <,>).MakeGenericType(pair.From.Type, pair.To.Type));
                        }

                        argFrom.EmitLoad();
                        pair.From.EmitLoadValue(il);

                        if (convertField != null)
                        {
                            il.EmitCall(EmitInfo.GetFuncInvokeDynamic(pair.From.Type, pair.To.Type));
                        }

                        pair.To.EmitStoreValue(il);
                        return;
                    }

                    // more aggressive inlining for primitive[]
                    if (pair.To.Type.IsArray)
                    {
                        var elemType      = pair.To.Type.GetElementType();
                        var mapMethodInfo = EmitInfo.GetMemoryCopyMapperMap(elemType);

                        if (mapMethodInfo != null)
                        {
                            il.EmitLdloc(toLocal);

                            if (convertFields.TryGetValue(pair, out var convertField))
                            {
                                il.EmitLoadThis();
                                il.EmitLdfld(convertField);
                                il.Emit(OpCodes.Castclass, typeof(Func <,>).MakeGenericType(pair.From.Type, pair.To.Type));
                            }

                            argFrom.EmitLoad();
                            pair.From.EmitLoadValue(il);
                            il.EmitCall(mapMethodInfo);

                            if (convertField != null)
                            {
                                il.EmitCall(EmitInfo.GetFuncInvokeDynamic(pair.From.Type, pair.To.Type));
                            }

                            pair.To.EmitStoreValue(il);
                            return;
                        }
                    }
                }

                // standard mapping(Mapper.Map)
                {
                    if (toLocal.LocalType.IsValueType)
                    {
                        il.EmitLdloca(toLocal);
                    }
                    else
                    {
                        il.EmitLdloc(toLocal);
                    }

                    if (convertFields.TryGetValue(pair, out var convertField))
                    {
                        il.EmitLoadThis();
                        il.EmitLdfld(convertField);
                        il.Emit(OpCodes.Castclass, typeof(Func <,>).MakeGenericType(pair.From.Type, pair.To.Type));
                    }

                    argResolver.EmitLoad();
                    il.EmitCall(EmitInfo.GetGetMapperWithVerifyDynamic(pair.From.Type, pair.To.Type));
                    argFrom.EmitLoad();
                    pair.From.EmitLoadValue(il);
                    argResolver.EmitLoad();
                    il.EmitCall(EmitInfo.GetMapDynamic(pair.From.Type, pair.To.Type));

                    if (convertField != null)
                    {
                        il.EmitCall(EmitInfo.GetFuncInvokeDynamic(pair.From.Type, pair.To.Type));
                    }

                    pair.To.EmitStoreValue(il);
                }
            }
        }