Demo entry 6523749

C#

   

Submitted by anonymous on May 31, 2017 at 17:59
Language: C#. Code size: 69.8 kB.

/***********PRIMO MODULO - MISSIONE DI VESTIZIONE***********/

/////////////////CompleteTrigger.cs/////////////////

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class CompleteTrigger : MonoBehaviour {

    public MissionVestizione m_MissionVestizione;
    private bool m_isInTrigger;

    public GameObject ControlloEnableTrigger;        //trigger che attiva quest'oggetto

    public bool IsInTrigger { get { return m_isInTrigger; } set { m_isInTrigger = value; } }

    void Awake()
    {
         GameManager.Register(this, typeof(Behaviour), true);
    }

    //eseguito solo una volta , prende varie reference e chiama IsCompleted()
    void OnTriggerEnter(Collider other)
    {
        if (!m_isInTrigger && other.gameObject == Player.Instance.gameObject)
        {
            m_isInTrigger = !m_isInTrigger;
            ControlloEnableTrigger.SetActive(true);
            IsCompleted();
        }
    }

    //controlla che l'abbigliamento sia equipaggiato 
    public void IsCompleted()
    {
        if (m_MissionVestizione.IsCompleted())
        {
            // pietro 12/01/201
            MissionManager.Instance.Success = true;
            MissionManager.Instance.CompleteMission();
            //_MissionVestizione.FinalizeMission();
            ControlloEnableTrigger.SetActive(false);

            // missing bit on siccess
          
        }
        else
        {
            StartCoroutine(m_MissionVestizione.WaitForPanelUnsuccess());
        }
    }
}

/////////////////ControlloEnableTrigger.cs/////////////////

using UnityEngine;
using System.Collections;

public class ControlloEnableTrigger : MonoBehaviour {

    public CompleteTrigger m_CompleteTrigger;     //trigger da riattivare in caso sia disattivo
    protected MessageBox m_MessageBox;

    void Awake()
    {
        m_MessageBox = GameManager.GetObjectOfType<MessageBox>();
    }

    //riattiva l'oggetto ControlloCapomastro
    void OnTriggerEnter()
    {
        if (!m_CompleteTrigger.gameObject.activeInHierarchy)
            m_CompleteTrigger.gameObject.SetActive(true);

        m_CompleteTrigger.IsInTrigger = false;
        m_MessageBox.gameObject.SetActive(false);
    }
}

/////////////////ElmettoArmadietto.cs/////////////////

using UnityEngine;
using System.Collections;

public class ElmettoArmadietto : EquipableObject
{

    [SerializeField]
    protected MissionVestizione m_MissionVestizione;

    //Inizializza gli oggetti siccome si trovano in una scena diversa
    public override void OnEnable()
    {
        base.OnEnable();
        Init();
        m_Selectable = false;
    }

    //indossa l'Elmetto
    protected override void Use()
    {
        gameObject.layer = m_EquipLayer;
        DestroyRigidbody();
        this.GetComponent<MeshRenderer>().enabled = false;   //disattiva gli l'oggetto nel box
        this.GetComponent<MeshCollider>().enabled = false;
        Player.Instance.Hat.SetActive(false);            //disattiva il cappello 
        Player.Instance.Elmetto.SetActive(true);         //attiva l'Elmetto (SkinnedMesh)
        if (m_MissionVestizione.IsTutaActive() && m_MissionVestizione.IsScarpeActive())      //Controlla se ha tutti gli oggetti equipaggiati
            m_MissionVestizione.SetPlayerLifeAndExp();
    }

}

/////////////////ScarpeArmadietto.cs/////////////////

using UnityEngine;
using System.Collections;

public class ScarpeArmadietto : EquipableObject
{
    [SerializeField]
    protected MissionVestizione m_MissionVestizione;


    //Inizializza gli oggetti siccome si trovano in una scena diversa
    public override void OnEnable()
    {
        base.OnEnable();
        Init();
        m_Selectable = false;
    }

    //indossa le Scarpe di sicurezza
    protected override void Use()
    {
        gameObject.layer = m_EquipLayer;
        DestroyRigidbody();
        this.GetComponent<MeshRenderer>().enabled = false;   //disattiva gli l'oggetto nel box
        this.GetComponent<MeshCollider>().enabled = false;
        Player.Instance.Scarpe.SetActive(true);         //Attiva la skinned mesh del Player
        if (m_MissionVestizione.IsTutaActive() && m_MissionVestizione.IsElmettoActive())        //Controlla se ha tutti gli oggetti equipaggiati
            m_MissionVestizione.SetPlayerLifeAndExp();
    }

}

/////////////////TutaArmadietto.cs/////////////////

using UnityEngine;
using System.Collections;

public class TutaArmadietto : EquipableObject
{
    [SerializeField]
    protected MissionVestizione m_MissionVestizione;
    
    //Inizializza gli oggetti siccome si trovano in una scena diversa
    public override void OnEnable()
    {
        base.OnEnable();
        Init();
        m_Selectable = false;
    }

    //indossa la Tuta
    protected override void Use()
    {
        gameObject.layer = m_EquipLayer;
        DestroyRigidbody();
        this.GetComponent<MeshRenderer>().enabled = false;   //disattiva gli l'oggetto nel box
        this.GetComponent<MeshCollider>().enabled = false;
        Player.Instance.Maglietta.SetActive(false);         //disabilita la maglietta che indossa
        Player.Instance.OperaioVestito.SetActive(false);    //e il resto del vestiario
        Player.Instance.Tuta.SetActive(true);               //attiva la tuta (SkinnedMesh)
        if (m_MissionVestizione.IsElmettoActive() && m_MissionVestizione.IsScarpeActive())      //Controlla se ha tutti gli oggetti equipaggiati
            m_MissionVestizione.SetPlayerLifeAndExp();
    }

}

/////////////////GuantiArmadietto.cs/////////////////

using UnityEngine;
using System.Collections;

public class GuantiArmadietto : EquipableObject
{

    //Inizializza gli oggetti siccome si trovano in una scena diversa
    public override void OnEnable()
    {
        base.OnEnable();
        Init();
    }
    
    //Indossa i Guanti protettivi
    protected override void Use()
    {
        base.Use();
        this.gameObject.SetActive(false);           //disattiva l'oggetto nel box
        //non ci sono le skinned mesh dei guanti
        //nel caso attivarle qui
    }

}

/////////////////ImbracaturaArmadietto.cs/////////////////

using UnityEngine;
using System.Collections;

public class ImbracaturaArmadietto : EquipableObject 
{

    //Inizializza gli oggetti siccome si trovano in una scena diversa
    public override void OnEnable()
    {
        base.OnEnable();
        Init();
    }

    //indossa l'Imbracatura
    protected override void Use()
    {
        base.Use();
        this.gameObject.SetActive(false);                   //disattiva l'oggetto nel Box
        Player.Instance.Imbracatura.SetActive(true);        //attiva l'Imbracatura (SkinnedMesh)
    }

}

/////////////////InitialTriggerCapomastro.cs/////////////////

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class InitialTriggerCapomastro : BaseGameStateListener
{
    private string message;

    [SerializeField]
    protected AudioClip audioclip;      //clip per il Capomastro

    protected UICapomastroManager m_MasterBuilder;
     

    protected override void Awake()
    {
        m_MasterBuilder = GameManager.GetObjectOfType<UICapomastroManager>();
    }

    void OnTriggerEnter()
    {
        StartCoroutine(WaitForStateChange());
    }

    IEnumerator WaitForStateChange()
    {
        while (GameManager.Instance.CurrentStateName != "PlayState")
        {
            yield return null;
        }
        message = MissionManager.Instance.CurrentMissionData.StepsData[0].Sentences[0] + "\n" + MissionManager.Instance.CurrentMissionData.StepsData[0].Sentences[1];
        StartCoroutine(m_MasterBuilder.PlayAndSound(audioclip, message));
        this.GetComponent<BoxCollider>().enabled = false; 
    }

}

/////////////////LoadingPanel.cs/////////////////

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using FSM;

public class LoadingPanel : BaseGameStateListener
{

    public Slider m_sliderBar;
    public GameObject m_LoadingPanel;
    public GameObject m_MissionCompletePanel;


    protected override void Awake()
    {
        m_ObservedStates.Add("LoadState", new StateEvent[] { OnLoadingInit, null, OnLoadingExit });
        base.Awake();
        GameManager.Register<LoadingPanel>(this, typeof(Behaviour), true);
    }
    void OnEnable() 
    {
        LevelLoader.OnLevelLoading += LevelLoader_OnLevelLoading;
    }

    public void OnLoadingInit(object sender, System.EventArgs args)
    {
        m_sliderBar.value = 0;
        m_MissionCompletePanel.SetActive(false);
        m_LoadingPanel.SetActive(true);
    }

    public void OnLoadingExit(object sender, System.EventArgs args)
    {
        m_LoadingPanel.SetActive(false);
    }

    void LevelLoader_OnLevelLoading(float progress) 
    {
        m_sliderBar.value += progress;
    }


}

/////////////////MessageBox.cs/////////////////

using UnityEngine;
using System.Collections;
using UnityEngine.UI;


