Beispiel #1
0
    public Projectile CreateProjectile(ProjectileSyncInfo syncInfo, Skill sourceSkill = null)
    {
        localClient.ServerAddSyncAction(new SyncCreateProjectile(syncInfo));

        GameObject     obj        = GameObjectPool.instance.Instantiate(projectilePrefab);
        ProjectileNode node       = obj.GetComponent <ProjectileNode>();
        Projectile     projectile = obj.GetComponent <Projectile>();

        ResourceManager.instance.LoadProjectileModel(syncInfo.baseInfo.model);  // high time cost
        ResourceManager.instance.AssignModelToProjectileNode(syncInfo.baseInfo.model, node);

        projectile.MoveSpeed      = (float)syncInfo.baseInfo.move;
        projectile.MaxHeightDelta = (float)syncInfo.baseInfo.height;
        projectile.TypeOfFire     = Projectile.FireNameToType(syncInfo.baseInfo.fire);
        projectile.EffectFlags    = (uint)syncInfo.baseInfo.effect;

        //node.position = syncInfo.position;
        //node.visible = syncInfo.visible;
        projectile.TypeOfFromTo  = syncInfo.fromTo;
        projectile.UseFireOffset = syncInfo.useFireOffset;
        projectile.SourceUnit    = GetUnit(syncInfo.srcUnit);
        projectile.FromUnit      = GetUnit(syncInfo.fromUnit);
        projectile.ToUnit        = GetUnit(syncInfo.toUnit);
        projectile.FromPosition  = syncInfo.fromPos;
        projectile.ToPosition    = syncInfo.toPos;
        if (sourceSkill != null)
        {
            projectile.SourceSkill        = sourceSkill;
            projectile.EffectiveTypeFlags = sourceSkill.effectiveTypeFlags;
        }

        AddProjectile(projectile);
        node.SetFrame(ModelNode.kFrameDefault);
        projectile.Fire();
        return(projectile);
    }
Beispiel #2
0
 public SyncCreateProjectile(ProjectileSyncInfo syncInfo)
 {
     this.syncInfo = syncInfo;
 }
Beispiel #3
0
    /// <summary>
    /// 当技能起效时,单位会调用该函数
    /// </summary>
    public void Effect()
    {
        Unit     o = m_owner;
        UnitNode d = o.Node;

        StartCoolingDown();
        OnUnitCastSkill();

        switch (m_castTargetType)
        {
        case CommandTarget.Type.kNoTarget:
            PlayEffectSound();
            OnUnitSkillEffect(null, null);
            break;

        case CommandTarget.Type.kUnitTarget:
        {
            Unit t = o.CastTarget.TargetUnit;

            if (t == null || t.isDead)
            {
                return;
            }

            if (m_projectileTemplate != null && t != o)
            {
                ProjectileSyncInfo syncInfo = new ProjectileSyncInfo(Utils.IdGen.nextId, m_projectileTemplate);
                syncInfo.fromTo        = Projectile.FromToType.kUnitToUnit;
                syncInfo.useFireOffset = true;
                syncInfo.srcUnit       = o.Id;
                syncInfo.fromUnit      = o.Id;
                syncInfo.toUnit        = t.Id;

                World.Current.CreateProjectile(syncInfo, this);

                //UnitNode td = t.Node;
                //Debug.Assert(td != null);
            }
            else
            {
                PlayEffectSound();
                OnUnitSkillEffect(null, t);
            }
        }
        break;

        case CommandTarget.Type.kPointTarget:
            if (m_projectileTemplate != null)
            {
                ProjectileSyncInfo syncInfo = new ProjectileSyncInfo(Utils.IdGen.nextId, m_projectileTemplate);
                syncInfo.fromTo        = Projectile.FromToType.kUnitToPoint;
                syncInfo.useFireOffset = true;
                syncInfo.srcUnit       = o.Id;
                syncInfo.fromUnit      = o.Id;
                syncInfo.toPos         = Utils.GetForwardPoint(d.position, o.CastTarget.TargetPoint, m_castRange);
                World.Current.CreateProjectile(syncInfo, this);
            }
            else
            {
                PlayEffectSound();
                OnUnitSkillEffect(null, null);
            }
            break;
        }
    }