Error in MVVM when building - mvvm

i just created a PCL called Tipcalc>core, the tutorial from witch i am building it is this one . here is
my TipViewModel.cs
using Cirrious.MvvmCross.ViewModels;
namespace TipCalc.Core
{
public class TipViewModel : MvxViewModel
{
private readonly ICalculation _calculation;
public TipViewModel(ICalculation calculation)
{
_calculation = calculation;
}
public override void Start()
{
_subTotal = 100;
_generosity = 10;
Recalcuate();
base.Start();
}
private double _subTotal;
public double SubTotal
{
get { return _subTotal; }
set { _subTotal = value; RaisePropertyChanged(() => SubTotal); Recalcuate(); }
}
private int _generosity;
public int Generosity
{
get { return _generosity; }
set { _generosity = value; RaisePropertyChanged(() => Generosity); Recalcuate(); }
}
private double _tip;
public double Tip
{
get { return _tip; }
set { _tip = value; RaisePropertyChanged(() => Tip); }
}
private void Recalcuate()
{
Tip = _calculation.TipAmount(SubTotal, Generosity);
}
}
}
The problem is that when i cuild this PCL, get the following errors:
Error 1 The type or namespace name 'ICalculation' could not be found (are you missing a using directive or an assembly reference?)
TipCalc.Core
Error 2 The type or namespace name 'ICalculation' could not be found (are you missing a using directive or an assembly reference?)
Altough my interface and class,are right there in the Services Folder,in project.
Calculation.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TipCalc.Core.Services
{
public class Calculation : ICalculation
{
public double TipAmount(double subTotal, int generosity)
{
return subTotal * ((double)generosity) / 100.0;
}
}
}
And ICalculation.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TipCalc.Core.Services
{
public interface ICalculation
{
double TipAmount(double subTotal, int generosity);
}
}
any help please?

You need to add using in Calculation.cs
to Use ICalculation.cs
Using TipCalc.Core.Services;

Related

Unity The name 'PrefabUtility' does not exist in the current context

I'm trying to build a Unity game, and keep getting the error:
Assets\charaterselection.cs(34,9): error CS0103: The name 'PrefabUtility' does not exist in the current context
The issue is I imported UnityEditor, I'm not sure what's going on
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.SceneManagement;
public class charaterselection : MonoBehaviour
{
public SpriteRenderer sr;
public List<Sprite> skins = new List<Sprite>();
private int selecectedSkin;
public GameObject player;
public void Next()
{
selecectedSkin=selecectedSkin+1;
if (selecectedSkin== skins.Count)
{
selecectedSkin=0;
}
sr.sprite= skins[selecectedSkin];
}
public void back()
{
selecectedSkin = selecectedSkin - 1;
if (selecectedSkin < 0)
{
selecectedSkin = skins.Count - 1;
}
sr.sprite = skins[selecectedSkin];
}
public void play()
{
PrefabUtility.SaveAsPrefabAsset(player, "Assets/Players/FROGY.prefab");
SceneManager.LoadScene(1);
}
}
Thank you guys for your help, I literately just made a file called "Editor" and it worked.

error CS0246: The type or namespace name 'SVGImage' could not be found (are you missing a using directive or an assembly reference?)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System;
namespace ModernMirror.App
{
public class IconPropertView : PropertyView
{
SVGImage icon;
public Sprite[] icons;
void Awake()
{
icon = GetComponent<SVGImage>();
}
override public void SetProp(object id)
{
int i = 0;
try
{
i = int.Parse((string)id);
}
catch(Exception e)
{
Debug.Log("Could not parse integer from property id " + id + e);
}
if (icons == null || i >= icons.Length)
{
Debug.LogWarning("Missing icons for IconProperty " + name);
return;
}
icon.sprite = icons[i];
}
}
}
I am building unity project and got this error.
error CS0246: The type or namespace name 'SVGImage' could not be found (are you missing a using directive or an assembly reference?)
Try adding
using Unity.VectorGraphics
per https://docs.unity3d.com/Packages/com.unity.vectorgraphics#2.0/api/Unity.VectorGraphics.SVGImage.html
Put your *.cs files to "Scripts" directory.

Photon list doesn't show up

