// ######################################## // Create/Remove Prop // ######################################## #region Create/Remove Prop // Create prop public void CreateProp() { if (m_PropGameObject == null && m_Prefab != null) { // Create Particle from m_Prefab m_PropGameObject = Instantiate(m_Prefab, transform.position + m_Prefab.transform.position + m_PosBegin, transform.rotation) as GameObject; // Get FCMain compoment m_Main = this.GetComponent <FCMain>(); m_PropGameObject.transform.parent = transform; // Set position variables m_PositionState = FCProp.eTransformState.Begin; //m_PositionStateOld = FCProp.eTransformState.Begin; m_PosValue = 0; // Set rotation variables //m_RotationState = FCProp.eTransformState.Begin; //m_RotationStateOld = FCProp.eTransformState.Begin; m_RotationValue = 0; //m_RotationRoundCount = 0; // Set scale variables m_ScaleState = FCProp.eTransformState.Begin; //m_ScaleStateOld = FCProp.eTransformState.Begin; m_ScaleValue = 0; } }
// ######################################## // Create and init functions // ######################################## #region Create and init functions // Create Particle public void CreateParticle() { if (m_Prefab != null && m_ParticleGameObject == null && this.gameObject != null) { // Make sure there is FCMain compoment m_Main = this.GetComponent <FCMain>(); if (m_Main == null) { return; } // Create Particle from m_Prefab m_ParticleGameObject = Instantiate(m_Prefab, this.gameObject.transform.position + m_Prefab.transform.position + m_OffSetLocalPosition, transform.rotation) as GameObject; // Update Particle position UpdateParticlePosition(); m_OffSetLocalPositionOld = m_OffSetLocalPosition; // Set up ParticleSystem variables if (m_ParticleSystem == null) { m_ParticleSystem = m_ParticleGameObject.GetComponent <ParticleSystem>(); m_ParticleDuration = m_ParticleSystem.main.duration; SetParticleLoop(m_ParticleGameObject.transform, m_isLoop); } // Increase counter of how many time this function is called m_CreateCount++; } }
// ######################################## // Player Input functions // ######################################## #region Player Input functions // Toggle Open or lock void MouseButtonUp(int Button) { FCMain pMain = GetHitChest(Input.mousePosition); if (pMain != null) { if (Button == 0) { pMain.ToggleOpen(); } else if (Button == 1) { pMain.ToggleLock(); } } }
// Start is called on the frame when a script is enabled just before any of the Update methods is called the first time. // http://docs.unity3d.com/ScriptReference/MonoBehaviour.Start.html void Start() { #if USE_DOTWEEN // use DOTween: https://www.assetstore.unity3d.com/en/#!/content/27676 Documentation: http://dotween.demigiant.com/documentation.php // DOTWEEN INITIALIZATION // Initialize DOTween (needs to be done only once). // If you don't initialize DOTween yourself, // it will be automatically initialized with default values. // DOTween.Init(false, true, LogBehaviour.ErrorsOnly); #elif USE_HOTWEEN // use HOTween: https://www.assetstore.unity3d.com/#/content/3311 Documentation: http://hotween.demigiant.com/documentation.html // HOTWEEN INITIALIZATION // Must be done only once, before the creation of your first tween // (you can skip this if you want, and HOTween will be initialized automatically // when you create your first tween - using default values) HOTween.Init(true, true, true); #elif USE_LEANTWEEN // use LeanTween: https://www.assetstore.unity3d.com/#/content/3595 Documentation: http://dentedpixel.com/LeanTweenDocumentation/classes/LeanTween.html #else // use iTween: https://www.assetstore.unity3d.com/#/content/84 Documentation: http://itween.pixelplacement.com/documentation.php #endif // Get FCMain compoment m_Main = this.GetComponent <FCMain>(); }
// Update is called every frame, if the MonoBehaviour is enabled. // http://docs.unity3d.com/ScriptReference/MonoBehaviour.Update.html void Update() { // If there is single touch input if (Input.touchCount == 1) { // Get touch Touch touch = Input.GetTouch(0); // Touch began if (touch.phase == TouchPhase.Began) { // Keep current touch phase currentSingleTouchPhase = TouchPhase.Began; // reset touch stationary duration TouchStationaryDuration = 0; } // Touch moves else if (touch.phase == TouchPhase.Moved) { // Keep current touch phase currentSingleTouchPhase = TouchPhase.Moved; // reset touch stationary duration TouchStationaryDuration = 0; } // Touch stationary else if (touch.phase == TouchPhase.Stationary) { // Check if there is a hit on a chest FCMain pMain = GetHitChest(touch.position); if (pMain != null) { // Keep current touch phase currentSingleTouchPhase = TouchPhase.Stationary; // If last touch phase is stationary if (previousSingleTouchPhase == TouchPhase.Stationary) { // Increase stationary duration TouchStationaryDuration += Time.deltaTime; // Toggle lock/unlock if stationary has reached it limitation duration if (TouchStationaryDuration > TouchStationaryTime && TouchStationaryDuration < TouchStationaryTime + 1) { // Toggle lock/unlock pMain.ToggleLock(); TouchStationaryDuration = TouchStationaryTime * 2; } } } } // Touch ended else if (touch.phase == TouchPhase.Ended) { // Keep current touch phase currentSingleTouchPhase = TouchPhase.Ended; // If last touch phase is not stationary if (previousSingleTouchPhase == TouchPhase.Began || (previousSingleTouchPhase == TouchPhase.Stationary && TouchStationaryDuration < TouchStationaryTime)) { // Toggle open/close FCMain pMain = GetHitChest(touch.position); if (pMain != null) { pMain.ToggleOpen(); } } // Reset touch stationary duration TouchStationaryDuration = 0; } // Store current touch phase in previous touch phase previousSingleTouchPhase = currentSingleTouchPhase; // set currentSingleTouchPhase to TouchPhase.Canceled currentSingleTouchPhase = TouchPhase.Canceled; } // Mouse inputs else { // User pressed the left mouse up if (Input.GetMouseButtonUp(0)) { MouseButtonUp(0); } // User pressed the right mouse up else if (Input.GetMouseButtonUp(1)) { MouseButtonUp(1); } } }
// ######################################## // MonoBehaviour Functions // http://docs.unity3d.com/ScriptReference/MonoBehaviour.html // ######################################## #region MonoBehaviour // Start is called on the frame when a script is enabled just before any of the Update methods is called the first time. // http://docs.unity3d.com/ScriptReference/MonoBehaviour.Start.html void Start() { // Get FCMain compoment objects m_Main = this.GetComponent <FCMain>(); }