public class MessageBox : ClickableUI
{
    [SerializeField]
    protected Text m_MessageBoxText;        //oggetto Text del figlio Panel
    [SerializeField]
    protected Text m_MessageBoxTitleText;

    private static int cnt = 0;
    public bool visible;

    //Get & Set
    public string MessageBoxText { get { return m_MessageBoxText.text; } set { m_MessageBoxText.text = value; } }
    public string MessageBoxTitleText { get { return m_MessageBoxTitleText.text; } set { m_MessageBoxTitleText.text = value; } }


    //override che salva in chache l'oggetto
    protected override void Awake()
    {
        GameManager.Register<MessageBox>(this, typeof(Behaviour), true);
        gameObject.SetActive(false);
    }

    public void InitMessageBox(string message, string title)
    {
        visible = true;
        m_MessageBoxText.text = message;
        m_MessageBoxTitleText.text = title;
        this.gameObject.SetActive(true);
    }

    //inizializza il messaggo nella Panel e lo visualizza
    public void InitMessageBox(string message)
    {
        visible = true;
        m_MessageBoxText.text = message;
        this.gameObject.SetActive(true);
    }

    //overload del precedente senza settaggio messaggio
    public void InitMessageBox()
    {
        visible = true;
        this.gameObject.SetActive(true);
    }

    //disattiva la MessageBox
    public override void Continua()
    {
        cnt++;
        visible = false;
        this.gameObject.SetActive(false);
    }
}

/////////////////PropsInteractTriggerOff.cs/////////////////

using UnityEngine;
using System.Collections;

public class PropsInteractTriggerOff : MonoBehaviour {

    public GameObject propsInteractTriggerOn;       //trigger che rende Interactable i Props
    public TutaArmadietto Tuta;                     //Props nel Box
    public ElmettoArmadietto Elmetto;
    public ScarpeArmadietto Scarpe;

    //disattiva l'interattività dei props e attiva il trigger di cui sopra
    void OnTriggerEnter()
    {
        if (Tuta.GetComponent<MeshRenderer>().enabled)
            Tuta.Selectable = false;
        if (Scarpe.GetComponent<MeshRenderer>().enabled)
            Scarpe.Selectable = false;
        if (Elmetto.GetComponent<MeshRenderer>().enabled)
            Elmetto.Selectable = false;

        propsInteractTriggerOn.SetActive(true); //attiva il trigger
        this.gameObject.SetActive(false);       //si disattiva
    }       
}

/////////////////PropsInteractTriggerOn.cs/////////////////

using UnityEngine;
using System.Collections;

public class PropsInteractTriggerOn : MonoBehaviour {

    public GameObject propsInteractTriggerOff;          //trigger che rende non Interactable i Props
    public TutaArmadietto Tuta;                         //Props nel Box
    public ElmettoArmadietto Elmetto;
    public ScarpeArmadietto Scarpe;

    //Attiva l'interattività dei props e attiva il trigger di cui sopra
    void OnTriggerEnter()
    {
        if (Tuta.GetComponent<MeshRenderer>().enabled)
            Tuta.Selectable = true;
        if (Scarpe.GetComponent<MeshRenderer>().enabled)
            Scarpe.Selectable = true;
        if (Elmetto.GetComponent<MeshRenderer>().enabled)
            Elmetto.Selectable = true;

        propsInteractTriggerOff.SetActive(true);    //attiva il trigger
        this.gameObject.SetActive(false);           //si disattiva
    }
}

/////////////////UICapomastroManager.cs/////////////////

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.Audio;

public delegate void CapomastroEvent();

public class UICapomastroManager : CachableObject
{
    [SerializeField]
    protected Text m_CapomastroText;                //testo del Capomastro

    [SerializeField]
    protected MovieTexture m_CapoMastroMovieTexture;

    [SerializeField]
    protected GameObject m_BoxCapomastro;

    [SerializeField]
    protected float m_Countdown;

    private AudioSource source;                     //audio source con la quale eseguire le clip

    public event CapomastroEvent OnActivated;
    public event CapomastroEvent OnDeactivated;

    //Get & Set
    public string CapomastroText { get { return m_CapomastroText.text; } set { m_CapomastroText.text = value; } }

    //override che salva in chache l'oggetto
    protected override void Awake()
    {
        GameManager.Register<UICapomastroManager>(this, typeof(Behaviour), true);
    }

    protected void OnEnable()
    {
        if (OnActivated != null)
            OnActivated();
    }

    protected void OnDisable()
    {
        if (OnDeactivated != null)
            OnDeactivated();
    }

    //setta la clip e fa partire la GUI del Capomastro
    public IEnumerator PlayAndSound(AudioClip audioClip, string text)
    {
        CapomastroText = text;
        Open();
        m_CapoMastroMovieTexture.loop = true;
        m_CapoMastroMovieTexture.Play();

        source = GetComponent<AudioSource>();
        if (audioClip != null && source != null)
        {
            source.clip = audioClip;
            source.Play();
            while (source.isPlaying)
                yield return null;
        }
        else
            yield return new WaitForSeconds(m_Countdown);
        m_CapoMastroMovieTexture.Stop();
        Close();
    }

    public void Open()
    {
        m_BoxCapomastro.SetActive(true);
        if (OnActivated != null)
            OnActivated();
    }

    public void Close()
    {
        m_BoxCapomastro.SetActive(false);
        if (OnDeactivated != null)
            OnDeactivated();
    }

}

/////////////////MissionVestizione.cs/////////////////

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UiGraphics;

public class MissionVestizione : Mission
{
    protected CompleteTrigger m_CompleteTrigger;
    [SerializeField]
    protected MessageBox m_MessageBox;
    protected UICapomastroManager m_MasterBuilder;
    [SerializeField]
    protected AudioClip audioClipDressing;
    [SerializeField]
    protected AudioClip audioClipUnsuccess;
    [SerializeField]
    protected AudioClip audioClipSuccess;


    protected override void Awake()
    {
        m_MessageBox = GameManager.GetObjectOfType<MessageBox>();
        m_MasterBuilder = GameManager.GetObjectOfType<UICapomastroManager>();
        m_CompleteTrigger = GameManager.GetObjectOfType<CompleteTrigger>();
        base.Awake();     
    }

    protected override void Init()
    {
        base.Init();
    }

    public override void InitializeSteps()
    {
        BaseMissionStep m_Vestizione = new BaseMissionStep(m_MissionData.StepsData[0], this);
    }

    public override MissionScore GetScore()
    {
        int exp = 0;
        if (IsCompleted())
            exp = m_MissionData.StepsData[0].ExperienceModifier;

        return new MissionScore(0,exp);
    }

    //controlla che l'abbigliamento sia equipaggiato 
    public override bool IsCompleted()
    {
        for (int i = 0; i < MissionManager.Instance.CurrentMissionData.StepsData[0].MissionStepObjects.Length; i++)
        {
            if (!MissionManager.Instance.CurrentMissionData.StepsData[0].MissionStepObjects[i].StepObject.m_IsUsing)
            {
                return false;
            }
        }
        return true;
    }

    //setta life and experience del Player
    public void SetPlayerLifeAndExp()
    {
        Player.Instance.PlayerExperience = (MissionManager.Instance.CurrentMissionData.StepsData[0].ExperienceModifier * MissionManager.Instance.CurrentMissionData.StepsData[0].MissionStepObjects.Length);
        if(MissionManager.Instance.CurrentMissionData.StepsData[0].LifeModifier != 0)
            Player.Instance.PlayerHealth -= MissionManager.Instance.CurrentMissionData.StepsData[0].LifeModifier;
        StartCoroutine(m_MasterBuilder.PlayAndSound(audioClipDressing, MissionManager.Instance.CurrentMissionData.StepsData[0].Sentences[2]));
    }

    //finalizza la missione registrandola come completata, salvando i dati del Player e caricando la nuova missione
    public override void FinalizeMission() 
    {
        MissionManager.Instance.IsOver = false;
        base.FinalizeMission();
    }

    //Visualizza i pannelli in ordine e attende per visualizzare il successivo
    //chiama capomastro e il pannello di missione completata e poi si disattiva
    protected override IEnumerator ShowSummary()
    {
        yield return WaitMissionOver();   
    }

    public IEnumerator WaitMissionOver()
    {
        while (!MissionManager.Instance.IsOver)
            yield return null;

        StartCoroutine( m_MasterBuilder.PlayAndSound(audioClipSuccess, MissionManager.Instance.CurrentMissionData.Sentences[1]));
        StartCoroutine(WaitForPanelSuccess());
    }