I am making a multiplayer game and I am at the MenuScene where I make the choose room - on one panel and create room - other panel . It works to create a room , but when I press to show the panel with "ChooseRoom" it doesn't appear anything. here is the script that I use.So it doesn't appear the prefab that I made with the RoomListing1(text)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SingletonReferences : MonoBehaviour
{
[SerializeField]
private MasterManager _masterManager;
}
using Photon.Pun;
using Photon.Realtime;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RoomListingsMenu : MonoBehaviourPunCallbacks
{
[SerializeField]
private Transform _content;
[SerializeField]
private RoomListing _roomListing;
private List<RoomListing> _listings = new List<RoomListing>();
private RoomsCanvases _roomsCanvases;
public void FirstInitialize(RoomsCanvases canvases)
{
_roomsCanvases = canvases;
}
public override void OnJoinedRoom()
{
_roomsCanvases.CurrentRoomCanvas.Show();
// _content.DestroyChildren();
_listings.Clear();
}
public override void OnRoomListUpdate(List<RoomInfo> roomList)
{
foreach (RoomInfo info in roomList)
{
//Removed from rooms list.
if (info.RemovedFromList)
{
int index = _listings.FindIndex(x => x.RoomInfo.Name == info.Name);
if (index != -1)
{
Destroy(_listings[index].gameObject);
_listings.RemoveAt(index);
}
}
//Added to rooms list.
else
{
int index = _listings.FindIndex(x => x.RoomInfo.Name == info.Name);
if (index == -1)
{
RoomListing listing = Instantiate(_roomListing, _content);
if (listing != null)
{
listing.SetRoomInfo(info);
_listings.Add(listing);
}
}
else
{
//Modify listing here.
//_listings[index].dowhatever.
}
}
}
}
}
using Photon.Pun;
using Photon.Realtime;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class RoomListing : MonoBehaviour
{
[SerializeField]
private Text _text;
public RoomInfo RoomInfo { get; private set; }
public void SetRoomInfo(RoomInfo roomInfo)
{
RoomInfo = roomInfo;
_text.text = roomInfo.MaxPlayers + ", " + roomInfo.Name;
}
public void OnClick_Button()
{
PhotonNetwork.JoinRoom(RoomInfo.Name);
}
}
using Photon.Pun;
using Photon.Realtime;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestConnect : MonoBehaviourPunCallbacks
{
private void Start()
{
Debug.Log("Connecting to Photon...", this);
AuthenticationValues authValues = new AuthenticationValues("0");
PhotonNetwork.AuthValues = authValues;
PhotonNetwork.SendRate = 20; //20.
PhotonNetwork.SerializationRate = 5; //10.
PhotonNetwork.AutomaticallySyncScene = true;
PhotonNetwork.NickName = MasterManager.GameSettings.NickName;
PhotonNetwork.GameVersion = MasterManager.GameSettings.GameVersion;
PhotonNetwork.ConnectUsingSettings();
}
public override void OnConnectedToMaster()
{
Debug.Log("Connected to Photon.", this);
Debug.Log("My nickname is " + PhotonNetwork.LocalPlayer.NickName, this);
if (!PhotonNetwork.InLobby)
PhotonNetwork.JoinLobby();
}
public override void OnDisconnected(DisconnectCause cause)
{
Debug.Log("Failed to connect to Photon: " + cause.ToString(), this);
}
public override void OnJoinedLobby()
{
print("Joined lobby");
PhotonNetwork.FindFriends(new string[] { "1" });
}
public override void OnFriendListUpdate(List<FriendInfo> friendList)
{
base.OnFriendListUpdate(friendList);
foreach (FriendInfo info in friendList)
{
Debug.Log("Friend info received " + info.UserId + " is online? " + info.IsOnline);
}
}
}

Using a delegate to handle a Javascript callback in JINT

In the following code using JINT, the call to the Setup1 method works and the call to Setup2 method does not. The call to Setup2 raises the error: Jint.Runtime.JavaScriptException: 'No public methods with the specified arguments were found.'
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp4
{
public delegate bool DoFunction();
public class TestClass
{
public TestClass() { }
public void Setup1(Func<bool> fn)
{
bool b = fn();
}
public void Setup2(DoFunction fn)
{
bool b = fn();
}
}
class Program
{
static void Main(string[] args)
{
Jint.Engine _engine = new Jint.Engine();
_engine.SetValue("test", new TestClass());
_engine.Execute("test.Setup1(function() { return true; })");
_engine.Execute("test.Setup2(function() { return true; })");
}
}
}
So why does the call to Setup2 fail? What is the different between Func and the delegate DoFunction()?

Get float from class in a SerializedProperty

I am trying to start using sciptable objects as describe in this talk. Here is my code:
Here is my FloatVariable:
using UnityEngine;
[CreateAssetMenu]
public class FloatVariable : ScriptableObject
{
public float value;
}
Here is my FloatReference:
using UnityEngine;
using System;
[Serializable]
public class FloatReference
{
public bool use_constant = true;
public float constant_value;
public FloatVariable variable_value;
public float v
{
get
{
return use_constant ? constant_value : variable_value.value;
}
set
{
if (use_constant) throw new Exception("Cannot assign constant_value");
else variable_value.value = value;
}
}
}
Here is my GameplayManager where I have one FloatReference value:
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEditor;
using System;
public class GameplayManager : MonoBehaviour
{
public FloatReference pl_orb_mode;
}
Here is my GameplayManagerEditor where I try to get float from FloatVariable class:
using UnityEngine;
using UnityEditor;
using System;
[CustomEditor(typeof(GameplayManager))]
public class GameplayManagerEditor : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
SerializedProperty pl_orb_mode = serializedObject.FindProperty("pl_orb_mode");
SerializedProperty variable = pl_orb_mode.FindPropertyRelative("variable_value");
SerializedProperty the_value = variable.FindPropertyRelative("value");
float test = the_value.floatValue;
Debug.Log(test);
}
}
When I try to get my float test = the_value.floatValue; I get an error:
NullReferenceException: Object reference not set to an instance of an object
GameplayManagerEditor.OnInspectorGUI () (at Assets/Shared/Scripts/Editor/GameplayManagerEditor.cs:18)
So I can get the FloatVariable variable class as a SerializedProperty but I can't get its value property. Why is that so and how to make it work?
Because FloatVariable is inherit from ScriptableObject, so variable_value becomes a reference not a property in SerializedObject.
You have 2 choice.
Don't use ScriptableObject:
[Serializable]
public class FloatVariable
{
public float value;
}
Or edit the reference object:
var so = new SerializedObject(((GameplayManager)target).pl_orb_mode.variable_value);
var the_value = so.FindPropertyRelative("value");
...
so.ApplyModifiedProperties();
Notice that the second way since FloatVariable is a reference object, change on it will change all other objects that refer to it.