Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity is not .NET

Discussion in 'General Discussion' started by ippdev, Aug 11, 2018.

  1. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Take this code, its probably the longest method I have written in our game and in need of refactor at some point, its still in active development so it will see refactor at some point. Anyway

    Code (CSharp):
    1.         private IEnumerator FollowFingerTarget(FingerIkConfig config, NVRInteractable interactable)
    2.         {
    3.             var transitionRatio = 0f;
    4.  
    5.             while (IsInteracting && CurrentlyInteracting == interactable)
    6.             {
    7.                 if (!config.Enabled || config.Ratio == null)
    8.                 {
    9.                     yield return null;
    10.                     continue;
    11.                 }
    12.  
    13.                 var finger = fingerIk.fingers[(int)config.Finger];
    14.  
    15.                 if (config.T.HasValue)
    16.                 {
    17.                  
    18.                     while (IsInteracting && CurrentlyInteracting == interactable && config.T.HasValue && config.TargetState ? transitionRatio < 1 : transitionRatio > 0)
    19.                     {
    20.                         var r = config.Ratio();
    21.  
    22.                         config.TransitionTarget.position = Vector3.Lerp(config.Start.position, config.End.position, r);
    23.                         config.TransitionTarget.rotation = Quaternion.Slerp(config.Start.rotation, config.End.rotation, r);
    24.  
    25.                         var deltaRatio = Time.deltaTime / config.T.Value;
    26.                         if (!config.TargetState)
    27.                             deltaRatio = -deltaRatio;
    28.                      
    29.                         transitionRatio += deltaRatio;
    30.                         transitionRatio = Mathf.Clamp(transitionRatio, 0, 1);
    31.                      
    32.                         var indexRatio = (config.TransitionKeyFrames.Length - 1) * transitionRatio;
    33.                         var index = (int) indexRatio;
    34.                         var weight = indexRatio - index;
    35.  
    36.                         var start = config.TransitionKeyFrames[index];
    37.                         var target = weight > 0 ? config.TransitionKeyFrames[index + 1] : start;
    38.  
    39.                         config.Target.position = Vector3.Lerp(start.position, target.position, weight);
    40.                         config.Target.rotation = Quaternion.Slerp(start.rotation, target.rotation, weight);
    41.  
    42.                         if (config.AlternativeHand)
    43.                         {
    44.                             var pose = IsRight ? CurrentlyInteracting.RightHandGrip : CurrentlyInteracting.LeftHandGrip;
    45.                             UpdateModelPose(pose.transform, config.AlternativeHand, transitionRatio*r, false);
    46.                         }
    47.  
    48.                         yield return null;
    49.                     }
    50.  
    51.                     config.T = null;
    52.                     config.Enabled = config.TargetState;
    53.                     finger.weight = config.Enabled ? 1 : 0;
    54.                 }
    55.  
    56.                 if (!config.Enabled) continue;
    57.  
    58.                 var ratio = config.Ratio();
    59.  
    60.                 config.Target.position = Vector3.Lerp(config.Start.position, config.End.position, ratio);
    61.                 config.Target.transform.rotation = Quaternion.Slerp(config.Start.rotation, config.End.rotation, ratio);
    62.  
    63.                 if (config.AlternativeHand)
    64.                 {
    65.                     var pose = IsRight ? CurrentlyInteracting.RightHandGrip : CurrentlyInteracting.LeftHandGrip;
    66.                     UpdateModelPose(pose.transform, config.AlternativeHand, ratio, false);
    67.                 }
    68.  
    69.                 yield return null;
    70.             }
    71.  
    72.             CleanupFingerIk();
    73.         }
    Can you tell me one place were explicit declaring the type would help readability? In most cases the var declared varaible is used within a few lines.
     
    Last edited: Aug 12, 2018
  2. Zuntatos

    Zuntatos

    Joined:
    Nov 18, 2012
    Posts:
    612
    It would help in most places in my opinion.

    Skimming through code using a lot of var: I need to look at the actual expression to run the resolve-result-type-code in my brain. Maybe there's an explicit conversion. Maybe it's in the method name. Maybe it's a combination of the variables involved making sense. I got to search for it.

    Skimming through code not using var: I can just look at the type at the start of the line. No effort.

    It's also dodgy when changing the returning type in a method and have all callsites change their behaviour automatically for better or worse. Often you'll get errors, but sometimes it compiles due to random compatibility of the types as a var.

    It makes me nervous as a control freak I guess :)

    Of course I use it sometimes, but most of my uses are in 1 specific case:
    "var a = new SomeType.SubTypeLong<OtherType, OtherOtherType>();" since I don't want to see that long thing twice on 1 line. If the type is reasonable length (< 25 chars or something?) I don't use var.
     
  3. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    In the enterprise world its pretty much consensus among seniors that you use var. Same with comments, you dont comment the code. Other than a few times to describe why not how
     
  4. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,965
    Are we talking no comments at all? Or just doc comments at the top of a method? Because the more you describe the enterprise world the more it comes across as an environment populated with people who have no business calling themselves programmers.
     
  5. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,462
    Morons do indeed populate the Enterprise world so this is not surprising.
     
    Kiwasi likes this.
  6. ShilohGames

    ShilohGames

    Joined:
    Mar 24, 2014
    Posts:
    3,015
    Every place. I personally don't like using var at all. I absolutely love explicitly declaring variable types. It helps with readability and debugging.
     
    ikazrima and Zuntatos like this.
  7. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850
    LOL! I have had it up to here with superior dynamic systems derived from enterprise software programmers. There is also an embedded in the box only hands tied until command on high rolls down the food chain. Not optimal for game dev minded talent to flex in. I ain't too fond of this scrum stuff either. It is the equivalent of a husband moving the furniture around for a hormone addled wife. I made a linkage controller that linked two objects/spheres that had a relationship in a given architectural construction project. It is obvious what the relationship would have to appear as..a frikkin' line connecting two objects. Something a game dev would see immediately that any user could understand instantaneously. It took five minutes to make the component, figured I would turn it on an show it for making decisions about color and thickness and got nixed and not spend my time writing it. I had to await several sprints for them to make a committee decision that it should indeed be a line connecting two related objects. I turned the component on. In they meantime they could have saved umpteen man hours of agonizing over the obvious and more features promoting vertical integration/bigger bucks could have been implemented.
     
  8. ShilohGames

    ShilohGames

    Joined:
    Mar 24, 2014
    Posts:
    3,015
    I agree with having comments for why and not what or how. Comments can be extremely helpful if you have to maintain code 6 months or more in the future. Being able to understand why something was done a certain way can be very helpful. I would never advocate coding without any comments at all. That would just cause trouble for my future self.

    Using var is a slippery slope. Using var is lazy and it can make it easy to create certain mistakes. Explicit type declarations make it easy for the programmer and the compiler to know exact what type a variable is. Using var hides that. For some enterprise code, that might be fine, but it can hide possible bugs in others.
     
    ippdev likes this.
  9. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850

    Wow.. Why not just attach the finger IK target to the trigger and use Mecanim to create variants of the grips from almost open handed to loose and set the float for the BlendTree Parameter GunGrip or RifleGrip per weapon. Player hits trigger button and the angle on the trigger changes..you can grab any bools you need to set or activate any systems for firing at that point. The finger follow is automatic. If you have set up the arm->hand IK you need very little code for aiming either. That is a whole lot of boilerplate to get something simple done.
     
    Kiwasi likes this.
  10. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    No comments in the code, documentation outside is fine. Code is self commentary, only comment why you did rare stuff that is not immediately clear. Most Devs comment how they did something, the code should document how by it self
     
  11. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    No it can hide bugs, it's the exact strong typed code as if you wrote the type yourself, the compiler while complian at compile time etc
     
  12. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Why? Thats not what make code readible. On the contrary it polutes the code with redundant text, just like 99.9 procent of all comments in code.
     
  13. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    This code is very flexible, you define 2 or 3 key frames and boom you have fingerik set up. We use it for a variety of things, from

    Trigger dicilpine



    To coking the hammer


    Its basicly just one line of code to add the function to a new place in the domain

    edit: The domain just do this first set a feeder

    Code (CSharp):
    1. SetFingerIkFeeder(Fingers.Thumb, () => Hammer.Ratio);
    Then you can set when to activate it

    Code (CSharp):
    1. AttachedHand.SetFingerIKState(Fingers.Thumb, AttachedHand.CheckForPlayerCommandTouched(Command.CockHammer), 0.25f);
     
    Last edited: Aug 12, 2018
  14. ShilohGames

    ShilohGames

    Joined:
    Mar 24, 2014
    Posts:
    3,015
    More useful information (such as explicit type declarations) does not pollute the code. That is complete nonsense. Explicit type declarations are extremely useful to both programmers and compilers.

    I realize that a lot of "enterprise programmers" like the automatic type handling in VBScript, but I saw plenty of examples where it lead to odd errors that would have been easy to track down if the programmers were using an environment with explicit declarations. Obviously, VBScript is a worst case example of non-explicit typing.

    I don't know what percent of comments are purely redundant vs how many are useful. It would vary widely between programmers. I highly doubt 99.9% of all comments are redundant text. I am personally a big advocate of using comments. Any comments that are merely repeating a command are useless. But comments that explain why a certain algorithm was chosen can be extremely useful, especially months or years later.

    To be honest, I don't necessarily dislike the use of redundant text simply because it wastes text. My primary complaint about having redundant text style comments is that sometimes the comments say one thing and the code does something else. That is one of the big dangers with redundant text style comments, and that can actually cause problems when people debug code.
     
    angrypenguin, bobisgod234 and Kiwasi like this.
  15. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    You don't know what you are talking about, var does not make C# dynamic typed, it's still static typed. All it does is removing the need to reduntaly write the type. The method that returns a type etc, still needs to explicit decslre the type.
     
  16. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    This is kind of a tangent, but one of the main advantages of hand rolling message senders is that you can ensure that all subscribers are notified of an event before any nested events are fired (this helps to guarantee order of operation regardless of subscriber ordering).

    Example:
    Code (csharp):
    1.  
    2.   public void Publish< T >( T message ) where T : IMessage{
    3.     // if another message gets published during notify, it goes
    4.     // into the queue.
    5.     if (m_PendingNotifications.Count == 0){
    6.       Notify( message );
    7.       while( m_PendingNotifications.Count > 0 ){
    8.         m_PendingNotifications
    9.           .Peek()
    10.           .Invoke();
    11.         // dequeue after invoke so count is 1
    12.         m_PendingNotifications.Dequeue();
    13.       }
    14.     }else{
    15.       m_PendingNotifications.Enqueue(() => Notify(message));
    16.     }
    17.   }
    18.   private void Notify<T>(T message) where T : IMessage {
    19.     List<ISubscriber> subs;
    20.     if (m_Subscribers.TryGetValue(typeof(T), out subs) == false)
    21.       subs = m_EMPTY;
    22.  
    23.     for (int i = 0; i < subs.Count; i++) {
    24.       var t = subs[i];
    25.       t.Handle(message);
    26.     }
    27.    }
    28.  
    You may want to try something like this in the future. IMO, it's significantly better. Nested event publish triggering before subscribers have all been notified is a major pet peeve of mine.
     
  17. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    I have no idea what type of variable config.Ratio is. That was just the first one that jumped out at me. By the name one would assume a float, except its obviously not used as a float.

    Also you have used var in a lot of places where you could have used int or float. Are you really that had up for key strokes?

    Var does make sense in a few places. If you are doing new Dictionary<String, List<GameObject>>(), then explicitly writing out the variable type twice isn't useful. Its also useful you are grabbing an obscure type from a third party framework.

    Its actually kinda sorta does. If someone changes the return type of a method you are calling, then the compiler will automatically change the type in the var declaration. Sure its not true dynamic typing, but its edging towards that territory. This can be a good or bad thing, depending on your environment.

    One thing it does do is move any errors that arise later in the code. I'm personally a big fan of making errors occur as early as possible, which is why I prefer the explicit type definition in most places.
     
    Ryiah likes this.
  18. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Have you actually done such a change to a method return type that it causes those kind of problems. I havent. Lets say you made a method that first returns a concrete type and then change so it returns a interface (This you should have done in the first place). Said interface does not have a member you are using in existing code. using var here does not change anything.

    Either the consumer of your method knew too much about the return type or the abstraction (interface) is abstracted faulty. Either way, the compiler will catch both at compile time.
     
  19. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    There problem here is the abuse of var begins when you move away from it's original design purpose: things like lambada expressions / LINQ. For anything else it edges into "it works but it makes code harder to read".

    Half the internet wouldn't be saying it makes code harder to read if it didn't.

     
    angrypenguin likes this.
  20. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850
    This is starting to sound just like the guy with the vaunted superior dynamic system I started this thread about. Var sucks wind on speed reading of code. The rest of your code is rather opaque in style. Mind you it is for you. I have been trained by writing code that integrated into a Unity environment and tested under fire by providing code for 30+ games and applications and bug fixing 100+ apps. Unity trained people can easily read my code. My API's are components that gather their kit from the Unity API.. Everything is named intuitively, all external references needed from their kit can be dragged and dropped and if they want to change it later the Unity knowledge base on the internets is huge. Folks should not have to go to the MS dev site to make sense of your code..if you are coding for other Unity devs..artist or hard core Unity coder. It just makes life easier and less money is spent on development in the long run.
     
  21. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,965
    Just because you've never had the problem doesn't mean it can't happen. I haven't dropped a laptop and broken the screen either but I'm still careful every time I carry one. Besides I'm not the only person working on the code I write. It's the people who aren't as good as I am that I worry about and making it slightly easier for them to foul up is not a good thing.
     
    angrypenguin likes this.
  22. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    Man, this is some passionate discussion of var... I personally prefer explicit types when it doesn't hamper readability.

    For example:
    Code (csharp):
    1. float x = 1; // nice cuz changing the value in a sloppy way (like forget the f on an integer)  it still works.
    If the name of a class is a too many characters, I tend to prefer var unless I need a reminder of what type something is.
    Code (csharp):
    1. SimpleClass x = ....; // this can be alright
    2. ClassNameOfManyWords x = ...; // not so great
    Generic arguments really like var.
    Code (csharp):
    1. List<SimpleClass> x = ...; // annoying to read, but sometimes the reminder is helpful.
    2. var x = ...; // much better in obvious cases
    Outside of long class names (or generic args) only real reason to use var is if you want to line up a bunch of stuff typographically.

    Code (csharp):
    1. var a = GetSomething();
    2. var b = GetSomethingElse(x);
    3. var c = GetAnotherThing(z);
    4.  
    5. //this is much harder on the eyes
    6. float a = GetSomething();
    7. MyObject b = GetSomethingElse(x);
    8. OtherThing c = GetAnotherThing(z);
     
    Last edited: Aug 12, 2018
  23. Zuntatos

    Zuntatos

    Joined:
    Nov 18, 2012
    Posts:
    612
    I feel like IDE color scheme is quite important here with the var discussion.

    If you have a bunch of lines of code like
    Code (CSharp):
    1. List<float> things = new List<float>();
    2. for (int i = 0; i < 100; i++) {
    3.     int ii = i * i;
    4.     float random = Random.Range(0, ii);
    5.     things.Add(random + ii);
    6. }
    then with visual studio's dark theme the "important" code is all white.
    You often get 3 columns:
    1) accessibility and/or type (blue/green/yellow)
    2) 'actual' code / names (white)
    3) constructor (blue/green/yellow)

    If the types are somewhat consistent in length you can easily ignore the "first column" and just start reading the uncolored code, but easily look back at that data when you need it. Add in some paragraphing of code so it's not one big wall of text and it'll start looking like something readable. Of course there will always be the ugly parts though (reflection with typeof() and casting are major causes of messing with the 'column' colors).

    @ the comments discussion; sometimes you do something that's non-standard (inline some small things, use something that's not the obvious case) and then you probably want to document the reason or what the "simple variant" would be (in case you want to change it later).

    And of course documenting possible ranges of values etc is quite useful (throw in some asserts as well when you're at it). I have looked at random methods' documentation countless times (is it inclusive or exclusive the max value? does it return [-1, 1] or [0, 1]?)
     
    frosted likes this.
  24. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Yeah, Im a system architect buddy, my sole purpose is to write core designs that make it easier for my devs to write code that is less prone to bugs.
     
  25. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    The biggest problem with your exampls are the names of the variables :p
     
  26. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    var r = config.Ratio() and then used on the next line to feed a Lerp, pretty clear to me
     
  27. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    To me its a bit strange a listener to a event fires a new event. There probably are some valid cases, like BulletFiredEvent triggers a death and that triggers a DeathEvent (just an example) but, i see some code smell here. if the order of operation is important than you have a HUGE high coupling in your domain
     
  28. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Maybe you are the that guy but you just dont realize it?
     
  29. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Most definitely. We get all types on this forums. There was a while when you couldn't swing a cat in the scripting section without hitting someone pushing a dependency injection framework. It makes sense that on a post complaining about over architecture that you will get some fans of heavy architecture.

    Sometimes the most valuable skill is nothing to do with coding. Sometimes its learning how to work with and get the most out of people with a very different mindset to you. You often can't win all of the arguments through debate or intellect. Persuasion and manipulation are important too.

    Clear to you is not the same thing as clear to a stranger unfamiliar with your code. Remind me to never pick up a project after you.
     
    QFSW, ikazrima, bobisgod234 and 5 others like this.
  30. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850
    Yup.. you sound exactly like him. My code conforms to the Unity API, tens of thousands of forum posts and thousands of Unity Answers. Anybody wanting to know what my code does just has to type the Unity parts into their browser and they get dozens of pages of info. They know what every variable type is. Anybody versed in Unity development can easily grab handles to it and/or extend it. Yours is a kngdom unto your intellect and habits..nothing more.
     
  31. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    This is one such example. There are plenty of others that are similar: SimulatedFight -> CharacterKilled is the same idea.

    If the level of granularity becomes lower, then it can become more of an issue: OnCharacterKilled -> OnQuestCancelled -> OnReputationChanged -> OnTitleChanged.

    There are almost no cases where event notification should execute depth first, it should always execute breadth first (and therefore have less dependency on the order of subscription).

    Honestly, I'm surprised that you think that chained notification is uncommon.
     
    ippdev and Kiwasi like this.
  32. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850
    Code smell.. Yup..When the C# engineers see something in Unity that violates their rules but works just dandy in Unity they toss that phrase "code smell" out there. Sounds like a dog whistle to me. High coupling..oh dread..it sounds like something dirty hippies do...at least it is yuge.
     
  33. ShilohGames

    ShilohGames

    Joined:
    Mar 24, 2014
    Posts:
    3,015
    I fully understand the difference regarding var, and that is why I said VBScript was obviously a worst case example regarding non-explicit declarations. The situation with var in C# is not as bad, but that does not make it good.

    The use of var can lead to mistakes and it can make code harder to debug. Explicit type declarations are awesome.
     
  34. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
  35. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    This is just a huge thing. Intellasense comments should always include a note on if a range is inclusive/exclusive. This kind of thing drives me nuts.
     
  36. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    I just want to make one more comment on this, it's really not true that this means there is high coupling.

    For example, let's say I want to build out a message box that display all major game events and I want them to display in correct order. In order to get that message box working, I need breadth first execution. There is no reasonable method for resorting the messages if they're raised depth first. All methods require tagging some kind of ordering data onto the messages and forcing the listener to resort.

    If the messages are fired depth first and have no ordering - there is literally no way for you to properly display the messages without guaranteeing that the 'all' listener is the absolute first subscriber for all events. That dependency on subscription ordering is the sign of serious problems.
     
    AndersMalmgren likes this.
  37. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    We've had reports of your blatant trolling and would like you to stop - or you risk being thread banned.
     
  38. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Unity API is a API, there is no fixed way you interact with it. You write your own domain ontop of it. There are bad and good ways to interact with it. Not only one way is good or bad
     
  39. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    We have written an entire FPS shooter without having any problem with it. Sounds like your event listeners are doing stuff they should not,for example each listener should not be dependent on what happened in the parent event, it should only be dependent on the info in the event it received..
     
    Last edited: Aug 13, 2018
  40. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    I dont care that much about using var or not. Thats code monkey concerns anyway and its not what makes a good domain. A good domain is more about the design and architecture, highly modular with seperation of concerns and low coupling and high cohesion, thats what makes a domain maintainable. var's or not.
     
    ShilohGames likes this.
  41. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    You can check them out here, let me know what you think, others have said things like

    https://github.com/AndersMalmgren/SignalR.EventAggregatorProxy
    https://github.com/AndersMalmgren/FreePIE
     
    Kiwasi likes this.
  42. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,251
    var may not be the biggest issue - what about Unity's naming conventions - using lower case properties and the UI code being full of old-fashioned m_memberVariables (VS pushes upper case auto properties now it seems so not even lowercase within class to reference variables)?
     
  43. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850
    This is true to a degree. When I am told that the goal of creating that domain is to have it so Unity developers..not C# enterprise engineers.. could work on it and extend it, change grfx etc. then I carry out the goals of the strictures of the contract I signed and instructions from the stakeholders.. The domain already looked like yours. They could not find anybody to work on it that understood wth was happening. I deciphered it with their lead C# dev and bit by bit turned it into a proper Unity style application. Now I have had this other guy reverting it and the other C# engineers thinking that is just dandy because he sold them a pile of BS an that BS looked familiar to them. It ain't fooling me.
     
  44. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850
    Reference what HippoCoder said earlier about breaking rules. You seem to be all about rules. I am all about performance and readability. I don't give a damn how many C# conventions i break to get that.
     
  45. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    I think you have misinterpreted me totally. Readability is my main concern in any domain. Performance too where its of concern.
     
  46. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Well I havent seen the project so cant say anything. The code I write in Unity is world class though and any developer with C# background Unity or not can understand it.
     
  47. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850
    In your finger code. How is Ratio derived? Is this discovered manually per weapon?
     
  48. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    All our items inherit the same base component. Our firearm class code just do in Awake

    Code (CSharp):
    1. SetFingerIkFeeder(Fingers.Index, GetTriggerFingerRatio);
    And

    Code (CSharp):
    1.         protected virtual float GetTriggerFingerRatio()
    2.         {
    3.             if (!AttachedHand.TriggerReleasedSincePickup) return 0;
    4.             if(Hammer && Hammer.SingleAction) return Hammer.Ratio;
    5.  
    6.             return AttachedHand.Inputs[EVRButtonId.k_EButton_SteamVR_Trigger].Axis.x;
    7.         }
    This works for all our firearms today, but some singleaction firearms work differently so its a candidate for refactor
     
  49. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850
    Did not answer my question. Same thing as the guy I began this about. Let me try again. Do you discover the Ratio manually per weapon? Or perhaps Ratio is not what it looks like..how is the minmax limits of trigger angle derived?
     
  50. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Its just in front of you, its read directly from the controller

    upload_2018-8-13_14-30-1.png