    public IEnumerator WaitForPanelSuccess()
    {
        m_MessageBox.gameObject.SetActive(true);
        m_MessageBox.InitMessageBox(MissionManager.Instance.CurrentMissionData.Sentences[3], "COMPLIMENTI");

        while (m_MessageBox.visible)
        {
            yield return null;
        }
        m_MessageBox.InitMessageBox(MissionManager.Instance.CurrentMissionData.StepsData[0].MissionStepObjects[0].PositiveFeedback, "TUTA PROTETTIVA");
        while (m_MessageBox.visible)
        {
            yield return null;
        }
        m_MessageBox.InitMessageBox(MissionManager.Instance.CurrentMissionData.StepsData[0].MissionStepObjects[1].PositiveFeedback, "CALZATURA DI SICUREZZA");
        while (m_MessageBox.visible)
        {
            yield return null;
        }
        m_MessageBox.InitMessageBox(MissionManager.Instance.CurrentMissionData.StepsData[0].MissionStepObjects[2].PositiveFeedback, "CASCO DI PROTEZIONE");
        while (m_MessageBox.visible)
        {
            yield return null;
        }
        MissionManager.Instance.SummaryCompleted();
    }

    //Visualizza i pannelli degli oggetti che non ha indossato invitando il Player a tornare allo Shelter
    public IEnumerator WaitForPanelUnsuccess()
    {
        StartCoroutine(m_MasterBuilder.PlayAndSound(audioClipUnsuccess, MissionManager.Instance.CurrentMissionData.Sentences[2]));
        m_MessageBox.gameObject.SetActive(true);
        if (!IsTutaActive())
        {
            m_MessageBox.InitMessageBox(MissionManager.Instance.CurrentMissionData.StepsData[0].MissionStepObjects[0].NegativeFeedback, "ABBIGLIAMENTO NON IDONEO");
            while (m_MessageBox.visible)
            {
                yield return null;
            }
        }

        if (!IsScarpeActive())
        {
            m_MessageBox.InitMessageBox(MissionManager.Instance.CurrentMissionData.StepsData[0].MissionStepObjects[1].NegativeFeedback, "ABBIGLIAMENTO NON IDONEO");
            while (m_MessageBox.visible)
            {
                yield return null;
            }
        }

        if (!IsElmettoActive())
        {
            m_MessageBox.InitMessageBox(MissionManager.Instance.CurrentMissionData.StepsData[0].MissionStepObjects[2].NegativeFeedback, "ABBIGLIAMENTO NON IDONEO");
            while (m_MessageBox.visible)
            {
                yield return null;
            }
        }
        m_CompleteTrigger.gameObject.SetActive(false);
    }

    #region Controlli singoli sui Props
    //Effettua controlli singoli sui Props
    public bool IsTutaActive()
    {
        if (MissionManager.Instance.CurrentMissionData.StepsData[0].MissionStepObjects[0].StepObject.m_IsUsing)
            return true;
        return false;
    }

    public bool IsScarpeActive()
    {
        if (MissionManager.Instance.CurrentMissionData.StepsData[0].MissionStepObjects[1].StepObject.m_IsUsing)
            return true;
        return false;
    }

    public bool IsElmettoActive()
    {
        if (MissionManager.Instance.CurrentMissionData.StepsData[0].MissionStepObjects[2].StepObject.m_IsUsing)
            return true;
        return false;
    }
    #endregion

    public override void OnRestartStateExecute(object sender,System.EventArgs args)
    {
        
    }
}

/***********SECONDO MODULO - MISSIONE SEGA CIRCOLARE***********/

/////////////////Board.cs/////////////////

using UnityEngine;
using RootMotion;
using System.Collections;
using RootMotion.Dynamics;

public class Board : InteractableObject
{
    public CircularSaw m_CircularSaw;
    public GameObject m_BoardPivotPosition;
    public WorkAreaTrigger m_WorkAreaTrigger;
    public GameObject m_HalfBoard_1;
    public GameObject m_HalfBoard_2;

    [SerializeField]
    BoardToCut m_BoardToCut;

    Transform CurrentTransform;

    public void OnEnable()
    {
        m_BoardToCut.OnObjectDropped += OnObjectDropped;
    }

    public override bool m_CanUse{ get{ return m_Usable && m_IsTaken && m_CircularSaw.CanCutBoard && m_WorkAreaTrigger.PlayerInWorkArea;}}

    public override bool m_CanTake{ get{ return base.m_CanTake && (m_DistanceFromPlayer <= 1.2f);}}

    protected override void Use()
    {
        gameObject.GetComponent<Rigidbody>().useGravity = false;
        gameObject.GetComponent<Rigidbody>().detectCollisions = false;
        m_IsUsing = true;
        Drop();

        m_Selectable = false;
        m_CircularSaw.SegaUse();
        gameObject.SetActive(false);
    }

    protected override void Take()
    {
        base.Take();
        m_CircularSaw.CurrentlyTakenBoard = this;
        m_CircularSaw.m_MissionCircularSaw.HideAllLabels();
    }

    protected override void Drop()
    {
        base.Drop();
        m_CircularSaw.m_MissionCircularSaw.ShowAllLabels();
    }

    public void ResetPosition()
    {
        transform.position = m_BoardPivotPosition.transform.position;
        transform.rotation = m_BoardPivotPosition.transform.rotation;
        gameObject.GetComponent<Rigidbody>().detectCollisions = true;
        gameObject.GetComponent<Rigidbody>().useGravity = true;

        gameObject.SetActive(true);

        m_IsUsing = false;
        m_IsTaken = false;

        if (!m_SegaCircolare.m_MissionCircularSaw.IsSawCompleted)
            m_Selectable = true;
    }    
}

/////////////////BoardToCut.cs/////////////////

using UnityEngine;
using RootMotion;
using System.Collections;
using RootMotion.Dynamics;
using UnityEngine.Events;
using RootMotion.FinalIK;

public class BoardToCut : InteractableObject
{
    public GameObject m_CutBoard_1;
    public GameObject m_CutBoard_2;
    public CircularSaw m_CircularSaw;
    public ParticleSystem m_ParticleSystem;
    public GameObject m_BoardPivot;
    public CutTrigger m_CutTrigger;

    [SerializeField]
    InteractionTarget RightHand;
    [SerializeField]
    InteractionTarget LeftHand;

    int m_BoardCount = 0;
    bool m_IsFirstTime = false;

    public int NumberOfBoardCut { get { return m_BoardCount; } set { m_BoardCount = value; } }

    WorkInjuries m_WorkInjuries;

    Vector3 m_CutBoard1Position;
    Quaternion m_CutBoard1Rotation;

    Vector3 m_CutBoard2Position;
    Quaternion m_CutBoard2Rotation;

    Vector3 m_translate;

    //resetto il numero di assi da segare
    void Awake()
    {
        m_WorkInjuries = GameManager.GetObjectOfType<MissionCircularSaw>().GetStep<WorkInjuries>();
        m_CutBoard1Position = m_CutBoard_1.transform.localPosition;
        m_CutBoard1Rotation = m_CutBoard_1.transform.localRotation;
        m_CutBoard2Position = m_CutBoard_2.transform.localPosition;
        m_CutBoard2Rotation = m_CutBoard_2.transform.localRotation;
        m_BoardCount = 0;
    }

    //mi metto in ascolto della pressione di tasti di movimento
    public void SetListeners(bool value)
    {
        if (value)
            InputManager.OnKeyAxisChanged += TranslateBoard;
        else
            InputManager.OnKeyAxisChanged -= TranslateBoard;
    }

    //muovo l'asse in avanti se avviene la pressione del tasto
    private void TranslateBoard(Vector3 translationVector)
    {
        if (translationVector.z > 0)
        {
           m_translate.x = translationVector.z; 
           m_IsFirstTime = false;
           TranslateAlongLocalZ(m_translate, m_CircularSaw.BoardSpeed);
        }
        
        //Nel caso in cui si interrompe la pressione quando si sta segando l'asse
        if (translationVector.z <= 0.1f && m_CircularSaw.IsCutting && !m_IsFirstTime)
        {
            m_WorkInjuries.BoardReject();
            m_CircularSaw.m_SchermoAttivo.Reset();
            m_IsFirstTime = true;
        }
    }

    public void InitBoard()
    {
        m_CutBoard_1.SetActive(true);
        m_CutBoard_2.SetActive(true);
    }

    //Taglio l'asse
    public void BoardIsCut()
    {
        StartCoroutine(SetHands(false));

        //disattivo l'input sull'asse
        SetListeners(false);

        //Controllo se è stata segata l'ultima asse e nel caso setta la missione a completata
        m_BoardCount += 1;
        if (m_BoardCount == m_CircularSaw.m_MissionCircularSaw.NumOfBoardsToCut)
            m_CircularSaw.m_MissionCircularSaw.IsSawCompleted = true;

        //disattivo il collider trigger
        gameObject.GetComponent<BoxCollider>().enabled = false;
        m_CutBoard_2.GetComponent<Rigidbody>().isKinematic = false;
        m_CutBoard_2.transform.Translate(0f, 0f, 0.025f);
        m_CutBoard_1.transform.Translate(0f, 0f, -0.01f);

        //Interrompo la segatura dell'asse
        m_CircularSaw.SegaInterrupt();

        //fermo le particelle che simulano le schegge 
        m_ParticleSystem.Stop();
        m_CircularSaw.StopAudio();

        StartCoroutine(ResetCuTBoard());
    }

    public void BoardInterruptByShortCircuit()
    {
        StartCoroutine(SetHands(false));

        //disattivo l'input sull'asse
        SetListeners(false);

        //Interrompo la segatura dell'asse
        m_CircularSaw.SegaInterrupt();

        //fermo le particelle che simulano le schegge 
        m_ParticleSystem.Stop();
        m_CircularSaw.StopAudio();
    }

