private void Register() { if (_prefab != null) { var meshRenderers = _prefab.GetComponentsInChildren <MeshRenderer>(); //========== Allows the building animation and material colors ==========// Shader shader = Shader.Find("MarmosetUBER"); Renderer[] renderers = _prefab.GetComponentsInChildren <Renderer>(true); SkyApplier skyApplier = _prefab.EnsureComponent <SkyApplier>(); skyApplier.renderers = renderers; skyApplier.anchorSky = Skies.Auto; //========== Allows the building animation and material colors ==========// // Add constructible var constructable = _prefab.EnsureComponent <Constructable>(); constructable.allowedOnWall = true; constructable.allowedOnGround = false; constructable.allowedInSub = true; constructable.allowedInBase = true; constructable.allowedOnCeiling = false; constructable.allowedOutside = false; constructable.model = _prefab.FindChild("model"); constructable.techType = TechType; GameObjectHelpers.AddConstructableBounds(_prefab, new Vector3(0.4528692f, 0.6682342f, 0.03642998f), new Vector3(0, -0.02660185f, 0.05301314f)); } }
/// <summary> /// Add all common components to a corner or rotate affordance. /// </summary> internal static void AddComponentsToAffordance(GameObject afford, Bounds bounds, HandlePrefabCollider colliderType, CursorContextInfo.CursorAction cursorType, Vector3 colliderPadding, Transform parent, bool drawTetherWhenManipulating) { if (colliderType == HandlePrefabCollider.Box) { BoxCollider collider = afford.AddComponent <BoxCollider>(); collider.size = bounds.size; collider.center = bounds.center; collider.size += colliderPadding; } else { SphereCollider sphere = afford.AddComponent <SphereCollider>(); sphere.center = bounds.center; sphere.radius = bounds.extents.x; sphere.radius += GetMaxComponent(colliderPadding); } // In order for the affordance to be grabbed using near interaction we need // to add NearInteractionGrabbable; var g = afford.EnsureComponent <NearInteractionGrabbable>(); g.ShowTetherWhenManipulating = drawTetherWhenManipulating; var contextInfo = afford.EnsureComponent <CursorContextInfo>(); contextInfo.CurrentCursorAction = cursorType; contextInfo.ObjectCenter = parent; }
public override GameObject GetGameObject() { //Instantiates a copy of the prefab that is loaded from the AssetBundle loaded above. GameObject _prefab = GameObject.Instantiate(Utils.Helper.Bundle.LoadAsset <GameObject>("DeepEngine_Kit.prefab")); _prefab.name = _ClassID; //Need a tech tag for most prefabs var techTag = _prefab.EnsureComponent <TechTag>(); techTag.type = TechType; _prefab.EnsureComponent <LargeWorldEntity>().cellLevel = LargeWorldEntity.CellLevel.Global; _prefab.EnsureComponent <PrefabIdentifier>().ClassId = _ClassID; _prefab.EnsureComponent <Pickupable>().isPickupable = true; // Add fabricating animation var fabricatingA = _prefab.EnsureComponent <VFXFabricating>(); fabricatingA.localMinY = -0.1f; fabricatingA.localMaxY = 0.6f; fabricatingA.posOffset = new Vector3(0f, 0f, 0f); fabricatingA.eulerOffset = new Vector3(0f, 0f, 0f); fabricatingA.scaleFactor = 0.4f; //Update all shaders ApplySubnauticaShaders(_prefab); return(_prefab); }
private void Standardization_Physics() { Axises: { for (int i = 0; i < 2; i++) { Transform axis = Axises [i]; CircleCollider2D cc2d = axis.gameObject.EnsureComponent <CircleCollider2D> (); cc2d.radius = .5f + chain_unit_height / Radius / 4f; cc2d.usedByEffector = true; Rigidbody2D r2d = axis.gameObject.EnsureComponent <Rigidbody2D> (); r2d.isKinematic = true; SurfaceEffector2D se2d = axis.gameObject.EnsureComponent <SurfaceEffector2D> (); se2d.speed = Speed; } } ChainPhysics: { BoxCollider2D bc2d = ChainPhysics.EnsureComponent <BoxCollider2D> (); bc2d.size = new Vector2(AxisDistance, Radius * 2f + chain_unit_height); ChainPhysics.transform.localPosition = Vector3.zero; ChainPhysics.transform.localScale = Vector3.one; ChainPhysics.transform.right = p0 - p1; bc2d.usedByEffector = true; Rigidbody2D r2d = ChainPhysics.EnsureComponent <Rigidbody2D> (); r2d.isKinematic = true; SurfaceEffector2D se2d = ChainPhysics.EnsureComponent <SurfaceEffector2D> (); se2d.speed = Speed; } }
private void Register() { if (_prefab != null) { var meshRenderers = _prefab.GetComponentsInChildren <MeshRenderer>(); //========== Allows the building animation and material colors ==========// Shader shader = Shader.Find("MarmosetUBER"); Renderer[] renderers = _prefab.GetComponentsInChildren <Renderer>(true); SkyApplier skyApplier = _prefab.EnsureComponent <SkyApplier>(); skyApplier.renderers = renderers; skyApplier.anchorSky = Skies.Auto; //========== Allows the building animation and material colors ==========// // Add constructible var constructable = _prefab.EnsureComponent <Constructable>(); constructable.allowedOnWall = false; constructable.allowedOnGround = true; constructable.allowedInSub = false; constructable.allowedInBase = false; constructable.allowedOnCeiling = false; constructable.allowedOutside = true; constructable.model = _prefab.FindChild("model"); constructable.techType = TechType; constructable.rotationEnabled = true; // Add large world entity ALLOWS YOU TO SAVE ON TERRAIN var lwe = _prefab.AddComponent <LargeWorldEntity>(); lwe.cellLevel = LargeWorldEntity.CellLevel.Global; _prefab.AddComponent <PlayerInteractionManager>(); _prefab.AddComponent <FMOD_CustomLoopingEmitter>(); } }
/// <summary> /// Sets up all of our objects/components, when we are ready to actually display text for the first time. /// </summary> private void InitializeText() { // Make our own text object TextObject = new GameObject("BasicText" + (++index)); TextFade = TextObject.EnsureComponent <uGUI_TextFade>(); // The uGUI's helpful automatic fade component TextText = TextFade?.text ?? TextObject.EnsureComponent <Text>(); // The text itself // This makes the text box fit the text (rather than the other way around) TextFitter = TextObject.EnsureComponent <ContentSizeFitter>(); TextFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; TextFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize; // This clones the in game "Press Any Button To Begin" message's font size, style, etc. TextText.font = CloneFont ? uGUI.main.intro.mainText.text.font : Font; TextText.fontSize = CloneSize ? uGUI.main.intro.mainText.text.fontSize : Size; TextText.fontStyle = CloneStyle ? uGUI.main.intro.mainText.text.fontStyle : Style; #if SUBNAUTICA TextText.alignment = CloneAlign ? uGUI.main.intro.mainText.text.alignment : Align; #elif BELOWZERO TextText.alignment = CloneAlign ? uGUI.main.intro.mainText.text.alignment : Convert(Align); #endif TextText.color = CloneColor ? uGUI.main.intro.mainText.text.color : Color; TextText.material = CloneMaterial ? uGUI.main.intro.mainText.text.material : Material; // Sets it to SN's highest layer -- note it will not appear on top of the black "you are dead" overlay. To do that // requires setting it HIGHER than uGUI.main.overlays.overlays[0].graphic -- which will make SN throw a sloppy exception // in the log, but will WORK. TextObject.transform.SetParent(uGUI.main.screenCanvas.transform, false); // Parents our text to the black overlay TextText.canvas.overrideSorting = true; // Turn on canvas sort override so the layers will work TextObject.layer = 31; // Set to what seems to be Subnautica's highest layer }
public GameObject Add(string textureName, Func<bool> isEnabled = null, Action onClick = null) { GameObject go = new GameObject(); UITexture buttonTexture = go.EnsureComponent<UITexture>(); if (onClick != null) { DaemonButton button = go.EnsureComponent<DaemonButton>(); UIButton buttonUI = go.EnsureComponent<UIButton>(); buttonUI.disabledColor = disabledColor; BoxCollider buttonBoxCollider = go.EnsureComponent<BoxCollider>(); if (isEnabled != null) { go.EnsureComponent<IsEnabled>().Predicate = isEnabled; bool enabled = isEnabled(); buttonUI.isEnabled = enabled; //buttonBoxCollider.enabled = enabled; } buttonBoxCollider.isTrigger = true; buttonTexture.ResizeCollider(); button.click += onClick; } buttonTexture.mainTexture = Resources.Load<Texture2D>("Textures/" + textureName); buttonTexture.autoResizeBoxCollider = true; buttonTexture.depth = 10; _gameObjects.Add(go); return go; }
public override GameObject GetGameObject() { GameObject prefab = null; try { prefab = GameObject.Instantiate <GameObject>(_prefab); prefab.name = this.PrefabFileName; PrefabIdentifier prefabID = prefab.EnsureComponent <PrefabIdentifier>(); prefabID.ClassId = this.ClassID; prefab.AddComponent <AnimationManager>(); prefab.AddComponent <OxStationScreenController>(); var techTag = prefab.EnsureComponent <TechTag>(); techTag.type = TechType; } catch (Exception e) { QuickLogger.Error(e.Message); } return(prefab); }
/// <summary> /// Create a prefab instance in the scene, in reaction to data being added to the data model. /// </summary> /// <param name="dataModel">Object to spawn's data model.</param> /// <param name="prefabToInstantiate">Prefab to instantiate.</param> /// <param name="parentObject">Parent object under which the prefab should be.</param> /// <param name="objectName">Name of the object.</param> /// <returns></returns> protected virtual GameObject CreatePrefabInstance(SyncSpawnedObject dataModel, GameObject prefabToInstantiate, GameObject parentObject, string objectName) { GameObject instance = Instantiate(prefabToInstantiate, dataModel.Transform.Position.Value, dataModel.Transform.Rotation.Value); instance.transform.localScale = dataModel.Transform.Scale.Value; instance.transform.SetParent(parentObject.transform, false); instance.gameObject.name = objectName; dataModel.GameObject = instance; // Set the data model on the various ISyncModelAccessor components of the spawned game obejct ISyncModelAccessor[] syncModelAccessors = instance.GetComponentsInChildren <ISyncModelAccessor>(true); if (syncModelAccessors.Length <= 0) { // If no ISyncModelAccessor component exists, create a default one that gives access to the SyncObject instance ISyncModelAccessor defaultAccessor = instance.EnsureComponent <DefaultSyncModelAccessor>(); defaultAccessor.SetSyncModel(dataModel); } for (int i = 0; i < syncModelAccessors.Length; i++) { syncModelAccessors[i].SetSyncModel(dataModel); } // Setup the transform synchronization TransformSynchronizer transformSynchronizer = instance.EnsureComponent <TransformSynchronizer>(); transformSynchronizer.TransformDataModel = dataModel.Transform; return(instance); }
public override GameObject GetGameObject() { GameObject prefab = null; try { prefab = GameObject.Instantiate(_prefab); var container2 = GameObject.Instantiate(CreateStorage()); container2.name = "StorageContainerUnit"; container2.transform.parent = prefab.transform; //========== Allows the building animation and material colors ==========// Shader shader = Shader.Find("MarmosetUBER"); Renderer[] renderers = prefab.GetComponentsInChildren <Renderer>(); SkyApplier skyApplier = prefab.EnsureComponent <SkyApplier>(); skyApplier.renderers = renderers; skyApplier.anchorSky = Skies.Auto; //========== Allows the building animation and material colors ==========// // Add constructible var constructable = prefab.EnsureComponent <Constructable>(); constructable.allowedOnWall = false; constructable.allowedOnGround = true; constructable.allowedInSub = false; constructable.allowedInBase = false; constructable.allowedOnCeiling = false; constructable.allowedOutside = true; constructable.model = prefab.FindChild("model"); constructable.techType = TechType; constructable.rotationEnabled = true; constructable.allowedOnConstructables = Player.main.GetDepth() > 1; // Add large world entity ALLOWS YOU TO SAVE ON TERRAIN var lwe = prefab.AddComponent <LargeWorldEntity>(); lwe.cellLevel = LargeWorldEntity.CellLevel.Global; //var beacon = prefab.AddComponent<Beacon>(); //beacon.label = "DeepDriller"; var center = new Vector3(0f, 1.579518f, 0f); var size = new Vector3(2.669801f, 2.776958f, 2.464836f); GameObjectHelpers.AddConstructableBounds(prefab, size, center); //prefab.AddComponent<MonoClassTest>(); prefab.AddComponent <PrefabIdentifier>().ClassId = this.ClassID; prefab.AddComponent <FMOD_CustomLoopingEmitter>(); prefab.AddComponent <ExStorageDepotController>(); } catch (Exception e) { QuickLogger.Error(e.Message); } return(prefab); }
public override GameObject GetGameObject() { GameObject prefab = null; try { prefab = GameObject.Instantiate(_prefab); var meshRenderers = prefab.GetComponentsInChildren <MeshRenderer>(); //========== Allows the building animation and material colors ==========// Shader shader = Shader.Find("MarmosetUBER"); Renderer[] renderers = prefab.GetComponentsInChildren <Renderer>(); SkyApplier skyApplier = prefab.EnsureComponent <SkyApplier>(); skyApplier.renderers = renderers; skyApplier.anchorSky = Skies.Auto; //========== Allows the building animation and material colors ==========// // Add constructible var constructable = prefab.EnsureComponent <Constructable>(); constructable.allowedOnWall = false; constructable.allowedOnGround = true; constructable.allowedInSub = false; constructable.allowedInBase = false; constructable.allowedOnCeiling = false; constructable.allowedOutside = true; constructable.model = prefab.FindChild("model"); constructable.techType = TechType; constructable.rotationEnabled = true; // Add large world entity ALLOWS YOU TO SAVE ON TERRAIN var lwe = prefab.AddComponent <LargeWorldEntity>(); lwe.cellLevel = LargeWorldEntity.CellLevel.Global; //var beacon = prefab.AddComponent<Beacon>(); var center = new Vector3(0, 3.048428f, 0); var size = new Vector3(4.821606f, 3.35228f, 4.941598f); GameObjectHelpers.AddConstructableBounds(prefab, size, center); //beacon.label = "DeepDriller"; //prefab.AddComponent<LiveMixin>(); prefab.AddComponent <PrefabIdentifier>().ClassId = this.ClassID; prefab.AddComponent <FMOD_CustomLoopingEmitter>(); prefab.AddComponent <FCSDeepDrillerController>(); } catch (Exception e) { QuickLogger.Error(e.Message); } return(prefab); }
private void Awake() { RadiationTrigger = new GameObject("RadiationTrigger"); RadiationTrigger.transform.SetParent(transform, false); playerDistanceTracker = RadiationTrigger.EnsureComponent <PlayerDistanceTracker>(); radiatePlayerInRange = RadiationTrigger.EnsureComponent <RadiatePlayerInRange>(); damagePlayerInRadius = RadiationTrigger.EnsureComponent <DamagePlayerInRadius>(); }
public override IEnumerator GetGameObjectAsync(IOut<GameObject> gameObject) { CoroutineTask<GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.SmallLocker); yield return task; var smallLockerPrefab = task.GetResult(); GameObject prefab = GameObject.Instantiate(smallLockerPrefab); var storageAccess = prefab.EnsureComponent<VehicleStorageAccess>(); storageAccess.textPrefab = GameObject.Instantiate(smallLockerPrefab.GetComponentInChildren<TextMeshProUGUI>()); #endif var container = prefab.EnsureComponent<StorageContainer>(); container.width = Mod.config.LockerWidth; container.height = Mod.config.LockerHeight; container.container.Resize(Mod.config.LockerWidth, Mod.config.LockerHeight); var meshRenderers = prefab.GetComponentsInChildren<MeshRenderer>(); foreach (var meshRenderer in meshRenderers) { meshRenderer.material.color = new Color(0, 0, 1); } var label = prefab.FindChild("Label"); DestroyImmediate(label); var canvas = LockerPrefabShared.CreateCanvas(prefab.transform); storageAccess.background = LockerPrefabShared.CreateBackground(canvas.transform); storageAccess.icon = LockerPrefabShared.CreateIcon(storageAccess.background.transform, PrimaryColor, 15); storageAccess.text = LockerPrefabShared.CreateText(storageAccess.background.transform, storageAccess.textPrefab, PrimaryColor, -40, 10, ""); storageAccess.seamothIcon = LockerPrefabShared.CreateIcon(storageAccess.background.transform, PrimaryColor, 80); storageAccess.seamothCountText = LockerPrefabShared.CreateText(storageAccess.background.transform, storageAccess.textPrefab, PrimaryColor, 55, 10, "none"); storageAccess.exosuitIcon = LockerPrefabShared.CreateIcon(storageAccess.background.transform, PrimaryColor, 80); storageAccess.exosuitCountText = LockerPrefabShared.CreateText(storageAccess.background.transform, storageAccess.textPrefab, PrimaryColor, 55, 10, "none"); storageAccess.seamothIcon.rectTransform.anchoredPosition += new Vector2(-23, 0); storageAccess.seamothCountText.rectTransform.anchoredPosition += new Vector2(-23, 0); storageAccess.exosuitIcon.rectTransform.anchoredPosition += new Vector2(23, 0); storageAccess.exosuitCountText.rectTransform.anchoredPosition += new Vector2(23, 0); if (Mod.config.UseAutosortMod) { storageAccess.autosortCheckbox = CheckboxButton.CreateCheckbox(storageAccess.background.transform, PrimaryColor, storageAccess.textPrefab, "Autosort"); storageAccess.autosortCheckbox.transform.localPosition = new Vector3(0, -104 + 19); } storageAccess.enableCheckbox = CheckboxButton.CreateCheckbox(storageAccess.background.transform, PrimaryColor, storageAccess.textPrefab, "Enabled"); storageAccess.enableCheckbox.transform.localPosition = new Vector3(0, -104); storageAccess.background.gameObject.SetActive(false); #if SN1 return prefab; #elif BZ gameObject.Set(prefab); #endif }
public override GameObject GetGameObject() { GameObject prefab = null; try { prefab = GameObject.Instantiate <GameObject>(_prefab); //========== Allows the building animation and material colors ==========// SkyApplier skyApplier = prefab.EnsureComponent <SkyApplier>(); skyApplier.renderers = prefab.GetComponentsInChildren <Renderer>(); skyApplier.anchorSky = Skies.Auto; //========== Allows the building animation and material colors ==========// // Add constructible var constructable = prefab.EnsureComponent <Constructable>(); constructable.allowedOnWall = false; constructable.allowedOnGround = true; constructable.allowedInSub = false; constructable.allowedInBase = false; constructable.allowedOnCeiling = false; constructable.allowedOutside = true; constructable.model = prefab.FindChild("model"); constructable.techType = TechType; constructable.rotationEnabled = true; constructable.forceUpright = true; constructable.placeDefaultDistance = 10f; // Add large world entity ALLOWS YOU TO SAVE ON TERRAIN var lwe = prefab.AddComponent <LargeWorldEntity>(); lwe.cellLevel = LargeWorldEntity.CellLevel.Global; //var beacon = prefab.AddComponent<Beacon>(); var center = new Vector3(0, 3.106274f, 0); var size = new Vector3(6.85554f, 6.670462f, 7.002856f); GameObjectHelpers.AddConstructableBounds(prefab, size, center); //beacon.label = "DeepDriller"; //prefab.AddComponent<LiveMixin>(); prefab.AddComponent <PrefabIdentifier>().ClassId = this.ClassID; prefab.AddComponent <TechTag>().type = TechTypeID; prefab.AddComponent <FMOD_CustomLoopingEmitter>(); prefab.AddComponent <FCSDeepDrillerController>(); } catch (Exception e) { QuickLogger.Error(e.Message); } return(prefab); }
public override IEnumerator GetGameObjectAsync(IOut <GameObject> gameObject) { if (processedPrefab == null) { CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.SeaglideFragment); yield return(task); GameObject prefab = GameObject.Instantiate(task.GetResult()); MeshRenderer[] meshRenderers = prefab.GetAllComponentsInChildren <MeshRenderer>(); SkinnedMeshRenderer[] skinnedMeshRenderers = prefab.GetAllComponentsInChildren <SkinnedMeshRenderer>(); Color powerGlideColour = new Color(PowerglideEquipable.PowerglideColourR, PowerglideEquipable.PowerglideColourG, PowerglideEquipable.PowerglideColourB); foreach (MeshRenderer mr in meshRenderers) { // MeshRenderers have the third-person mesh, apparently? if (mr.name.Contains("SeaGlide_01_damaged")) { mr.material.color = powerGlideColour; } } foreach (SkinnedMeshRenderer smr in skinnedMeshRenderers) { if (smr.name.Contains("SeaGlide_geo")) { smr.material.color = powerGlideColour; } } PrefabIdentifier prefabIdentifier = prefab.GetComponent <PrefabIdentifier>(); prefabIdentifier.ClassId = this.ClassID; prefab.GetComponent <LargeWorldEntity>().cellLevel = LargeWorldEntity.CellLevel.VeryFar; prefab.EnsureComponent <TechTag>().type = this.TechType; Pickupable pickupable = prefab.GetComponent <Pickupable>(); pickupable.isPickupable = false; ResourceTracker resourceTracker = prefab.EnsureComponent <ResourceTracker>(); resourceTracker.prefabIdentifier = prefabIdentifier; typeof(ResourceTracker).GetField("techType", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(resourceTracker, this.TechType); //resourceTracker.techType = this.TechType; resourceTracker.overrideTechType = TechType.Fragment; resourceTracker.rb = prefab.GetComponent <Rigidbody>(); resourceTracker.pickupable = pickupable; prefab.SetActive(true); processedPrefab = prefab; ModPrefabCache.AddPrefab(processedPrefab, false); // This doesn't actually do any caching, but it does disable the prefab without "disabling" it - the prefab doesn't show up in the world [as with SetActive(false)] // but it can still be instantiated. [unlike with SetActive(false)] } gameObject.Set(processedPrefab); }
internal void Register() { HydroponicHarvestersModelPrefab.GetPrefabs(); _prefab = HydroponicHarvestersModelPrefab.BottlePrefab; if (_prefab == null) { QuickLogger.Error("FloraKleen prefab is null"); return; } GameObjectHelpers.AddConstructableBounds(_prefab, new Vector3(0.1969692f, 0.25098f, 0.1916926f), new Vector3(0, -0.01675579f, 0)); QuickLogger.Debug("Added Constructable Bounds"); //Make the rigid body isKinematic so it doesnt shake the cyclops var rb = _prefab.AddComponent <Rigidbody>(); rb.isKinematic = true; QuickLogger.Debug("Added Rigid Body"); // Make the object drop slowly in water var wf = _prefab.EnsureComponent <WorldForces>(); wf.underwaterGravity = 0; wf.underwaterDrag = 10f; wf.enabled = true; QuickLogger.Debug("Ensuring World Forces"); // Add fabricating animation var fabricatingA = _prefab.EnsureComponent <VFXFabricating>(); fabricatingA.localMinY = -0.1f; fabricatingA.localMaxY = 0.6f; fabricatingA.posOffset = new Vector3(0f, 0f, 0f); fabricatingA.eulerOffset = new Vector3(0f, 0f, 0f); fabricatingA.scaleFactor = 1.0f; QuickLogger.Debug("Ensuring VFXFabricating"); //// Set proper shaders (for crafting animation) var renderer = _prefab.GetComponentInChildren <Renderer>(); QuickLogger.Debug("Getting Renderer"); // Update sky applier var applier = _prefab.EnsureComponent <SkyApplier>(); applier.renderers = new Renderer[] { renderer }; applier.anchorSky = Skies.Auto; QuickLogger.Debug("Ensuring SkyApplier"); }
public override GameObject GetGameObject() { GameObject obj = new GameObject("SharkBattery"); Battery batt = obj.EnsureComponent <Battery>(); batt._capacity = 1000f; obj.EnsureComponent <Pickupable>(); obj.EnsureComponent <TechTag>().type = TechType; return(obj); }
public override GameObject GetGameObject() { //Instantiates a copy of the prefab that is loaded from the AssetBundle loaded above. GameObject _prefab = GameObject.Instantiate(Utils.Helper.Bundle.LoadAsset <GameObject>("DeepEngine.prefab")); _prefab.name = Constant.ClassID; //Need a tech tag for most prefabs var techTag = _prefab.AddComponent <TechTag>(); techTag.type = TechType; _prefab.EnsureComponent <LargeWorldEntity>().cellLevel = LargeWorldEntity.CellLevel.Global; _prefab.EnsureComponent <PrefabIdentifier>().ClassId = ClassID; //Collider for the turbine pole and builder tool var collider = _prefab.AddComponent <BoxCollider>(); collider.center = new Vector3(-0.1f, 1.2f, 00f); collider.size = new Vector3(3f, 2.35f, 2f); //Update all shaders ApplySubnauticaShaders(_prefab); // Add constructable - This prefab normally isn't constructed. Constructable constructible = _prefab.AddComponent <Constructable>(); constructible.constructedAmount = 1; constructible.allowedInBase = false; constructible.allowedInSub = false; constructible.allowedOutside = true; constructible.allowedOnCeiling = false; constructible.allowedOnGround = true; constructible.allowedOnWall = false; constructible.allowedOnConstructables = false; constructible.techType = this.TechType; constructible.rotationEnabled = true; constructible.placeDefaultDistance = 6f; constructible.placeMinDistance = 0.5f; constructible.placeMaxDistance = 15f; constructible.surfaceType = VFXSurfaceTypes.metal; constructible.model = _prefab.transform.GetChild(0).gameObject; constructible.forceUpright = true; var deepEngineAnim = _prefab.AddComponent <DeepEngineAnim>(); var deepEngineAction = _prefab.AddComponent <DeepEngineAction>(); return(_prefab); }
public override GameObject GetGameObject() { GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cylinder); obj.transform.localScale = Vector3.one * 0.1f; var wf = obj.EnsureComponent <WorldForces>(); wf.useRigidbody = obj.EnsureComponent <Rigidbody>(); wf.useRigidbody.useGravity = false; obj.EnsureComponent <TechTag>().type = TechType; obj.EnsureComponent <Pickupable>(); return(obj); }
/// <summary> /// Bind a Unity Collision event to a ViewModel command. /// </summary> /// <param name="t">The view that owns the binding</param> /// <param name="eventType">The collision event to bind to.</param> /// <returns>The collision binding class that allows chaining extra options.</returns> public static IObservable <Collision> OnCollisionObservable(this GameObject t, CollisionEventType eventType) { if (eventType == CollisionEventType.Enter) { return(t.EnsureComponent <ObservableCollisionEnterBehaviour>().OnCollisionEnterAsObservable()); } else if (eventType == CollisionEventType.Exit) { return(t.EnsureComponent <ObservableCollisionExitBehaviour>().OnCollisionExitAsObservable()); } else { return(t.EnsureComponent <ObservableCollisionStayBehaviour>().OnCollisionStayAsObservable()); } }
/// <summary> /// Bind a Unity Collision event to a ViewModel command. /// </summary> /// <param name="t">The view that owns the binding</param> /// <param name="eventType">The collision event to bind to.</param> /// <returns>The collision binding class that allows chaining extra options.</returns> public static IObservable <Collider2D> OnTrigger2DObservable(this GameObject t, CollisionEventType eventType) { if (eventType == CollisionEventType.Enter) { return(t.EnsureComponent <ObservableTriggerEnter2DBehaviour>().OnTriggerEnter2DAsObservable()); } else if (eventType == CollisionEventType.Exit) { return(t.EnsureComponent <ObservableTriggerExit2DBehaviour>().OnTriggerExit2DAsObservable()); } else { return(t.EnsureComponent <ObservableTriggerStay2DBehaviour>().OnTriggerStay2DAsObservable()); } }
/// <summary> /// This game uses its own shader system and as such the shaders from UnityEditor do not work and will leave you with a black object unless in direct sunlight. /// Note: When copying prefabs from the game itself this is already setup and is only needed when importing new prefabs to the game. /// </summary> /// <param name="gameObject"></param> private static void ApplySubnauticaShaders(GameObject gameObject) { Shader shader = Shader.Find("MarmosetUBER"); List <Renderer> Renderers = gameObject.GetComponentsInChildren <Renderer>().ToList(); foreach (Renderer renderer in Renderers) { foreach (Material material in renderer.materials) { //get the old emission before overwriting the shader Texture emissionTexture = material.GetTexture("_EmissionMap"); //overwrites your prefabs shader with the shader system from the game. material.shader = shader; //These enable the item to emit a glow of its own using Subnauticas shader system. material.EnableKeyword("MARMO_EMISSION"); material.SetFloat(ShaderPropertyID._EnableGlow, 1f); material.SetTexture(ShaderPropertyID._Illum, emissionTexture); material.SetColor(ShaderPropertyID._GlowColor, new Color(1f, 1f, 1f, 1f)); } } //This applies the games sky lighting to the object when in the game but also only really works combined with the above code as well. SkyApplier skyApplier = gameObject.EnsureComponent <SkyApplier>(); skyApplier.renderers = Renderers.ToArray(); skyApplier.anchorSky = Skies.Auto; }
public void Rescan() { foreach (Collider collider in baseGameObject.GetComponents <Collider>()) { int cInstanceID = collider.GetInstanceID(); if (!ColliderBases.Keys.Contains(cInstanceID)) { GameObject childContainer = new GameObject($"childContainer_{childCount}"); childContainer.transform.SetParent(transform, false); childContainer.transform.localPosition = Vector3.zero; childContainer.transform.localRotation = Quaternion.identity; var dcb = childContainer.EnsureComponent <DrawColliderBounds>(); dcb.cInstanceID = cInstanceID; dcb.collider = collider; collider.SetColliderInfo(ref dcb.colliderInfo); dcb.Init(); ColliderBases.Add(cInstanceID, new ColliderDraw() { Container = childContainer, ColliderBase = new ColliderInfo(collider), DCB = dcb }); Main.Instance.OutputWindow_Log($"Collider drawing instance added to this [ID: {cInstanceID}] collider. Type: {dcb.colliderInfo.ColliderType}"); childCount++; } } }
public void Awake() { baseGameObject = GetComponentInParent <DrawObjectBounds>().transform.parent.gameObject; pointer = gameObject.CreatePointerLine(PointerType.Collider); foreach (Collider collider in baseGameObject.GetComponents <Collider>()) { int cInstanceID = collider.GetInstanceID(); GameObject childContainer = new GameObject($"childContainer_{childCount}"); childContainer.transform.SetParent(transform, false); childContainer.transform.localPosition = Vector3.zero; childContainer.transform.localRotation = Quaternion.identity; var dcb = childContainer.EnsureComponent <DrawColliderBounds>(); dcb.cInstanceID = cInstanceID; dcb.collider = collider; collider.SetColliderInfo(ref dcb.colliderInfo); dcb.Init(); ColliderBases.Add(cInstanceID, new ColliderDraw() { Container = childContainer, ColliderBase = new ColliderInfo(collider), DCB = dcb }); Main.Instance.OutputWindow_Log($"Collider drawing instance added to this gameobject: [{baseGameObject.name}], collider ID:[{cInstanceID}], Type: [{dcb.colliderInfo.ColliderType}]"); childCount++; } }
private void Awake() { Transform parent = transform.parent; transformBase = new TransformInfo(parent); if (parent.GetType().Equals(typeof(RectTransform))) { gameObject.CreateLineContainers(ref lineContainers, ContainerType.Rectangle, 0.008f, Color.green, false); lineContainers.DrawRectangle((RectTransform)parent); } else { gameObject.CreateLineContainers(ref lineContainers, ContainerType.Box, 0.008f, Color.green, false); Vector3 newSize = LineHelper.CompensateSizefromScale(new Vector3(0.6f, 0.6f, 0.6f), transform.parent.localScale); lineContainers.DrawBox(Vector3.zero, newSize); } gameObject.CreatePointerLine(PointerType.Object); Main.AllVisuals.Add(gameObject); if (gameObject.GetComponentInParent <Collider>() != null) { GameObject colliderContainerBase = gameObject.GetOrAddVisualBase(BaseType.Collider); colliderContainerBase.EnsureComponent <DrawColliderControl>(); } }
protected virtual void OnValidate() { ValidateHeirarchy(); label.EnsureComponent <TextMeshPro>(); gameObject.EnsureComponent <ToolTipConnector>(); }
private static IEnumerator SpawnCreature(WaterPark waterPark, WaterParkCreature parkCreature, ItemsContainer container) { CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(parkCreature.pickupable.GetTechType(), false); yield return(task); GameObject prefab = task.GetResult(); prefab.SetActive(false); GameObject gameObject = GameObject.Instantiate(prefab); Pickupable pickupable = gameObject.EnsureComponent <Pickupable>(); #if SUBNAUTICA_EXP TaskResult <Pickupable> taskResult = new TaskResult <Pickupable>(); yield return(pickupable.PickupAsync(taskResult, false)); pickupable = taskResult.Get(); #else pickupable.Pickup(false); #endif container.AddItem(pickupable); yield break; }
/// <summary> /// Util method for drawing a consistent constraints section. /// Use this method in a component inspector for linking to a constraint manager. /// </summary> /// <param name="gameObject">Game object the constraint manager is attached to.</param> /// <param name="managerEnabled">Serialized property for enabling the manager - needs to be of type bool.</param> /// <param name="managerRef">Serialized property of the constraint manager component link - needs to be type of ConstraintManager.</param> /// <param name="isExpanded">Flag for indicating if the constraint foldout was previously collapsed or expanded.</param> /// <returns>Current state of expanded or collapsed constraint foldout. Returns true if expanded / contents visible.</returns> static public bool DrawConstraintManagerFoldout(GameObject gameObject, SerializedProperty managerEnabled, SerializedProperty managerRef, bool isExpanded) { isExpanded = EditorGUILayout.Foldout(isExpanded, "Constraints", true); if (isExpanded) { EditorGUILayout.PropertyField(managerEnabled); GUI.enabled = managerEnabled.boolValue; // Make sure we're having at least one constraint manager available. // Usually this should be ensured by the component requirement. However // for components that had this requirement added after they were serialized // this won't work out of the box. gameObject.EnsureComponent <ConstraintManager>(); var constraintManagers = gameObject.GetComponents <ConstraintManager>(); int selected = 0; string[] options = new string[constraintManagers.Length]; int manualSelectionCount = 0; for (int i = 0; i < constraintManagers.Length; ++i) { var manager = constraintManagers[i]; if (managerRef.objectReferenceValue == manager) { selected = i; } // popups will only show unique elements // in case of auto selection we don't care which one we're selecting as the behavior will be the same. // in case of manual selection users might want to differentiate which constraintmanager they are referring to. if (manager.AutoConstraintSelection == true) { options[i] = manager.GetType().Name + " (auto)"; } else { manualSelectionCount++; options[i] = manager.GetType().Name + " (manual " + manualSelectionCount + ")"; } } using (new EditorGUILayout.HorizontalScope()) { selected = EditorGUILayout.Popup("Constraint Manager", selected, options, GUILayout.ExpandWidth(true)); ConstraintManager selectedConstraintManager = constraintManagers[selected]; managerRef.objectReferenceValue = selectedConstraintManager; if (GUILayout.Button("Go to component")) { EditorGUIUtility.PingObject(selectedConstraintManager); Highlighter.Highlight("Inspector", $"ComponentId: {selectedConstraintManager.GetInstanceID()}"); EditorGUIUtility.ExitGUI(); } } GUI.enabled = true; } return(isExpanded); }
protected virtual void Start() { // Make sure we have all the components in the scene we need. if (WorldAnchorManager.Instance == null) { Debug.LogError("This script expects that you have a WorldAnchorManager component in your scene."); } if (WorldAnchorManager.Instance != null) { // If we are not starting out with actively placing the object, give it a World Anchor if (!IsBeingPlaced) { WorldAnchorManager.Instance.AttachAnchor(gameObject, SavedAnchorFriendlyName); } } DetermineParent(); interpolator = PlaceParentOnTap ? ParentGameObjectToPlace.EnsureComponent <Interpolator>() : gameObject.EnsureComponent <Interpolator>(); if (IsBeingPlaced) { HandlePlacement(); } }
private static IEnumerator AddItemToAlterraGen(TechType parkCreatureTechType, IFCSStorage container) { CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(parkCreatureTechType, false); yield return(task); GameObject prefab = task.GetResult(); prefab.SetActive(false); while (!container.CanBeStored(1, parkCreatureTechType)) { yield return(new WaitForSecondsRealtime(1)); } GameObject gameObject = GameObject.Instantiate(prefab); Pickupable pickupable = gameObject.EnsureComponent <Pickupable>(); #if SUBNAUTICA_EXP TaskResult <Pickupable> taskResult = new TaskResult <Pickupable>(); yield return(pickupable.PickupAsync(taskResult, false)); pickupable = taskResult.Get(); #else pickupable.Pickup(false); #endif container.AddItemToContainer(new InventoryItem(pickupable)); yield break; }
/// <inheritdoc /> public void ApplyEffect(GameObject soundEmittingObject) { if (!isActiveAndEnabled) { return; } AudioSource audioSource = soundEmittingObject.GetComponent <AudioSource>(); if (audioSource == null) { Debug.LogWarning("The specified emitter does not have an attached AudioSource component."); return; } // Audio occlusion is performed using a low pass filter. AudioLowPassFilter lowPass = soundEmittingObject.EnsureComponent <AudioLowPassFilter>(); lowPass.enabled = true; // In the real world, chaining multiple low-pass filters will result in the // lowest of the cutoff frequencies being the highest pitches heard. lowPass.cutoffFrequency = Mathf.Min(lowPass.cutoffFrequency, CutoffFrequency); // Unlike the cutoff frequency, volume pass-through is cumulative. audioSource.volume *= VolumePassThrough; }
// Use this for initialization void Start() { cube = GameObject.CreatePrimitive(PrimitiveType.Cube); cube.transform.parent = this.gameObject.transform; cube.transform.localPosition = new Vector3(0, 3f, 0); cube.transform.localScale = new Vector3(1, .25f, 0f); cube.RemoveComponent<BoxCollider>(); cube.GetComponent<MeshRenderer>().material.color = new Color(.6f, 0f, 0f, .5f); cube.GetComponent<MeshRenderer>().material.shader = Shader.Find("Transparent/Cutout/Soft Edge Unlit"); cube.transform.localRotation = new Quaternion(); cube.EnsureComponent<LookAtCamera>(); }
// Use this for initialization void Start() { this.transform.rotation = Random.rotation; if (Target == null) Target = GameObject.FindGameObjectWithTag("Player"); TargetRotationHelper = new GameObject("RotationHelper"); TargetRotationHelper.transform.parent = this.transform; TargetRotationHelper.EnsureComponent<lookatPlayer>(); //this.EnsureComponent<ImpactDamage>().Damage = Damage; this.EnsureComponent<Rigidbody>(); rigidbody.useGravity = false; }
void Start() { GameObject outline = new GameObject(); outline.transform.parent = this.gameObject.transform; outline.transform.localPosition = Vector3.zero; outline.name = Name; _sprite = outline.EnsureComponent<UISprite>(); _sprite.atlas = Resources.Load<GameObject>("GUI/Atlas").GetComponent<UIAtlas>(); _sprite.spriteName = "Radiance"; _sprite.type = UISprite.Type.Filled; _sprite.fillDirection = UISprite.FillDirection.Radial360; _sprite.invert = Clockwise; _sprite.transform.localScale = new Vector3(1, 1, 1); _sprite.width = Diameter; _sprite.height = Diameter; _sprite.depth = Depth; _sprite.color = Color; _totalPerimeterPercentage = (DegreeEnd - DegreeStart) / 360f; }