示例#1
0
        /// <summary>
        /// Creates a new random prop prefab.
        /// </summary>
        /// <param name="propName">Name of prefab</param>
        /// <returns>New prop prefab</returns>
        internal static PropInfo NewRandomProp(string propName)
        {
            // Need valid name.
            if (propName == null)
            {
                Logging.Error("null prop name for random prop");
                return(null);
            }

            // Need unique name.
            if (DuplicatePropName(propName))
            {
                Logging.Error("duplicate prop name for random prop");
                return(null);
            }

            // Instantiate existing prop and use as base for new prop.
            GameObject objectInstance = Object.Instantiate(PrefabCollection <PropInfo> .FindLoaded("Amp Stack").gameObject);

            objectInstance.name = propName;
            PropInfo randomProp = objectInstance.GetComponent <PropInfo>();

            objectInstance.SetActive(false);
            randomProp.m_prefabInitialized = false;
            randomProp.InitializePrefab();

            // Add new prop to list and return direct reference.
            randomProps.Add(randomProp);
            return(randomProp);
        }
示例#2
0
文件: RandomProps.cs 项目: Alexof/BOB
        /// <summary>
        /// Instantiates a new PropInfp prefab.
        /// </summary>
        /// <param name="propName">Name to instantiate</param>
        /// <returns>New tree prefab, or null if instantiation fialed</returns>
        internal static PropInfo InstantiateProp(string propName)
        {
            // Need valid name.
            if (propName == null)
            {
                Logging.Error("null prop name for random prop");
                return(null);
            }

            // Instantiate prop template and use as base for new prop.
            if (PrefabLists.RandomPropTemplate != null)
            {
                GameObject objectInstance = UnityEngine.Object.Instantiate(PrefabLists.RandomPropTemplate.gameObject);
                objectInstance.name = propName;
                PropInfo randomProp = objectInstance.GetComponent <PropInfo>();
                objectInstance.SetActive(false);
                randomProp.m_isCustomContent   = true;
                randomProp.m_prefabInitialized = false;
                randomProp.InitializePrefab();
                randomProp.m_prefabInitialized = true;
                return(randomProp);
            }

            // If we got here, then we weren't able to find the random prop template.
            Logging.Error("random prop template not found");
            return(null);
        }
示例#3
0
        private void SwapMeshes(VehicleInfo template, PropInfo target)
        {
            var vehicle   = Util.InstantiateVehicleCopy(template);
            var vehicleGO = vehicle.gameObject;
            var propGO    = target.gameObject;

            var vehicleMf = vehicleGO.GetComponent <MeshFilter>();
            var propMf    = propGO.GetComponent <MeshFilter>();

            // set mesh
            vehicleMf.sharedMesh = vehicleMf.mesh;
            propMf.mesh          = vehicleMf.sharedMesh;
            propMf.sharedMesh    = propMf.mesh;

            // set material
            var renderer    = propGO.GetComponent <Renderer>();
            var vehRenderer = vehicleGO.GetComponent <Renderer>();

            if (renderer != null)
            {
                var shader         = renderer.sharedMaterial.shader;
                var shaderKeyWords = renderer.sharedMaterial.shaderKeywords;

                var material = vehRenderer.sharedMaterial;
                CleanACIMap(material);
                renderer.sharedMaterial = material;

                renderer.sharedMaterial.shader         = shader;
                renderer.sharedMaterial.shaderKeywords = shaderKeyWords;
            }

            // set lod
            if (vehicle.m_lodObject != null)
            {
                var lodRenderer    = target.m_lodObject.GetComponent <Renderer>();
                var lodVehRenderer = vehicle.m_lodObject.GetComponent <Renderer>();

                var material = lodVehRenderer.sharedMaterial;
                CleanACIMap(material);
                lodVehRenderer.sharedMaterial = material;

                lodVehRenderer.sharedMaterial.shader         = lodRenderer.sharedMaterial.shader;
                lodVehRenderer.sharedMaterial.shaderKeywords = lodRenderer.sharedMaterial.shaderKeywords;

                target.m_lodObject = vehicle.m_lodObject;
            }

            // Recalculate generated info
            target.CalculateGeneratedInfo();
            target.m_mesh = null;       // Required to get InitializePrefab to do its thing
            target.m_prefabInitialized = false;
            target.InitializePrefab();
            target.m_prefabInitialized = true;

            Destroy(vehicleGO);
        }
        /// <summary>
        /// Creates and instantiates a copy of a PropInfo
        /// </summary>
        public static PropInfo InstantiatePropCopy(PropInfo template)
        {
            if (template == null)
            {
                return(null);
            }

            PropInfo copyInfo = GameObject.Instantiate(template);

            copyInfo.name = template.name;
            copyInfo.gameObject.SetActive(false);

            // Create generated info
            copyInfo.m_generatedInfo            = ScriptableObject.CreateInstance <PropInfoGen>();
            copyInfo.m_generatedInfo.name       = copyInfo.name;
            copyInfo.m_generatedInfo.m_propInfo = copyInfo;
            copyInfo.CalculateGeneratedInfo();

            // Create LOD object
            if (template.m_lodObject != null)
            {
                GameObject copyLod = GameObject.Instantiate(template.m_lodObject);
                copyLod.SetActive(false);
                // Set sharedmaterial
                Renderer lodRenderer = copyLod.GetComponent <Renderer>();
                if (lodRenderer != null)
                {
                    lodRenderer.sharedMaterial = lodRenderer.material;
                }
                copyInfo.m_lodObject = copyLod;
            }

            // Set sharedmaterial
            Renderer r = copyInfo.GetComponent <Renderer>();

            if (r != null)
            {
                r.sharedMaterial = r.material;
            }
            copyInfo.InitializePrefab();
            copyInfo.m_prefabInitialized = true;
            return(copyInfo);
        }