    //resetto l'asse segata nella posizione iniziale 
    public void ResetBoard()
    {
        m_CircularSaw.IsCutting = false;
        m_CircularSaw.StopAudio();      //fermo l'audio
        m_CircularSaw.BoardSpeed = 150; //resetto la velocità del'asse
        m_ParticleSystem.Stop();        //fermo le particelle che simulano le schegge
        
        m_CutBoard_2.GetComponent<Rigidbody>().detectCollisions = false;
        m_CutBoard_2.GetComponent<Rigidbody>().isKinematic = true;
        transform.localPosition = m_BoardPivot.transform.localPosition;     //riposiziono l'asse
        transform.localRotation = m_BoardPivot.transform.localRotation;

        m_CutBoard_2.transform.localPosition = m_CutBoard2Position;
        m_CutBoard_2.transform.localRotation = m_CutBoard2Rotation;

        m_CutBoard_1.transform.localPosition = m_CutBoard1Position;
        m_CutBoard_1.transform.localRotation = m_CutBoard1Rotation;
        m_CutBoard_2.GetComponent<Rigidbody>().detectCollisions = true;

        //Nel caso l'asse sia stata rigettata 
        if (!m_CircularSaw.IsBoardRejected)
        {
           gameObject.GetComponent<BoxCollider>().enabled = true;
        }
        else
        {
            m_CircularSaw.IsBoardRejected = false;
        }
        m_CutTrigger.IsFirstTime = false;
    }

    //effettuo lo spostamento dell'asse in base alla direzione e alla velocità
    public void TranslateAlongLocalZ(Vector3 direction, float speed)
    {
        if (speed != 0)
        {
            gameObject.transform.Translate(direction / speed);
        }
        else
        {
            Debug.Log("Division by 0");
        }
    }

    public IEnumerator SetHands(bool value)
    {
        if (value)
        {
            yield return new WaitForSeconds(2f);
            SetListeners(true);
            Player.Instance.SetLeftHandEffector(LeftHand.transform);
            Player.Instance.SetRightHandEffector(RightHand.transform);
        }
        else
        {
            Player.Instance.ResetLeftHandEffector();
            Player.Instance.ResetRightHandEffector();
        }

    }

    public IEnumerator ResetCuTBoard()
    {
        yield return new WaitForSeconds(3);

        ResetBoard();
        m_CutBoard_1.SetActive(false);
        m_CutBoard_2.SetActive(false);
    }
}

/////////////////CutTrigger.cs/////////////////

using UnityEngine;
using System.Collections;

public class CutTrigger : MonoBehaviour 
{
    public CircularSaw m_CircularSaw;

    bool m_IsFirstTime = false;

    public bool IsFirstTime { get { return m_IsFirstTime; } set { m_IsFirstTime = value; } }

    void OnTriggerEnter(Collider other)
    {
        //se l'asse entra nel trigger viene segata
        if (other.gameObject == m_CircularSaw.m_BoardToCut.gameObject && !m_IsFirstTime){
            m_CircularSaw.IsCut = true;
            m_CircularSaw.m_BoardToCut.BoardIsCut();
            m_IsFirstTime = !m_IsFirstTime;
        }
    }
}

/////////////////GuantiDemolizione.cs/////////////////

using UnityEngine;
using System.Collections;

public class GuantiDemolizione: EquipableObject 
{
    public MovieTexture m_Video;
    public MovieTexture m_VideoRemove;

    bool mWearing = false;
    bool mRemoving = false;

    protected override void Use()
    {
        StartClip(true);
        base.Use();
        m_CanRemove = false;
        m_Selectable = false;
        gameObject.SetActive(false);
        Player.Instance.Guanti.SetActive(true);               //attiva i guanti (SkinnedMesh)
    }

    public void StartClip(bool val)
    {
        MediaManager.Instance.OnVideoPlay += OnPlay;
        MediaManager.Instance.OnVideoStop += OnStop;
        if (val)
        {
            mWearing = true;
            mRemoving = false;
            MediaManager.Instance.PlayVideo(m_Video);
        }
        else
        {
            mRemoving = true;
            mWearing = true;
            MediaManager.Instance.PlayVideo(m_VideoRemove);
        }
    }

    public void OnPlay()
    {
        Player.Instance.DisableAll();
    }

    public void OnStop()
    {
        Player.Instance.EnableAll();
        MediaManager.Instance.OnVideoPlay -= OnPlay;
        MediaManager.Instance.OnVideoStop -= OnStop;
    }

    public override void Reset()
    {
        base.Reset();

        gameObject.SetActive(true);
        Player.Instance.Guanti.SetActive(false);
    }
}

/////////////////OcchialiSega.cs/////////////////

using UnityEngine;
using System.Collections;

public class OcchialiSega : EquipableObject
{

    public Mesh m_WornMesh;
    public Mesh m_DroppedMesh;

    public MovieTexture m_Video;
    public MovieTexture m_VideoRemove;

    public MeshFilter m_Mesh{ get{ return GetComponent<MeshFilter>();}}

    bool mWearing = false;
    bool mRemoving = false;

    protected override void Use()
    {
        StartClip(true);
        gameObject.layer = m_EquipLayer;
        DestroyRigidbody();
        m_Mesh.mesh = m_WornMesh;
        m_CanRemove = false;
        m_Selectable = false;
        gameObject.SetActive(false);
    }

    public void StartClip(bool val)
    {
        MediaManager.Instance.OnVideoPlay += OnPlay;
        MediaManager.Instance.OnVideoStop += OnStop;
        if (val)
        {
            mWearing = true;
            mRemoving = false;
            MediaManager.Instance.PlayVideo(m_Video);
        }
        else
        {
            mRemoving = true;
            mWearing = true;
            MediaManager.Instance.PlayVideo(m_VideoRemove);
        }
    }

    public void OnPlay()
    {
        Player.Instance.DisableAll();
    }

    public void OnStop()
    {
        Player.Instance.EnableAll();
        MediaManager.Instance.OnVideoPlay -= OnPlay;
        MediaManager.Instance.OnVideoStop -= OnStop;
    }

    public override void Reset()
    {
        base.Reset();

        gameObject.SetActive(true);
        m_Mesh.mesh = m_DroppedMesh;
    }
}

/////////////////WorkAreaTrigger.cs/////////////////

using UnityEngine;
using System.Collections;

public class WorkAreaTrigger : MonoBehaviour
{
    public CircularSaw m_CircularSaw;
    bool m_PlayerInWorkArea = false;
    bool m_IsFirstTime = false;

    public bool PlayerInWorkArea { get { return m_PlayerInWorkArea; } set { m_PlayerInWorkArea = value; } }

    //quando entra nel trigger con l'aase e la sega attiva può iniziare la segatura
    void OnTriggerEnter(Collider other)
    {
        if (Player.Instance.gameObject == other.gameObject && !m_PlayerInWorkArea)
        {
            m_PlayerInWorkArea = true;
        }

        InteractableObject obj = Player.Instance.m_PickUp.ObjectPicked;
        Board board = obj as Board;
        if (board == null)
            return;

        if (Player.Instance.gameObject == other.gameObject && board.m_IsTaken && !m_CircularSaw.m_MissionCircularSaw.IsSawOn && !m_IsFirstTime)
        {
            StartCoroutine(GameManager.Instance.Master.PlayAndSound(null, m_CircularSaw.m_MissionCircularSaw.GetStep<CircularSawActivationStep>().StepData.Sentences[1]));
            m_IsFirstTime = true;
        }
    }

    void OnTriggerExit(Collider other)
    {
        if (Player.Instance.gameObject == other.gameObject)
        {
            m_PlayerInWorkArea = false;
        }
    }
}

/////////////////CircularSaw.cs/////////////////

using UnityEngine;
using System.Collections;

public class CircularSaw : MonoBehaviour
{
    //Camere
    protected GameObject m_MainCamera;
    public Camera m_SawCamera;

    //Audio
    private AudioSource source;
    public AudioClip m_SawAudioclip;

    public MissionCircularSaw m_MissionCircularSaw;
    public BoardToCut m_BoardToCut;
    public GameObject m_SawCuttingPosition;
    public Board m_Board;
    public SegaCircolareSchermoAttivo m_SchermoAttivo;
    public SegaCircolareSchermo m_SegaCircolareSchermo;

    PlayerPositionSetter setter;        //per settare la posizione del Player

    //Eventi
    public delegate void SawEvent();
    public event SawEvent OnSawActivation;
    public event SawEvent OnSawDeactivation;

    bool m_IsCutting = false;
    bool m_IsCut = false;
    float m_BoardSpeed = 150;
    bool m_IsBoardRejected = false;
    bool m_CanCutBoard = false;

    public bool IsBoardRejected { get { return m_IsBoardRejected; } set { m_IsBoardRejected = value; } }
    public bool IsCutting { get { return m_IsCutting; } set { m_IsCutting = value; } }
    public bool IsCut { get { return m_IsCut; } set { m_IsCut = value; } }
    public bool CanCutBoard { get { return m_CanCutBoard; } set { m_CanCutBoard = value; } }

