Exemplo n.º 1
0
        public EquipmentInstallationResult InstallEquipment(int equipmentIdentifier, string userReferenceName, MountPoint mountPoint)
        {
            b.Verbose.Log("InstallEquipment - selecting " + equipmentIdentifier + " as user - " + userReferenceName);
            CheckPreparation();
            EquipmentInstallationResult result = new EquipmentInstallationResult();

            ItemClassification clas = KnownEquipmentIds.GetClassificationFromId(equipmentIdentifier);

            if ((this.PowerPack != null) && (clas == ItemClassification.PowerPack))
            {
                return(null);
            }

            if (namedEquipment.ContainsKey(userReferenceName))
            {
                throw new BdBaseException("The name is already in use");
            }

            EquipmentInstallationResult ae = engineActionProvider.MountEquipment(this, equipmentIdentifier, mountPoint);

            b.Assert.True(ae != null, "You have to return a result, if it failed use the status indicator.");

            if (ae.Result != InstallationResult.Installed)
            {
                b.Warning.Log("Failed to install equipment to " + mountPoint.ToString() + " reason " + ae.Result.ToString());
                return(ae);
            }
            else
            {
                namedEquipment.Add(userReferenceName, ae);
                allInstalledEquipment.Add(ae);
                if (clas == ItemClassification.PowerPack)
                {
                    b.Verbose.Log("Powerpack Installed");
                    this.PowerPack = ae;
                }
            }
            return(ae);
        }
Exemplo n.º 2
0
 private static void ValidateFitPosition(EquipmentItem sut, MountPoint position)
 {
     Assert.True(sut.IsInstallationPermitted(position), "The " + position.ToString() + "mount point must be permitted when setting external");
 }
Exemplo n.º 3
0
    private bool MountWeapon(MountPoint p,
                             GameObject obj,
                             WeaponMountRecord mountRecord,
                             EquipModelViewRecord record,
                             int part,
                             bool sync,
                             Action <GameObject> callback)
    {
        if (_body == null)
        {
            return(false);
        }

        if (obj == null)
        {
            return(false);
        }

        var parent = GetPart(_body.transform, p.ToString());

        if (parent == null)
        {
            return(false);
        }

        var o            = obj;
        var objTransform = o.transform;

        objTransform.parent        = parent;
        objTransform.localPosition = new Vector3(mountRecord.PosX, mountRecord.PosY, mountRecord.PosZ);
        objTransform.localRotation = Quaternion.Euler(mountRecord.DirX, mountRecord.DirY, mountRecord.DirZ);
        objTransform.localScale    = Vector3.one;
        o.SetLayerRecursive(Layer, LayerMask);
        o.SetRenderQueue(mRenderQueue);
        _parts[part].Add(o);

        if (callback != null)
        {
            callback(o);
        }

        Material material;
        Renderer renderer = o.renderer;

        if (renderer != null)
        {
            material = renderer.sharedMaterial;
        }
        else
        {
            renderer = objTransform.GetComponentInChildren <SkinnedMeshRenderer>();
            if (renderer == null)
            {
                Logger.Log2Bugly("MountWeapon renderer is null, {0}, {1}, {2}", p, obj.name, record.Id);
                return(false);
            }
            material = renderer.sharedMaterial;
        }

        if (material == null)
        {
            return(false);
        }

        // 翅膀没有这个
        if (!material.HasProperty("_BColor"))
        {
            return(true);
        }

        const string MainTexVariableName = "_MainTex";

        if (IsMainPlayer)
        {
            _loading++;
            ResourceManager.PrepareResource <Material>(Resource.Material.MainPlayerMaterial, mat =>
            {
                _loading--;

                if (!mat)
                {
                    TryContinue();
                    return;
                }

                if (!o || !renderer)
                {
                    TryContinue();
                    return;
                }

                if (!material)
                {
                    TryContinue();
                    return;
                }

                var newMat = new Material(mat);
                newMat.SetTexture(MainTexVariableName, material.GetTexture(MainTexVariableName));
                renderer.material = newMat;

                if (record != null)
                {
                    newMat.SetColor("_BColor",
                                    new Color(record.FlowRed / 255.0f, record.FlowGreen / 255.0f, record.FlowBlue / 255.0f,
                                              record.FlowAlpha / 255.0f));
                    newMat.SetColor("_TexColor",
                                    new Color(record.SepcularRed / 255.0f, record.SepcularGreen / 255.0f, record.SepcularBlue / 255.0f,
                                              record.SepcularAlpha / 255.0f));
                }
                else
                {
                    newMat.SetColor("_BColor", Color.black);
                    newMat.SetColor("_TexColor", Color.black);
                }

                ResourceManager.ChangeShader(objTransform);

                TryContinue();
            }, true, true, sync);
        }
        else
        {
            if (renderer)
            {
                var newMat = new Material(material);
                newMat.SetTexture(MainTexVariableName, material.GetTexture(MainTexVariableName));
                renderer.material = newMat;

                if (record != null)
                {
                    newMat.SetColor("_BColor",
                                    new Color(record.FlowRed / 255.0f, record.FlowGreen / 255.0f, record.FlowBlue / 255.0f,
                                              record.FlowAlpha / 255.0f));
                    newMat.SetColor("_TexColor",
                                    new Color(record.SepcularRed / 255.0f, record.SepcularGreen / 255.0f, record.SepcularBlue / 255.0f,
                                              record.SepcularAlpha / 255.0f));
                }
                else
                {
                    newMat.SetColor("_BColor", Color.black);
                    newMat.SetColor("_TexColor", Color.black);
                }

                ResourceManager.ChangeShader(objTransform);
            }
        }

        return(true);
    }
