public static T GetExportedValueByType <T>(this CompositionContainer container, string type)
 {
     foreach (var PartDef in container.Catalog.Parts)
     {
         foreach (var ExportDef in PartDef.ExportDefinitions)
         {
             if (ExportDef.ContractName == type)
             {
                 return((T)PartDef.CreatePart().GetExportedValue(ExportDef));
             }
         }
     }
     return(default(T));
 }
Exemple #2
0
    void SetAttached(PartData part, bool attached)
    {
        if (part.isAttached == attached)
        {
            return;
        }

        PartDef partDef = GetPartDefForKind(part.kind);

        part.hitPoints  = attached ? partDef.hitPoints : 0;
        part.isAttached = attached;

        part.detached.rootBone.parent = attached ? part.detachedParent : null;

        SetActive(part.attached, attached);
        SetActive(part.detached, !attached);
    }
 public static T GetExportedValue <T>(this CompositionContainer container,
                                      Func <IDictionary <string, object>, bool> predicate)
 {
     foreach (var PartDef in container.Catalog.Parts)
     {
         foreach (var ExportDef in PartDef.ExportDefinitions)
         {
             if (ExportDef.ContractName == typeof(T).FullName)
             {
                 if (predicate(ExportDef.Metadata))
                 {
                     return((T)PartDef.CreatePart().GetExportedValue(ExportDef));
                 }
             }
         }
     }
     return(default(T));
 }
Exemple #4
0
        public static IEnumerable <T> GetExportedValues <T>(this CompositionContainer Container,
                                                            Func <IDictionary <string, object>, bool> Predicate)
        {
            var result = new List <T>();

            foreach (var PartDef in Container.Catalog.Parts)
            {
                foreach (var ExportDef in PartDef.ExportDefinitions)
                {
                    if (ExportDef.ContractName == typeof(T).FullName)
                    {
                        if (Predicate(ExportDef.Metadata))
                        {
                            result.Add((T)PartDef.CreatePart().GetExportedValue(ExportDef));
                        }
                    }
                }
            }

            return(result);
        }
Exemple #5
0
    public void Setup(Unit unit)
    {
        for (int i = 0; i < EnumHelper <PartKind> .count; i++)
        {
            PartKind kind = EnumHelper <PartKind> .values[i];

            PartDef  def  = partDefs[kind];
            PartData data = parts[kind];

            data.kind      = kind;
            data.hitPoints = def.hitPoints;

            SkinnedMeshRenderer rend = def.rend.SetupWithSelf(transform);

            var rigidRend = unit.parts.rigidRoot.FindDeep(rend.name).GetComponent <SkinnedMeshRenderer>();

            SetupNode(rend, data.attached);
            SetupNode(rigidRend, data.detached);

            // Add a rigid to not count as static collider
            // Don't assign since it should never not be kinematic
            Rigidbody attachedRigid = data.attached.rootBone.gameObject.AddComponent <Rigidbody>();
            attachedRigid.isKinematic = true;
            attachedRigid.useGravity  = false;

            data.detached.rigid = data.detached.rootBone.gameObject.AddComponent <Rigidbody>();

            // Detached parts needs to be in root, since parts are childed under eachother
            data.detachedParent           = rigidRend.transform.parent;
            data.detached.rootBone.parent = data.detachedParent;

            attachedCollToPart[data.attached.coll] = data;
        }

        ReattachAll();
    }