    public float BoardSpeed { get { return m_BoardSpeed; } set { m_BoardSpeed = value; } }
    public Board CurrentlyTakenBoard{ get { return m_Board; } set { m_Board = value; } }


    //Prendo le referenze di cui ho bisogno
    void Awake()
    {
        source = GetComponent<AudioSource>();
        setter = GameManager.GetObjectOfType<PlayerPositionSetter>();
    }

    public void SegaUse()
    {
        //attivo l'asse che prima non era visibile
        if (!m_BoardToCut.m_CutBoard_1.activeInHierarchy)
            m_BoardToCut.m_CutBoard_1.SetActive(true);
        if (!m_BoardToCut.m_CutBoard_2.activeInHierarchy)
            m_BoardToCut.m_CutBoard_2.SetActive(true);

        //Setto la posizione del Player
        Player.Instance.DisableAll();
        Player.Instance.TurnOff();
        setter.SetPlayerPostionRotation(m_SawCuttingPosition.transform.position, m_SawCuttingPosition.transform.rotation);

        //Faccio il cambio di Camera
        m_MainCamera = CameraManager.Instance.CurrentUsedCamera;
        m_MainCamera.SetActive(false);
        m_SawCamera.gameObject.SetActive(true);
        TargetController.Instance.RegisterInputs(false);

        //Nascondo tutte le label degli oggetti utilizzabili
        m_MissionCircularSaw.HideAllLabels();

        //Inizializzo l'asse da segare e la protezione della lama se inserita
        m_BoardToCut.InitBoard();
        StartCoroutine(m_BoardToCut.SetHands(true));

        if(m_SchermoAttivo.gameObject.activeInHierarchy)
            m_SchermoAttivo.Reset();
    }

    public void SegaInterrupt()
    {
        //In caso ci siano altre assi da segare
        if(!m_MissionCircularSaw.IsSawCompleted)
            StartCoroutine(MakePlayerWait());

        //Faccio il cambio di Camera
        m_SawCamera.gameObject.SetActive(false);
        m_MainCamera.SetActive(true);
    }

    //Riattivo il Player
    IEnumerator MakePlayerWait()
    {
        yield return new WaitForSeconds(1.5f);
        Player.Instance.EnableAll();
        Player.Instance.TurnOn();
        TargetController.Instance.RegisterInputs(true);
        m_MissionCircularSaw.ShowAllLabels();
        if (m_MissionCircularSaw.IsSawOn)
             m_SegaCircolareSchermo.Selectable = false;
    }

    //eventi di attivazione della sega circolare
    public void SawActivation()
    {
        if (OnSawActivation != null)
            OnSawActivation();
    }

    public void SawDeactivation()
    {
        if (OnSawDeactivation != null)
            OnSawDeactivation();
    }

    //Audio della lama che taglia l'asse
    public void PlayAudio()
    {
        if (m_SawAudioclip != null && source != null)
        {
            source.clip = m_SawAudioclip;
            source.loop = true;
            source.Play();
        }
    }

    public void StopAudio()
    {
        if (source != null)
            source.Stop();
    }

    public void ResetSaw()
    {
        StopAudio();

        m_BoardToCut.NumberOfBoardCut = 0;
        m_BoardToCut.SetListeners(false);
        StartCoroutine(m_BoardToCut.SetHands(false));
        m_BoardToCut.ResetBoard();
        m_BoardToCut.m_CutBoard_1.SetActive(false);
        m_BoardToCut.m_CutBoard_2.SetActive(false);

        m_Board.Selectable = true;
    }
}

/////////////////SegaCircolareActivation.cs/////////////////

using UnityEngine;
using System.Collections;

public class SegaCircolareActivation : InteractableObject
{
    public CircularSaw m_CircularSaw;
    public SegaCircolareLama m_SegaCircolareLama;
    public SegaCircolareSchermo m_SegaCircolareSchermo;
    public GameObject m_SchermoMontato;

    //Attivo la sega circolare facendo ruotare la lama
    protected override void Use()
    {
        if (!m_SchermoMontato.gameObject.activeInHierarchy)      //non puoi inserire la protezione della lama
            m_SegaCircolareSchermo.Selectable = false;        //se la sega è attiva
        m_SegaCircolareLama.StartRotate();
        m_CircularSaw.SawActivation();                          //evento di attivazione della sega
    }

    //spengo la sega circolare e fermo la rotazione della lama
    protected override void Interrupt()
    {
        if (!m_SchermoMontato.gameObject.activeInHierarchy)
            m_SegaCircolareSchermo.Selectable = true;     
        m_SegaCircolareLama.StopRotate();
        m_CircularSaw.SawDeactivation();
    }
}

/////////////////SegaCircolareCuffie.cs/////////////////

using UnityEngine;
using System.Collections;

public class SegaCircolareCuffie : EquipableObject
{
    public MovieTexture m_Video;
    public MovieTexture m_VideoRemove;

    bool mWearing = false;
    bool mRemoving = false;

    protected override void Use()
    {
        StartClip(true);
        base.Use();
        m_CanRemove = false;
        m_Selectable = false;
        gameObject.SetActive(false);
        Player.Instance.Cuffie.SetActive(true);
    }

    public void StartClip(bool val)
    {
        MediaManager.Instance.OnVideoPlay += OnPlay;
        MediaManager.Instance.OnVideoStop += OnStop;
        if (val)
        {
            mWearing = true;
            mRemoving = false;
            MediaManager.Instance.PlayVideo(m_Video);
        }
        else
        {
            mRemoving = true;
            mWearing = true;
            MediaManager.Instance.PlayVideo(m_VideoRemove);
        }
    }

    public void OnPlay()
    {
        Player.Instance.DisableAll();
    }

    public void OnStop()
    {
        Player.Instance.EnableAll();
        MediaManager.Instance.OnVideoPlay -= OnPlay;
        MediaManager.Instance.OnVideoStop -= OnStop;
    }

    public override void Reset()
    {
        base.Reset();

        gameObject.SetActive(true);
        Player.Instance.Cuffie.SetActive(false);
    }
}

/////////////////SegaCircolareLama.cs/////////////////

using UnityEngine;
using System.Collections;

public class SegaCircolareLama : MonoBehaviour
{
    [SerializeField]
    Animator anim;

    public BoardToCut m_BoardToCut;
    public ParticleSystem m_ParticleSystem;
    public CircularSaw m_CircularSaw;
    public GameObject m_SchermoLama;

    //Avvia l'animazione di rotazione della lama della sega
    public void StartRotate()
    {
        anim.SetBool("Start", true);
    }

    //ferma l'animazione
    public void StopRotate()
    {
        anim.SetBool("Start", false);
    }

    //quando collide con l'asse simula la segatura della stessa
    void OnTriggerEnter(Collider other)
    {
        if (!m_CircularSaw.IsCutting && other.gameObject == m_BoardToCut.gameObject)
        {
            if (!m_SchermoLama.activeInHierarchy)   //visualizzo schegge solo nel caso in cui
                m_ParticleSystem.Play();            //non è stata inserita la protezione della lama
            m_CircularSaw.PlayAudio();
            m_CircularSaw.BoardSpeed = 500;         //rallento il movimento dell'asse per simulare il taglio
            m_CircularSaw.IsCutting = true;
        }
    }
}

/////////////////SegaCircolareSchermo.cs/////////////////

using UnityEngine;
using System.Collections;

public class SegaCircolareSchermo : InteractableObject
{
    public SegaCircolareSchermoAttivo m_SchermoMontato;
    public GameObject m_SchermoBraccetto;

    //Inserisce la protezione della lama
    protected override void Use()
    {
        m_SchermoMontato.gameObject.SetActive(true);
        gameObject.GetComponent<MeshRenderer>().enabled = false;
        gameObject.GetComponent<BoxCollider>().enabled = false;
        m_SchermoBraccetto.GetComponent<MeshRenderer>().enabled = false;
    }

    public void ResetSchermo()
    {
        m_SchermoMontato.gameObject.SetActive(false);
        m_SchermoMontato.Reset();
        gameObject.GetComponent<MeshRenderer>().enabled = true;
        gameObject.GetComponent<BoxCollider>().enabled = true;
        m_SchermoBraccetto.GetComponent<MeshRenderer>().enabled = true;
    }
    
}

/////////////////SegaCircolareSchermoAttivo.cs/////////////////

using UnityEngine;
using System.Collections;

public class SegaCircolareSchermoAttivo : MonoBehaviour 
{
    public GameObject m_pivot;
    public BoardToCut m_BoardToCut;
    private float speed = 50f;

    private Quaternion rot;

    void Awake()
    {
        rot = transform.rotation;
    }

    void OnTriggerStay(Collider other)
    {
        if (other.gameObject == m_BoardToCut.gameObject)
        {
            transform.RotateAround(m_pivot.transform.position, Vector3.left, speed * Time.deltaTime);
        }
    }

    public void Reset()
    {
        transform.rotation = rot;
    }
}

/////////////////MissionCircularSaw.cs/////////////////

using UnityEngine;
using System.Collections;
using UiGraphics;

