static public void ViewScene(DialogPartData data)
    {
// TODO...
#if false
        ViNoSceneManager sm = GameObject.FindObjectOfType(typeof(ViNoSceneManager)) as ViNoSceneManager;
        if (sm != null)
        {
            GameObject advSceneRoot = sm.theSavedPanel;

            if (data.isClearScene)
            {
                bool destroyImmediate = true;
                ClearSceneNode.Do(advSceneRoot, destroyImmediate);
            }

//			if( data.isLoadScene && data.Scene != null ){
            if (!string.IsNullOrEmpty(data.sceneFilePath) && sm != null)
            {
                bool  TODO1 = false;
                bool  TODO2 = false;
                Scene scene = Resources.Load(data.sceneFilePath, typeof(Scene)) as Scene;
//				LoadSceneNode.Do( advSceneRoot , data.Scene , TODO1 , TODO2 ,  true );
                LoadSceneNode.Do(advSceneRoot, scene, TODO1, TODO2, true);
            }
        }

// No need to warning , if user do not need Scene Save and Load function.
//		else{
//			Debug.LogWarning( "There is no ViNoSceneManager object. Scene Save and Load will not work..." );
//		}
#endif
    }
Пример #2
0
        void enterscene(Hashtable param)
        {
            string sceneName = param["name"] as string;

            // Attached a sceneLib.
//			if( sceneLib != null ){
//				Debug.Log( "OnEnterScene :" + sceneName );
//				for( int i=0;i<sceneLib.sceneEntries.Length;i++){
//					Scene scene = sceneLib.sceneEntries[ i ];
//					if( scene.name == sceneName ){
            if (m_SceneMap.ContainsKey(sceneName))
            {
                Scene scene = m_SceneMap[sceneName];
//					Debug.Log( "matched Scene Name  ," + sceneName + " and Enter this actor." );
                LoadSceneNode.Do(scene, param);
//						break;
//					}
//				}
            }
            // If not attached sceneLib , then Load from Resources folder.
            else
            {
                Scene scene = Resources.Load(sceneName, typeof(Scene)) as Scene;
                if (scene != null)
                {
                    LoadSceneNode.Do(scene, param);
                }
            }
        }
