public void GetReferences() { m_Renderer = GetComponent <MeshRenderer>(); m_Filter = GetComponent <MeshFilter>(); m_BoxCollider = GetComponent <BoxCollider2D>(); m_BuoyancyEffector = GetComponent <BuoyancyEffector2D>(); }
/// <summary> /// Membuat Collider /// </summary> private void AddCollider() { BoxCollider2D bCol = gameObject.AddComponent <BoxCollider2D>(); BuoyancyEffector2D bEffector = gameObject.AddComponent <BuoyancyEffector2D>(); List <Vector2> v = new List <Vector2>(); switch (meshType) { case MeshType.StreamDown: bCol.offset = new Vector2(2.25f, -1f); bCol.size = new Vector2(4.5f, 2f); bCol.isTrigger = true; bCol.usedByEffector = true; bEffector.flowMagnitude = 15; //mengambil semua titik vektor bagian atas dari array vertices v = GetTopVertices(41, 0.1f); v.Add(vertices[vertices.Count - 2]); //menempatkan sudut colliders sesuai dengan titik vektor dari array vertices EdgeCollider2D col = gameObject.AddComponent <EdgeCollider2D>(); col.points = v.ToArray(); break; case MeshType.Flat: bCol.isTrigger = true; bCol.usedByEffector = true; bEffector.flowMagnitude = 10; break; } }
public void GetReferences() { m_Renderer = GetComponent <MeshRenderer>(); m_Filter = GetComponent <MeshFilter>(); m_BoxCollider = GetComponent <BoxCollider2D>(); m_Bubbles = transform.Find("Bubbles").GetComponent <ParticleSystem>(); m_Steam = transform.Find("Steam").GetComponent <ParticleSystem>(); m_BuoyancyEffector = GetComponent <BuoyancyEffector2D>(); }
public void OnSceneGUI() { BuoyancyEffector2D buoyancyEffector2D = (BuoyancyEffector2D)this.target; if (!buoyancyEffector2D.enabled) { return; } float y = buoyancyEffector2D.transform.position.y + buoyancyEffector2D.transform.lossyScale.y * buoyancyEffector2D.surfaceLevel; List <Vector3> list = new List <Vector3>(); float num = float.NegativeInfinity; float num2 = num; foreach (Collider2D current in from c in buoyancyEffector2D.gameObject.GetComponents <Collider2D>() where c.enabled && c.usedByEffector select c) { Bounds bounds = current.bounds; float x = bounds.min.x; float x2 = bounds.max.x; if (float.IsNegativeInfinity(num)) { num = x; num2 = x2; } else { if (x < num) { num = x; } if (x2 > num2) { num2 = x2; } } Vector3 item = new Vector3(x, y, 0f); Vector3 item2 = new Vector3(x2, y, 0f); list.Add(item); list.Add(item2); } Handles.color = Color.red; Handles.DrawAAPolyLine(new Vector3[] { new Vector3(num, y, 0f), new Vector3(num2, y, 0f) }); Handles.color = Color.cyan; for (int i = 0; i < list.Count - 1; i += 2) { Handles.DrawAAPolyLine(new Vector3[] { list[i], list[i + 1] }); } }
// Use this for initialization void Start() { speechObj = GameObject.Find("SpeechRecognition"); speech = speechObj.GetComponent <SpeechRecognition01>(); waterEffect = water.GetComponent <WaterFX>(); waterBounce = waterline.GetComponent <BuoyancyEffector2D>(); stormStarted = false; }
private void activateGeyser(BuoyancyEffector2D buoy) { // height limit float limit = buoy.GetComponent <GeyserBehaviour>().limit; // increase density/buoyancy buoy.density = 5f; geyserCoroutine = buoy.GetComponent <GeyserBehaviour>().BuildGeyser(targetPosition, 0.025f); StartCoroutine(geyserCoroutine); }
public void OnSceneGUI() { BuoyancyEffector2D target = (BuoyancyEffector2D)this.target; if (target.enabled) { float y = target.transform.position.y + (target.transform.lossyScale.y * target.surfaceLevel); List <Vector3> list = new List <Vector3>(); float negativeInfinity = float.NegativeInfinity; float x = negativeInfinity; if (< > f__am$cache0 == null) {
void Start() { m_Effector = GetComponent <BuoyancyEffector2D>(); m_EffectorBounds = GetComponent <Collider2D>().bounds; // Calculate the slider bounds. var camera = Camera.main; var min = camera.WorldToScreenPoint(m_EffectorBounds.min); var max = camera.WorldToScreenPoint(m_EffectorBounds.max); m_SliderBounds.Set(20.0f, 20.0f, 30.0f, max.y - min.y); }
internal void Initialize() { _buoyancyEffector = _mainModule.Transform.GetComponent <BuoyancyEffector2D>(); _hasAnimatorAttached = _mainModule.Transform.GetComponent <Animator>() != null; _edgeCollider = _mainModule.Transform.GetComponent <EdgeCollider2D>(); _boxCollider = _mainModule.Transform.GetComponent <BoxCollider2D>(); _boxCollider.isTrigger = true; _boxCollider.usedByEffector = true; //used by the buoyancy effector _cachedWaterSize = _mainModule.WaterSize; ApplyChanges(); }
void Update() { if (!Application.isPlaying) { if (!mBuoyancy) { mBuoyancy = GetComponent <BuoyancyEffector2D>(); } if (!mColl) { mColl = GetComponent <BoxCollider2D>(); } if (!mColl || !mBuoyancy) { return; } var collBounds = mColl.bounds; if (topRoot) { Vector2 topPos = new Vector2( collBounds.center.x, transform.position.y + mBuoyancy.surfaceLevel); topRoot.position = topPos; Vector3 topScale = topRoot.localScale; topScale.x = collBounds.size.x; topRoot.localScale = topScale; } if (fillRoot) { Vector2 fillPos = new Vector2( collBounds.center.x, transform.position.y); fillRoot.position = fillPos; Vector3 fillScale = fillRoot.localScale; fillScale.x = collBounds.size.x; fillScale.y = mBuoyancy.surfaceLevel; fillRoot.localScale = fillScale; } return; } }
protected override void Start() { base.Start(); startX = transform.position.x; rb = GetComponent <Rigidbody2D>(); startCenterMass = rb.centerOfMass; effector2D = GetComponentInParent <BuoyancyEffector2D>(); layerNames[0] = "Platforms"; layerNames[1] = "Enemy"; layerNames[2] = "Player"; }
void Start() { // Get scoreboard and sound object GameObject obj = GameObject.Find("scoreText"); scoreBoard = obj.GetComponent <ScoreBoard>(); sound = GameObject.Find("SoundObjects").GetComponent <SoundController>(); // Animation objects handcamRenderer = handcamObj.GetComponent <Renderer>() as SpriteRenderer; golightRenderer = golightObj.GetComponent <Renderer>() as SpriteRenderer; handcamAniController = handcamObj.GetComponent <AnimateController>(); golightAniController = golightObj.GetComponent <AnimateController>(); effect = GetComponent <BuoyancyEffector2D>(); }
private void Initialize() { //Setup global state material.color = color; int thePartsCount = (int)(width / partSize); parts = new WaterLinePart[thePartsCount]; //Generate parts for (int i = 0; i < thePartsCount; i++) { //Object & geometry GameObject theGameObject = new GameObject("WavePart_" + i); theGameObject.tag = "waterPart"; theGameObject.transform.parent = this.transform; theGameObject.transform.localPosition = new Vector3(i * partSize, 0, -1); //Physics PolygonCollider2D polygonCollider2D = theGameObject.AddComponent <PolygonCollider2D>(); polygonCollider2D.isTrigger = true; polygonCollider2D.usedByEffector = true; BuoyancyEffector2D theEffector = theGameObject.AddComponent <BuoyancyEffector2D>(); //Graphics Mesh mesh = new Mesh(); mesh.MarkDynamic(); theGameObject.AddComponent <MeshFilter>().mesh = mesh; theGameObject.AddComponent <MeshRenderer>().material = material; //Setup part parts[i] = new WaterLinePart(); parts[i]._heightOld = 0.0f; parts[i]._heightNew = 0.0f; parts[i]._speed = 0.0f; parts[i]._effector = theEffector; parts[i].mesh = mesh; parts[i].gameObject = theGameObject; } for (int i = 0; i < thePartsCount; i++) { UpdateMeshVertices(i); InitializeTrianglesAndNormalsForMesh(i); } }
// Start is called before the first frame update void Start() { manager = GameObject.FindGameObjectWithTag("GameManager").GetComponent <GameManager>(); if (manager.firstTimePlay) { tutorial.gameObject.SetActive(true); } else { Destroy(tutorial); } pGen = transform.parent.transform.parent.gameObject.GetComponent <BuoyancyEffector2D>(); }
void Awake() { socket = transform.Find("Socket"); plugOff = transform.Find("PlugOff"); plugIn = transform.Find("PlugIn"); trigger = transform.Find("Trigger"); plugTrigger = transform.Find("PlugTrigger"); buoyancy = GetComponent <BuoyancyEffector2D>(); boxCollider = GetComponent <BoxCollider2D>(); boxSize = boxCollider.size; boxCollider.size = Vector2.zero; EventCenter.AddListener(EventType.AnRespawn, Reset); Physics2D.IgnoreCollision(boxCollider, FindObjectOfType <An>().GetComponent <CapsuleCollider2D>()); }
protected void Awake() { _buoyancyEffector2D = GetComponent <BuoyancyEffector2D>(); _surfaceLevel = _buoyancyEffector2D.surfaceLevel; _splashCache = new Water2DSplashFX[SplashFXPrecache]; var container = new GameObject("Splash Container").transform; for (var i = 0; i < _splashCache.Length; i++) { var splash = Instantiate(SplashFXPrefab); splash.transform.parent = container; _splashCache[i] = splash; } }
void Awake() { #if UNITY_EDITOR if (!Application.isPlaying) { return; } #endif mBuoyancy = GetComponent <BuoyancyEffector2D>(); mColl = GetComponent <BoxCollider2D>(); mSurfaceBaseLevel = mBuoyancy.surfaceLevel; mSurfaceCache = new M8.CacheList <SurfaceCache>(triggerCacheCapacity); mKillableCache = new M8.CacheList <KillableCache>(triggerCacheCapacity); }
public static int get_density(IntPtr l) { int result; try { BuoyancyEffector2D buoyancyEffector2D = (BuoyancyEffector2D)LuaObject.checkSelf(l); LuaObject.pushValue(l, true); LuaObject.pushValue(l, buoyancyEffector2D.density); result = 2; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
void Update() { if (abilityLock) { return; } if (Input.GetButtonDown("tSwitch")) { if (switchObject != null) { switchObject.GetComponent <SwitchBehaviour>().toggleState(); } } if (Input.GetButtonDown("Geyser") || Input.GetKeyDown(KeyCode.M)) { // initiate geyser animator.SetTrigger("Ability"); if (canGeyser) { // get geyser object buoyancyObject = buoyancyParent.transform.GetChild(0).gameObject; buoy = buoyancyObject.GetComponent <BuoyancyEffector2D>(); targetGeyser = buoy; startPosition = buoy.GetComponent <GeyserBehaviour>().getReset(); // reset geyser after time targetPosition = new Vector2(0.0f, buoy.transform.position.y + buoy.GetComponent <GeyserBehaviour>().limit); // need limit if (!buoy.GetComponent <GeyserBehaviour>().getActiveGeyser()) { FindObjectOfType <AudioManager>().Play("Geyser"); activateGeyser(buoy); buoy.GetComponent <GeyserBehaviour>().setActiveGeyser(true); } } } if (Input.GetButtonDown("Dive") || Input.GetKeyDown(KeyCode.P) && diveObject != null) { animator.SetTrigger("Dive"); diveActive = true; atDive = Time.time + 0.54f; FindObjectOfType <AudioManager>().Play("PipeEnter"); } }
public static int set_flowVariation(IntPtr l) { int result; try { BuoyancyEffector2D buoyancyEffector2D = (BuoyancyEffector2D)LuaObject.checkSelf(l); float flowVariation; LuaObject.checkType(l, 2, out flowVariation); buoyancyEffector2D.flowVariation = flowVariation; LuaObject.pushValue(l, true); result = 1; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
public static int set_angularDrag(IntPtr l) { int result; try { BuoyancyEffector2D buoyancyEffector2D = (BuoyancyEffector2D)LuaObject.checkSelf(l); float angularDrag; LuaObject.checkType(l, 2, out angularDrag); buoyancyEffector2D.angularDrag = angularDrag; LuaObject.pushValue(l, true); result = 1; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
public static int set_surfaceLevel(IntPtr l) { int result; try { BuoyancyEffector2D buoyancyEffector2D = (BuoyancyEffector2D)LuaObject.checkSelf(l); float surfaceLevel; LuaObject.checkType(l, 2, out surfaceLevel); buoyancyEffector2D.surfaceLevel = surfaceLevel; LuaObject.pushValue(l, true); result = 1; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
//Awake is called when the script instance is being loaded. void Awake() { meshFilter = GetComponent <MeshFilter> (); meshRenderer = GetComponent <MeshRenderer> (); if (!meshRenderer.sharedMaterial) { waterMaterial = new Material(Shader.Find("Game2DWaterKit/Unlit (Supports Lightmap)")); } else { //Ensure that when duplicating our gameobject, the duplicate copy gets its own unique material waterMaterial = new Material(meshRenderer.sharedMaterial); } meshRenderer.sharedMaterial = waterMaterial; waterMaterial.name = "Game2DWater Material"; meshRenderer.sharedMaterial = waterMaterial; meshRenderer.sortingLayerID = sortingLayerID; meshRenderer.sortingOrder = sortingOrder; boxCollider = GetComponent <BoxCollider2D> (); //BuoyancyEffector only works when an attached collider is marked as a trigger and used by effector boxCollider.isTrigger = true; boxCollider.usedByEffector = true; edgeCollider = GetComponent <EdgeCollider2D> (); buoyancyEffector = GetComponent <BuoyancyEffector2D> (); audioSource = GetComponent <AudioSource> (); gameObject.layer = LayerMask.NameToLayer("Water"); renderRefraction = waterMaterial.IsKeywordEnabled("Water2D_Refraction"); renderReflection = waterMaterial.IsKeywordEnabled("Water2D_Reflection"); refractionTextureID = Shader.PropertyToID("_RefractionTexture"); reflectionTextureID = Shader.PropertyToID("_ReflectionTexture"); waterMatrixID = Shader.PropertyToID("_WaterMVP"); RecomputeMesh(); }
private void Start() { global = GameObject.FindWithTag("global").GetComponent <Global>(); if (!cameraFollow) { cameraFollow = Camera.main.GetComponent <cameraFollowPlayer>(); } bEffectorOne = GetComponent <BuoyancyEffector2D>() as BuoyancyEffector2D; if (buoyancyEffectorTwoGo != null) { bEffectorTwo = buoyancyEffectorTwoGo.GetComponent <BuoyancyEffector2D>() as BuoyancyEffector2D; } if (noInitialSplash) { canSplash = false; Invoke("initialSplashSwitch", 0.1f); } Reset(); InvokeRepeating("UpdateSurface", 0.0f, 1.0f / sampleRate); }
void OnTriggerExit2D(Collider2D col) { // reset colliders // col = null; if (abilityLock) { return; } if (col.gameObject == buoyancyParent) { //deactivate colliders buoyancyParent = buoyancyObject = null; targetGeyser = null; buoy = null; canGeyser = false; } if (col.gameObject == diveSwitch) { diveSwitch = null; } if (col.gameObject.tag == "BinarySwitch") { switchObject = null; } if (col.gameObject == diveObject) { // canGeyser = false; diveObject = null; diveParent = null; diveContainer = null; } }
public void OnSceneGUI() { BuoyancyEffector2D target = (BuoyancyEffector2D)this.target; if (!target.enabled) { return; } float y = target.transform.position.y + target.transform.lossyScale.y * target.surfaceLevel; List <Vector3> vector3List = new List <Vector3>(); float num = float.NegativeInfinity; float x1 = num; foreach (Collider2D collider2D in ((IEnumerable <Collider2D>)target.gameObject.GetComponents <Collider2D>()).Where <Collider2D>((Func <Collider2D, bool>)(c => { if (c.enabled) { return(c.usedByEffector); } return(false); }))) { Bounds bounds = collider2D.bounds; float x2 = bounds.min.x; float x3 = bounds.max.x; if (float.IsNegativeInfinity(num)) { num = x2; x1 = x3; } else { if ((double)x2 < (double)num) { num = x2; } if ((double)x3 > (double)x1) { x1 = x3; } } Vector3 vector3_1 = new Vector3(x2, y, 0.0f); Vector3 vector3_2 = new Vector3(x3, y, 0.0f); vector3List.Add(vector3_1); vector3List.Add(vector3_2); } Handles.color = Color.red; Handles.DrawAAPolyLine(new Vector3[2] { new Vector3(num, y, 0.0f), new Vector3(x1, y, 0.0f) }); Handles.color = Color.cyan; int index = 0; while (index < vector3List.Count - 1) { Handles.DrawAAPolyLine(new Vector3[2] { vector3List[index], vector3List[index + 1] }); index += 2; } }
public void TakeCareOfComponenets() { #if UNITY_EDITOR Tools.pivotMode = PivotMode.Pivot; #endif //Get material to use if (useMaterial == null) { RefreshMaterial(); } if (GetComponent <MeshFilter>() == null) { gameObject.AddComponent <MeshFilter>(); } if (GetComponent <MeshRenderer>() == null) { gameObject.AddComponent <MeshRenderer>(); } if (GetComponent <BoxCollider2D>() == null && shape == Shape.Surface) { gameObject.AddComponent <BoxCollider2D>(); #if UNITY_EDITOR DestroyImmediate(gameObject.GetComponent <CircleCollider2D>()); #else Destroy(gameObject.GetComponent <CircleCollider2D>()); #endif } if (GetComponent <CircleCollider2D>() == null && shape == Shape.Circle) { gameObject.AddComponent <CircleCollider2D>(); #if UNITY_EDITOR DestroyImmediate(gameObject.GetComponent <BoxCollider2D>()); #else Destroy(gameObject.GetComponent <BoxCollider2D>()); #endif } if (GetComponent <BuoyancyEffector2D>() == null) { gameObject.AddComponent <BuoyancyEffector2D>(); } mf = GetComponent <MeshFilter>(); mr = GetComponent <MeshRenderer>(); mr.sharedMaterial = useMaterial; sortingLayer = mr.sortingLayerID; renderingLayerMask = mr.renderingLayerMask; orderInLayer = mr.sortingOrder; boxCol = GetComponent <BoxCollider2D>(); if (boxCol != null) { boxCol.isTrigger = true; boxCol.usedByEffector = true; } circleCol = GetComponent <CircleCollider2D>(); if (circleCol != null) { circleCol.isTrigger = true; circleCol.usedByEffector = true; } buo = GetComponent <BuoyancyEffector2D>(); ////buo.density=1.5f; //Work with audio //Add array of audio chennels if (channels[0] == null && audioEnabled) { if (gameObject.GetComponents <AudioSource>().Length == channels.Length) { //If we already added the components but not set them, we jsut need to assign them channels = gameObject.GetComponents <AudioSource>(); } else { //Destroy existing audiosources AudioSource[] AudioSources = gameObject.GetComponents <AudioSource>(); for (int i = 0; i < AudioSources.Length; i++) { #if UNITY_EDITOR DestroyImmediate(AudioSources[i]); #else Destroy(AudioSources[i]); #endif } //Create new audiosources for each chennel for (int i = 0; i < channels.Length; i++) { channels[i] = gameObject.AddComponent <AudioSource>(); } } } else if (!audioEnabled && gameObject.GetComponents <AudioSource>().Length > 0) { //Destroy existing audiosources AudioSource[] AudioSources = gameObject.GetComponents <AudioSource>(); for (int i = 0; i < AudioSources.Length; i++) { #if UNITY_EDITOR DestroyImmediate(AudioSources[i]); #else Destroy(AudioSources[i]); #endif } } //Get default sounds if ((enterSounds == null || enterSounds.Length == 0) && (exitSounds == null || exitSounds.Length == 0) && audioEnabled) { Object[] audioClips = Resources.LoadAll("", typeof(AudioClip)); List <AudioClip> enterSoundsList = new List <AudioClip>(3); List <AudioClip> exitSoundsList = new List <AudioClip>(3); for (int i = 0; i < audioClips.Length; i++) { if (Regex.IsMatch(((AudioClip)audioClips[i]).name, "^plop[0-9]+$")) { enterSoundsList.Add((AudioClip)audioClips[i]); } else if (Regex.IsMatch(((AudioClip)audioClips[i]).name, "^squirt[0-9]+$")) { exitSoundsList.Add((AudioClip)audioClips[i]); } } enterSounds = enterSoundsList.ToArray(); exitSounds = exitSoundsList.ToArray(); } }
private void SetupBuoyancyEffector() { _buoyancyEffector = _mainModule.Transform.GetComponent <BuoyancyEffector2D>(); }
public void Generate() { points.Clear(); //Build a line of points if (shape == WaterWaves2D.Shape.Surface) { for (int i = 0; i < resolution; i++) { loop = false; points.Add(new Point( new Vector2( bounds.min.x + ((bounds.size.x / (resolution - 1)) * i), bounds.size.y / 2 ), Vector2.down, 45f )); } //Build a cicle of points } else if (shape == WaterWaves2D.Shape.Circle) { for (int i = 0; i < resolution; i++) { loop = true; float a = (((360f / resolution) * i) * Mathf.Deg2Rad); points.Add(new Point( new Vector2( (float)(Mathf.Cos(a) * bounds.extents.x), (float)(Mathf.Sin(a) * bounds.extents.y) ), new Vector2( (float)(Mathf.Cos(a) * bounds.extents.x), (float)(Mathf.Sin(a) * bounds.extents.y) ), 90f )); } } if (boxCol == null) { boxCol = GetComponent <BoxCollider2D>(); } if (circleCol == null) { circleCol = GetComponent <CircleCollider2D>(); } if (buo == null) { buo = GetComponent <BuoyancyEffector2D>(); } if (boxCol != null) { boxCol.offset = bounds.center; boxCol.size = bounds.size; } if (circleCol != null) { circleCol.offset = bounds.center; circleCol.radius = bounds.size.x / 2; } buo.surfaceLevel = bounds.size.y / 2; BuildMesh(); }
private void Start() { water = GetComponent <BuoyancyEffector2D>(); scaleY = transform.localScale.y; }