public class MissionCircularSaw : Mission
{
    [SerializeField]
    CircularSaw m_CircularSaw;

    [SerializeField]
    public ParticleSystem m_ParticleSystem;

    [SerializeField]
    SegaCircolareLama m_SegaCircolareLama;

    MessageBox m_MessageBox;

    bool m_IsSawOn = false;
    bool m_PlayerDead = false;
    bool m_MissionCompleted = false;
    bool m_IsSawCompleted = false;

    [SerializeField]
    int m_ShortCirtcuitProbability = 0;      //probabilità che avvenga il corto circuito
    [SerializeField]
    int m_TimeToWaitShortCircuit = 1;    //tempo di attesa per far si che si generi il corto circuito
    [SerializeField]
    int m_SplinterProbability = 0;           //probabilità che venga generata una scheggia
    [SerializeField]
    int m_BoardRejectProbability= 100;            //probabilità che avvenga il rigetto dell'asse
    [SerializeField]
    protected int m_NumOfBoardsToCut;        //Numero di assi da tagliare per superare la missione

    public int NumOfBoardsToCut { get { return m_NumOfBoardsToCut; } set { m_NumOfBoardsToCut = value; } }
    public int ShortCirtcuitProbability { get { return m_ShortCirtcuitProbability; } set { m_ShortCirtcuitProbability = value; } }
    public int ShortCircuitTimeToWait { get { return m_TimeToWaitShortCircuit; } set { m_TimeToWaitShortCircuit = value; } }
    public int SplinterProbability { get { return m_SplinterProbability; } set { m_SplinterProbability = value; } }
    public int BoardRejectProbability { get { return m_BoardRejectProbability; } set { m_BoardRejectProbability = value; } }

    public bool IsSawCompleted { get { return m_IsSawCompleted; } set { m_IsSawCompleted = value; } }
    public bool IsPlayerDead { get { return m_PlayerDead; } set { m_PlayerDead = value; } }
    public bool IsMissionCompleted { get { return m_MissionCompleted; } set { m_MissionCompleted = value; } }
    public bool IsSawOn { get { return m_IsSawOn; } }

    public CircularSaw CircularSaw { get { return m_CircularSaw; } }


    protected override void Init()
    {
        base.Init();
        m_CircularSaw.OnSawActivation += SawActive;
        m_CircularSaw.OnSawDeactivation += SawDeactive;
        m_MessageBox = GameManager.GetObjectOfType<MessageBox>();
    }

    public override void InitializeSteps()
    {
        GoToCircularSawAreaStep m_SegaCircolare = new GoToCircularSawAreaStep(m_MissionData.StepsData[0], this);
        BaseMissionStep m_WearDPI = new BaseMissionStep(m_MissionData.StepsData[1], this);
        CircularSawActivationStep m_CircularSawActivation = new CircularSawActivationStep(m_MissionData.StepsData[2], this);
        WorkInjuries m_WorkInjuries = new WorkInjuries(m_MissionData.StepsData[3], this);
        CircularSawCuttingStep m_CircularSawCuttingStep = new CircularSawCuttingStep(m_MissionData.StepsData[4], this);
    }

    public override bool IsCompleted()
    {
        return false;
    }

    public override MissionScore GetScore()
    {
        int exp = 0, life = 0;
        for (int i = 0; i < m_MissionSteps.Count; i++)
        {
            exp += m_MissionSteps[i].GetScore().ExperiencePoints;
            life += m_MissionSteps[i].GetScore().LifePoints;
        }
        return new MissionScore(life, exp);
    }

    public bool CheckProps()
    {
        //check sui props
        for (int i = 0; i < m_MissionData.StepsData[1].MissionStepObjects.Length; i++)
        {
            if (!m_MissionData.StepsData[1].MissionStepObjects[i].StepObject.m_IsUsing)
                return false;
        }
        return true;
    }

    public override void OnRestartStateExecute(object sender, System.EventArgs args)
    {
        
    }

    private void SawActive()
    {
        m_IsSawOn = true;
        m_CircularSaw.CanCutBoard = true;
    }


    private void SawDeactive()
    {
        m_IsSawOn = false;
        m_CircularSaw.CanCutBoard = false;
    }

    public void HideAllLabels()
    {
        for (int i = 0; i < m_MissionData.StepsData.Count; i++)
        {
            for (int j = 0; j < m_MissionData.StepsData[i].MissionStepObjects.Length; j++)
            {
                m_MissionData.StepsData[i].MissionStepObjects[j].StepObject.Selectable = false;
            }
        }
        m_CircularSaw.m_Board.Selectable = false;
    }

    public void ShowAllLabels()
    {
        for (int i = 0; i < m_MissionData.StepsData.Count; i++)
        {
            for (int j = 0; j < m_MissionData.StepsData[i].MissionStepObjects.Length; j++)
            {
                m_MissionData.StepsData[i].MissionStepObjects[j].StepObject.Selectable = true;
            }
        }
        m_CircularSaw.m_Board.Selectable = true;
    }

    public void PlayerIsDead()
    {
        Player.Instance.Die();
        Player.Instance.PlayerHealth = 0;
        MissionManager.Instance.Success = false;
        MissionManager.Instance.CompleteMission();
    }


    public override void FinalizeMission()
    {
        HideAllLabels();

        if (m_PlayerDead || Player.Instance.PlayerHealth <= 0)
        {
            if (m_CircularSaw.m_SawCamera.gameObject.activeInHierarchy)
                m_CircularSaw.m_SawCamera.gameObject.SetActive(false);
            m_PlayerDead = true;
            PlayerIsDead();
        }

        base.FinalizeMission();
    }

    protected override IEnumerator ShowSummary()
    {
        yield return WaitMissionOver();
    }

    public IEnumerator WaitMissionOver()
    {
        while (!MissionManager.Instance.IsOver)
            yield return null;

        StartCoroutine(WaitForPanels());
    }

    IEnumerator WaitForPanels()
    {
        while (m_MessageBox.visible)
        {
            yield return null;
        }

        m_MessageBox.gameObject.SetActive(true);

        if (m_MissionSteps[1].MissionStepObjects[0].StepObject.m_IsUsing)
            m_MessageBox.InitMessageBox(m_MissionSteps[1].MissionStepObjects[0].PositiveFeedback, "OCCHIALI PROTETTIVI");
        else
            m_MessageBox.InitMessageBox(m_MissionSteps[1].MissionStepObjects[0].NegativeFeedback, "OCCHIALI PROTETTIVI");
        while (m_MessageBox.visible)
        {
            yield return null;
        }

        if (m_MissionSteps[1].MissionStepObjects[1].StepObject.m_IsUsing)
            m_MessageBox.InitMessageBox(m_MissionSteps[1].MissionStepObjects[1].PositiveFeedback, "GUANTI DEMOLIZIONE");
        else
            m_MessageBox.InitMessageBox(m_MissionSteps[1].MissionStepObjects[1].NegativeFeedback, "GUANTI DEMOLIZIONE");
        while (m_MessageBox.visible)
        {
            yield return null;
        }

        if (m_MissionSteps[1].MissionStepObjects[2].StepObject.m_IsUsing)
            m_MessageBox.InitMessageBox(m_MissionSteps[1].MissionStepObjects[2].PositiveFeedback, "CUFFIE PROTETTIVE");
        else
            m_MessageBox.InitMessageBox(m_MissionSteps[1].MissionStepObjects[2].NegativeFeedback, "CUFFIE PROTETTIVE");
        while (m_MessageBox.visible)
        {
            yield return null;
        }

        if (m_MissionSteps[2].MissionStepObjects[1].StepObject.m_IsUsing)
            m_MessageBox.InitMessageBox(m_MissionSteps[2].MissionStepObjects[1].PositiveFeedback, "PROTEZIONE LAMA");
        else
            m_MessageBox.InitMessageBox(m_MissionSteps[2].MissionStepObjects[1].NegativeFeedback, "PROTEZIONE LAMA");
        while (m_MessageBox.visible)
        {
            yield return null;
        }

        GameManager.Instance.Master.gameObject.SetActive(false);
        MissionManager.Instance.SummaryCompleted();
    }

    public override void ResetMission()
    {
        m_IsSawOn = false;
        m_PlayerDead = false;
        m_MissionCompleted = false;
        m_IsSawCompleted = false;

        m_CircularSaw.ResetSaw();
        
        m_SegaCircolareLama.StopRotate();
        
        m_CircularSaw.m_SegaCircolareSchermo.ResetSchermo();

        base.ResetMission();
    }
}

/////////////////MissionCircularSawSteps.cs/////////////////

using UnityEngine;
using System.Collections;

[System.Serializable]
public class GoToCircularSawAreaStep : BaseMissionStep
{
    /*Questo step semplicemente aspetta che il player entra nell'area di lavoro per assegnare punti esperienza e avvisa sulla pericolosità 
   * della sega circolare*/

    bool m_InArea;

    public GoToCircularSawAreaStep(MissionStepData stepdata, Mission owner) : base(stepdata, owner)
    {

    }

    public override void InitStep()
    {
        //m_Owner.StartCoroutine(WaitForEnterArea());
        m_InArea = false;
        WorkingArea area = m_Owner.GetWorkingArea(0);
        area.OnPlayerTriggerEnter += EnterInArea;
    }