Exemplo n.º 4
0
    public void MountWeapon(MountPoint p,
                            string model,
                            WeaponMountRecord mountRecord,
                            EquipModelViewRecord record,
                            int part,
                            bool sync,
                            Action <GameObject> callback = null)
    {
        mWeaponModels[part] = model;

        // remove all the objs with the same tag.
        List <GameObject> l;

        if (!_parts.TryGetValue(part, out l))
        {
            l = new List <GameObject>();
            _parts.Add(part, l);
        }
        var lCount0 = l.Count;

        for (var i = 0; i < lCount0; i++)
        {
            ComplexObjectPool.Release(l[i], Layer == UnityEngine.LayerMask.NameToLayer("UI"));
        }
        l.Clear();

        if (string.IsNullOrEmpty(model))
        {
            TryContinue();
            return;
        }

        if (_body == null || _loading > 0)
        {
            _avatarLoadQueue.Enqueue(new KeyValuePair <string, WaitingResource>(p.ToString(),
                                                                                new WaitingResource
            {
                ModelPath         = model,
                ModelViewRecord   = record,
                IsWeapon          = true,
                Part              = part,
                Callback          = callback,
                WeaponMountRecord = mountRecord
            }));
            return;
        }

        _loading++;
        ComplexObjectPool.NewObject(model, obj =>
        {
            _loading--;

            string value;
            if (mWeaponModels.TryGetValue(part, out value) && value != model)
            {
                ComplexObjectPool.Release(obj, Layer == UnityEngine.LayerMask.NameToLayer("UI"));
                TryContinue();
                return;
            }

            if (null != obj)
            {
                if (!MountWeapon(p, obj, mountRecord, record, part, sync, callback))
                {
                    ComplexObjectPool.Release(obj);
                    TryContinue();
                    return;
                }
            }

            if (record == null)
            {
                TryContinue();
                return;
            }

            var recordEffectPathLength1 = record.EffectPath.Length;
            for (var i = 0; i < recordEffectPathLength1; i++)
            {
                if (!string.IsNullOrEmpty(record.EffectPath[i]))
                {
                    _loading++;
                    var index = i;
                    ComplexObjectPool.NewObject(record.EffectPath[index], effect =>
                    {
                        _loading--;
                        string _model;
                        if (mWeaponModels.TryGetValue(part, out _model) && _model != model)
                        {
                            ComplexObjectPool.Release(effect, Layer == UnityEngine.LayerMask.NameToLayer("UI"));
                            TryContinue();
                            return;
                        }

                        if (obj != null && effect != null)
                        {
                            if (record.EffectMount[index] == -1)
                            {
                                AddEffect(obj.transform, effect,
                                          new Vector3(record.EffectPosX[index], record.EffectPosY[index],
                                                      record.EffectPosZ[index]),
                                          Quaternion.Euler(record.EffectDirX[index], record.EffectDirY[index],
                                                           record.EffectDirZ[index]), part);
                            }
                            else
                            {
                                AddEffect(
                                    GetPart(_body.transform, ((MountPoint)record.EffectMount[index]).ToString()),
                                    effect,
                                    new Vector3(record.EffectPosX[index], record.EffectPosY[index],
                                                record.EffectPosZ[index]),
                                    Quaternion.Euler(record.EffectDirX[index], record.EffectDirY[index],
                                                     record.EffectDirZ[index]), part);
                            }
                        }
                        TryContinue();
                    }, null, null, sync);
                }
            }

            TryContinue();
        }, null, null, sync);
    }