Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JucanAndreiDaniel committed Jan 30, 2024
1 parent 07aa760 commit acf9c38
Show file tree
Hide file tree
Showing 22 changed files with 66 additions and 119 deletions.
3 changes: 0 additions & 3 deletions Assets/GothicVR/Scripts/Creator/VobCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,6 @@ public static void CreateItem(int itemId, GameObject go)
CreateItemMesh(item, go);
}

/// <summary>
/// Render item inside GameObject
/// </summary>
public static void CreateItem(int itemId, string spawnpoint, GameObject go)
{
var item = AssetCache.TryGetItemData(itemId);
Expand Down
31 changes: 0 additions & 31 deletions Assets/GothicVR/Scripts/Globals/Hero.cs

This file was deleted.

3 changes: 0 additions & 3 deletions Assets/GothicVR/Scripts/Globals/Hero.cs.meta

This file was deleted.

4 changes: 1 addition & 3 deletions Assets/GothicVR/Scripts/Manager/GvrBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ private static void LoadGothicVm(string g1Dir)
var fullPath = Path.GetFullPath(Path.Join(g1Dir, "/_work/DATA/scripts/_compiled/GOTHIC.DAT"));
GameData.GothicVm = new DaedalusVm(fullPath);

// If we don't set it early, other calls within VM will fail.
// TODO - Could be moved to a separate Hero.cs class and set during GvrEvents.GeneralSceneLoaded event.
Hero.LoadHeroVM();
NpcHelper.LoadHero();

VmGothicExternals.RegisterExternals();
}
Expand Down
20 changes: 6 additions & 14 deletions Assets/GothicVR/Scripts/Manager/GvrSceneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class GvrSceneManager : SingletonBehaviour<GvrSceneManager>
private bool generalSceneLoaded;

private GameObject startPoint;
private GameObject player;

private bool debugFreshlyDoneLoading;

Expand Down Expand Up @@ -245,22 +244,15 @@ public void MoveToWorldScene(GameObject go)
SceneManager.MoveGameObjectToScene(go, SceneManager.GetSceneByName(GameData.WorldScene.Value.name));
}

private void SetPlayer()
{
player = generalScene.GetRootGameObjects().FirstOrDefault(go => go.name == "PlayerController").transform.Find("VRPlayer").gameObject;
LookupCache.NpcCache[GameData.GothicVm.GlobalHero.Index].go = player;
}

public void TeleportPlayerToSpot()
{
if (player == null)
SetPlayer();
if (startPoint == null)
return;

if (startPoint != null)
{
player.transform.position = startPoint.transform.position;
player.transform.rotation = startPoint.transform.rotation;
}
var player = NpcHelper.GetHeroGameObject();
player.transform.position = startPoint.transform.position;
player.transform.rotation = startPoint.transform.rotation;
}
}
}
}
24 changes: 23 additions & 1 deletion Assets/GothicVR/Scripts/Manager/NpcHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using GVR.Properties;
using GVR.Vm;
using UnityEngine;
using UnityEngine.SceneManagement;
using ZenKit.Daedalus;

namespace GVR.Manager
Expand Down Expand Up @@ -233,7 +234,7 @@ public static string ExtNpcGetNextWp(NpcInstance npc)
{
var pos = GetProperties(npc).transform.position;

return WayNetHelper.FindSecondNearestWayPoint(pos).Name;
return WayNetHelper.FindNearestWayPoint(pos, true).Name;
}

public static int ExtNpcGetTalentSkill(NpcInstance npc, int skillId)
Expand Down Expand Up @@ -521,5 +522,26 @@ public static void ExchangeRoutine(GameObject go, NpcInstance npcInstance, int r
var startRoutine = routineComp.CurrentRoutine;
go.GetComponent<AiHandler>().StartRoutine(startRoutine.action, startRoutine.waypoint);
}

public static void LoadHero()
{
var hero = GameData.GothicVm.InitInstance<NpcInstance>("hero");
GameData.GothicVm.GlobalHero = hero;

var heroProperties = new NpcProperties();
LookupCache.NpcCache[hero.Index] = heroProperties;
}

public static GameObject GetHeroGameObject()
{
return LookupCache.NpcCache[GameData.GothicVm.GlobalHero.Index].go;
}

public static void SetHeroGameObject(GameObject hero)
{
var generalScene = SceneManager.GetSceneByName(Constants.SceneGeneral);
if (GameData.GothicVm.GlobalHero != null)
LookupCache.NpcCache[GameData.GothicVm.GlobalHero.Index].go = hero;
}
}
}
18 changes: 5 additions & 13 deletions Assets/GothicVR/Scripts/Manager/WayNetHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,14 @@ public static List<FreePoint> FindFreePointsWithName(Vector3 lookupPosition, str
return matchingFreePoints.ToList();
}

public static WayPoint FindNearestWayPoint(Vector3 lookupPosition)
public static WayPoint FindNearestWayPoint(Vector3 lookupPosition, bool findSecondNearest = false)
{
var nearestWayPoint = GameData.WayPoints
.OrderBy(pair => Vector3.Distance(pair.Value.Position, lookupPosition))
.First();

return nearestWayPoint.Value;
}

public static WayPoint FindSecondNearestWayPoint(Vector3 lookupPosition)
{
var nearestWayPoint = GameData.WayPoints
var wayPoint = GameData.WayPoints
.OrderBy(pair => Vector3.Distance(pair.Value.Position, lookupPosition))
.Skip(1).First();
.Skip(findSecondNearest ? 1 : 0)
.FirstOrDefault();

return nearestWayPoint.Value;
return wayPoint.Value;
}