    public override bool IsCompleted()
    {
        return m_InArea;
    }

    public override MissionScore GetScore()
    {
        if(m_InArea)
            return new MissionScore(0, m_MissionStepData.ExperienceModifier);
        else
            return new MissionScore(0, 0);
    }

    //metodo chiamato appena il player entra nell'area di lavoro per la prima volta
    public void EnterInArea()
    {
        m_InArea = true;
        m_Owner.StartCoroutine(GameManager.Instance.Master.PlayAndSound(null, m_MissionStepData.Sentences[1]));

        Player.Instance.PlayerExperience += m_MissionStepData.ExperienceModifier;
        WorkingArea area = m_Owner.GetWorkingArea(0);
        area.OnPlayerTriggerEnter -= EnterInArea;
    }

    public override void ResetStep()
    {
        WorkingArea area = m_Owner.GetWorkingArea(0);
        area.OnPlayerTriggerEnter -= EnterInArea;
        m_InArea = false;

        base.ResetStep();
    }
}

[System.Serializable]
public class CircularSawActivationStep : BaseMissionStep
{
    /*Questo step controlla l'attivazione della sega circolare e avvia e ferma le coroutine che gestiscono i possibili infortuni
    * descritti nello step WorkInjuries.
    * controlla se la sega è stata attivata in maniere corretta in sicurezza e assegna i dovuti exp*/

    bool m_IsSawActivatedCorrectly;
    bool m_IsSawSafe;
    bool m_AreAllPropsOn;
    int m_PropsCnt;

    WorkInjuries m_WorkInjuries;

    public Coroutine m_RandomShortCircuit;
    public Coroutine m_RandomSplinterToTheEye;
    public Coroutine m_WaitForSawCorrectActivation;

    public bool IsSawSafe { get { return m_IsSawSafe; } set { m_IsSawSafe = value; } }

    public CircularSawActivationStep(MissionStepData stepdata, Mission owner) : base(stepdata, owner)
    {

    }

    public override void InitStep()
    {
        m_IsSawActivatedCorrectly = false;
        m_WaitForSawCorrectActivation = m_Owner.StartCoroutine(WaitForSawCorrectActivation());
        m_WorkInjuries = m_Owner.GetStep<WorkInjuries>();
    }

    public override bool IsCompleted()
    {
        return m_IsSawActivatedCorrectly;
    }

    public override MissionScore GetScore()
    {
        if (m_IsSawActivatedCorrectly)
            return new MissionScore(0, m_MissionStepData.ExperienceModifier);
        else
            return new MissionScore(0, 0);
    }

    IEnumerator WaitForSawCorrectActivation()
    {
        CircularSaw m_sega = ((MissionCircularSaw)m_Owner).CircularSaw;
        m_sega.OnSawActivation += SawActivation;
        m_sega.OnSawDeactivation += SawDeactivation;
        yield return new WaitUntil(() => m_IsSawActivatedCorrectly == true);

        m_Owner.StartCoroutine(GameManager.Instance.Master.PlayAndSound(null, m_MissionStepData.Sentences[0]));

        Player.Instance.PlayerExperience += m_MissionStepData.ExperienceModifier;
    }

    private void SawActivation()
    {
        if(!m_WorkInjuries.SawInShortCircuit)
            m_RandomShortCircuit = m_Owner.StartCoroutine(m_WorkInjuries.RandomSawShortCircuit());
        m_RandomSplinterToTheEye = m_Owner.StartCoroutine(m_WorkInjuries.RandomSplinterToTheEye());

        if (CheckAllProps() && m_MissionStepData.MissionStepObjects[1].StepObject.m_IsUsing)
            m_IsSawActivatedCorrectly = true;
    }

    private void SawDeactivation()
    {
        m_Owner.StopCoroutine(m_RandomShortCircuit);
        m_Owner.StopCoroutine(m_RandomSplinterToTheEye);
    }

    public bool CheckAllProps()
    {
        for (int i = 0; i < m_Owner.GetDataByName("WearDPI").MissionStepObjects.Length; i++)
        {
            if (!m_Owner.GetDataByName("WearDPI").MissionStepObjects[i].StepObject.m_IsUsing)
                return false;
        }
        return true;
    }

    public override void ResetStep()
    {
        SawDeactivation();
        ((MissionCircularSaw)m_Owner).CircularSaw.OnSawActivation -= SawActivation;
        ((MissionCircularSaw)m_Owner).CircularSaw.OnSawDeactivation -= SawDeactivation;
        m_Owner.StopCoroutine(m_WaitForSawCorrectActivation);

        m_IsSawActivatedCorrectly = false;
        m_IsSawSafe = false;
        m_AreAllPropsOn = false;
        m_PropsCnt = 0;

        base.ResetStep();
    }
}

[System.Serializable]
public class WorkInjuries : BaseMissionStep
{
    /*Questo step gestisce gli infortuni come il corto circuito e le schegge che possono infortunare il player fino alla morte*/

    public int m_ShortCircuitSeconds = 10;      //tempo di attesa per fermare la sega prima che il player riceva la scossa in caso di corto circuito
    public int m_TimeToWaitforSawDeactivated = 3;   //Tempo di attesa per controllare se viene attivata la sega quando è in corto circuito
    bool m_IsSawInShortCircuit = false;
    bool m_FirstTimeBoardReject = true;

    public Coroutine m_SawActivatedOnShortCircuit;

    WorkAreaTrigger m_SawArea;
    CircularSawActivationStep m_CircularSawActivationStep;

    public bool SawInShortCircuit { get { return m_IsSawInShortCircuit; } set { m_IsSawInShortCircuit = value; } }

    public WorkInjuries(MissionStepData stepdata, Mission owner) : base(stepdata, owner)
    {

    }

    public override void InitStep()
    {
        m_CircularSawActivationStep = m_Owner.GetStep<CircularSawActivationStep>();
        m_SawArea = GameManager.GetObjectOfType<WorkAreaTrigger>();
    }

    #region ShortCircuit
    //coroutine che gestisce il corto circuito della sega
    public IEnumerator RandomSawShortCircuit()
    {
        CircularSaw m_sega = ((MissionCircularSaw)m_Owner).CircularSaw;
        m_sega.OnSawDeactivation += SawDeactivated; //mi metto in ascolto dell'evento di disattivazione sega

        yield return new WaitForSeconds(((MissionCircularSaw)m_Owner).ShortCircuitTimeToWait);  //attendo tot secondi per simulare il corto

        int m_probability = Random.Range(0, 100);        //numero casuale per il calcolo delle probabilità

        if (((MissionCircularSaw)m_Owner).IsSawOn && m_probability < ((MissionCircularSaw)m_Owner).ShortCirtcuitProbability)        //in caso la sega è accesa
        {
            ((MissionCircularSaw)m_Owner).CircularSaw.m_BoardToCut.BoardInterruptByShortCircuit();
            m_Owner.StartCoroutine((((MissionCircularSaw)m_Owner).CircularSaw.m_BoardToCut.SetHands(false)));

            m_IsSawInShortCircuit = true;
            ShortCircuitParticles(true);        //visualizzo scintille
            m_Owner.StartCoroutine(GameManager.Instance.Master.PlayAndSound(null, m_MissionStepData.Sentences[0])); //avviso il player dell'imminente corto
        }
        else
        {
            m_sega.OnSawDeactivation -= SawDeactivated;     //nel caso le probabilità non sia soddisfatte o la sega è spenta esco
            yield break;
        }

        m_sega.OnSawActivation += SawActivated;      //mi metto in ascolto dell'evento di deattivazione della sega
        yield return new WaitForSeconds(m_ShortCircuitSeconds);     //attendo tot secondi (in cui il player dovrà spegnere la sega), altrimenti avverrà il corto circuito

        if (((MissionCircularSaw)m_Owner).IsSawOn)     //se il player non spegne la sega circolare
        {
            //riceve scossa e muore
            m_sega.OnSawActivation -= SawActivated;
            m_Owner.StartCoroutine(GameManager.Instance.Master.PlayAndSound(null, m_MissionStepData.Sentences[1]));
            ((MissionCircularSaw)m_Owner).IsPlayerDead = true;
            MissionManager.Instance.Success = false;
            MissionManager.Instance.CompleteMission();
        }
    }

    private void SawActivated()
    {
        //nel caso il player riattiva la sega dopo averla spenta per corto circuito muore
        CircularSaw m_sega = ((MissionCircularSaw)m_Owner).CircularSaw;
        m_sega.OnSawActivation -= SawActivated;
        m_Owner.StopCoroutine(m_SawActivatedOnShortCircuit);

        m_Owner.StartCoroutine(GameManager.Instance.Master.PlayAndSound(null, m_MissionStepData.Sentences[4]));
        ((MissionCircularSaw)m_Owner).IsPlayerDead = true;
        MissionManager.Instance.Success = false;
        MissionManager.Instance.CompleteMission();
    }

    private void SawDeactivated()
    {
        ShortCircuitParticles(false);       //spengo le scintille
        if (m_IsSawInShortCircuit)
            m_SawActivatedOnShortCircuit = m_Owner.StartCoroutine(SawActivatedOnShortCircuit());

    }

