Esempio n. 1
0
        /// <summary>
        /// Instantiates an object in a cell. Called by InstantiateCellObjectsCoroutine after the object's assets have been pre-loaded.
        /// </summary>
        private void InstantiatePreLoadedCellObject(CELLRecord CELL, GameObject parent, RefCellObjInfo refCellObjInfo)
        {
            if (refCellObjInfo.referencedRecord != null)
            {
                GameObject modelObj = null;

                // If the object has a model, instantiate it.
                if (refCellObjInfo.modelFilePath != null)
                {
                    modelObj = theNIFManager.InstantiateNIF(refCellObjInfo.modelFilePath);
                    PostProcessInstantiatedCellObject(modelObj, refCellObjInfo);

                    modelObj.transform.parent = parent.transform;
                }

                // If the object has a light, instantiate it.
                if (refCellObjInfo.referencedRecord is LIGHRecord)
                {
                    var lightObj = InstantiateLight((LIGHRecord)refCellObjInfo.referencedRecord, CELL.isInterior);

                    // If the object also has a model, parent the model to the light.
                    if (modelObj != null)
                    {
                        // Some NIF files have nodes named "AttachLight". Parent it to the light if it exists.
                        GameObject attachLightObj = GameObjectUtils.FindChildRecursively(modelObj, "AttachLight");

                        if (attachLightObj == null)
                        {
                            //attachLightObj = GameObjectUtils.FindChildWithNameSubstringRecursively(modelObj, "Emitter");
                            attachLightObj = modelObj;
                        }

                        if (attachLightObj != null)
                        {
                            lightObj.transform.position = attachLightObj.transform.position;
                            lightObj.transform.rotation = attachLightObj.transform.rotation;

                            lightObj.transform.parent = attachLightObj.transform;
                        }
                        else // If there is no "AttachLight", center the light in the model's bounds.
                        {
                            lightObj.transform.position = GameObjectUtils.CalcVisualBoundsRecursive(modelObj).center;
                            lightObj.transform.rotation = modelObj.transform.rotation;

                            lightObj.transform.parent = modelObj.transform;
                        }
                    }
                    else // If the light has no associated model, instantiate the light as a standalone object.
                    {
                        PostProcessInstantiatedCellObject(lightObj, refCellObjInfo);
                        lightObj.transform.parent = parent.transform;
                    }
                }
            }

            /*else
             *          {
             *                  Debug.Log("Unknown Object: " + refCellObjInfo.refObjDataGroup.NAME.value);
             *          }*/
        }
Esempio n. 2
0
 /// <summary>
 /// Instantiates an object in a cell. Called by InstantiateCellObjectsCoroutine after the object's assets have been pre-loaded.
 /// </summary>
 void InstantiateCellObject(CELLRecord cell, GameObject parent, RefCellObjInfo refCellObjInfo)
 {
     if (refCellObjInfo.ReferencedRecord != null)
     {
         GameObject modelObj = null;
         // If the object has a model, instantiate it.
         if (refCellObjInfo.ModelFilePath != null)
         {
             modelObj = _asset.CreateObject(refCellObjInfo.ModelFilePath);
             PostProcessInstantiatedCellObject(modelObj, refCellObjInfo);
             modelObj.transform.parent = parent.transform;
         }
         // If the object has a light, instantiate it.
         if (refCellObjInfo.ReferencedRecord is LIGHRecord)
         {
             var lightObj = InstantiateLight((LIGHRecord)refCellObjInfo.ReferencedRecord, cell.IsInterior);
             // If the object also has a model, parent the model to the light.
             if (modelObj != null)
             {
                 // Some SIF files have nodes named "AttachLight". Parent it to the light if it exists.
                 var attachLightObj = GameObjectUtils.FindChildRecursively(modelObj, "AttachLight");
                 if (attachLightObj == null)
                 {
                     //attachLightObj = GameObjectUtils.FindChildWithNameSubstringRecursively(modelObj, "Emitter");
                     attachLightObj = modelObj;
                 }
                 if (attachLightObj != null)
                 {
                     lightObj.transform.position = attachLightObj.transform.position;
                     lightObj.transform.rotation = attachLightObj.transform.rotation;
                     lightObj.transform.parent   = attachLightObj.transform;
                 }
                 else // If there is no "AttachLight", center the light in the model's bounds.
                 {
                     lightObj.transform.position = GameObjectUtils.CalcVisualBoundsRecursive(modelObj).center;
                     lightObj.transform.rotation = modelObj.transform.rotation;
                     lightObj.transform.parent   = modelObj.transform;
                 }
             }
             else // If the light has no associated model, instantiate the light as a standalone object.
             {
                 PostProcessInstantiatedCellObject(lightObj, refCellObjInfo);
                 lightObj.transform.parent = parent.transform;
             }
         }
     }
     else
     {
         Utils.Log("Unknown Object: " + ((CELLRecord.RefObj)refCellObjInfo.RefObj).Name);
     }
 }