Пример #3
0
    // ------------- Override --------------------.

    /// <summary>
    /// Handles the opcode.
    /// </summary>
    public override void OnUpdate()
    {
        if (IsFinish())
        {
            return;
        }

        // Pomp Message to MessagingHandler.
        if (m_MessagePompToMsghandler)
        {
            if (m_MessagingHandler != null)
            {
                bool handled = m_MessagingHandler.HandleOpcode(this);
                m_MessagePompToMsghandler = !handled;
            }
            return;
        }

        m_CanTextProgress = false;
        switch (code[pc])
        {
        case Opcode.STRING:             pc = ByteCodeReader.readString(code, pc + 1);        m_TextBuilder.Append(loadedString);   break;

        case Opcode.TEXT:               pc = ReadText(pc);                                                                                                                                            break;

        case Opcode.VAR:                pc = ByteCodeReader.readVar(code, pc, ref paramHash, ref m_TextBuilder, stubIndent);       break;

        case Opcode.TABLE:              pc = ByteCodeReader.readTable(code, pc, ref paramHash);                                                                     break;

        case Opcode.ASSIGN_STRING:
//			Debug.Log("OPCODE>ASSIGN_STRING");
            pc        = ByteCodeReader.readString(code, pc + 2);
            leftHand  = loadedString;
            pc        = ByteCodeReader.readString(code, pc + 1);
            rightHand = loadedString;
//			Debug.Log(  "Opcode.ASSIGN key=" + leftHand + " value=\"" + rightHand + "\"" );

// Assign Value to Hashtable ?.
#if false
            symbolTable[leftHand] = rightHand;

// Assign Value to FlagTable.
#else
            ScenarioNode scenario = ScenarioNode.Instance;
            if (scenario != null && scenario.flagTable != null)
            {
                scenario.flagTable.SetStringValue(leftHand, rightHand);
            }
#endif
            leftHand  = "";
            rightHand = "";
            break;

        case Opcode.NULL:              pc++;                                                                                                                                                                           break;

        case Opcode.MESSAGING:
            pc = ByteCodeReader.readString(code, pc + 2);
            messagingTargetName       = loadedString;
            m_MessagePompToMsghandler = true;
            bool isIgnoreObj = loadedString.Equals("env");
            if (!isIgnoreObj)
            {
                if (tweenDataCached.tweenTarget != null)
                {
                    if (!tweenDataCached.tweenTarget.name.Equals(messagingTargetName))
                    {
                        tweenDataCached.tweenTarget = GameObject.Find(messagingTargetName);
                    }
                }
                else
                {
                    tweenDataCached.tweenTarget = GameObject.Find(messagingTargetName);
                }
            }
            tweenDataCached.paramTable = paramHash;
            break;

        case Opcode.NODE:
            m_PrevNodeName = m_CurrNodeName;
            pc             = ByteCodeReader.readString(code, pc + 2);
            ViNoDebugger.Log("NODE", loadedString);

            m_CurrNodeName            = loadedString;
            m_NodePcMap[loadedString] = pc;
            SetCurrentNodeToScriptEngine();

            // Callback to ScriptBinder.
            scriptBinder.OnEnterNode(this);
            break;

        case Opcode.LOAD_RESOURCE:
            m_LoadedResourcePath = VirtualMachine.loadedTextLiteralString;
            m_LoadedResource     = UnityWrapper.LoadResource(m_LoadedResourcePath);
            pc++;
            break;

// TODO : Need to Test .
        case Opcode.PLAY_AUDIO_FROM_RESOURCE:
            m_LoadedResourcePath = VirtualMachine.loadedTextLiteralString;
            ISoundPlayer.Instance.PlayAudioClip(m_LoadedResource as AudioClip, m_LoadedResourcePath, ViNoConfig.prefsBgmVolume, 0f);
            m_LoadedResource = null;
            Resources.UnloadUnusedAssets();

            pc++;
            break;

        case Opcode.INSTANTIATE_AS_GAMEOBJECT:
            if (m_LoadedResource != null)
            {
                string parentName = VirtualMachine.loadedTextLiteralString;

                UnityWrapper.InstantiateAsGameObject(m_LoadedResource, parentName);

                m_LoadedResource = null;
                Resources.UnloadUnusedAssets();
            }
            else
            {
                Debug.LogError("Resource not loaded.");
            }
            pc++;
            break;

        case Opcode.DESTROY_OBJECT:
            string     goName = VirtualMachine.loadedTextLiteralString;
            GameObject go     = GameObject.Find(goName);                                // TODO : GO.Find is Slow .
            GameObject.Destroy(go);
            pc++;
            break;

        case Opcode.JUMP:               // Jump to loadedString Node  .
            ByteCodeReader.readString(code, pc + 2);
            GoToLabel(loadedString);
            ViNoDebugger.Log("NODE", "jump to :" + loadedString);
            break;

        case Opcode.IF:
            pc = ByteCodeReader.readString(code, pc + 2);
            string flagName = VirtualMachine.loadedString;
            Debug.Log("flag name :" + flagName);

            bool isOnOrOff = (code[pc] == 1) ? true : false;
            pc++;

            pc = ByteCodeReader.readString(code, pc + 1);
            string ifTarget = VirtualMachine.loadedString;
            Debug.Log("IF =>" + ifTarget);
            pc = ByteCodeReader.readString(code, pc + 1);
            string elseTarget = VirtualMachine.loadedString;
            Debug.Log("ELSE =>" + elseTarget);

            bool isFlagOn = ScenarioNode.Instance.flagTable.CheckFlagBy(flagName);
            if (isFlagOn == isOnOrOff)
            {
                Debug.Log("IF");
                GoToLabel(ifTarget);
            }
            else
            {
                Debug.Log("ELSE");
                GoToLabel(elseTarget);
            }
            break;

            // ----- Layer -----.
#if false
        case Opcode.LAYOPT:                             GOOptionNode.Do(paramHash);           pc++;   break;
#endif
        case Opcode.BEGIN_TRANSITION:   UnityWrapper.BeginTransition();         pc++;   break;

        case Opcode.END_TRANSITION:             UnityWrapper.EndTransition();           pc++;   break;

        case Opcode.SCENE_NODE:
            SceneData.SceneNodeData data = SceneCreator.CreateNodeData(paramHash);
            SceneCreator.Create(data);
            pc++;
            break;

        case Opcode.LOAD_SCENE:
//			bool destroy = ( code[ pc + 1 ] == 0 ) ? true : false ;
//			UnityWrapper.LoadScene( m_LoadedResource , destroy );
            LoadSceneNode.Do(m_LoadedResource, paramHash);
            m_LoadedResource = null;
            Resources.UnloadUnusedAssets();
            pc++;
            break;

        case Opcode.CLEAR_SCENE:
            GameObject advSceneRoot     = ViNoSceneManager.Instance.theSavedPanel;
            bool       immediateDestroy = false;
            SceneCreator.DestroyScene(advSceneRoot, immediateDestroy);
            pc++;
            break;

/*		case Opcode.PLAY_ANIMATION:
 *                      byte animationID = code[ pc + 1 ];
 *                      ViNoAnimationManager.Instance.PlayAnimation( (int)animationID );
 *                      pc+= 2;
 *                      break;
 * //*/

        // ----- Message -----.
        case Opcode.BR:
//			m_TextBuilder.Append( "\n" );
            pc++;           break;            //scriptBinder.BR( this );	pc++;		break;

        case Opcode.CM:         ClearMessage();                         pc++;           break;

        case Opcode.ER:
            AddToBacklog();
            ClearTextBuilder();
            if (m_MsgTargetTextBox != null)
            {
                m_MsgTargetTextBox.ClearMessage();
            }
            else
            {
                Debug.LogWarning("Current Message Target Not Set.");
            }
            pc++;
            break;

        case Opcode.PRINT:              scriptBinder.PRINT(this);                     pc++;           break;

        case Opcode.CURRENT:
            TriggerMessageEvent("OnMessageTargetChanged", code[pc + 1], "", true);
            break;

        case Opcode.SET_TEXT:
            TriggerMessageEvent("OnSetText", code[pc + 1], VirtualMachine.loadedTextLiteralString, true);
            m_CurrentText = m_MessageEventData.message;
            break;

        case Opcode.HIDE_MESSAGE:
            TriggerMessageEvent("OnHideMessage", code[pc + 1], "", false);
            break;

        // ------ System Opcode -----.
        case Opcode.START_WAIT:
            m_ElapsedSec = 0f;
            if (!string.IsNullOrEmpty(loadedTextLiteralString))
            {
                m_WaitSec = float.Parse(loadedTextLiteralString);
            }
            else
            {
                m_WaitSec = kWaitSec;
            }
            pc++;
            break;

        case Opcode.UPDATE_WAIT:
//			ViNoDebugger.Log( "VM" , "waiting ...");
            m_ElapsedSec += Time.deltaTime;
            if (m_ElapsedSec > m_WaitSec)
            {
                pc++;
            }
            break;

        case Opcode.STOP:
            // Wait Until Player choosing from options . or reached to the end of a leaf node .
            // Nothing to do...

            break;

        case Opcode.END:
            ViNoEventManager.Instance.TriggerEvent("OnFinishScenario");
            update = false;
            break;

        case Opcode.PLAY_SCENARIO:
            pc = ByteCodeReader.readString(code, pc + 2);
            string     scenarioName = loadedString;
            GameObject scenarioObj  = GOCache.SetActive(scenarioName, true);
            if (scenarioObj != null)
            {
                ScenarioNode s = scenarioObj.GetComponent <ScenarioNode>();
                s.Play();
            }
            break;

        case Opcode.FLAG_ON:
            if (ScenarioNode.Instance != null && ScenarioNode.Instance.flagTable != null)
            {
                ScenarioNode.Instance.flagTable.SetFlagBy(VirtualMachine.loadedTextLiteralString, true);
            }
            pc++;
            break;

        case Opcode.FLAG_OFF:
            if (ScenarioNode.Instance != null && ScenarioNode.Instance.flagTable != null)
            {
                ScenarioNode.Instance.flagTable.SetFlagBy(VirtualMachine.loadedTextLiteralString, false);
            }
            pc++;
            break;

        case Opcode.SELECTIONS:
            ISelectionsCtrl selCtrl = ISelectionsCtrl.Instance;
            if (selCtrl != null)
            {
                if (!selCtrl.IsActive())
                {
                    string title = VirtualMachine.loadedTextLiteralString;
                    selCtrl.SetTitle(title);
                    ISelectionsCtrl.Instance.ChangeActive(true);
                }
            }
            else
            {
                Debug.LogError("ISelectionsCtrl instance not found.");
            }
            pc++;
            break;

        case Opcode.LINK:               ISelectionsCtrl.Instance.AddSelection(ref paramHash); pc++;   break;

        case Opcode.WAIT_TOUCH:
            if (IScriptEngine.skip)
            {
                if (IScriptEngine.skipAlreadyPass && !VirtualMachine._ALREADY_PASS_THE_NODE)
                {
                    return;
                }

                _SkipText( );

                ISoundPlayer pl = ISoundPlayer.Instance;
                if (pl != null)
                {
                    if (pl.IsPlayingVoice())
                    {
                        pl.StopVoice();
                    }
                }
                m_CanTextProgress = true;
                return;
            }

            if (autoMode)
            {
                float dt = Time.deltaTime;
                m_TimeElapsed += dt;
                if (m_TimeElapsed > _AUTO_MODE_WAIT_TIME)
                {
                    m_TimeElapsed = 0f;
                    _SkipText();
                }
                return;
            }
            m_CanTextProgress = true;
            break;

//		case Opcode.PLAY_BGM:
//			break;

        // -----Audio -----.
        case Opcode.PLAY_SOUND:
            byte soundCategory = code[pc + 1];                  // 0: BGM 1:SE 2: VOICE.
            byte soundID       = code[pc + 2];

            UnityWrapper.PlaySound(soundCategory, soundID);
            if (soundCategory == 2)
            {
                SET_CURRENT_VOICE_ID(true, soundID);
            }
            pc += 3;
            break;

        case Opcode.STOP_SOUND:
            //TODO :

            pc++;
            break;

        case Opcode.STOP_VOICE:
            SET_CURRENT_VOICE_ID(false, 0);
            if (ISoundPlayer.Instance != null)
            {
                ISoundPlayer.Instance.StopVoice();
            }
            pc++;
            break;

        default:
            ViNoDebugger.LogError("VM", "PC : " + pc);
            break;
        }
    }