    //Il player ha spento la sega. Controllo che non la riaccenda per almeno tot secondi
    IEnumerator SawActivatedOnShortCircuit()
    {
        CircularSaw m_sega = ((MissionCircularSaw)m_Owner).CircularSaw;
        m_sega.OnSawDeactivation -= SawDeactivated;
        yield return new WaitForSeconds(m_TimeToWaitforSawDeactivated);     //attendo tot secondi, nel caso il player attivi la sega si verifica l'evento e il player muore per scossa
        m_sega.OnSawActivation -= SawActivated;
        //La missione termina con Successo
        m_Owner.StartCoroutine(GameManager.Instance.Master.PlayAndSound(null, m_MissionStepData.Sentences[3])); 
        MissionManager.Instance.Success = true;
        MissionManager.Instance.CompleteMission();
    }

    public void ShortCircuitParticles(bool value)
    {
        //Le scintille sono simulate con un particle system
        if (value)
        {
            ((MissionCircularSaw)m_Owner).m_ParticleSystem.Play();
        }
        else
        {
            ((MissionCircularSaw)m_Owner).m_ParticleSystem.Stop();
        }
    }
    #endregion

    #region Splinter
    //Coroutine che gestisce le schegge della sega in caso manchino occhiali protettivi o protezione della lama della sega
    public IEnumerator RandomSplinterToTheEye() 
    {
        int m_probability = Random.Range(0, 100);        //numero casuale per il calcolo delle probabilità
        float m_RandomWaitSec = Random.Range(0f, 2f);    //numero casuale per attesa della scheggia

        yield return new WaitUntil(() => ((MissionCircularSaw)m_Owner).CircularSaw.IsCutting);
        yield return new WaitForSeconds(m_RandomWaitSec);

        //Se la sega è accesa e il player è in prossimità di essa e la sta usando
        if (((MissionCircularSaw)m_Owner).CircularSaw.IsCutting && m_probability < ((MissionCircularSaw)m_Owner).SplinterProbability)
        {
            //se ha gli occhiali ma non ha inserito la protezione della lama
            if (m_Owner.GetDataByName("WearDPI").MissionStepObjects[0].StepObject.m_IsUsing && !m_CircularSawActivationStep.MissionStepObjects[1].StepObject.m_IsUsing)
            {
                SplinterToTheEye();     //simulo la scheggia
                Player.Instance.PlayerHealth -= m_MissionStepData.LifeModifier * 2; //il player perde vita
                if (Player.Instance.PlayerHealth <= 0)      //se muore
                {
                    ((MissionCircularSaw)m_Owner).IsPlayerDead = true;
                    MissionManager.Instance.Success = false;
                    MissionManager.Instance.CompleteMission();
                }
                m_Owner.StartCoroutine(GameManager.Instance.Master.PlayAndSound(null, string.Format(m_MissionStepData.Sentences[5], (m_MissionStepData.LifeModifier * 2))));
            }
            // se non ha gli occhiali protettivi ma ha inserito la protezione della lama
            else if (!m_Owner.GetDataByName("WearDPI").MissionStepObjects[0].StepObject.m_IsUsing && m_CircularSawActivationStep.MissionStepObjects[1].StepObject.m_IsUsing)
            {
                SplinterToTheEye();     //simulo la scheggia
                Player.Instance.PlayerHealth -= m_MissionStepData.LifeModifier * 2; //il player perde vita
                if (Player.Instance.PlayerHealth <= 0)     //se muore
                {
                    ((MissionCircularSaw)m_Owner).IsPlayerDead = true;
                    MissionManager.Instance.Success = false;
                    MissionManager.Instance.CompleteMission();
                }
                m_Owner.StartCoroutine(GameManager.Instance.Master.PlayAndSound(null, string.Format(m_MissionStepData.Sentences[6], (m_MissionStepData.LifeModifier * 2))));
            }
            //se non ha ne occhiali e non ha inserito la protezione della lama muore
            else if (!m_Owner.GetDataByName("WearDPI").MissionStepObjects[0].StepObject.m_IsUsing && !m_CircularSawActivationStep.MissionStepObjects[1].StepObject.m_IsUsing)
            {
                SplinterToTheEye();
                m_Owner.StartCoroutine(GameManager.Instance.Master.PlayAndSound(null, m_MissionStepData.Sentences[7]));
                ((MissionCircularSaw)m_Owner).IsPlayerDead = true;
                MissionManager.Instance.Success = false;
                MissionManager.Instance.CompleteMission();
            }
        }
        else
        {
            yield break;
        }
    }

    private void SplinterToTheEye()
    {
        //generate a splinter
    }
    #endregion

    #region Board Rejection
    public void BoardReject()
    {
        float speed = 1f;
        speed = speed * Time.deltaTime;
        Vector3 direction = new Vector3(0f, 0f, -50f);

        int randomNumber = Random.Range(0, 100);        //numero casuale per il calcolo delle probabilità

        if (((MissionCircularSaw)m_Owner).CircularSaw.IsCutting && randomNumber < ((MissionCircularSaw)m_Owner).BoardRejectProbability)
        {
            ((MissionCircularSaw)m_Owner).CircularSaw.m_BoardToCut.transform.position = Vector3.MoveTowards(((MissionCircularSaw)m_Owner).CircularSaw.m_BoardToCut.transform.position, ((MissionCircularSaw)m_Owner).CircularSaw.m_BoardToCut.m_BoardPivot.transform.position, speed);

            if (((MissionCircularSaw)m_Owner).CircularSaw.IsCutting && !((MissionCircularSaw)m_Owner).CircularSaw.IsBoardRejected)
            {
                Player.Instance.PlayerHealth -= m_MissionStepData.LifeModifier;
                ((MissionCircularSaw)m_Owner).CircularSaw.IsBoardRejected = true;
                if (Player.Instance.PlayerHealth <= 0)      //se muore
                {
                    ((MissionCircularSaw)m_Owner).IsPlayerDead = true;
                    MissionManager.Instance.Success = false;
                    MissionManager.Instance.CompleteMission();
                }
                else if (m_FirstTimeBoardReject)
                {
                    m_Owner.StartCoroutine(GameManager.Instance.Master.PlayAndSound(null, m_MissionStepData.Sentences[8]));
                    m_FirstTimeBoardReject = false;
                }
                ((MissionCircularSaw)m_Owner).CircularSaw.m_BoardToCut.ResetBoard();
            }
        }
    }
    #endregion

    public override void ResetStep()
    {
        m_IsSawInShortCircuit = false;
        ShortCircuitParticles(false);

        base.ResetStep();
    }
}

[System.Serializable]
public class CircularSawCuttingStep : BaseMissionStep
{
    /*Questo step attende la conclusione della missione che consiste nella segatura di 10 assi di legno.
     * Quando questo avviene viene completata la missione con relativa assegnazione di punti esperienza*/

    CircularSawActivationStep m_CircularSawActivationStep;

    public Coroutine m_WaitForStepCompleted;

    public CircularSawCuttingStep(MissionStepData stepdata, Mission owner) : base(stepdata, owner)
    {

    }

    public override void InitStep()
    {
        m_CircularSawActivationStep = m_Owner.GetStep<CircularSawActivationStep>();
        m_WaitForStepCompleted = m_Owner.StartCoroutine(WaitForStepCompleted());
    }

    public override bool IsCompleted()
    {
        return ((MissionCircularSaw)m_Owner).IsSawCompleted;
    }

    public override MissionScore GetScore()
    {
        if (((MissionCircularSaw)m_Owner).IsSawCompleted)
            return new MissionScore(0, m_MissionStepData.ExperienceModifier);
        else
            return new MissionScore(0, 0);
    }

    IEnumerator WaitForStepCompleted()
    {
        for (int i = 0; i < ((MissionCircularSaw)m_Owner).NumOfBoardsToCut; i++)
        {
            yield return new WaitUntil(() => ((MissionCircularSaw)m_Owner).CircularSaw.IsCut);

            ((MissionCircularSaw)m_Owner).CircularSaw.IsCut = false;
            m_Owner.StartCoroutine(GameManager.Instance.Master.PlayAndSound(null, m_MissionStepData.Sentences[1]));
        }

        Player.Instance.DisableAll();
        ((MissionCircularSaw)m_Owner).HideAllLabels();

        if (m_CircularSawActivationStep.CheckAllProps() && m_CircularSawActivationStep.MissionStepObjects[1].StepObject.m_IsUsing)
            Player.Instance.PlayerExperience += m_MissionStepData.ExperienceModifier;
        else
            Player.Instance.PlayerExperience += (m_MissionStepData.ExperienceModifier / 2);

        yield return m_Owner.StartCoroutine(GameManager.Instance.Master.PlayAndSound(null, m_MissionStepData.Sentences[0]));

        MissionManager.Instance.Success = true;
        MissionManager.Instance.CompleteMission();
    }

    public override void ResetStep()
    {
        m_Owner.StopCoroutine(m_WaitForStepCompleted);
        base.ResetStep();
    }
}

This snippet took 0.17 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).