[CanBeNull]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using System;
using GVR.Caches;
using GVR.Creator;
using GVR.Vm;
using GVR.Vob.WayNet;
using UnityEngine;
using ZenKit;

namespace GVR.Npc.Actions.AnimationActions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using GVR.Caches;
using GVR.Creator;
using GVR.Vm;
using UnityEngine;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using GVR.Caches;
using GVR.Creator;
using GVR.Data.ZkEvents;
using GVR.Extensions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using GVR.Manager;
using UnityEngine;

namespace GVR.Npc.Actions.AnimationActions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using UnityEngine;

namespace GVR.Npc.Actions.AnimationActions
Expand All @@ -9,9 +10,15 @@ public AlignToWp(AnimationAction action, GameObject npcGo) : base(action, npcGo)

protected override Vector3 GetRotationDirection()
{
if(Props.CurrentWayPoint == null)
try
{
return Props.CurrentWayPoint.Direction;
}
catch (Exception e)
{
Debug.LogError(e);
return Vector3.zero;
return Props.CurrentWayPoint.Direction;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,8 @@ public override void Start()
var routine = Props.GetComponent<Routine>().CurrentRoutine;

ai.StartRoutine(routine.action, routine.waypoint);
}

/// <summary>
/// This one is actually no animation, but we need to call Start() only.
/// FIXME - We need to create an additional inheritance below AbstractAnimationAction if we have more like this class.
/// </summary>
/// <returns></returns>
public override bool IsFinished()
{
return true;
IsFinishedFlag = true;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using GVR.Manager;
using GVR.Vob.WayNet;
using GVR.World;
using UnityEngine;

namespace GVR.Npc.Actions.AnimationActions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System.Linq;
using GVR.Manager;
using GVR.Vob.WayNet;
using UnityEngine;

namespace GVR.Npc.Actions.AnimationActions
Expand Down
12 changes: 4 additions & 8 deletions Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToNpc.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using GVR.Caches;
using UnityEngine;

Expand All @@ -11,15 +10,12 @@ public class GoToNpc : AbstractWalkAnimationAction
private int otherIndex => Action.Int1;

public GoToNpc(AnimationAction action, GameObject npcGo) : base(action, npcGo)
{ }
{
}

public override void Start()
{
// Hero
if (otherId == 0)
destinationTransform = Camera.main!.transform;
else
destinationTransform = LookupCache.NpcCache[otherIndex].transform;
destinationTransform = LookupCache.NpcCache[otherIndex].transform;
}

protected override Vector3 GetWalkDestination()
Expand All @@ -35,4 +31,4 @@ public override void AnimationEndEventCallback()
IsFinishedFlag = false;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ public class LookAtNpc : AbstractRotateAnimationAction
private int otherIndex => Action.Int1;

public LookAtNpc(AnimationAction action, GameObject npcGo) : base(action, npcGo)
{ }
{
}

public override void Start()
{
// Hero
if (otherId == 0)
destinationTransform = Camera.main!.transform;
else
destinationTransform = LookupCache.NpcCache[otherIndex].transform;
destinationTransform = LookupCache.NpcCache[otherIndex].transform;
}

protected override Vector3 GetRotationDirection()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using GVR.Creator.Sounds;
using GVR.Extensions;
using GVR.Globals;
using GVR.Manager;
using UnityEngine;
using Random = UnityEngine.Random;

Expand All @@ -28,8 +29,7 @@ public override void Start()
// If NPC talked before, we stop it immediately (As some audio samples are shorter than the actual animation)
AnimationCreator.StopAnimation(NpcGo);

// FIXME - Play sound file on Hero's AudioSource - Use global lookup for Hero's AudioSource component
GameObject.Find("HeroVoice").GetComponent<AudioSource>().PlayOneShot(audioClip);
NpcHelper.GetHeroGameObject().GetComponent<AudioSource>().PlayOneShot(audioClip);
// FIXME - Show subtitles somewhere next to Hero (== ourself/main camera)
}
// NPC
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using GVR.Caches;
using GVR.Creator;
using UnityEngine;

Expand All @@ -7,11 +6,12 @@ namespace GVR.Npc.Actions.AnimationActions
public class PlayAni : AbstractAnimationAction
{
public PlayAni(AnimationAction action, GameObject npcGo) : base(action, npcGo)
{ }
{
}

public override void Start()
{
AnimationCreator.PlayAnimation(Props.mdsNames, Action.String0, NpcGo);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GVR.Caches;
using GVR.Manager;
using UnityEngine;

namespace GVR.Npc.Actions.AnimationActions
Expand All @@ -11,15 +10,12 @@ public class TurnToNpc : AbstractRotateAnimationAction
private int otherIndex => Action.Int1;

public TurnToNpc(AnimationAction action, GameObject npcGo) : base(action, npcGo)
{ }
{
}

public override void Start()
{
// Hero
if (otherId == 0)
destinationTransform = Camera.main!.transform;
else
destinationTransform = LookupCache.NpcCache[otherIndex].transform;
destinationTransform = LookupCache.NpcCache[otherIndex].transform;
}

protected override Vector3 GetRotationDirection()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using GVR.Data;
using GVR.Extensions;
using GVR.Globals;
using GVR.GothicVR.Scripts.Manager;
using GVR.Manager;
using GVR.Util;
using TMPro;
using UnityEngine;
Expand Down Expand Up @@ -38,6 +38,8 @@ public class ControllerManager : SingletonBehaviour<ControllerManager>
private void Start()
{
GvrEvents.ZenKitBootstrapped.AddListener(Initialize);

NpcHelper.SetHeroGameObject(transform.parent.gameObject);
}

private void Initialize()
Expand Down
Loading

0 comments on commit acf9c38

Please sign in to comment.