Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Erdrik_Ironrose · Sep 22, 2014 at 09:12 AM · xmldelegatesadvicepolymorphism

The best way to trigger game events in a list

I'm trying to create a system that can read through a list of "game events" and activate them accordingly, but am having difficulty creating a solid, efficient approach that's easy to expand and work with. A pseudo-code example of what I mean is

 manager.Text(player_portrait, "Hello!")
 manager.Move( npc, 2, -2)
 manager.ShowImage("random bottle")
 manager.Text(npc_portrait, "Do you like my bottle?")
 switch (manager.Choice(Yes, No))
 {
     case 1: {
         manager.Reward(Reward.Gold, 100);
     }
     case 2: {
         manager.StartBattle("crazy person");
     }
 }
 manager.Text(player_portrait, "That was odd.")
 }

My question is: what's the best way to achieve this?

I've tried having a base class "gameEvent" that all events (text, move, reward, battle, etc.) derived from, but Unity is not keen on polymorphism and I couldn't get a List where I could edit each member of the list inside the Unity Editor (I tried custom editors and property drawers, I had issues with Unity's serialization).

I'm currently toying with the idea of creating a Unity Script (C#/JavaScript, whatever) for every "event thread" as it were, which would just call lots of functions in a "manager" class, but I feel this would seriously bloat my project file, as it's an RPG and I imagine using this game event system for talking to all NPCs, controlling cutscenes, random or scripted battles, or the like.

I've thought about using XML - or even a binary file, created external to Unity - that could be read in, but I worry about the performance issues for that? First there's looking up the file and then I believe also that parsing strings is not very desirable for performance.

From reading around this site I feel I might be able to do this with delegates, but I can't see how I could customise the inputs (such as varying text) for each delegate in the list?

Anyway, I understand this question is kind of vague, but I'm just curious what other people would try? I've only been working with Unity for a little over a year and I know there's a lot more I can do with learning.

P.S. This is my first question on here, apologies if it's badly formatted! I've tried searching for existing answers, but am having difficulty coming to a conclusion.

EDIT: I had some formatting issues with my pseudo-code, so I fixed it to look a bit more like C#.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Smitlord · Apr 15, 2016 at 07:51 PM

there is a much more simple way to do this just put these into booleans but have the results in an array so heres an example

var attack:int;

var powerboost:boolean;

var damaged:boolean;

var damage:int;

var enemy health:int;

var health:int;

var results:[];

Function Start (){

enemyhealth=100;

attack=10;

health=100;

damage=10;

if(results.Random.Range(1,100)<49)

{

damaged=true;

}

if(damaged==true)

{

health=health-damage;

} else { powerboost=true; } if(powerboost==true) { enemyhealth=enemyhealth-powerboost; }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

foreach Element Problem 1 Answer

C Sharp Messenger Extended Warning 1 Answer

An OS design issue: File types associated with their appropriate programs 1 Answer

A node in a childnode? 1 Answer

Need advice for C# Freelance-Work 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges