Ejemplo n.º 1
0
        public override void OnPlace()
        {
            base.OnPlace();
            GameObject model = GetModel();

            if (!HasBeenPlaced)
            {
                // If model is correct, apply translation.
                if (model != null)
                {
                    model.transform.localPosition += GetTranslate();
                }
                HasBeenPlaced = true;
            }
            // If model is correct, refresh its SkyApplier.
            if (model != null)
            {
                // Grab model renderers.
                Renderer[] rends = model.GetComponentsInChildren <Renderer>();
                if (rends == null || rends.Length <= 0)
                {
                    rends = model.GetComponents <Renderer>();
                }
                // If model has renderers.
                if (rends != null && rends.Length > 0)
                {
                    // Remove the original SkyApplier.
                    SkyApplier sa = model.GetComponent <SkyApplier>() ?? model.GetComponentInParent <SkyApplier>();
                    if (sa != null)
                    {
                        Object.DestroyImmediate(sa);
                    }
                    // Add the new SkyApplier with dynamic "true" and anchor sky "auto" that will ensure proper rendering (because item can be placed anywhere).
                    sa              = model.AddComponent <SkyApplier>();
                    sa.renderers    = rends;
                    sa.anchorSky    = Skies.Auto;
                    sa.dynamic      = true;
                    sa.updaterIndex = 0; // Updater index set to 0 for quick visual refresh of the model, but this line could be removed safely (last updater index is used by default).
                    sa.enabled      = true;
                    sa.RefreshDirtySky();
                }
            }
        }
Ejemplo n.º 2
0
        public static void FixPlaceToolSkyAppliers(GameObject go)
        {
#if DEBUG_PLACE_TOOL
            Logger.Log("DEBUG: FIX PT-SA: goName=[" + go.name + "]");
#endif
            foreach (KeyValuePair <string, string> placeTool in _placeToolSAFix)
            {
                if (go.name.StartsWith(placeTool.Key, false, CultureInfo.InvariantCulture) || (placeTool.Key == "Battery" && go.GetComponent <Battery>() != null))
                {
                    GameObject model = go.FindChild(placeTool.Value);
                    if (model != null)
                    {
                        SkyApplier[] sas = model.GetComponents <SkyApplier>();
                        if (sas == null || sas.Length != 1)
                        {
                            sas = model.GetComponentsInParent <SkyApplier>();
                        }
                        if (sas != null && sas.Length == 1)
                        {
                            Object.DestroyImmediate(sas[0]); // Prevent accumulation of SkyAppliers
                            SkyApplier sa = model.AddComponent <SkyApplier>();
                            if (sa != null)
                            {
                                sa.anchorSky = Skies.Auto;
                                Renderer[] rends = model.GetAllComponentsInChildren <Renderer>();
                                if (rends == null || rends.Length <= 0)
                                {
                                    rends = model.GetComponents <Renderer>();
                                }
                                sa.renderers    = rends;
                                sa.dynamic      = true;
                                sa.updaterIndex = 0;
                                if (placeTool.Key == "PlasteelIngot" || placeTool.Key == "TitaniumIngot" || placeTool.Key == "CopperWire" || placeTool.Key == "Glass" || placeTool.Key == "EnameledGlass" || placeTool.Key == "SeaTreaderPoop")
                                {
                                    sa.emissiveFromPower = true;
                                }
                                sa.enabled = true;
                                sa.RefreshDirtySky();
                            }
#if DEBUG_PLACE_TOOL
                            else
                            {
                                Logger.Log("DEBUG: FIX PT-SA: SkyApplier 1 do not match! sasLength=[" + (sas != null ? sas.Length.ToString() : "null") + "] goName=[" + go.name + "] modelName=[" + model.name + "]");
                                Logger.PrintTransform(go.transform);
                            }
                        }
                        else
                        {
                            Logger.Log("DEBUG: FIX PT-SA: SkyAppliers 2 do not match! sasLength=[" + (sas != null ? sas.Length.ToString() : "null") + "] goName=[" + go.name + "] modelName=[" + model.name + "]");
                            Logger.PrintTransform(go.transform);
                        }
                    }
                    else
                    {
                        Logger.Log("DEBUG: FIX PT-SA: Could not find model!");
                        Logger.PrintTransform(go.transform);
                    }
#else
                        }
                    }
#endif
                }