Пример #4
0
    static public void CreateConvScene(string templScenePath)
    {
        GameObject sceneRoot = CreateTemplScene(templScenePath);

        sceneRoot.name = "A Conversation Scene";

        string scenarioName = "A_Conversation";

        if (!System.IO.Directory.Exists("Assets/" + scenarioName))
        {
            AssetDatabase.CreateFolder("Assets", scenarioName);
        }

        GameObject scenarioObj = ViNoToolUtil.CreateANewScenario(scenarioName, true);
        GameObject startObj    = scenarioObj.transform.FindChild("START").gameObject;
//		scenarioObj.transform.parent.transform.parent = sceneRoot.transform;

        GameObject    node0         = new GameObject("0_Scene");
        LoadSceneNode loadSceneNode = node0.AddComponent <LoadSceneNode>();

        loadSceneNode.sceneName  = "Scene1";
        loadSceneNode.method     = LoadSceneNode.Methods.DESTROY_AND_LOAD;
        loadSceneNode.withFadeIn = true;

        loadSceneNode.transform.parent = startObj.transform;

        DialogPartNode dlgNode = ViNoToolUtil.AddDialogPartNode(startObj.transform);

        dlgNode.name = "1_Dialog";
        DialogPartData data0 = dlgNode.AddData("", "");
        DialogPartData data1 = dlgNode.AddData("Sachi", "Hello. I am Sachi.");
        DialogPartData data2 = dlgNode.AddData("", "");
        DialogPartData data3 = dlgNode.AddData("Maiko", "Hi. Sachi.");
        DialogPartData data4 = dlgNode.AddData("Sachi", "Bye Bye !");
        DialogPartData data5 = dlgNode.AddData("Maiko", "Bye Bye !");
        DialogPartData data6 = dlgNode.AddData("", "");

        data0.enterActorEntries              = new DialogPartData.ActorEntry[1];
        data0.enterActorEntries[0]           = new DialogPartData.ActorEntry();
        data0.enterActorEntries[0].actorName = "Sachi";
        data0.actionID = DialogPartNodeActionType.EnterActor;
        data0.enterActorEntries[0].position = ViNoToolkit.SceneEvent.ActorPosition.middle_left;

        data1.isName = true;

        data2.enterActorEntries              = new DialogPartData.ActorEntry[1];
        data2.enterActorEntries[0]           = new DialogPartData.ActorEntry();
        data2.enterActorEntries[0].actorName = "Maiko";
        data2.actionID = DialogPartNodeActionType.EnterActor;
        data2.enterActorEntries[0].position = ViNoToolkit.SceneEvent.ActorPosition.middle_right;
        data3.isName = true;

        data4.isName = true;
        data5.isName = true;

        data6.actionID                      = DialogPartNodeActionType.ExitActor;
        data6.exitActorEntries              = new DialogPartData.ActorEntry[2];
        data6.exitActorEntries[0]           = new DialogPartData.ActorEntry();
        data6.exitActorEntries[1]           = new DialogPartData.ActorEntry();
        data6.exitActorEntries[0].actorName = "Sachi";
        data6.exitActorEntries[1].actorName = "Maiko";

#if false
        GameObject parentObj = GameObject.Find("Panels");

        DrawObjectsTab.CreateBG("BG", parentObj);
        GameObject ch1 = DrawObjectsTab.Create2Layer("Ch1", parentObj);
        GameObject ch2 = DrawObjectsTab.Create2Layer("Ch2", parentObj);

        ch1.transform.localPosition = new Vector3(-120f, 0f, 0f);
        ch2.transform.localPosition = new Vector3(120f, 0f, 0f);

        AssetDatabase.MoveAsset("Assets/BG", "Assets/" + scenarioName + "/BG");
        AssetDatabase.MoveAsset("Assets/Ch1", "Assets/" + scenarioName + "/Ch1");
        AssetDatabase.MoveAsset("Assets/Ch2", "Assets/" + scenarioName + "/Ch2");
#endif

        string       scenarioFlagDataPath = "Assets/" + scenarioName + "/" + scenarioName + "Flags.asset";
        string       scenarioSaveDataPath = "Assets/" + scenarioName + "/" + scenarioName + "SaveData.asset";
        FlagTable    flagTable            = ScriptableObjectUtility.CreateScriptableObject("FlagTable", scenarioFlagDataPath) as FlagTable;
        ViNoSaveInfo saveInfo             = ScriptableObjectUtility.CreateScriptableObject("ViNoSaveInfo", scenarioSaveDataPath) as ViNoSaveInfo;
        ScenarioNode scenarioNode         = scenarioObj.GetComponent <ScenarioNode>();
        scenarioNode.m_PlayAtStart = true;
        scenarioNode.flagTable     = flagTable;
//		scenarioNode.saveInfo = saveInfo;

        ScenarioCtrl scenarioCtrl = GameObject.FindObjectOfType(typeof(ScenarioCtrl)) as ScenarioCtrl;
        scenarioCtrl.quickSaveSlot = saveInfo;
        scenarioCtrl.saveInfo      = saveInfo;

        // Create an ActorLibrary and a SceneLibrary.
        string actorLibPrefabPath = "Assets/" + scenarioName + "/ActorLibrary.prefab";
        string sceneLibPrefabPath = "Assets/" + scenarioName + "/SceneLibrary.prefab";

        ViNoScenarioDataUtil.CreateActorLibrary(actorLibPrefabPath);
        ViNoScenarioDataUtil.CreateSceneLibrary(sceneLibPrefabPath);
        GameObject.DestroyImmediate(GameObject.Find("ActorLibrary"));
        GameObject.DestroyImmediate(GameObject.Find("SceneLibrary"));

//		ViNoToolkit.ActorInfo actor1 = ViNoScenarioDataUtil.CreateActorInfo() as ViNoToolkit.ActorInfo;
        ViNoToolkit.SceneEvent sceneEvt = GameObject.FindObjectOfType(typeof(ViNoToolkit.SceneEvent)) as ViNoToolkit.SceneEvent;

        ViNoToolkit.ActorLibrary actorLib = AssetDatabase.LoadAssetAtPath(actorLibPrefabPath, typeof(ViNoToolkit.ActorLibrary)) as ViNoToolkit.ActorLibrary;
        ViNoToolkit.SceneLibrary sceneLib = AssetDatabase.LoadAssetAtPath(sceneLibPrefabPath, typeof(ViNoToolkit.SceneLibrary)) as ViNoToolkit.SceneLibrary;

/*		actorLib.actorEntries = new ViNoToolkit.ActorInfo[ 1 ];
 *              actorLib.actorEntries[ 0 ] = actor1;
 * //*/
        sceneEvt.actorLib = actorLib;
        sceneEvt.sceneLib = sceneLib;
    }